forked from kriasoft/react-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.js
47 lines (41 loc) · 1.27 KB
/
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* React Starter Kit (https://www.reactstarterkit.com/)
*
* Copyright © 2014-present Kriasoft, LLC. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
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.info(
`[${format(start)}] Starting '${task.name}${
options ? ` (${options})` : ''
}'...`,
);
return task(options).then(resolution => {
const end = new Date();
const time = end.getTime() - start.getTime();
console.info(
`[${format(end)}] Finished '${task.name}${
options ? ` (${options})` : ''
}' after ${time} ms`,
);
return resolution;
});
}
if (require.main === module && process.argv.length > 2) {
// eslint-disable-next-line no-underscore-dangle
delete require.cache[__filename];
// eslint-disable-next-line global-require, import/no-dynamic-require
const module = require(`./${process.argv[2]}.js`).default;
run(module).catch(err => {
console.error(err.stack);
process.exit(1);
});
}
export default run;