task.js 791 B

12345678910111213141516171819202122232425
  1. /**
  2. * React Static Boilerplate
  3. * https://github.com/koistya/react-static-boilerplate
  4. *
  5. * Copyright © 2015-2016 Konstantin Tarkus (@koistya)
  6. *
  7. * This source code is licensed under the MIT license found in the
  8. * LICENSE.txt file in the root directory of this source tree.
  9. */
  10. function format(time) {
  11. return time.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1')
  12. }
  13. function task(name, action) {
  14. const start = new Date()
  15. console.log(`[${format(start)}] Starting '${name}'...`)
  16. return Promise.resolve(action instanceof Function ? action() : action).then(() => {
  17. const end = new Date()
  18. const time = end.getTime() - start.getTime()
  19. console.log(`[${format(end)}] Finished '${name}' after ${time}ms`)
  20. }, err => console.error(err.stack))
  21. }
  22. module.exports = task