1 | #!/usr/bin/env node
|
2 | 'use strict';
|
3 |
|
4 | var chalk = require('chalk');
|
5 |
|
6 | var currentNodeVersion = process.versions.node;
|
7 | var semver = currentNodeVersion.split('.');
|
8 | var major = semver[0];
|
9 |
|
10 | if (major < 4) {
|
11 | console.error(
|
12 | chalk.red(
|
13 | '您当前的node版本是 ' +
|
14 | currentNodeVersion +
|
15 | '.\n' +
|
16 | 'mk依赖>=4的版本. \n' +
|
17 | '请升级您的node版本.'
|
18 | )
|
19 | );
|
20 | process.exit(1);
|
21 | }
|
22 |
|
23 | var which = require('which'),
|
24 | flag = false
|
25 |
|
26 | try{
|
27 | const resolved = which.sync('yarn')
|
28 | if( resolved ){
|
29 | flag = true
|
30 | }
|
31 | }catch(err){
|
32 | console.log(err)
|
33 | }
|
34 | if( !flag ){
|
35 | console.log(chalk.yellowBright('mk依赖yarn,您没有安装 \n'))
|
36 | console.log(chalk.greenBright('请先安装yarn \n'))
|
37 | console.log(chalk.cyan('npm i -g yarn'))
|
38 | process.exit(1);
|
39 | }
|
40 |
|
41 | const packageJson = require('../package.json');
|
42 | const program = require('commander');
|
43 |
|
44 | program
|
45 | .version(packageJson.version)
|
46 |
|
47 | program
|
48 | .command('app <appName>')
|
49 | .action(function (...args) {
|
50 | let s = run('app', args);
|
51 | process.exit(s);
|
52 | })
|
53 |
|
54 | program
|
55 | .command('website <website>')
|
56 | .action(function (...args) {
|
57 | let s = run('website', args)
|
58 | process.exit(s);
|
59 | })
|
60 |
|
61 | program
|
62 | .command('build')
|
63 | .action(function (...args) {
|
64 | let s = run('build', args)
|
65 | s = run('build-dev', args)
|
66 | process.exit(s);
|
67 | })
|
68 |
|
69 | program
|
70 | .command('pkg')
|
71 | .action(function (...args) {
|
72 | let s = run('pkg', args);
|
73 | s = run('pkg-dev', args);
|
74 | process.exit(s);
|
75 | })
|
76 |
|
77 | program
|
78 | .command('scan')
|
79 | .action(function (...args) {
|
80 | let s = run('scan', args);
|
81 | process.exit(s);
|
82 | })
|
83 | program
|
84 | .command('copy-local-dep')
|
85 | .action(function (...args) {
|
86 | let s = run('copy-local-dep', args);
|
87 | process.exit(s);
|
88 | })
|
89 | program
|
90 | .command('start')
|
91 | .action(function (...args) {
|
92 | let s = run('start', args);
|
93 | process.exit(s);
|
94 | })
|
95 |
|
96 | program
|
97 | .command('website-start')
|
98 | .action(function (...args) {
|
99 | let s = run('website-start', args);
|
100 | process.exit(s);
|
101 | })
|
102 |
|
103 | program
|
104 | .command('website-pkg')
|
105 | .action(function (...args) {
|
106 | let s = run('website-pkg', args);
|
107 | s = run('website-pkg-dev', args);
|
108 | process.exit(s);
|
109 | })
|
110 |
|
111 | program
|
112 | .command('install')
|
113 | .action(function (...args) {
|
114 | let s = run('install', args);
|
115 | process.exit(s);
|
116 | })
|
117 |
|
118 | program
|
119 | .command('upgrade')
|
120 | .action(function (...args) {
|
121 | let s = run('upgrade', args);
|
122 | process.exit(s);
|
123 | })
|
124 |
|
125 | program
|
126 | .command('add')
|
127 | .action(function (...args) {
|
128 | let s = run('add', args);
|
129 | process.exit(s);
|
130 | })
|
131 |
|
132 | program
|
133 | .command('clone')
|
134 | .action(function (...args) {
|
135 | let s = run('clone', args);
|
136 | process.exit(s);
|
137 | })
|
138 |
|
139 | program
|
140 | .command('remove')
|
141 | .action(function (...args) {
|
142 | let s = run('remove', args);
|
143 | process.exit(s);
|
144 | })
|
145 |
|
146 | program
|
147 | .command('publish')
|
148 | .action(function (...args){
|
149 | let s = run('publish', args);
|
150 | process.exit(s);
|
151 | })
|
152 |
|
153 |
|
154 | program
|
155 | .command('adduser')
|
156 | .action(function (...args){
|
157 | let s = run('adduser', args);
|
158 | process.exit(s);
|
159 | })
|
160 |
|
161 |
|
162 | program
|
163 | .command('*')
|
164 | .action(function (env) {
|
165 | console.log('没有这个命令 "%s"', env)
|
166 | })
|
167 |
|
168 | program.parse(process.argv)
|
169 |
|
170 | function run(script, args) {
|
171 |
|
172 | if(typeof args[0] !== 'string')
|
173 | args = []
|
174 |
|
175 | if(typeof args[args.length-1] != 'string')
|
176 | args.pop()
|
177 |
|
178 | args.splice(0, 0, require.resolve('../scripts/' + script))
|
179 | const spawn = require('react-dev-utils/crossSpawn');
|
180 | const result = spawn.sync(
|
181 | 'node',
|
182 | args,
|
183 | { stdio: 'inherit' }
|
184 | );
|
185 | if (result.signal) {
|
186 | if (result.signal === 'SIGKILL') {
|
187 | console.log("构建失败,内存溢出或者进程太早退出导致,使用 kill -9 删除进程");
|
188 | } else if (result.signal === 'SIGTERM') {
|
189 | console.log('构建失败,进程太早退出,可能有人调用kill 或者killall或者系统关闭. ');
|
190 | }
|
191 | process.exit(1);
|
192 | }
|
193 | return result.status;
|
194 |
|
195 | } |
\ | No newline at end of file |