mirror of https://github.com/grpc/grpc-node.git
slight gulpfile changes (#16)
This commit is contained in:
parent
7de87642fe
commit
0774aafb01
|
|
@ -4,7 +4,7 @@ const help = require('gulp-help');
|
||||||
// gulp-help monkeypatches tasks to have an additional description parameter
|
// gulp-help monkeypatches tasks to have an additional description parameter
|
||||||
const gulp = help(_gulp);
|
const gulp = help(_gulp);
|
||||||
|
|
||||||
require('./packages/grpc-js-core/gulpfile')(gulp);
|
require('./packages/grpc-js-core/gulpfile');
|
||||||
|
|
||||||
gulp.task('lint', 'Emit linting errors in source and test files', ['js.core.lint']);
|
gulp.task('lint', 'Emit linting errors in source and test files', ['js.core.lint']);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,9 @@
|
||||||
|
const _gulp = require('gulp');
|
||||||
|
const help = require('gulp-help');
|
||||||
|
|
||||||
|
// gulp-help monkeypatches tasks to have an additional description parameter
|
||||||
|
const gulp = help(_gulp);
|
||||||
|
|
||||||
const del = require('del');
|
const del = require('del');
|
||||||
const mocha = require('gulp-mocha');
|
const mocha = require('gulp-mocha');
|
||||||
const sourcemaps = require('gulp-sourcemaps');
|
const sourcemaps = require('gulp-sourcemaps');
|
||||||
|
|
@ -10,155 +16,151 @@ const through = require('through2');
|
||||||
|
|
||||||
Error.stackTraceLimit = Infinity;
|
Error.stackTraceLimit = Infinity;
|
||||||
|
|
||||||
module.exports = function(gulp) {
|
const jsCoreDir = __dirname;
|
||||||
|
const tslintPath = path.resolve(jsCoreDir, 'node_modules/google-ts-style/tslint.json');
|
||||||
|
const tsconfigPath = path.resolve(jsCoreDir, 'tsconfig.json');
|
||||||
|
const outDir = path.resolve(jsCoreDir, 'build');
|
||||||
|
const srcDir = path.resolve(jsCoreDir, 'src');
|
||||||
|
const testDir = path.resolve(jsCoreDir, 'test');
|
||||||
|
|
||||||
const jsCoreDir = __dirname;
|
function onError() {}
|
||||||
const tslintPath = path.resolve(jsCoreDir, 'node_modules/google-ts-style/tslint.json');
|
|
||||||
const tsconfigPath = path.resolve(jsCoreDir, 'tsconfig.json');
|
|
||||||
const outDir = path.resolve(jsCoreDir, 'build');
|
|
||||||
const srcDir = path.resolve(jsCoreDir, 'src');
|
|
||||||
const testDir = path.resolve(jsCoreDir, 'test');
|
|
||||||
|
|
||||||
function onError() {}
|
// Coalesces all specified --file parameters into a single array
|
||||||
|
const files = !util.env.file ? [] :
|
||||||
|
Array.isArray(util.env.file) ? util.env.file : [util.env.file];
|
||||||
|
|
||||||
// Coalesces all specified --file parameters into a single array
|
// If --dev is passed, override certain ts config options
|
||||||
const files = !util.env.file ? [] :
|
let tsDevOptions = {};
|
||||||
Array.isArray(util.env.file) ? util.env.file : [util.env.file];
|
if (util.env.dev) {
|
||||||
|
tsDevOptions = {
|
||||||
|
allowUnreachableCode: true,
|
||||||
|
noUnusedParameters: false,
|
||||||
|
noImplicitAny: false,
|
||||||
|
noImplicitThis: false,
|
||||||
|
noEmitOnError: false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// If --dev is passed, override certain ts config options
|
/**
|
||||||
let tsDevOptions = {};
|
* Helper function that creates a gulp task function that opens files in a
|
||||||
if (util.env.dev) {
|
* directory that match a certain glob pattern, transpiles them, and writes them
|
||||||
tsDevOptions = {
|
* to an output directory.
|
||||||
allowUnreachableCode: true,
|
* @param {Object} globs
|
||||||
noUnusedParameters: false,
|
* @param {string=} globs.transpile The glob pattern for files to transpile.
|
||||||
noImplicitAny: false,
|
* Defaults to match all *.ts files in baseDir (incl. subdirectories).
|
||||||
noImplicitThis: false,
|
* @param {string=} globs.copy The glob pattern for files to transpile.
|
||||||
noEmitOnError: false
|
* Defaults to match all but *.ts files in baseDir (incl. subdirectories).
|
||||||
};
|
* @return A gulp task function.
|
||||||
}
|
*/
|
||||||
|
function makeCompileFn(globs) {
|
||||||
|
const transpileGlob = globs.transpile || `${srcDir}/**/*.ts`;
|
||||||
|
const copyGlob = globs.copy || '!(**/*)';
|
||||||
|
return () => {
|
||||||
|
const tsProject = typescript.createProject(tsconfigPath, tsDevOptions)();
|
||||||
|
const { dts, js } = gulp.src(transpileGlob, { base: jsCoreDir })
|
||||||
|
.pipe(sourcemaps.init())
|
||||||
|
.pipe(tsProject)
|
||||||
|
.on('error', onError);
|
||||||
|
const jsmap = js.pipe(sourcemaps.write(jsCoreDir, {
|
||||||
|
includeContent: false,
|
||||||
|
sourceRoot: path.resolve(jsCoreDir, '..')
|
||||||
|
}));
|
||||||
|
const copy = gulp.src(copyGlob, { base: jsCoreDir });
|
||||||
|
return merge2([
|
||||||
|
js.pipe(gulp.dest(`${outDir}`)),
|
||||||
|
dts.pipe(gulp.dest(`${outDir}/types`)),
|
||||||
|
jsmap.pipe(gulp.dest(`${outDir}`)),
|
||||||
|
copy.pipe(gulp.dest(`${outDir}`))
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function that creates a gulp task function that opens files in a
|
* Runs tslint on files in src/, with linting rules defined in tslint.json.
|
||||||
* directory that match a certain glob pattern, transpiles them, and writes them
|
*/
|
||||||
* to an output directory.
|
gulp.task('js.core.lint', 'Emits linting errors found in src/ and test/.', () => {
|
||||||
* @param {Object} globs
|
const program = require('tslint').Linter.createProgram(tsconfigPath);
|
||||||
* @param {string=} globs.transpile The glob pattern for files to transpile.
|
gulp.src([`${srcDir}/**/*.ts`, `${srcDir}/**/*.ts`])
|
||||||
* Defaults to match all *.ts files in baseDir (incl. subdirectories).
|
.pipe(tslint({
|
||||||
* @param {string=} globs.copy The glob pattern for files to transpile.
|
configuration: tslintPath,
|
||||||
* Defaults to match all but *.ts files in baseDir (incl. subdirectories).
|
formatter: 'codeFrame',
|
||||||
* @return A gulp task function.
|
program
|
||||||
*/
|
}))
|
||||||
function makeCompileFn(globs) {
|
.pipe(tslint.report())
|
||||||
const transpileGlob = globs.transpile || `${srcDir}/**/*.ts`;
|
.on('warning', onError);
|
||||||
const copyGlob = globs.copy || '!(**/*)';
|
});
|
||||||
return () => {
|
|
||||||
const tsProject = typescript.createProject(tsconfigPath, tsDevOptions)();
|
|
||||||
const { dts, js } = gulp.src(transpileGlob, { base: jsCoreDir })
|
|
||||||
.pipe(sourcemaps.init())
|
|
||||||
.pipe(tsProject)
|
|
||||||
.on('error', onError);
|
|
||||||
const jsmap = js.pipe(sourcemaps.write(jsCoreDir, {
|
|
||||||
includeContent: false,
|
|
||||||
sourceRoot: path.resolve(jsCoreDir, '..')
|
|
||||||
}));
|
|
||||||
const copy = gulp.src(copyGlob, { base: jsCoreDir });
|
|
||||||
return merge2([
|
|
||||||
js.pipe(gulp.dest(`${outDir}`)),
|
|
||||||
dts.pipe(gulp.dest(`${outDir}/types`)),
|
|
||||||
jsmap.pipe(gulp.dest(`${outDir}`)),
|
|
||||||
copy.pipe(gulp.dest(`${outDir}`))
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
gulp.task('js.core.clean', 'Deletes transpiled code.', () => {
|
||||||
* Runs tslint on files in src/, with linting rules defined in tslint.json.
|
return del(outDir);
|
||||||
*/
|
});
|
||||||
gulp.task('js.core.lint', 'Emits linting errors found in src/ and test/.', () => {
|
|
||||||
const program = require('tslint').Linter.createProgram(tsconfigPath);
|
|
||||||
gulp.src([`${srcDir}/**/*.ts`, `${srcDir}/**/*.ts`])
|
|
||||||
.pipe(tslint({
|
|
||||||
configuration: tslintPath,
|
|
||||||
formatter: 'codeFrame',
|
|
||||||
program
|
|
||||||
}))
|
|
||||||
.pipe(tslint.report())
|
|
||||||
.on('warning', onError);
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('js.core.clean', 'Deletes transpiled code.', () => {
|
/**
|
||||||
return del(outDir);
|
* Transpiles TypeScript files in src/ to JavaScript according to the settings
|
||||||
});
|
* found in tsconfig.json.
|
||||||
|
* Currently, all errors are emitted twice. This is being tracked here:
|
||||||
|
* https://github.com/ivogabe/gulp-typescript/issues/438
|
||||||
|
*/
|
||||||
|
gulp.task('js.core.compile', 'Transpiles src/.',
|
||||||
|
makeCompileFn({ transpile: [`${srcDir}/**/*.ts`] }));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transpiles TypeScript files in src/ to JavaScript according to the settings
|
* Transpiles TypeScript files in both src/ and test/.
|
||||||
* found in tsconfig.json.
|
*/
|
||||||
* Currently, all errors are emitted twice. This is being tracked here:
|
gulp.task('js.core.test.compile', 'After dep tasks, transpiles test/.', ['js.core.compile'],
|
||||||
* https://github.com/ivogabe/gulp-typescript/issues/438
|
makeCompileFn({ transpile: [`${testDir}/**/*.ts`], copy: `${testDir}/**/!(*.ts)` }));
|
||||||
*/
|
|
||||||
gulp.task('js.core.compile', 'Transpiles src/.',
|
|
||||||
makeCompileFn({ transpile: [`${srcDir}/**/*.ts`] }));
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transpiles TypeScript files in both src/ and test/.
|
* Transpiles src/ and test/, and then runs all tests.
|
||||||
*/
|
*/
|
||||||
gulp.task('js.core.test.compile', 'After dep tasks, transpiles test/.', ['js.core.compile'],
|
gulp.task('js.core.test', 'After dep tasks, runs all tests.',
|
||||||
makeCompileFn({ transpile: [`${testDir}/**/*.ts`], copy: `${testDir}/**/!(*.ts)` }));
|
['js.core.test.compile'], () => {
|
||||||
|
return gulp.src(`${outDir}/test/**/*.js`)
|
||||||
|
.pipe(mocha());
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transpiles src/ and test/, and then runs all tests.
|
* Transpiles individual files, specified by the --file flag.
|
||||||
*/
|
*/
|
||||||
gulp.task('js.core.test', 'After dep tasks, runs all tests.',
|
gulp.task('js.core.compile.single', 'Transpiles individual files specified by --file.',
|
||||||
['js.core.test.compile'], () => {
|
makeCompileFn({
|
||||||
return gulp.src(`${outDir}/test/**/*.js`)
|
transpile: files.map(f => path.relative('.', f))
|
||||||
.pipe(mocha());
|
})
|
||||||
}
|
);
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transpiles individual files, specified by the --file flag.
|
* Run individual tests, specified by their pre-transpiled source path (as
|
||||||
*/
|
* supplied through the '--file' flag). This is intended to be used as part of a
|
||||||
gulp.task('js.core.compile.single', 'Transpiles individual files specified by --file.',
|
* VS Code "Gulp task" launch configuration; setting the "args" field to
|
||||||
makeCompileFn({
|
* ["test.single", "--file", "${file}"] makes it possible for one to debug the
|
||||||
transpile: files.map(f => path.relative('.', f))
|
* currently open TS mocha test file in one step.
|
||||||
})
|
*/
|
||||||
);
|
gulp.task('js.core.test.single', 'After dep tasks, runs individual files specified ' +
|
||||||
|
'by --file.', ['js.core.compile', 'js.core.compile.single'], () => {
|
||||||
/**
|
// util.env contains CLI arguments for the gulp task.
|
||||||
* Run individual tests, specified by their pre-transpiled source path (as
|
// Determine the path to the transpiled version of this TS file.
|
||||||
* supplied through the '--file' flag). This is intended to be used as part of a
|
const getTranspiledPath = (file) => {
|
||||||
* VS Code "Gulp task" launch configuration; setting the "args" field to
|
const dir = path.dirname(path.relative('.', file));
|
||||||
* ["test.single", "--file", "${file}"] makes it possible for one to debug the
|
const basename = path.basename(file, '.ts');
|
||||||
* currently open TS mocha test file in one step.
|
return `${outDir}/${dir}/${basename}.js`;
|
||||||
*/
|
};
|
||||||
gulp.task('js.core.test.single', 'After dep tasks, runs individual files specified ' +
|
// Construct an instance of Mocha's runner API and feed it the path to the
|
||||||
'by --file.', ['js.core.compile', 'js.core.compile.single'], () => {
|
// transpiled source.
|
||||||
// util.env contains CLI arguments for the gulp task.
|
return gulp.src(files.map(getTranspiledPath))
|
||||||
// Determine the path to the transpiled version of this TS file.
|
.pipe(through.obj((file, enc, cb) => {
|
||||||
const getTranspiledPath = (file) => {
|
// Construct a new Mocha runner instance.
|
||||||
const dir = path.dirname(path.relative('.', file));
|
const Mocha = require('mocha');
|
||||||
const basename = path.basename(file, '.ts');
|
const runner = new Mocha();
|
||||||
return `${outDir}/${dir}/${basename}.js`;
|
// Add the path to the test file to debug.
|
||||||
};
|
runner.addFile(file.path);
|
||||||
// Construct an instance of Mocha's runner API and feed it the path to the
|
// Run the test suite.
|
||||||
// transpiled source.
|
runner.run((failures) => {
|
||||||
return gulp.src(files.map(getTranspiledPath))
|
if (failures > 0) {
|
||||||
.pipe(through.obj((file, enc, cb) => {
|
cb(new Error(`Mocha: ${failures} failures in ${file.path}]`));
|
||||||
// Construct a new Mocha runner instance.
|
} else {
|
||||||
const Mocha = require('mocha');
|
cb(null);
|
||||||
const runner = new Mocha();
|
}
|
||||||
// Add the path to the test file to debug.
|
});
|
||||||
runner.addFile(file.path);
|
}));
|
||||||
// Run the test suite.
|
}
|
||||||
runner.run((failures) => {
|
);
|
||||||
if (failures > 0) {
|
|
||||||
cb(new Error(`Mocha: ${failures} failures in ${file.path}]`));
|
|
||||||
} else {
|
|
||||||
cb(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue