2018-04-04 10:39:21 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
'use strict';
|
2018-04-04 10:39:21 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
require('colorful').colorful();
|
2020-07-10 05:28:44 +00:00
|
|
|
require('colorful').isatty = true;
|
2019-01-12 03:33:27 +00:00
|
|
|
const gulp = require('gulp');
|
|
|
|
const program = require('commander');
|
2018-04-04 10:39:21 +00:00
|
|
|
|
|
|
|
program.on('--help', () => {
|
2021-09-25 08:51:32 +00:00
|
|
|
// eslint-disable-next-line no-console
|
2019-01-12 03:33:27 +00:00
|
|
|
console.log(' Usage:'.to.bold.blue.color);
|
2021-09-25 08:51:32 +00:00
|
|
|
// eslint-disable-next-line no-console
|
2019-01-12 03:33:27 +00:00
|
|
|
console.log();
|
|
|
|
});
|
2018-04-04 10:39:21 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
program.parse(process.argv);
|
2018-04-04 10:39:21 +00:00
|
|
|
|
2019-07-10 10:14:41 +00:00
|
|
|
function runTask(toRun) {
|
|
|
|
const metadata = { task: toRun };
|
|
|
|
// Gulp >= 4.0.0 (doesn't support events)
|
|
|
|
const taskInstance = gulp.task(toRun);
|
|
|
|
if (taskInstance === undefined) {
|
|
|
|
gulp.emit('task_not_found', metadata);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const start = process.hrtime();
|
|
|
|
gulp.emit('task_start', metadata);
|
|
|
|
try {
|
|
|
|
taskInstance.apply(gulp);
|
|
|
|
metadata.hrDuration = process.hrtime(start);
|
|
|
|
gulp.emit('task_stop', metadata);
|
|
|
|
gulp.emit('stop');
|
|
|
|
} catch (err) {
|
|
|
|
err.hrDuration = process.hrtime(start);
|
|
|
|
err.task = metadata.task;
|
|
|
|
gulp.emit('task_err', err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const task = program.args[0];
|
2018-04-04 10:39:21 +00:00
|
|
|
|
|
|
|
if (!task) {
|
2019-01-12 03:33:27 +00:00
|
|
|
program.help();
|
2018-04-04 10:39:21 +00:00
|
|
|
} else {
|
2021-09-25 08:51:32 +00:00
|
|
|
// eslint-disable-next-line no-console
|
2019-01-12 03:33:27 +00:00
|
|
|
console.log('scripts run', task);
|
2018-04-04 10:39:21 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
require('./gulpfile');
|
2018-04-04 10:39:21 +00:00
|
|
|
|
2019-07-10 10:14:41 +00:00
|
|
|
runTask(task);
|
2018-04-04 10:39:21 +00:00
|
|
|
}
|