forked from grpc/grpc-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.ts
110 lines (89 loc) · 4.07 KB
/
gulpfile.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* Copyright 2017 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import * as _gulp from 'gulp';
import * as help from 'gulp-help';
// gulp-help monkeypatches tasks to have an additional description parameter
const gulp = help(_gulp);
const runSequence = require('run-sequence');
/**
* Require a module at the given path with a patched gulp object that prepends
* the given prefix to each task name.
* @param path The path to require.
* @param prefix The string to use as a prefix. This will be prepended to a task
* name with a '.' separator.
*/
function loadGulpTasksWithPrefix(path: string, prefix: string) {
const gulpTask = gulp.task;
gulp.task = ((taskName: string, ...args: any[]) => {
// Don't create a task for ${prefix}.help
if (taskName === 'help') {
return;
}
// The only array passed to gulp.task must be a list of dependent tasks.
const newArgs = args.map(arg => Array.isArray(arg) ?
arg.map(dep => `${prefix}.${dep}`) : arg);
gulpTask(`${prefix}.${taskName}`, ...newArgs);
});
const result = require(path);
gulp.task = gulpTask;
return result;
}
[
['./packages/grpc-health-check/gulpfile', 'health-check'],
['./packages/grpc-js/gulpfile', 'js.core'],
['./packages/grpc-native-core/gulpfile', 'native.core'],
['./packages/proto-loader/gulpfile', 'protobuf'],
['./test/gulpfile', 'internal.test'],
].forEach((args) => loadGulpTasksWithPrefix(args[0], args[1]));
const root = __dirname;
gulp.task('install.all', 'Install dependencies for all subdirectory packages',
['js.core.install', 'native.core.install', 'health-check.install', 'protobuf.install', 'internal.test.install']);
gulp.task('install.all.windows', 'Install dependencies for all subdirectory packages for MS Windows',
['js.core.install', 'native.core.install.windows', 'health-check.install', 'protobuf.install', 'internal.test.install']);
gulp.task('lint', 'Emit linting errors in source and test files',
['js.core.lint', 'native.core.lint']);
gulp.task('build', 'Build packages', ['js.core.compile', 'native.core.build', 'protobuf.compile']);
gulp.task('link.surface', 'Link to surface packages',
['health-check.link.add']);
gulp.task('link', 'Link together packages', (callback) => {
/**
* We use workarounds for linking in some modules. See npm/npm#18835
*/
runSequence('link.surface', callback);
});
gulp.task('setup', 'One-time setup for a clean repository', (callback) => {
runSequence('install.all', 'link', callback);
});
gulp.task('setup.windows', 'One-time setup for a clean repository for MS Windows', (callback) => {
runSequence('install.all.windows', 'link', callback);
});
gulp.task('clean', 'Delete generated files', ['js.core.clean', 'native.core.clean', 'protobuf.clean']);
gulp.task('clean.all', 'Delete all files created by tasks',
['js.core.clean.all', 'native.core.clean.all', 'health-check.clean.all',
'internal.test.clean.all', 'protobuf.clean.all']);
gulp.task('native.test.only', 'Run tests of native code without rebuilding anything',
['native.core.test', 'health-check.test']);
gulp.task('native.test', 'Run tests of native code', (callback) => {
runSequence('build', 'native.test.only', callback);
});
gulp.task('test.only', 'Run tests without rebuilding anything',
['js.core.test', 'native.test.only', 'protobuf.test']);
gulp.task('test', 'Run all tests', (callback) => {
runSequence('build', 'test.only', 'internal.test.test', callback);
});
gulp.task('doc.gen', 'Generate documentation', ['native.core.doc.gen']);
gulp.task('default', ['help']);