-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstart.js
47 lines (43 loc) · 1.38 KB
/
start.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* eslint-disable max-nested-callbacks */
// https://juejin.cn/post/6974171023025389576
const inquirer = require('inquirer')
const promiseExeca = import('execa')
async function run () {
const execa = await promiseExeca
inquirer.prompt([
{
type: 'rawlist',
name: 'action',
message: '选择动作-Select Action',
default: 'webpack-dev-server',
choices: ['webpack-dev-server', 'webpack build']
}
]).then((res) => {
const { action } = res
inquirer
.prompt([
{
type: 'rawlist',
name: 'strapiHost',
message: '选择strapi后端地址-Select Strapi Host',
default: 'http://localhost:1337',
choices: ['http://localhost:1337', 'https://strapi-1882446-1259550831.ap-shanghai.run.tcloudbase.com']
}
])
.then(({ strapiHost }) => {
console.log(action, strapiHost)
const actionMap = {
'webpack-dev-server': 'cross-env NODE_ENV=development webpack-dev-server --config ./scripts/config/webpack.dev.js',
'webpack build': 'cross-env NODE_ENV=production webpack --config ./scripts/config/webpack.prod.js'
}
process.env.baseUrl = strapiHost
const commands = [`${actionMap[action]}`]
commands.forEach(item => {
execa.execaCommandSync(item, {
stdio: 'inherit'
})
})
})
})
}
run()