Skip to content

Commit ad8aa54

Browse files
committed
simplify gulp commands in package directories
1 parent e48ac4e commit ad8aa54

File tree

16 files changed

+219
-262
lines changed

16 files changed

+219
-262
lines changed

gulpfile.js renamed to gulpfile.ts

+43-20
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,72 @@
1515
*
1616
*/
1717

18-
const _gulp = require('gulp');
19-
const help = require('gulp-help');
18+
import * as _gulp from 'gulp';
19+
import * as help from 'gulp-help';
2020

2121
// gulp-help monkeypatches tasks to have an additional description parameter
2222
const gulp = help(_gulp);
2323

24-
var runSequence = require('run-sequence');
24+
const runSequence = require('run-sequence');
2525

26-
require('./packages/grpc-health-check/gulpfile');
27-
require('./packages/grpc-js/gulpfile');
28-
require('./packages/grpc-js-core/gulpfile');
29-
require('./packages/grpc-native/gulpfile');
30-
require('./packages/grpc-native-core/gulpfile');
31-
require('./packages/grpc-surface/gulpfile');
32-
require('./test/gulpfile');
26+
/**
27+
* Require a module at the given path with a patched gulp object that prepends
28+
* the given prefix to each task name.
29+
* @param path The path to require.
30+
* @param prefix The string to use as a prefix. This will be prepended to a task
31+
* name with a '.' separator.
32+
*/
33+
function loadGulpTasksWithPrefix(path: string, prefix: string) {
34+
const gulpTask = gulp.task;
35+
gulp.task = ((taskName: string, ...args: any[]) => {
36+
// Don't create a task for ${prefix}.help
37+
if (taskName === 'help') {
38+
return;
39+
}
40+
// The only array passed to gulp.task must be a list of dependent tasks.
41+
const newArgs = args.map(arg => Array.isArray(arg) ?
42+
arg.map(dep => `${prefix}.${dep}`) : arg);
43+
gulpTask(`${prefix}.${taskName}`, ...newArgs);
44+
});
45+
const result = require(path);
46+
gulp.task = gulpTask;
47+
return result;
48+
}
49+
50+
[
51+
['./packages/grpc-health-check/gulpfile', 'health-check'],
52+
['./packages/grpc-js/gulpfile', 'js'],
53+
['./packages/grpc-js-core/gulpfile', 'js.core'],
54+
['./packages/grpc-native/gulpfile', 'native'],
55+
['./packages/grpc-native-core/gulpfile', 'native.core'],
56+
['./packages/grpc-surface/gulpfile', 'surface'],
57+
['./test/gulpfile', 'internal.test']
58+
].forEach((args) => loadGulpTasksWithPrefix(args[0], args[1]));
3359

3460
const root = __dirname;
3561

3662
gulp.task('install.all', 'Install dependencies for all subdirectory packages',
37-
['js.core.install', 'native.core.install', 'surface.install', 'health-check.install', 'internal.test.install']);
63+
['js.install', 'js.core.install', 'native.core.install', 'surface.install', 'health-check.install', 'internal.test.install']);
3864

3965
gulp.task('install.all.windows', 'Install dependencies for all subdirectory packages for MS Windows',
4066
['js.core.install', 'native.core.install.windows', 'surface.install', 'health-check.install', 'internal.test.install']);
4167

4268
gulp.task('lint', 'Emit linting errors in source and test files',
4369
['js.core.lint', 'native.core.lint']);
4470

45-
gulp.task('build', 'Build packages', ['js.core.compile', 'native.core.build']);
71+
gulp.task('build', 'Build packages', ['js.compile', 'js.core.compile', 'native.core.build']);
4672

47-
gulp.task('core.link', 'Add links to core packages without rebuilding',
73+
gulp.task('link.core', 'Add links to core packages without rebuilding',
4874
['js.link.add', 'native.link.add']);
4975

50-
gulp.task('surface.link', 'Link to surface packages',
76+
gulp.task('link.surface', 'Link to surface packages',
5177
['health-check.link.add']);
5278

5379
gulp.task('link', 'Link together packages', (callback) => {
54-
/* Currently, the target 'surface.link.create' doesn't work properly, and it
55-
* is also not needed for the existing tests. The comment indicates where it
56-
* belongs in the sequence. See npm/npm#18835 for the primary problem with it.
57-
* This also means that 'core.link' is not needed, and the item
58-
* 'native.core.link.create' should actually be 'core.link.create'
80+
/**
81+
* We use workarounds for linking in some modules. See npm/npm#18835
5982
*/
60-
runSequence('core.link', 'surface.link',
83+
runSequence('link.core', 'link.surface',
6184
callback);
6285
});
6386

package.json

+9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99
},
1010
"license": "Apache-2.0",
1111
"devDependencies": {
12+
"@types/execa": "^0.8.0",
13+
"@types/gulp": "^4.0.5",
14+
"@types/gulp-help": "0.0.34",
15+
"@types/gulp-mocha": "0.0.31",
16+
"@types/ncp": "^2.0.1",
1217
"@types/node": "^8.0.32",
18+
"@types/pify": "^3.0.0",
1319
"del": "^3.0.0",
1420
"execa": "^0.8.0",
1521
"gulp": "^3.9.1",
@@ -27,7 +33,10 @@
2733
"merge2": "^1.1.0",
2834
"mocha": "^3.5.3",
2935
"mocha-jenkins-reporter": "^0.3.9",
36+
"ncp": "^2.0.0",
37+
"pify": "^3.0.0",
3038
"through2": "^2.0.3",
39+
"ts-node": "^3.3.0",
3140
"tslint": "^5.5.0",
3241
"typescript": "^2.5.1",
3342
"xml2js": "^0.4.19"

packages/grpc-health-check/gulpfile.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ const healthCheckDir = __dirname;
2929
const baseDir = path.resolve(healthCheckDir, '..', '..');
3030
const testDir = path.resolve(healthCheckDir, 'test');
3131

32-
gulp.task('health-check.clean.links', 'Delete npm links', () => {
32+
gulp.task('clean.links', 'Delete npm links', () => {
3333
return del(path.resolve(healthCheckDir, 'node_modules/grpc'));
3434
});
3535

36-
gulp.task('health-check.clean.all', 'Delete all code created by tasks',
37-
['health-check.clean.links']);
36+
gulp.task('clean.all', 'Delete all code created by tasks',
37+
['clean.links']);
3838

39-
gulp.task('health-check.install', 'Install health check dependencies', () => {
39+
gulp.task('install', 'Install health check dependencies', () => {
4040
return execa('npm', ['install', '--unsafe-perm'], {cwd: healthCheckDir, stdio: 'inherit'});
4141
});
4242

43-
gulp.task('health-check.link.add', 'Link local copy of grpc', () => {
43+
gulp.task('link.add', 'Link local copy of grpc', () => {
4444
linkSync(healthCheckDir, './node_modules/grpc', '../grpc-native-core');
4545
});
4646

47-
gulp.task('health-check.test', 'Run health check tests',
47+
gulp.task('test', 'Run health check tests',
4848
() => {
4949
return gulp.src(`${testDir}/*.js`).pipe(mocha({reporter: 'mocha-jenkins-reporter'}));
5050
});

packages/grpc-js-core/gulpfile.js

-197
This file was deleted.

0 commit comments

Comments
 (0)