UNPKG

tix-react-ssr

Version:

Tiket.com React Project Scripts

36 lines (26 loc) 989 B
const format = (time) => { return time.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1'); }; const 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]); run(module).catch(err => { console.error(err.stack); process.exit(1) }) } run.format = format; module.exports = run;