Skip to content

Commit 2b0eaab

Browse files
committed
2 parents ffdcd46 + 497ba67 commit 2b0eaab

File tree

10 files changed

+192
-222
lines changed

10 files changed

+192
-222
lines changed

gulpfile.ts

Lines changed: 35 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -15,96 +15,55 @@
1515
*
1616
*/
1717

18-
import * as _gulp from 'gulp';
19-
import * as help from 'gulp-help';
20-
21-
// gulp-help monkeypatches tasks to have an additional description parameter
22-
const gulp = help(_gulp);
23-
24-
const runSequence = require('run-sequence');
25-
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.core'],
53-
['./packages/grpc-native-core/gulpfile', 'native.core'],
54-
['./packages/proto-loader/gulpfile', 'protobuf'],
55-
['./test/gulpfile', 'internal.test'],
56-
].forEach((args) => loadGulpTasksWithPrefix(args[0], args[1]));
18+
import * as gulp from 'gulp';
19+
import * as healthCheck from './packages/grpc-health-check/gulpfile';
20+
import * as jsCore from './packages/grpc-js/gulpfile';
21+
import * as nativeCore from './packages/grpc-native-core/gulpfile';
22+
import * as protobuf from './packages/proto-loader/gulpfile';
23+
import * as internalTest from './test/gulpfile';
5724

5825
const root = __dirname;
5926

60-
gulp.task('install.all', 'Install dependencies for all subdirectory packages',
61-
['js.core.install', 'native.core.install', 'health-check.install', 'protobuf.install', 'internal.test.install']);
27+
const installAll = gulp.parallel(jsCore.install, nativeCore.install, healthCheck.install, protobuf.install, internalTest.install);
6228

63-
gulp.task('install.all.windows', 'Install dependencies for all subdirectory packages for MS Windows',
64-
['js.core.install', 'native.core.install.windows', 'health-check.install', 'protobuf.install', 'internal.test.install']);
29+
const installAllWindows = gulp.parallel(jsCore.install, nativeCore.installWindows, healthCheck.install, protobuf.install, internalTest.install);
6530

66-
gulp.task('lint', 'Emit linting errors in source and test files',
67-
['js.core.lint', 'native.core.lint']);
31+
const lint = gulp.parallel(jsCore.lint, nativeCore.lint);
6832

69-
gulp.task('build', 'Build packages', ['js.core.compile', 'native.core.build', 'protobuf.compile']);
33+
const build = gulp.parallel(jsCore.compile, nativeCore.build, protobuf.compile);
7034

71-
gulp.task('link.surface', 'Link to surface packages',
72-
['health-check.link.add']);
35+
const link = gulp.series(healthCheck.linkAdd);
7336

74-
gulp.task('link', 'Link together packages', (callback) => {
75-
/**
76-
* We use workarounds for linking in some modules. See npm/npm#18835
77-
*/
78-
runSequence('link.surface', callback);
79-
});
37+
const setup = gulp.series(installAll, link);
8038

81-
gulp.task('setup', 'One-time setup for a clean repository', (callback) => {
82-
runSequence('install.all', 'link', callback);
83-
});
84-
gulp.task('setup.windows', 'One-time setup for a clean repository for MS Windows', (callback) => {
85-
runSequence('install.all.windows', 'link', callback);
86-
});
39+
const setupWindows = gulp.series(installAllWindows, link);
8740

88-
gulp.task('clean', 'Delete generated files', ['js.core.clean', 'native.core.clean', 'protobuf.clean']);
41+
const clean = gulp.parallel(jsCore.clean, nativeCore.clean, protobuf.clean);
8942

90-
gulp.task('clean.all', 'Delete all files created by tasks',
91-
['js.core.clean.all', 'native.core.clean.all', 'health-check.clean.all',
92-
'internal.test.clean.all', 'protobuf.clean.all']);
43+
const cleanAll = gulp.parallel(jsCore.cleanAll, nativeCore.cleanAll, healthCheck.cleanAll, internalTest.cleanAll, protobuf.cleanAll);
9344

94-
gulp.task('native.test.only', 'Run tests of native code without rebuilding anything',
95-
['native.core.test', 'health-check.test']);
45+
const nativeTestOnly = gulp.parallel(nativeCore.test, healthCheck.test);
9646

97-
gulp.task('native.test', 'Run tests of native code', (callback) => {
98-
runSequence('build', 'native.test.only', callback);
99-
});
47+
const nativeTest = gulp.series(build, nativeTestOnly);
10048

101-
gulp.task('test.only', 'Run tests without rebuilding anything',
102-
['js.core.test', 'native.test.only', 'protobuf.test']);
49+
const testOnly = gulp.parallel(jsCore.test, nativeTestOnly, protobuf.test);
10350

104-
gulp.task('test', 'Run all tests', (callback) => {
105-
runSequence('build', 'test.only', 'internal.test.test', callback);
106-
});
51+
const test = gulp.series(build, testOnly, internalTest.test);
10752

108-
gulp.task('doc.gen', 'Generate documentation', ['native.core.doc.gen']);
53+
const docGen = gulp.series(nativeCore.docGen);
10954

110-
gulp.task('default', ['help']);
55+
export {
56+
installAll,
57+
installAllWindows,
58+
lint,
59+
build,
60+
link,
61+
setup,
62+
setupWindows,
63+
clean,
64+
cleanAll,
65+
nativeTestOnly,
66+
nativeTest,
67+
test,
68+
docGen
69+
};

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"devDependencies": {
1212
"@types/execa": "^0.8.0",
1313
"@types/gulp": "^4.0.5",
14-
"@types/gulp-help": "0.0.34",
1514
"@types/gulp-mocha": "0.0.31",
1615
"@types/ncp": "^2.0.1",
1716
"@types/node": "^8.0.32",
@@ -20,8 +19,7 @@
2019
"coveralls": "^3.0.1",
2120
"del": "^3.0.0",
2221
"execa": "^0.8.0",
23-
"gulp": "^3.9.1",
24-
"gulp-help": "^1.6.1",
22+
"gulp": "^4.0.1",
2523
"gulp-jsdoc3": "^1.0.1",
2624
"gulp-jshint": "^2.0.4",
2725
"gulp-mocha": "^4.3.1",
@@ -42,7 +40,7 @@
4240
"semver": "^5.5.0",
4341
"symlink": "^2.1.0",
4442
"through2": "^2.0.3",
45-
"ts-node": "^3.3.0",
43+
"ts-node": "^8.1.0",
4644
"tslint": "^5.5.0",
4745
"typescript": "~3.3.3333",
4846
"xml2js": "^0.4.19"

packages/grpc-health-check/gulpfile.js

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2019 gRPC authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
import * as gulp from 'gulp';
19+
import * as mocha from 'gulp-mocha';
20+
import * as execa from 'execa';
21+
import * as path from 'path';
22+
import * as del from 'del';
23+
import {linkSync} from '../../util';
24+
25+
const healthCheckDir = __dirname;
26+
const baseDir = path.resolve(healthCheckDir, '..', '..');
27+
const testDir = path.resolve(healthCheckDir, 'test');
28+
29+
const cleanLinks = () => del(path.resolve(healthCheckDir, 'node_modules/grpc'));
30+
31+
const cleanAll = gulp.parallel(cleanLinks);
32+
33+
const runInstall = () => execa('npm', ['install', '--unsafe-perm'], {cwd: healthCheckDir, stdio: 'inherit'});
34+
35+
const install = gulp.series(cleanLinks, runInstall);
36+
37+
const linkAdd = (callback) => {
38+
linkSync(healthCheckDir, './node_modules/grpc', '../grpc-native-core');
39+
callback();
40+
}
41+
42+
const test = () => gulp.src(`${testDir}/*.js`).pipe(mocha({reporter: 'mocha-jenkins-reporter'}));
43+
44+
export {
45+
cleanLinks,
46+
cleanAll,
47+
install,
48+
linkAdd,
49+
test
50+
}

packages/grpc-js/gulpfile.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
*
1616
*/
1717

18-
import * as _gulp from 'gulp';
19-
import * as help from 'gulp-help';
18+
import * as gulp from 'gulp';
2019

2120
import * as fs from 'fs';
2221
import * as mocha from 'gulp-mocha';
@@ -26,9 +25,6 @@ import * as pify from 'pify';
2625
import * as semver from 'semver';
2726
import { ncp } from 'ncp';
2827

29-
// gulp-help monkeypatches tasks to have an additional description parameter
30-
const gulp = help(_gulp);
31-
3228
const ncpP = pify(ncp);
3329

3430
Error.stackTraceLimit = Infinity;
@@ -44,34 +40,28 @@ const execNpmVerb = (verb: string, ...args: string[]) =>
4440
execa('npm', [verb, ...args], {cwd: jsCoreDir, stdio: 'inherit'});
4541
const execNpmCommand = execNpmVerb.bind(null, 'run');
4642

47-
gulp.task('install', 'Install native core dependencies', () =>
48-
execNpmVerb('install', '--unsafe-perm'));
43+
const install = () => execNpmVerb('install', '--unsafe-perm');
4944

5045
/**
5146
* Runs tslint on files in src/, with linting rules defined in tslint.json.
5247
*/
53-
gulp.task('lint', 'Emits linting errors found in src/ and test/.', () =>
54-
execNpmCommand('check'));
48+
const lint = () => execNpmCommand('check');
49+
50+
const cleanFiles = () => execNpmCommand('clean');
5551

56-
gulp.task('clean', 'Deletes transpiled code.', ['install'],
57-
() => execNpmCommand('clean'));
52+
const clean = gulp.series(install, cleanFiles);
5853

59-
gulp.task('clean.all', 'Deletes all files added by targets', ['clean']);
54+
const cleanAll = gulp.parallel(clean);
6055

6156
/**
6257
* Transpiles TypeScript files in src/ to JavaScript according to the settings
6358
* found in tsconfig.json.
6459
*/
65-
gulp.task('compile', 'Transpiles src/.', () => execNpmCommand('compile'));
60+
const compile = () => execNpmCommand('compile');
6661

67-
gulp.task('copy-test-fixtures', 'Copy test fixtures.', () => {
68-
return ncpP(`${jsCoreDir}/test/fixtures`, `${outDir}/test/fixtures`);
69-
});
62+
const copyTestFixtures = () => ncpP(`${jsCoreDir}/test/fixtures`, `${outDir}/test/fixtures`);
7063

71-
/**
72-
* Transpiles src/ and test/, and then runs all tests.
73-
*/
74-
gulp.task('test', 'Runs all tests.', ['lint', 'copy-test-fixtures'], () => {
64+
const runTests = () => {
7565
if (semver.satisfies(process.version, '^8.11.2 || >=9.4')) {
7666
return gulp.src(`${outDir}/test/**/*.js`)
7767
.pipe(mocha({reporter: 'mocha-jenkins-reporter',
@@ -80,4 +70,15 @@ gulp.task('test', 'Runs all tests.', ['lint', 'copy-test-fixtures'], () => {
8070
console.log(`Skipping grpc-js tests for Node ${process.version}`);
8171
return Promise.resolve(null);
8272
}
83-
});
73+
};
74+
75+
const test = gulp.series(install, copyTestFixtures, runTests);
76+
77+
export {
78+
install,
79+
lint,
80+
clean,
81+
cleanAll,
82+
compile,
83+
test
84+
}

0 commit comments

Comments
 (0)