Simplify gulp tasks for extensions
This commit is contained in:
parent
a592b43925
commit
77b61a1e55
|
@ -47,11 +47,7 @@ const tasks = compilations.map(function (tsconfigFile) {
|
|||
const clean = 'clean-extension:' + name;
|
||||
const compile = 'compile-extension:' + name;
|
||||
const watch = 'watch-extension:' + name;
|
||||
|
||||
// Build Tasks
|
||||
const cleanBuild = 'clean-extension-build:' + name;
|
||||
const compileBuild = 'compile-extension-build:' + name;
|
||||
const watchBuild = 'watch-extension-build:' + name;
|
||||
|
||||
const root = path.join('extensions', relativeDirname);
|
||||
const srcBase = path.join(root, 'src');
|
||||
|
@ -112,15 +108,18 @@ const tasks = compilations.map(function (tsconfigFile) {
|
|||
const srcOpts = { cwd: path.dirname(__dirname), base: srcBase };
|
||||
|
||||
gulp.task(clean, cb => rimraf(out, cb));
|
||||
const cleanTask = () => util.primraf(out);
|
||||
|
||||
gulp.task(compile, [clean], () => {
|
||||
gulp.task(compile, util.taskSeries(cleanTask, () => {
|
||||
const pipeline = createPipeline(false, true);
|
||||
const input = gulp.src(src, srcOpts);
|
||||
|
||||
return input
|
||||
return util.streamToPromise(
|
||||
input
|
||||
.pipe(pipeline())
|
||||
.pipe(gulp.dest(out));
|
||||
});
|
||||
.pipe(gulp.dest(out))
|
||||
);
|
||||
}));
|
||||
|
||||
gulp.task(watch, [clean], () => {
|
||||
const pipeline = createPipeline(false);
|
||||
|
@ -132,39 +131,24 @@ const tasks = compilations.map(function (tsconfigFile) {
|
|||
.pipe(gulp.dest(out));
|
||||
});
|
||||
|
||||
gulp.task(cleanBuild, cb => rimraf(out, cb));
|
||||
|
||||
gulp.task(compileBuild, [clean], () => {
|
||||
gulp.task(compileBuild, util.taskSeries(cleanTask, () => {
|
||||
const pipeline = createPipeline(true, true);
|
||||
const input = gulp.src(src, srcOpts);
|
||||
|
||||
return input
|
||||
return util.streamToPromise(
|
||||
input
|
||||
.pipe(pipeline())
|
||||
.pipe(gulp.dest(out));
|
||||
});
|
||||
|
||||
gulp.task(watchBuild, [clean], () => {
|
||||
const pipeline = createPipeline(true);
|
||||
const input = gulp.src(src, srcOpts);
|
||||
const watchInput = watcher(src, srcOpts);
|
||||
|
||||
return watchInput
|
||||
.pipe(util.incremental(() => pipeline(), input))
|
||||
.pipe(gulp.dest(out));
|
||||
});
|
||||
.pipe(gulp.dest(out))
|
||||
);
|
||||
}));
|
||||
|
||||
return {
|
||||
clean: clean,
|
||||
compile: compile,
|
||||
watch: watch,
|
||||
cleanBuild: cleanBuild,
|
||||
compileBuild: compileBuild,
|
||||
watchBuild: watchBuild
|
||||
compileBuild: compileBuild
|
||||
};
|
||||
});
|
||||
|
||||
gulp.task('compile-extensions', tasks.map(t => t.compile));
|
||||
gulp.task('watch-extensions', tasks.map(t => t.watch));
|
||||
|
||||
gulp.task('compile-extensions-build', tasks.map(t => t.compileBuild));
|
||||
gulp.task('watch-extensions-build', tasks.map(t => t.watchBuild));
|
||||
|
|
|
@ -183,6 +183,39 @@ function rimraf(dir) {
|
|||
return cb => retry(cb);
|
||||
}
|
||||
exports.rimraf = rimraf;
|
||||
/**
|
||||
* Like rimraf (with 5 retries), but with a promise instead of a callback.
|
||||
*/
|
||||
function primraf(dir) {
|
||||
const fn = rimraf(dir);
|
||||
return new Promise((resolve, reject) => {
|
||||
fn((err) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.primraf = primraf;
|
||||
/**
|
||||
* Convert a stream to a promise.
|
||||
*/
|
||||
function streamToPromise(stream) {
|
||||
return new Promise((resolve, reject) => {
|
||||
stream.on('end', _ => resolve());
|
||||
stream.on('error', err => reject(err));
|
||||
});
|
||||
}
|
||||
exports.streamToPromise = streamToPromise;
|
||||
function taskSeries(...tasks) {
|
||||
return async () => {
|
||||
for (let i = 0; i < tasks.length; i++) {
|
||||
await tasks[i]();
|
||||
}
|
||||
};
|
||||
}
|
||||
exports.taskSeries = taskSeries;
|
||||
function getVersion(root) {
|
||||
let version = process.env['BUILD_SOURCEVERSION'];
|
||||
if (!version || !/^[0-9a-f]{40}$/i.test(version)) {
|
||||
|
|
|
@ -237,6 +237,40 @@ export function rimraf(dir: string): (cb: any) => void {
|
|||
return cb => retry(cb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Like rimraf (with 5 retries), but with a promise instead of a callback.
|
||||
*/
|
||||
export function primraf(dir: string): Promise<void> {
|
||||
const fn = rimraf(dir);
|
||||
return new Promise((resolve, reject) => {
|
||||
fn((err: any) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a stream to a promise.
|
||||
*/
|
||||
export function streamToPromise(stream: NodeJS.ReadWriteStream): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
stream.on('end', _ => resolve());
|
||||
stream.on('error', err => reject(err));
|
||||
});
|
||||
}
|
||||
|
||||
export type PromiseTask = () => Promise<void>;
|
||||
export function taskSeries(...tasks: PromiseTask[]): () => Promise<void> {
|
||||
return async () => {
|
||||
for (let i = 0; i < tasks.length; i++) {
|
||||
await tasks[i]();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function getVersion(root: string): string | undefined {
|
||||
let version = process.env['BUILD_SOURCEVERSION'];
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ gulp.task('watch-client', ['clean-client'], compilation.watchTask('out', false))
|
|||
// Full compile, including nls and inline sources in sourcemaps, for build
|
||||
gulp.task('clean-client-build', util.rimraf('out-build'));
|
||||
gulp.task('compile-client-build', ['clean-client-build'], compilation.compileTask('src', 'out-build', true));
|
||||
gulp.task('watch-client-build', ['clean-client-build'], compilation.watchTask('out-build', true));
|
||||
|
||||
// Default
|
||||
gulp.task('default', ['compile']);
|
||||
|
@ -32,7 +31,6 @@ gulp.task('watch', [/* 'monaco-typecheck-watch', */ 'watch-client', 'watch-exten
|
|||
|
||||
// All Build
|
||||
gulp.task('compile-build', ['compile-client-build', 'compile-extensions-build']);
|
||||
gulp.task('watch-build', ['watch-client-build', 'watch-extensions-build']);
|
||||
|
||||
process.on('unhandledRejection', (reason, p) => {
|
||||
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
|
||||
|
|
Loading…
Reference in a new issue