run.js (1230B)
1 /** 2 * React Starter Kit (https://www.reactstarterkit.com/) 3 * 4 * Copyright © 2014-present Kriasoft, LLC. All rights reserved. 5 * 6 * This source code is licensed under the MIT license found in the 7 * LICENSE.txt file in the root directory of this source tree. 8 */ 9 10 export function format(time) { 11 return time.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1'); 12 } 13 14 function run(fn, options) { 15 const task = typeof fn.default === 'undefined' ? fn : fn.default; 16 const start = new Date(); 17 console.log( 18 `[${format(start)}] Starting '${task.name}${options ? ` (${options})` : ''}'...`, 19 ); 20 return task(options).then((resolution) => { 21 const end = new Date(); 22 const time = end.getTime() - start.getTime(); 23 console.log( 24 `[${format(end)}] Finished '${task.name}${options ? ` (${options})` : ''}' after ${time} ms`, 25 ); 26 return resolution; 27 }); 28 } 29 30 if (require.main === module && process.argv.length > 2) { 31 delete require.cache[__filename]; // eslint-disable-line no-underscore-dangle 32 const module = require(`./${process.argv[2]}.js`).default; // eslint-disable-line import/no-dynamic-require 33 run(module).catch((err) => { console.error(err.stack); process.exit(1); }); 34 } 35 36 export default run;