-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun.js
27 lines (24 loc) · 964 Bytes
/
run.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
export function format(time) {
return time.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1');
}
function run(fn, options) {
const task = typeof fn.default === 'undefined' ? fn : fn.default;
const start = new Date();
console.log(
`[${format(start)}] Starting '${task.name}${options ? ` (${options})` : ''}'...`,
);
return task(options).then((resolution) => {
const end = new Date();
const time = end.getTime() - start.getTime();
console.log(
`[${format(end)}] Finished '${task.name}${options ? ` (${options})` : ''}' after ${time} ms`,
);
return resolution;
});
}
if (require.main === module && process.argv.length > 2) {
delete require.cache[__filename]; // eslint-disable-line no-underscore-dangle
const module = require(`./${process.argv[2]}.js`).default; // eslint-disable-line import/no-dynamic-require
run(module).catch((err) => { console.error(err.stack); process.exit(1); });
}
export default run;