Skip to content

Commit

Permalink
More gulp clean task simiplifications (microsoft#67863)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Feb 4, 2019
1 parent 67b30c0 commit 4676da4
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 68 deletions.
18 changes: 6 additions & 12 deletions build/gulpfile.extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,34 +106,28 @@ const tasks = compilations.map(function (tsconfigFile) {
const pipeline = createPipeline(false, true);
const input = gulp.src(src, srcOpts);

return util.streamToPromise(
input
return input
.pipe(pipeline())
.pipe(gulp.dest(out))
);
.pipe(gulp.dest(out));
});

const watchTask = util.task.series(cleanTask, () => {
const pipeline = createPipeline(false);
const input = gulp.src(src, srcOpts);
const watchInput = watcher(src, srcOpts);

return util.streamToPromise(
watchInput
return watchInput
.pipe(util.incremental(pipeline, input))
.pipe(gulp.dest(out))
);
.pipe(gulp.dest(out));
});

const compileBuildTask = util.task.series(cleanTask, () => {
const pipeline = createPipeline(true, true);
const input = gulp.src(src, srcOpts);

return util.streamToPromise(
input
return input
.pipe(pipeline())
.pipe(gulp.dest(out))
);
.pipe(gulp.dest(out));
});

// Tasks
Expand Down
37 changes: 12 additions & 25 deletions build/gulpfile.vscode.linux.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,41 +229,28 @@ function buildSnapPackage(arch) {
return shell.task(`cd ${snapBuildPath} && snapcraft build`);
}

gulp.task('clean-vscode-linux-ia32-deb', util.rimraf('.build/linux/deb/i386'));
gulp.task('clean-vscode-linux-x64-deb', util.rimraf('.build/linux/deb/amd64'));
gulp.task('clean-vscode-linux-arm-deb', util.rimraf('.build/linux/deb/armhf'));
gulp.task('clean-vscode-linux-arm64-deb', util.rimraf('.build/linux/deb/arm64'));
gulp.task('clean-vscode-linux-ia32-rpm', util.rimraf('.build/linux/rpm/i386'));
gulp.task('clean-vscode-linux-x64-rpm', util.rimraf('.build/linux/rpm/x86_64'));
gulp.task('clean-vscode-linux-arm-rpm', util.rimraf('.build/linux/rpm/armhf'));
gulp.task('clean-vscode-linux-arm64-rpm', util.rimraf('.build/linux/rpm/arm64'));
gulp.task('clean-vscode-linux-ia32-snap', util.rimraf('.build/linux/snap/x64'));
gulp.task('clean-vscode-linux-x64-snap', util.rimraf('.build/linux/snap/x64'));
gulp.task('clean-vscode-linux-arm-snap', util.rimraf('.build/linux/snap/x64'));
gulp.task('clean-vscode-linux-arm64-snap', util.rimraf('.build/linux/snap/x64'));

gulp.task('vscode-linux-ia32-prepare-deb', ['clean-vscode-linux-ia32-deb'], prepareDebPackage('ia32'));
gulp.task('vscode-linux-x64-prepare-deb', ['clean-vscode-linux-x64-deb'], prepareDebPackage('x64'));
gulp.task('vscode-linux-arm-prepare-deb', ['clean-vscode-linux-arm-deb'], prepareDebPackage('arm'));
gulp.task('vscode-linux-arm64-prepare-deb', ['clean-vscode-linux-arm64-deb'], prepareDebPackage('arm64'));
gulp.task('vscode-linux-ia32-prepare-deb', util.task.series(util.rimraf('.build/linux/deb/i386'), prepareDebPackage('ia32')));
gulp.task('vscode-linux-x64-prepare-deb', util.task.series(util.rimraf('.build/linux/deb/amd64'), prepareDebPackage('x64')));
gulp.task('vscode-linux-arm-prepare-deb', util.task.series(util.rimraf('.build/linux/deb/armhf'), prepareDebPackage('arm')));
gulp.task('vscode-linux-arm64-prepare-deb', util.task.series(util.rimraf('.build/linux/deb/arm64'), prepareDebPackage('arm64')));
gulp.task('vscode-linux-ia32-build-deb', ['vscode-linux-ia32-prepare-deb'], buildDebPackage('ia32'));
gulp.task('vscode-linux-x64-build-deb', ['vscode-linux-x64-prepare-deb'], buildDebPackage('x64'));
gulp.task('vscode-linux-arm-build-deb', ['vscode-linux-arm-prepare-deb'], buildDebPackage('arm'));
gulp.task('vscode-linux-arm64-build-deb', ['vscode-linux-arm64-prepare-deb'], buildDebPackage('arm64'));

gulp.task('vscode-linux-ia32-prepare-rpm', ['clean-vscode-linux-ia32-rpm'], prepareRpmPackage('ia32'));
gulp.task('vscode-linux-x64-prepare-rpm', ['clean-vscode-linux-x64-rpm'], prepareRpmPackage('x64'));
gulp.task('vscode-linux-arm-prepare-rpm', ['clean-vscode-linux-arm-rpm'], prepareRpmPackage('arm'));
gulp.task('vscode-linux-arm64-prepare-rpm', ['clean-vscode-linux-arm64-rpm'], prepareRpmPackage('arm64'));
gulp.task('vscode-linux-ia32-prepare-rpm', util.task.series(util.rimraf('.build/linux/rpm/i386'), prepareRpmPackage('ia32')));
gulp.task('vscode-linux-x64-prepare-rpm', util.task.series(util.rimraf('.build/linux/rpm/x86_64'), prepareRpmPackage('x64')));
gulp.task('vscode-linux-arm-prepare-rpm', util.task.series(util.rimraf('.build/linux/rpm/armhf'), prepareRpmPackage('arm')));
gulp.task('vscode-linux-arm64-prepare-rpm', util.task.series(util.rimraf('.build/linux/rpm/arm64'), prepareRpmPackage('arm64')));
gulp.task('vscode-linux-ia32-build-rpm', ['vscode-linux-ia32-prepare-rpm'], buildRpmPackage('ia32'));
gulp.task('vscode-linux-x64-build-rpm', ['vscode-linux-x64-prepare-rpm'], buildRpmPackage('x64'));
gulp.task('vscode-linux-arm-build-rpm', ['vscode-linux-arm-prepare-rpm'], buildRpmPackage('arm'));
gulp.task('vscode-linux-arm64-build-rpm', ['vscode-linux-arm64-prepare-rpm'], buildRpmPackage('arm64'));

gulp.task('vscode-linux-ia32-prepare-snap', ['clean-vscode-linux-ia32-snap'], prepareSnapPackage('ia32'));
gulp.task('vscode-linux-x64-prepare-snap', ['clean-vscode-linux-x64-snap'], prepareSnapPackage('x64'));
gulp.task('vscode-linux-arm-prepare-snap', ['clean-vscode-linux-arm-snap'], prepareSnapPackage('arm'));
gulp.task('vscode-linux-arm64-prepare-snap', ['clean-vscode-linux-arm64-snap'], prepareSnapPackage('arm64'));
gulp.task('vscode-linux-ia32-prepare-snap', util.task.series(util.rimraf('.build/linux/snap/x64'), prepareSnapPackage('ia32')));
gulp.task('vscode-linux-x64-prepare-snap', util.task.series(util.rimraf('.build/linux/snap/x64'), prepareSnapPackage('x64')));
gulp.task('vscode-linux-arm-prepare-snap', util.task.series(util.rimraf('.build/linux/snap/x64'), prepareSnapPackage('arm')));
gulp.task('vscode-linux-arm64-prepare-snap', util.task.series(util.rimraf('.build/linux/snap/x64'), prepareSnapPackage('arm64')));
gulp.task('vscode-linux-ia32-build-snap', ['vscode-linux-ia32-prepare-snap'], buildSnapPackage('ia32'));
gulp.task('vscode-linux-x64-build-snap', ['vscode-linux-x64-prepare-snap'], buildSnapPackage('x64'));
gulp.task('vscode-linux-arm-build-snap', ['vscode-linux-arm-prepare-snap'], buildSnapPackage('arm'));
Expand Down
4 changes: 2 additions & 2 deletions build/gulpfile.vscode.win32.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ function buildWin32Setup(arch, target) {
}

function defineWin32SetupTasks(arch, target) {
gulp.task(`clean-vscode-win32-${arch}-${target}-setup`, util.rimraf(setupDir(arch, target)));
gulp.task(`vscode-win32-${arch}-${target}-setup`, [`clean-vscode-win32-${arch}-${target}-setup`], buildWin32Setup(arch, target));
const cleanTask = () => util.primraf(setupDir(arch, target));
gulp.task(`vscode-win32-${arch}-${target}-setup`, util.task.series(cleanTask, buildWin32Setup(arch, target)));
}

defineWin32SetupTasks('ia32', 'system');
Expand Down
48 changes: 33 additions & 15 deletions build/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,32 +198,50 @@ function primraf(dir) {
});
}
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;
var task;
(function (task) {
(function (task_1) {
function _isPromise(p) {
if (typeof p.then === 'function') {
return true;
}
return false;
}
async function _execute(task) {
// Always invoke as if it were a callback task
return new Promise((resolve, reject) => {
const taskResult = task((err) => {
if (err) {
return reject(err);
}
resolve();
});
if (typeof taskResult === 'undefined') {
// this was a callback task
return;
}
if (_isPromise(taskResult)) {
// this was a promise returning task
taskResult.then(resolve, reject);
return;
}
taskResult.on('end', _ => resolve());
taskResult.on('error', err => reject(err));
});
}
function series(...tasks) {
return async () => {
for (let i = 0; i < tasks.length; i++) {
await tasks[i]();
await _execute(tasks[i]);
}
};
}
task.series = series;
task_1.series = series;
function parallel(...tasks) {
return async () => {
await Promise.all(tasks.map(t => t()));
await Promise.all(tasks.map(t => _execute(t)));
};
}
task.parallel = parallel;
task_1.parallel = parallel;
})(task = exports.task || (exports.task = {}));
function getVersion(root) {
let version = process.env['BUILD_SOURCEVERSION'];
Expand Down
55 changes: 41 additions & 14 deletions build/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,30 +252,57 @@ export function primraf(dir: string): Promise<void> {
});
}

/**
* 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 type StreamTask = () => NodeJS.ReadWriteStream;
export type CallbackTask = (cb: (err?: any) => void) => void;
export type Task = PromiseTask | StreamTask | CallbackTask;

export namespace task {
export function series(...tasks: PromiseTask[]): () => Promise<void> {

function _isPromise(p: Promise<void> | NodeJS.ReadWriteStream): p is Promise<void> {
if (typeof (<any>p).then === 'function') {
return true;
}
return false;
}

async function _execute(task: Task): Promise<void> {
// Always invoke as if it were a callback task
return new Promise((resolve, reject) => {
const taskResult = task((err) => {
if (err) {
return reject(err);
}
resolve();
});

if (typeof taskResult === 'undefined') {
// this was a callback task
return;
}

if (_isPromise(taskResult)) {
// this was a promise returning task
taskResult.then(resolve, reject);
return;
}

taskResult.on('end', _ => resolve());
taskResult.on('error', err => reject(err));
});
}

export function series(...tasks: Task[]): () => Promise<void> {
return async () => {
for (let i = 0; i < tasks.length; i++) {
await tasks[i]();
await _execute(tasks[i]);
}
};
}

export function parallel(...tasks: PromiseTask[]): () => Promise<void> {
export function parallel(...tasks: Task[]): () => Promise<void> {
return async () => {
await Promise.all(tasks.map(t => t()));
await Promise.all(tasks.map(t => _execute(t)));
};
}
}
Expand Down

0 comments on commit 4676da4

Please sign in to comment.