Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for directories/packagePath in package.json. #8

Merged
merged 5 commits into from
Oct 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ lib
lib-amd
node_modules
npm*.log
temp
temp
package
29 changes: 17 additions & 12 deletions common/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions common/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"dependencies": {
"npmx-gulp-core-build-typescript": "file:./temp_modules/npmx-gulp-core-build-typescript",
"npmx-gulp-core-build": "file:./temp_modules/npmx-gulp-core-build",
"npmx-gulp-core-build-karma": "file:./temp_modules/npmx-gulp-core-build-karma",
"npmx-gulp-core-build-mocha": "file:./temp_modules/npmx-gulp-core-build-mocha",
"npmx-gulp-core-build-sass": "file:./temp_modules/npmx-gulp-core-build-sass",
"npmx-gulp-core-build-serve": "file:./temp_modules/npmx-gulp-core-build-serve",
"npmx-gulp-core-build-typescript": "file:./temp_modules/npmx-gulp-core-build-typescript",
"npmx-gulp-core-build-karma": "file:./temp_modules/npmx-gulp-core-build-karma",
"npmx-gulp-core-build-webpack": "file:./temp_modules/npmx-gulp-core-build-webpack",
"npmx-node-library-build": "file:./temp_modules/npmx-node-library-build",
"npmx-web-library-build": "file:./temp_modules/npmx-web-library-build",
"npmx-web-build-tools-scripts": "file:./temp_modules/npmx-web-build-tools-scripts"
"npmx-web-build-tools-scripts": "file:./temp_modules/npmx-web-build-tools-scripts",
"npmx-test-web-library-build": "file:./temp_modules/npmx-test-web-library-build"
},
"description": "Temporary file generated by the NPMX tool",
"name": "npmx-common",
Expand Down
11 changes: 11 additions & 0 deletions common/temp_modules/npmx-test-web-library-build/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "npmx-test-web-library-build",
"version": "0.0.0",
"private": true,
"dependencies": {
"gulp": "~3.9.1"
},
"npmxDependencies": {
"@microsoft/web-library-build": ">=0.5.0 < 1.0.0"
}
}
24 changes: 16 additions & 8 deletions gulp-core-build-karma/src/KarmaTask.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { GulpTask } from '@microsoft/gulp-core-build';
import { GulpTask, IBuildConfig } from '@microsoft/gulp-core-build';

import * as gulp from 'gulp';
import * as karma from 'karma';
import * as path from 'path';

export interface IKarmaTaskConfig {
karmaConfigPath: string;
configPath: string;
}

export class KarmaTask extends GulpTask<IKarmaTaskConfig> {
public name: string = 'karma';
public taskConfig: IKarmaTaskConfig = {
karmaConfigPath: './karma.config.js'
configPath: './karma.config.js'
};

public resources: Object = {
Expand All @@ -27,16 +27,24 @@ export class KarmaTask extends GulpTask<IKarmaTaskConfig> {
]
};

public isEnabled(buildConfig: IBuildConfig): boolean {
return (
super.isEnabled(buildConfig) &&
this.taskConfig.configPath !== null // tslint:disable-line:no-null-keyword
);
}

public executeTask(gulp: gulp.Gulp, completeCallback: (error?: Error | string) => void): void {
const { karmaConfigPath }: IKarmaTaskConfig = this.taskConfig;
const { configPath }: IKarmaTaskConfig = this.taskConfig;

if (!this.fileExists(karmaConfigPath)) {
if (!this.fileExists(configPath)) {
const shouldInitKarma: boolean = (process.argv.indexOf('--initkarma') > -1);

if (!shouldInitKarma) {
this.logWarning(
`The karma config location '${ karmaConfigPath }' doesn't exist. ` +
`Run again using --initkarma to create a default config.`);
`No karma config has been provided. ` +
`Run again using --initkarma to create a default config, or call ` +
` karma.setConfig({ configPath: null }) in your gulpfile.`);
} else {
this.copyFile(path.resolve(__dirname, '../karma.config.js'));
this.copyFile(path.resolve(__dirname, '../tests.js'), 'src/tests.js');
Expand All @@ -60,7 +68,7 @@ export class KarmaTask extends GulpTask<IKarmaTaskConfig> {
grep: matchString
}
},
configFile: this.resolvePath(karmaConfigPath),
configFile: this.resolvePath(configPath),
singleRun: singleRun
}, (exitCode) => {
if (exitCode) {
Expand Down
47 changes: 19 additions & 28 deletions gulp-core-build-webpack/src/WebpackTask.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Webpack from 'webpack';
import { GulpTask } from '@microsoft/gulp-core-build';
import { GulpTask, IBuildConfig } from '@microsoft/gulp-core-build';
import gulp = require('gulp');
import { EOL } from 'os';

Expand Down Expand Up @@ -33,6 +33,13 @@ export class WebpackTask extends GulpTask<IWebpackTaskConfig> {
webpack: require('webpack')
};

public isEnabled(buildConfig: IBuildConfig): boolean {
return (
super.isEnabled(buildConfig) &&
this.taskConfig.configPath !== null // tslint:disable-line:no-null-keyword
);
}

public executeTask(gulp: gulp.Gulp, completeCallback: (result?: Object) => void): void {
let shouldInitWebpack: boolean = (process.argv.indexOf('--initwebpack') > -1);

Expand All @@ -50,33 +57,17 @@ export class WebpackTask extends GulpTask<IWebpackTaskConfig> {
} else {
let webpackConfig: Object;

if (!this.taskConfig.configPath && !this.taskConfig.config) {
this.logMissingConfigWarning();
completeCallback();
return;
} else if (this.taskConfig.configPath) {
if (this.fileExists(this.taskConfig.configPath)) {
try {
webpackConfig = require(this.resolvePath(this.taskConfig.configPath));
} catch (err) {
completeCallback(`Error parsing webpack config: ${ this.taskConfig.configPath }: ${ err }`);
return;
}
} else if (!this.taskConfig.config) {
this.logWarning(
`The webpack config location '${ this.taskConfig.configPath }' doesn't exist. ` +
`Run again using --initwebpack to create a default config, or call ` +
`webpack.setConfig({ configPath: null }).`);

completeCallback();
if (this.taskConfig.configPath && this.fileExists(this.taskConfig.configPath)) {
try {
webpackConfig = require(this.resolvePath(this.taskConfig.configPath));
} catch (err) {
completeCallback(`Error parsing webpack config: ${this.taskConfig.configPath}: ${err}`);
return;
} else {
webpackConfig = this.taskConfig.config;
}
} else if (this.taskConfig.config) {
webpackConfig = this.taskConfig.config;
} else {
this.logMissingConfigWarning();
this._logMissingConfigWarning();
completeCallback();
return;
}
Expand Down Expand Up @@ -134,7 +125,7 @@ export class WebpackTask extends GulpTask<IWebpackTaskConfig> {
}

let duration = (new Date().getTime() - startTime);
let statsResultChildren = statsResult.children ? statsResult.children : [ statsResult ];
let statsResultChildren = statsResult.children ? statsResult.children : [statsResult];

statsResultChildren.forEach(child => {
if (child.chunks) {
Expand All @@ -156,10 +147,10 @@ export class WebpackTask extends GulpTask<IWebpackTaskConfig> {
}
}

private logMissingConfigWarning() {
private _logMissingConfigWarning() {
this.logWarning(
'No webpack config has been provided.' +
'Run again using --initwebpack to create a default config,' +
`or call webpack.setConfig({ configPath: null }).`);
'No webpack config has been provided. ' +
'Run again using --initwebpack to create a default config, ' +
`or call webpack.setConfig({ configPath: null }) in your gulpfile.`);
}
}
9 changes: 9 additions & 0 deletions gulp-core-build/src/IBuildConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ export interface IBuildConfig {
/** Full physical path to the root path directory. */
rootPath?: string;

/**
* Package output folder in which publishable output should be dropped.
* @default package.json directories/packagePath value.
*/
packageFolder?: string;

/** Source folder name where source is included. */
srcFolder?: string;

Expand Down Expand Up @@ -63,4 +69,7 @@ export interface IBuildConfig {

/** Optional callback to be executed when a task ends. */
onTaskEnd?: (taskName: string, duration: number[], error?: any) => void;

/** Flag used to indicate if the build is redundant and should be exited prematurely. */
isRedundantBuild?: boolean;
}
2 changes: 1 addition & 1 deletion gulp-core-build/src/IExecutable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface IExecutable {
name?: string;

/** Optional callback to indicate if the task is enabled or not. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For props like this which takes in callbacks, good to document what kind of callback signature is expected..

isEnabled?: () => boolean;
isEnabled?: (config?: IBuildConfig) => boolean;

/** Optional method to indicate directory matches to clean up when the nuke task is run. */
getNukeMatch?: (config: IBuildConfig, taskConfig?: any) => string[]; /* tslint:disable-line:no-any */
Expand Down
10 changes: 7 additions & 3 deletions gulp-core-build/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ const packageJSON: any = require(path.resolve(process.cwd(), 'package.json'));

const _taskMap: { [key: string]: IExecutable } = {};
const _uniqueTasks: IExecutable[] = [];
const packageFolder: string =
(packageJSON.directories && packageJSON.directories.packagePath) ?
packageJSON.directories.packagePath : '';

let _buildConfig: IBuildConfig = {
packageFolder,
srcFolder: 'src',
distFolder: 'dist',
distFolder: path.join(packageFolder, 'dist'),
libAMDFolder: undefined,
libFolder: 'lib',
libFolder: path.join(packageFolder, 'lib'),
tempFolder: 'temp',
properties: {},
relogIssues: getFlagValue('relogIssues', true),
Expand Down Expand Up @@ -340,7 +344,7 @@ function _executeTask(task: IExecutable, buildConfig: IBuildConfig): Promise<voi
return Promise.reject(new Error(`A task was scheduled, but the task was null. This probably means the task wasn't imported correctly.`));
}

if (task.isEnabled === undefined || task.isEnabled()) {
if (task.isEnabled === undefined || task.isEnabled(buildConfig)) {
const startTime: [number, number] = process.hrtime();

if (buildConfig.onTaskStart && task.name) {
Expand Down
Loading