Skip to content

Commit 4b7b440

Browse files
authored
Adding support for directories/packagePath in package.json. (microsoft#8)
* Updating core build to respect directories/packagePath in package.json. * Removing web-library-build integration for now. * PR feedback addressed. * Allowing karma and webpack to be skipped correctly and consistently.
1 parent b05b7ac commit 4b7b440

File tree

16 files changed

+307
-58
lines changed

16 files changed

+307
-58
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ lib
1111
lib-amd
1212
node_modules
1313
npm*.log
14-
temp
14+
temp
15+
package

common/npm-shrinkwrap.json

Lines changed: 17 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
22
"dependencies": {
3+
"npmx-gulp-core-build-typescript": "file:./temp_modules/npmx-gulp-core-build-typescript",
34
"npmx-gulp-core-build": "file:./temp_modules/npmx-gulp-core-build",
4-
"npmx-gulp-core-build-karma": "file:./temp_modules/npmx-gulp-core-build-karma",
55
"npmx-gulp-core-build-mocha": "file:./temp_modules/npmx-gulp-core-build-mocha",
66
"npmx-gulp-core-build-sass": "file:./temp_modules/npmx-gulp-core-build-sass",
77
"npmx-gulp-core-build-serve": "file:./temp_modules/npmx-gulp-core-build-serve",
8-
"npmx-gulp-core-build-typescript": "file:./temp_modules/npmx-gulp-core-build-typescript",
8+
"npmx-gulp-core-build-karma": "file:./temp_modules/npmx-gulp-core-build-karma",
99
"npmx-gulp-core-build-webpack": "file:./temp_modules/npmx-gulp-core-build-webpack",
1010
"npmx-node-library-build": "file:./temp_modules/npmx-node-library-build",
1111
"npmx-web-library-build": "file:./temp_modules/npmx-web-library-build",
12-
"npmx-web-build-tools-scripts": "file:./temp_modules/npmx-web-build-tools-scripts"
12+
"npmx-web-build-tools-scripts": "file:./temp_modules/npmx-web-build-tools-scripts",
13+
"npmx-test-web-library-build": "file:./temp_modules/npmx-test-web-library-build"
1314
},
1415
"description": "Temporary file generated by the NPMX tool",
1516
"name": "npmx-common",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "npmx-test-web-library-build",
3+
"version": "0.0.0",
4+
"private": true,
5+
"dependencies": {
6+
"gulp": "~3.9.1"
7+
},
8+
"npmxDependencies": {
9+
"@microsoft/web-library-build": ">=0.5.0 < 1.0.0"
10+
}
11+
}

gulp-core-build-karma/src/KarmaTask.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { GulpTask } from '@microsoft/gulp-core-build';
1+
import { GulpTask, IBuildConfig } from '@microsoft/gulp-core-build';
22

33
import * as gulp from 'gulp';
44
import * as karma from 'karma';
55
import * as path from 'path';
66

77
export interface IKarmaTaskConfig {
8-
karmaConfigPath: string;
8+
configPath: string;
99
}
1010

1111
export class KarmaTask extends GulpTask<IKarmaTaskConfig> {
1212
public name: string = 'karma';
1313
public taskConfig: IKarmaTaskConfig = {
14-
karmaConfigPath: './karma.config.js'
14+
configPath: './karma.config.js'
1515
};
1616

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

30+
public isEnabled(buildConfig: IBuildConfig): boolean {
31+
return (
32+
super.isEnabled(buildConfig) &&
33+
this.taskConfig.configPath !== null // tslint:disable-line:no-null-keyword
34+
);
35+
}
36+
3037
public executeTask(gulp: gulp.Gulp, completeCallback: (error?: Error | string) => void): void {
31-
const { karmaConfigPath }: IKarmaTaskConfig = this.taskConfig;
38+
const { configPath }: IKarmaTaskConfig = this.taskConfig;
3239

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

3643
if (!shouldInitKarma) {
3744
this.logWarning(
38-
`The karma config location '${ karmaConfigPath }' doesn't exist. ` +
39-
`Run again using --initkarma to create a default config.`);
45+
`No karma config has been provided. ` +
46+
`Run again using --initkarma to create a default config, or call ` +
47+
` karma.setConfig({ configPath: null }) in your gulpfile.`);
4048
} else {
4149
this.copyFile(path.resolve(__dirname, '../karma.config.js'));
4250
this.copyFile(path.resolve(__dirname, '../tests.js'), 'src/tests.js');
@@ -60,7 +68,7 @@ export class KarmaTask extends GulpTask<IKarmaTaskConfig> {
6068
grep: matchString
6169
}
6270
},
63-
configFile: this.resolvePath(karmaConfigPath),
71+
configFile: this.resolvePath(configPath),
6472
singleRun: singleRun
6573
}, (exitCode) => {
6674
if (exitCode) {

gulp-core-build-webpack/src/WebpackTask.ts

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as Webpack from 'webpack';
2-
import { GulpTask } from '@microsoft/gulp-core-build';
2+
import { GulpTask, IBuildConfig } from '@microsoft/gulp-core-build';
33
import gulp = require('gulp');
44
import { EOL } from 'os';
55

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

36+
public isEnabled(buildConfig: IBuildConfig): boolean {
37+
return (
38+
super.isEnabled(buildConfig) &&
39+
this.taskConfig.configPath !== null // tslint:disable-line:no-null-keyword
40+
);
41+
}
42+
3643
public executeTask(gulp: gulp.Gulp, completeCallback: (result?: Object) => void): void {
3744
let shouldInitWebpack: boolean = (process.argv.indexOf('--initwebpack') > -1);
3845

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

53-
if (!this.taskConfig.configPath && !this.taskConfig.config) {
54-
this.logMissingConfigWarning();
55-
completeCallback();
56-
return;
57-
} else if (this.taskConfig.configPath) {
58-
if (this.fileExists(this.taskConfig.configPath)) {
59-
try {
60-
webpackConfig = require(this.resolvePath(this.taskConfig.configPath));
61-
} catch (err) {
62-
completeCallback(`Error parsing webpack config: ${ this.taskConfig.configPath }: ${ err }`);
63-
return;
64-
}
65-
} else if (!this.taskConfig.config) {
66-
this.logWarning(
67-
`The webpack config location '${ this.taskConfig.configPath }' doesn't exist. ` +
68-
`Run again using --initwebpack to create a default config, or call ` +
69-
`webpack.setConfig({ configPath: null }).`);
70-
71-
completeCallback();
60+
if (this.taskConfig.configPath && this.fileExists(this.taskConfig.configPath)) {
61+
try {
62+
webpackConfig = require(this.resolvePath(this.taskConfig.configPath));
63+
} catch (err) {
64+
completeCallback(`Error parsing webpack config: ${this.taskConfig.configPath}: ${err}`);
7265
return;
73-
} else {
74-
webpackConfig = this.taskConfig.config;
7566
}
7667
} else if (this.taskConfig.config) {
7768
webpackConfig = this.taskConfig.config;
7869
} else {
79-
this.logMissingConfigWarning();
70+
this._logMissingConfigWarning();
8071
completeCallback();
8172
return;
8273
}
@@ -134,7 +125,7 @@ export class WebpackTask extends GulpTask<IWebpackTaskConfig> {
134125
}
135126

136127
let duration = (new Date().getTime() - startTime);
137-
let statsResultChildren = statsResult.children ? statsResult.children : [ statsResult ];
128+
let statsResultChildren = statsResult.children ? statsResult.children : [statsResult];
138129

139130
statsResultChildren.forEach(child => {
140131
if (child.chunks) {
@@ -156,10 +147,10 @@ export class WebpackTask extends GulpTask<IWebpackTaskConfig> {
156147
}
157148
}
158149

159-
private logMissingConfigWarning() {
150+
private _logMissingConfigWarning() {
160151
this.logWarning(
161-
'No webpack config has been provided.' +
162-
'Run again using --initwebpack to create a default config,' +
163-
`or call webpack.setConfig({ configPath: null }).`);
152+
'No webpack config has been provided. ' +
153+
'Run again using --initwebpack to create a default config, ' +
154+
`or call webpack.setConfig({ configPath: null }) in your gulpfile.`);
164155
}
165156
}

gulp-core-build/src/IBuildConfig.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ export interface IBuildConfig {
1414
/** Full physical path to the root path directory. */
1515
rootPath?: string;
1616

17+
/**
18+
* Package output folder in which publishable output should be dropped.
19+
* @default package.json directories/packagePath value.
20+
*/
21+
packageFolder?: string;
22+
1723
/** Source folder name where source is included. */
1824
srcFolder?: string;
1925

@@ -63,4 +69,7 @@ export interface IBuildConfig {
6369

6470
/** Optional callback to be executed when a task ends. */
6571
onTaskEnd?: (taskName: string, duration: number[], error?: any) => void;
72+
73+
/** Flag used to indicate if the build is redundant and should be exited prematurely. */
74+
isRedundantBuild?: boolean;
6675
}

gulp-core-build/src/IExecutable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface IExecutable {
88
name?: string;
99

1010
/** Optional callback to indicate if the task is enabled or not. */
11-
isEnabled?: () => boolean;
11+
isEnabled?: (config?: IBuildConfig) => boolean;
1212

1313
/** Optional method to indicate directory matches to clean up when the nuke task is run. */
1414
getNukeMatch?: (config: IBuildConfig, taskConfig?: any) => string[]; /* tslint:disable-line:no-any */

gulp-core-build/src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ const packageJSON: any = require(path.resolve(process.cwd(), 'package.json'));
3535

3636
const _taskMap: { [key: string]: IExecutable } = {};
3737
const _uniqueTasks: IExecutable[] = [];
38+
const packageFolder: string =
39+
(packageJSON.directories && packageJSON.directories.packagePath) ?
40+
packageJSON.directories.packagePath : '';
3841

3942
let _buildConfig: IBuildConfig = {
43+
packageFolder,
4044
srcFolder: 'src',
41-
distFolder: 'dist',
45+
distFolder: path.join(packageFolder, 'dist'),
4246
libAMDFolder: undefined,
43-
libFolder: 'lib',
47+
libFolder: path.join(packageFolder, 'lib'),
4448
tempFolder: 'temp',
4549
properties: {},
4650
relogIssues: getFlagValue('relogIssues', true),
@@ -340,7 +344,7 @@ function _executeTask(task: IExecutable, buildConfig: IBuildConfig): Promise<voi
340344
return Promise.reject(new Error(`A task was scheduled, but the task was null. This probably means the task wasn't imported correctly.`));
341345
}
342346

343-
if (task.isEnabled === undefined || task.isEnabled()) {
347+
if (task.isEnabled === undefined || task.isEnabled(buildConfig)) {
344348
const startTime: [number, number] = process.hrtime();
345349

346350
if (buildConfig.onTaskStart && task.name) {

0 commit comments

Comments
 (0)