1 | const execa = require('execa');
|
2 | const path = require('path');
|
3 | const { checkAliInternal } = require('ice-npm-utils');
|
4 |
|
5 | function installDEF() {
|
6 | console.log('>>> Start install DEF client...');
|
7 |
|
8 | return execa
|
9 | .shell('tnpm install @ali/def-pub-client', {
|
10 | stdio: 'inherit',
|
11 | cwd: path.join(__dirname, '..'),
|
12 | })
|
13 | .then(() => Promise.resolve(true))
|
14 | .catch(() => {
|
15 | console.log('>>> install @ali/def-pub-client error \r\n');
|
16 |
|
17 | return Promise.resolve(true);
|
18 | });
|
19 | }
|
20 |
|
21 | function installStark() {
|
22 | console.log('>>> Start install stark biz generator...');
|
23 |
|
24 | return execa.shell('tnpm install @ali/stark-biz-generator', {
|
25 | stdio: 'inherit',
|
26 | cwd: path.join(__dirname, '..'),
|
27 | });
|
28 | }
|
29 |
|
30 | function checkTNPM() {
|
31 | return execa
|
32 | .shell('tnpm -v')
|
33 | .then(() => Promise.resolve(true))
|
34 | .catch(() => {
|
35 | console.log('>>> Please install tnpm by: \r\n');
|
36 | console.log('`npm install --registry=https://registry.npm.alibaba-inc.com -g tnpm` \r\n');
|
37 | console.log('>>> More infos: https://npm.alibaba-inc.com/ \r\n');
|
38 |
|
39 | return Promise.resolve(false);
|
40 | });
|
41 | }
|
42 |
|
43 | function install() {
|
44 | checkAliInternal()
|
45 | .then((isInternal) => {
|
46 | if (isInternal) {
|
47 | return checkTNPM();
|
48 | }
|
49 | })
|
50 | .then((checked) => {
|
51 | if (checked) {
|
52 | return installDEF();
|
53 | }
|
54 | })
|
55 | .then((finished) => {
|
56 | if (finished) {
|
57 | return installStark();
|
58 | }
|
59 | })
|
60 | .catch(() => {
|
61 |
|
62 | });
|
63 | }
|
64 |
|
65 | install();
|