ant-design-vue/antd-tools/cli/run.js
2021-10-07 22:13:56 +08:00

53 lines
1.1 KiB
JavaScript

#!/usr/bin/env node
/* eslint-disable no-console */
'use strict';
require('colorful').colorful();
require('colorful').isatty = true;
const gulp = require('gulp');
const program = require('commander');
program.option('-c --npm-tag <type>', 'add --npm-tag=xxx');
program.on('--help', () => {
console.log(' Usage:'.to.bold.blue.color);
console.log();
});
program.parse(process.argv);
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);
}
}
const task = program.args[0];
if (!task) {
program.help();
} else {
console.log('antd-tools run', task);
require('../gulpfile');
runTask(task);
}