Skip to content

Commit 7d38cdc

Browse files
committed
Render more task names
1 parent 0a61bab commit 7d38cdc

5 files changed

Lines changed: 73 additions & 42 deletions

File tree

build/gulpfile.extensions.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,26 +100,30 @@ const tasks = compilations.map(function (tsconfigFile) {
100100

101101
const srcOpts = { cwd: path.dirname(__dirname), base: srcBase };
102102

103-
const cleanTask = () => util.primraf(out);
103+
const cleanTask = util.rimraf(out);
104104

105-
const compileTask = util.task.series(cleanTask, () => {
105+
const compileTask_ = () => {
106106
const pipeline = createPipeline(false, true);
107107
const input = gulp.src(src, srcOpts);
108108

109109
return input
110110
.pipe(pipeline())
111111
.pipe(gulp.dest(out));
112-
});
112+
};
113+
compileTask_.displayName = `compile-extension-${name}`;
114+
const compileTask = util.task.series(cleanTask, compileTask_);
113115

114-
const watchTask = util.task.series(cleanTask, () => {
116+
const watchTask_ = () => {
115117
const pipeline = createPipeline(false);
116118
const input = gulp.src(src, srcOpts);
117119
const watchInput = watcher(src, srcOpts);
118120

119121
return watchInput
120122
.pipe(util.incremental(pipeline, input))
121123
.pipe(gulp.dest(out));
122-
});
124+
};
125+
watchTask_.displayName = `watch-extension-${name}`;
126+
const watchTask = util.task.series(cleanTask, watchTask_);
123127

124128
const compileBuildTask = util.task.series(cleanTask, () => {
125129
const pipeline = createPipeline(true, true);

build/lib/compilation.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const typesDts = [
7878
'!node_modules/@types/uglify-js/**/*',
7979
];
8080
function compileTask(src, out, build) {
81-
return function () {
81+
const result = function () {
8282
const compile = createCompile(src, build, true);
8383
const srcPipe = es.merge(gulp.src(`${src}/**`, { base: `${src}` }), gulp.src(typesDts));
8484
let generator = new MonacoGenerator(false);
@@ -90,10 +90,12 @@ function compileTask(src, out, build) {
9090
.pipe(compile())
9191
.pipe(gulp.dest(out));
9292
};
93+
result.displayName = `compile-task-${out}${build ? '-build' : ''}`;
94+
return result;
9395
}
9496
exports.compileTask = compileTask;
9597
function watchTask(out, build) {
96-
return function () {
98+
const result = function () {
9799
const compile = createCompile('src', build);
98100
const src = es.merge(gulp.src('src/**', { base: 'src' }), gulp.src(typesDts));
99101
const watchSrc = watch('src/**', { base: 'src' });
@@ -104,6 +106,8 @@ function watchTask(out, build) {
104106
.pipe(util.incremental(compile, src, true))
105107
.pipe(gulp.dest(out));
106108
};
109+
result.displayName = `watch-task-${out}${build ? '-build' : ''}`;
110+
return result;
107111
}
108112
exports.watchTask = watchTask;
109113
const REPO_SRC_FOLDER = path.join(__dirname, '../../src');

build/lib/compilation.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const typesDts = [
9090

9191
export function compileTask(src: string, out: string, build: boolean): () => NodeJS.ReadWriteStream {
9292

93-
return function () {
93+
const result = function () {
9494
const compile = createCompile(src, build, true);
9595

9696
const srcPipe = es.merge(
@@ -108,11 +108,13 @@ export function compileTask(src: string, out: string, build: boolean): () => Nod
108108
.pipe(compile())
109109
.pipe(gulp.dest(out));
110110
};
111+
result.displayName = `compile-task-${out}${build ? '-build' : ''}`;
112+
return result;
111113
}
112114

113115
export function watchTask(out: string, build: boolean): () => NodeJS.ReadWriteStream {
114116

115-
return function () {
117+
const result = function () {
116118
const compile = createCompile('src', build);
117119

118120
const src = es.merge(
@@ -129,6 +131,8 @@ export function watchTask(out: string, build: boolean): () => NodeJS.ReadWriteSt
129131
.pipe(util.incremental(compile, src, true))
130132
.pipe(gulp.dest(out));
131133
};
134+
result.displayName = `watch-task-${out}${build ? '-build' : ''}`;
135+
return result;
132136
}
133137

134138
const REPO_SRC_FOLDER = path.join(__dirname, '../../src');

build/lib/util.js

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const fs = require("fs");
1414
const _rimraf = require("rimraf");
1515
const git = require("./git");
1616
const VinylFile = require("vinyl");
17+
const fancyLog = require("fancy-log");
18+
const ansiColors = require("ansi-colors");
1719
const NoCancellationToken = { isCancellationRequested: () => false };
1820
function incremental(streamProvider, initial, supportsCancellation) {
1921
const input = es.through();
@@ -180,24 +182,10 @@ function rimraf(dir) {
180182
return cb(err);
181183
});
182184
};
183-
return cb => retry(cb);
185+
retry.displayName = `clean-${path.basename(dir)}`;
186+
return retry;
184187
}
185188
exports.rimraf = rimraf;
186-
/**
187-
* Like rimraf (with 5 retries), but with a promise instead of a callback.
188-
*/
189-
function primraf(dir) {
190-
const fn = rimraf(dir);
191-
return new Promise((resolve, reject) => {
192-
fn((err) => {
193-
if (err) {
194-
return reject(err);
195-
}
196-
resolve();
197-
});
198-
});
199-
}
200-
exports.primraf = primraf;
201189
var task;
202190
(function (task_1) {
203191
function _isPromise(p) {
@@ -206,7 +194,28 @@ var task;
206194
}
207195
return false;
208196
}
197+
function _renderTime(time) {
198+
if (time < 1000) {
199+
return `${time.toFixed(2)} ms`;
200+
}
201+
let seconds = time / 1000;
202+
if (seconds < 60) {
203+
return `${seconds.toFixed(1)} s`;
204+
}
205+
let minutes = Math.floor(seconds / 60);
206+
seconds -= minutes * 60;
207+
return `${minutes} m and ${seconds} s`;
208+
}
209209
async function _execute(task) {
210+
const name = task.displayName || task.name || `<anonymous>`;
211+
fancyLog('Starting', ansiColors.cyan(name), '...');
212+
const startTime = process.hrtime();
213+
await _doExecute(task);
214+
const elapsedArr = process.hrtime(startTime);
215+
const elapsedNanoseconds = (elapsedArr[0] * 1e9 + elapsedArr[1]);
216+
fancyLog(`Finished`, ansiColors.cyan(name), 'after', ansiColors.green(_renderTime(elapsedNanoseconds / 1e6)));
217+
}
218+
async function _doExecute(task) {
210219
// Always invoke as if it were a callback task
211220
return new Promise((resolve, reject) => {
212221
if (task.length === 1) {

build/lib/util.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import * as git from './git';
1717
import * as VinylFile from 'vinyl';
1818
import { ThroughStream } from 'through';
1919
import * as sm from 'source-map';
20+
import * as fancyLog from 'fancy-log';
21+
import * as ansiColors from 'ansi-colors';
2022

2123
export interface ICancellationToken {
2224
isCancellationRequested(): boolean;
@@ -233,23 +235,8 @@ export function rimraf(dir: string): (cb: any) => void {
233235
return cb(err);
234236
});
235237
};
236-
237-
return cb => retry(cb);
238-
}
239-
240-
/**
241-
* Like rimraf (with 5 retries), but with a promise instead of a callback.
242-
*/
243-
export function primraf(dir: string): Promise<void> {
244-
const fn = rimraf(dir);
245-
return new Promise((resolve, reject) => {
246-
fn((err: any) => {
247-
if (err) {
248-
return reject(err);
249-
}
250-
resolve();
251-
});
252-
});
238+
retry.displayName = `clean-${path.basename(dir)}`;
239+
return retry;
253240
}
254241

255242
export type PromiseTask = () => Promise<void>;
@@ -266,7 +253,30 @@ export namespace task {
266253
return false;
267254
}
268255

256+
function _renderTime(time: number): string {
257+
if (time < 1000) {
258+
return `${time.toFixed(2)} ms`;
259+
}
260+
let seconds = time / 1000;
261+
if (seconds < 60) {
262+
return `${seconds.toFixed(1)} s`;
263+
}
264+
let minutes = Math.floor(seconds / 60);
265+
seconds -= minutes * 60;
266+
return `${minutes} m and ${seconds} s`;
267+
}
268+
269269
async function _execute(task: Task): Promise<void> {
270+
const name = (<any>task).displayName || task.name || `<anonymous>`;
271+
fancyLog('Starting', ansiColors.cyan(name), '...');
272+
const startTime = process.hrtime();
273+
await _doExecute(task);
274+
const elapsedArr = process.hrtime(startTime);
275+
const elapsedNanoseconds = (elapsedArr[0] * 1e9 + elapsedArr[1]);
276+
fancyLog(`Finished`, ansiColors.cyan(name), 'after', ansiColors.green(_renderTime(elapsedNanoseconds / 1e6)));
277+
}
278+
279+
async function _doExecute(task: Task): Promise<void> {
270280
// Always invoke as if it were a callback task
271281
return new Promise((resolve, reject) => {
272282
if (task.length === 1) {

0 commit comments

Comments
 (0)