run.js 999 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * React Starter Kit (https://www.reactstarterkit.com/)
  3. *
  4. * Copyright © 2014-2016 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. function format(time) {
  10. return time.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1');
  11. }
  12. function run(fn, options) {
  13. const task = typeof fn.default === 'undefined' ? fn : fn.default;
  14. const start = new Date();
  15. console.log(`[${format(start)}] Starting '${task.name}'...`);
  16. return task(options).then(() => {
  17. const end = new Date();
  18. const time = end.getTime() - start.getTime();
  19. console.log(`[${format(end)}] Finished '${task.name}' after ${time} ms`);
  20. });
  21. }
  22. if (process.mainModule.children.length === 0 && process.argv.length > 2) {
  23. delete require.cache[__filename];
  24. const module = require(`./${process.argv[2]}.js`).default;
  25. run(module).catch(err => console.error(err.stack));
  26. }
  27. export default run;