vue-vben-admin/build/jsc.js

53 lines
1.1 KiB
JavaScript
Raw Normal View History

// js调用cli 兼容调用ts
2020-10-14 22:57:52 +08:00
// const { sh } = require('tasksfile');
const { argv } = require('yargs');
2020-10-14 22:57:52 +08:00
const execa = require('execa');
let command = ``;
Object.keys(argv).forEach((key) => {
if (!/^\$/.test(key) && key !== '_') {
// @ts-ignore
if (argv[key]) {
command += `--${key} `;
}
}
});
// 执行任务名称
let taskList = argv._;
let NODE_ENV = process.env.NODE_ENV || 'development';
if (taskList.includes('build') || taskList.includes('report') || taskList.includes('preview')) {
NODE_ENV = 'production';
}
if (taskList && Array.isArray(taskList) && taskList.length) {
2020-10-14 22:57:52 +08:00
execa(
'cross-env',
[
`NODE_ENV=${NODE_ENV}`,
'ts-node',
'--project',
'./build/tsconfig.json',
'./build/script/cli.ts',
taskList.join(' '),
command,
],
{
2020-10-14 22:57:52 +08:00
stdio: 'inherit',
}
);
2020-10-14 22:57:52 +08:00
// sh(
// `cross-env NODE_ENV=${NODE_ENV} ts-node --project ./build/tsconfig.json ./build/script/cli.ts ${taskList.join(
// ' '
// )} ${command}`,
// {
// async: true,
// nopipe: true,
// }
// );
}