UNPKG

948 BJavaScriptView Raw
1'use strict';
2const { debugWrapper } = require('@midwayjs/debugger');
3const cliFun = async argv => {
4 require('source-map-support/register');
5 const { CLI, checkUpdate, findNpm } = require('../dist');
6 if (!argv.npm) {
7 argv.npm = findNpm(argv).cmd;
8 }
9 // 检查更新
10 checkUpdate(argv.npm);
11 const cli = new CLI(argv);
12 cli
13 .start()
14 .then(() => {
15 process.exit();
16 })
17 .catch(e => {
18 console.log('\n\n\n');
19 console.log(
20 'Error! You can try adding the -V parameter for more information output.'
21 );
22 console.log('\n\n\n');
23 console.error(e);
24 process.exitCode = 1;
25 process.exit(1);
26 });
27};
28
29const cli = argv => {
30 const isDebug = argv.debug;
31 delete argv.debug;
32 debugWrapper({
33 file: __filename, // 要包裹的方法所在文件
34 export: 'cliFun', // 要包裹的方法的方法名
35 debug: isDebug,
36 })(argv);
37};
38
39module.exports = {
40 cliFun,
41 cli,
42};