Update gulp to version 4, rewrite scripts

This commit is contained in:
murgatroid99 2019-04-24 16:12:02 -07:00
parent 7ee7154fd6
commit df57548805
9 changed files with 183 additions and 189 deletions

View File

@ -15,96 +15,55 @@
*
*/
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]));
import * as gulp from 'gulp';
import * as healthCheck from './packages/grpc-health-check/gulpfile';
import * as jsCore from './packages/grpc-js/gulpfile';
import * as nativeCore from './packages/grpc-native-core/gulpfile';
import * as protobuf from './packages/proto-loader/gulpfile';
import * as internalTest from './test/gulpfile';
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']);
const installAll = gulp.parallel(jsCore.install, nativeCore.install, healthCheck.install, protobuf.install, internalTest.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']);
const installAllWindows = gulp.parallel(jsCore.install, nativeCore.installWindows, healthCheck.install, protobuf.install, internalTest.install);
gulp.task('lint', 'Emit linting errors in source and test files',
['js.core.lint', 'native.core.lint']);
const lint = gulp.parallel(jsCore.lint, nativeCore.lint);
gulp.task('build', 'Build packages', ['js.core.compile', 'native.core.build', 'protobuf.compile']);
const build = gulp.parallel(jsCore.compile, nativeCore.build, protobuf.compile);
gulp.task('link.surface', 'Link to surface packages',
['health-check.link.add']);
const link = gulp.series(healthCheck.linkAdd);
gulp.task('link', 'Link together packages', (callback) => {
/**
* We use workarounds for linking in some modules. See npm/npm#18835
*/
runSequence('link.surface', callback);
});
const setup = gulp.series(installAll, link);
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);
});
const setupWindows = gulp.series(installAllWindows, link);
gulp.task('clean', 'Delete generated files', ['js.core.clean', 'native.core.clean', 'protobuf.clean']);
const clean = gulp.parallel(jsCore.clean, nativeCore.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']);
const cleanAll = gulp.parallel(jsCore.cleanAll, nativeCore.cleanAll, healthCheck.cleanAll, internalTest.cleanAll, protobuf.cleanAll);
gulp.task('native.test.only', 'Run tests of native code without rebuilding anything',
['native.core.test', 'health-check.test']);
const nativeTestOnly = gulp.parallel(nativeCore.test, healthCheck.test);
gulp.task('native.test', 'Run tests of native code', (callback) => {
runSequence('build', 'native.test.only', callback);
});
const nativeTest = gulp.series(build, nativeTestOnly);
gulp.task('test.only', 'Run tests without rebuilding anything',
['js.core.test', 'native.test.only', 'protobuf.test']);
const testOnly = gulp.parallel(jsCore.test, nativeTestOnly, protobuf.test);
gulp.task('test', 'Run all tests', (callback) => {
runSequence('build', 'test.only', 'internal.test.test', callback);
});
const test = gulp.series(build, testOnly, internalTest.test);
gulp.task('doc.gen', 'Generate documentation', ['native.core.doc.gen']);
const docGen = gulp.series(nativeCore.docGen);
gulp.task('default', ['help']);
export {
installAll,
installAllWindows,
lint,
build,
link,
setup,
setupWindows,
clean,
cleanAll,
nativeTestOnly,
nativeTest,
test,
docGen
};

View File

@ -11,7 +11,6 @@
"devDependencies": {
"@types/execa": "^0.8.0",
"@types/gulp": "^4.0.5",
"@types/gulp-help": "0.0.34",
"@types/gulp-mocha": "0.0.31",
"@types/ncp": "^2.0.1",
"@types/node": "^8.0.32",
@ -20,8 +19,7 @@
"coveralls": "^3.0.1",
"del": "^3.0.0",
"execa": "^0.8.0",
"gulp": "^3.9.1",
"gulp-help": "^1.6.1",
"gulp": "^4.0.1",
"gulp-jsdoc3": "^1.0.1",
"gulp-jshint": "^2.0.4",
"gulp-mocha": "^4.3.1",
@ -42,7 +40,7 @@
"semver": "^5.5.0",
"symlink": "^2.1.0",
"through2": "^2.0.3",
"ts-node": "^3.3.0",
"ts-node": "^8.1.0",
"tslint": "^5.5.0",
"typescript": "~3.3.3333",
"xml2js": "^0.4.19"

View File

@ -1,5 +1,5 @@
/*
* Copyright 2017 gRPC authors.
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -15,36 +15,41 @@
*
*/
const _gulp = require('gulp');
const help = require('gulp-help');
const mocha = require('gulp-mocha');
const execa = require('execa');
const path = require('path');
const del = require('del');
const linkSync = require('../../util').linkSync;
const gulp = help(_gulp);
import * as gulp from 'gulp';
import * as mocha from 'gulp-mocha';
import * as execa from 'execa';
import * as path from 'path';
import * as del from 'del';
import linkSync from '../../util';
const healthCheckDir = __dirname;
const baseDir = path.resolve(healthCheckDir, '..', '..');
const testDir = path.resolve(healthCheckDir, 'test');
gulp.task('clean.links', 'Delete npm links', () => {
const cleanLinks = () => {
return del(path.resolve(healthCheckDir, 'node_modules/grpc'));
});
}
gulp.task('clean.all', 'Delete all code created by tasks',
['clean.links']);
const cleanAll = gulp.parallel(cleanLinks);
gulp.task('install', 'Install health check dependencies', ['clean.links'], () => {
const runInstall = () => {
return execa('npm', ['install', '--unsafe-perm'], {cwd: healthCheckDir, stdio: 'inherit'});
});
};
gulp.task('link.add', 'Link local copy of grpc', () => {
const install = gulp.series(cleanLinks, runInstall);
const linkAdd = () => {
linkSync(healthCheckDir, './node_modules/grpc', '../grpc-native-core');
});
};
gulp.task('test', 'Run health check tests',
() => {
return gulp.src(`${testDir}/*.js`).pipe(mocha({reporter: 'mocha-jenkins-reporter'}));
});
const test = () => {
return gulp.src(`${testDir}/*.js`).pipe(mocha({reporter: 'mocha-jenkins-reporter'}));
};
export {
cleanLinks,
cleanAll,
install,
linkAdd,
test
}

View File

@ -15,8 +15,7 @@
*
*/
import * as _gulp from 'gulp';
import * as help from 'gulp-help';
import * as gulp from 'gulp';
import * as fs from 'fs';
import * as mocha from 'gulp-mocha';
@ -26,9 +25,6 @@ import * as pify from 'pify';
import * as semver from 'semver';
import { ncp } from 'ncp';
// gulp-help monkeypatches tasks to have an additional description parameter
const gulp = help(_gulp);
const ncpP = pify(ncp);
Error.stackTraceLimit = Infinity;
@ -44,34 +40,36 @@ const execNpmVerb = (verb: string, ...args: string[]) =>
execa('npm', [verb, ...args], {cwd: jsCoreDir, stdio: 'inherit'});
const execNpmCommand = execNpmVerb.bind(null, 'run');
gulp.task('install', 'Install native core dependencies', () =>
execNpmVerb('install', '--unsafe-perm'));
const install = () => {
execNpmVerb('install', '--unsafe-perm');
};
/**
* Runs tslint on files in src/, with linting rules defined in tslint.json.
*/
gulp.task('lint', 'Emits linting errors found in src/ and test/.', () =>
execNpmCommand('check'));
const lint = () => {
execNpmCommand('check');
};
gulp.task('clean', 'Deletes transpiled code.', ['install'],
() => execNpmCommand('clean'));
const clean = () => {
execNpmCommand('clean');
};
gulp.task('clean.all', 'Deletes all files added by targets', ['clean']);
const cleanAll = gulp.parallel(clean);
/**
* Transpiles TypeScript files in src/ to JavaScript according to the settings
* found in tsconfig.json.
*/
gulp.task('compile', 'Transpiles src/.', () => execNpmCommand('compile'));
const compile = () => {
execNpmCommand('compile');
}
gulp.task('copy-test-fixtures', 'Copy test fixtures.', () => {
const copyTestFixtures = () => {
return ncpP(`${jsCoreDir}/test/fixtures`, `${outDir}/test/fixtures`);
});
}
/**
* Transpiles src/ and test/, and then runs all tests.
*/
gulp.task('test', 'Runs all tests.', ['lint', 'copy-test-fixtures'], () => {
const runTests = () => {
if (semver.satisfies(process.version, '^8.11.2 || >=9.4')) {
return gulp.src(`${outDir}/test/**/*.js`)
.pipe(mocha({reporter: 'mocha-jenkins-reporter',
@ -80,4 +78,15 @@ gulp.task('test', 'Runs all tests.', ['lint', 'copy-test-fixtures'], () => {
console.log(`Skipping grpc-js tests for Node ${process.version}`);
return Promise.resolve(null);
}
});
};
const test = gulp.series(install, copyTestFixtures, runTests);
export {
install,
lint,
clean,
cleanAll,
compile,
test
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2017 gRPC authors.
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -15,18 +15,13 @@
*
*/
const _gulp = require('gulp');
const help = require('gulp-help');
// gulp-help monkeypatches tasks to have an additional description parameter
const gulp = help(_gulp);
const jsdoc = require('gulp-jsdoc3');
const jshint = require('gulp-jshint');
const mocha = require('gulp-mocha');
const execa = require('execa');
const path = require('path');
const del = require('del');
import * as gulp from 'gulp';
import * as jsdoc from 'gulp-jsdoc3';
import * as jshint from 'gulp-jshint';
import * as mocha from 'gulp-mocha';
import * as execa from 'execa';
import * as path from 'path';
import * as del from 'del';
const nativeCoreDir = __dirname;
const srcDir = path.resolve(nativeCoreDir, 'src');
@ -35,44 +30,56 @@ const testDir = path.resolve(nativeCoreDir, 'test');
const pkg = require('./package');
const jshintConfig = pkg.jshintConfig;
gulp.task('clean', 'Delete generated files', () => {
const clean = () => {
return del([path.resolve(nativeCoreDir, 'build'),
path.resolve(nativeCoreDir, 'ext/node')]);
});
path.resolve(nativeCoreDir, 'ext/node')]);
};
gulp.task('clean.all', 'Delete all files created by tasks',
['clean']);
const cleanAll = gulp.parallel(clean);
gulp.task('install', 'Install native core dependencies', () => {
const install = () => {
return execa('npm', ['install', '--build-from-source', '--unsafe-perm'],
{cwd: nativeCoreDir, stdio: 'inherit'});
});
};
gulp.task('install.windows', 'Install native core dependencies for MS Windows', () => {
const installWindows = () => {
return execa('npm', ['install', '--build-from-source'],
{cwd: nativeCoreDir, stdio: 'inherit'}).catch(() =>
del(path.resolve(process.env.USERPROFILE, '.node-gyp', process.versions.node, 'include/node/openssl'), { force: true }).then(() =>
execa('npm', ['install', '--build-from-source'],
{cwd: nativeCoreDir, stdio: 'inherit'})
))
});
));
};
gulp.task('lint', 'Emits linting errors', () => {
const lint = () => {
return gulp.src([`${nativeCoreDir}/index.js`, `${srcDir}/*.js`, `${testDir}/*.js`])
.pipe(jshint(pkg.jshintConfig))
.pipe(jshint.reporter('default'));
});
};
gulp.task('build', 'Build native package', () => {
const build = () => {
return execa('npm', ['run', 'build'], {cwd: nativeCoreDir, stdio: 'inherit'});
});
};
gulp.task('test', 'Run all tests', ['build'], () => {
const runTests = () => {
return gulp.src(`${testDir}/*.js`).pipe(mocha({timeout: 5000, reporter: 'mocha-jenkins-reporter'}));
});
}
gulp.task('doc.gen', 'Generate docs', (cb) => {
const test = gulp.series(build, runTests);
const docGen = (cb) => {
var config = require('./jsdoc_conf.json');
gulp.src([`${nativeCoreDir}/README.md`, `${nativeCoreDir}/index.js`, `${srcDir}/*.js`], {read: false})
.pipe(jsdoc(config, cb));
});
};
export {
clean,
cleanAll,
install,
installWindows,
lint,
build,
test,
docGen
};

View File

@ -15,8 +15,7 @@
*
*/
import * as _gulp from 'gulp';
import * as help from 'gulp-help';
import * as gulp from 'gulp';
import * as fs from 'fs';
import * as mocha from 'gulp-mocha';
@ -24,9 +23,6 @@ import * as path from 'path';
import * as execa from 'execa';
import * as semver from 'semver';
// gulp-help monkeypatches tasks to have an additional description parameter
const gulp = help(_gulp);
Error.stackTraceLimit = Infinity;
const protojsDir = __dirname;
@ -40,30 +36,37 @@ const execNpmVerb = (verb: string, ...args: string[]) =>
execa('npm', [verb, ...args], {cwd: protojsDir, stdio: 'inherit'});
const execNpmCommand = execNpmVerb.bind(null, 'run');
gulp.task('install', 'Install native core dependencies', () =>
execNpmVerb('install', '--unsafe-perm'));
const install = () => {
execNpmVerb('install', '--unsafe-perm');
};
/**
* Runs tslint on files in src/, with linting rules defined in tslint.json.
*/
gulp.task('lint', 'Emits linting errors found in src/ and test/.', () =>
execNpmCommand('check'));
const lint = () => {
execNpmCommand('check');
};
gulp.task('clean', 'Deletes transpiled code.', ['install'],
() => execNpmCommand('clean'));
const cleanFiles = () => {
execNpmCommand('clean');
};
gulp.task('clean.all', 'Deletes all files added by targets', ['clean']);
const clean = gulp.series(install, cleanFiles);
const cleanAll = gulp.parallel(clean);
/**
* Transpiles TypeScript files in src/ and test/ to JavaScript according to the settings
* found in tsconfig.json.
*/
gulp.task('compile', 'Transpiles src/ and test/.', () => execNpmCommand('compile'));
const compile = () => {
execNpmCommand('compile');
};
/**
* Transpiles src/ and test/, and then runs all tests.
*/
gulp.task('test', 'Runs all tests.', () => {
const runTests = () => {
if (semver.satisfies(process.version, ">=6")) {
return gulp.src(`${outDir}/test/**/*.js`)
.pipe(mocha({reporter: 'mocha-jenkins-reporter',
@ -72,4 +75,15 @@ gulp.task('test', 'Runs all tests.', () => {
console.log(`Skipping proto-loader tests for Node ${process.version}`);
return Promise.resolve(null);
}
});
}
const test = gulp.series(install, runTests);
export {
install,
lint,
clean,
cleanAll,
compile,
test
}

View File

@ -53,8 +53,8 @@ for %%v in (6 7 8 9 10 11) do (
node -e "process.exit(process.version.startsWith('v%%v') ? 0 : -1)" || goto :error
call .\node_modules\.bin\gulp clean.all || SET FAILED=1
call .\node_modules\.bin\gulp setup.windows || SET FAILED=1
call .\node_modules\.bin\gulp cleanAll || SET FAILED=1
call .\node_modules\.bin\gulp setupWindows || SET FAILED=1
call .\node_modules\.bin\gulp test || SET FAILED=1
)

View File

@ -68,7 +68,7 @@ do
node -e 'process.exit(process.version.startsWith("v'$version'") ? 0 : -1)'
# Install dependencies and link packages together.
./node_modules/.bin/gulp clean.all
./node_modules/.bin/gulp cleanAll
./node_modules/.bin/gulp setup
# npm test calls nyc gulp test

View File

@ -1,5 +1,5 @@
/*
* Copyright 2017 gRPC authors.
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -15,28 +15,24 @@
*
*/
const _gulp = require('gulp');
const help = require('gulp-help');
const mocha = require('gulp-mocha');
const execa = require('execa');
const path = require('path');
const del = require('del');
const semver = require('semver');
const linkSync = require('../util').linkSync;
// gulp-help monkeypatches tasks to have an additional description parameter
const gulp = help(_gulp);
import * as gulp from 'gulp';
import * as mocha from 'gulp-mocha';
import * as execa from 'execa';
import * as path from 'path';
import * as del from 'del';
import * as semver from 'semver';
import linkSync from '../util';
const testDir = __dirname;
const apiTestDir = path.resolve(testDir, 'api');
gulp.task('install', 'Install test dependencies', () => {
const install = () => {
return execa('npm', ['install'], {cwd: testDir, stdio: 'inherit'});
});
};
gulp.task('clean.all', 'Delete all files created by tasks', () => {});
const cleanAll = () => {};
gulp.task('test', 'Run API-level tests', () => {
const test = () => {
// run mocha tests matching a glob with a pre-required fixture,
// returning the associated gulp stream
if (!semver.satisfies(process.version, '>=9.4')) {
@ -50,7 +46,7 @@ gulp.task('test', 'Run API-level tests', () => {
gulp.src(apiTestGlob)
.pipe(mocha({
reporter: 'mocha-jenkins-reporter',
require: `${testDir}/fixtures/${fixture}.js`
require: [`${testDir}/fixtures/${fixture}.js`]
}))
.resume() // put the stream in flowing mode
.on('end', resolve)
@ -72,4 +68,10 @@ gulp.task('test', 'Run API-level tests', () => {
return runTestsArgPairs.reduce((previousPromise, argPair) => {
return previousPromise.then(runTestsWithFixture.bind(null, argPair[0], argPair[1]));
}, Promise.resolve());
});
};
export {
install,
cleanAll,
test
};