-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.config.js
55 lines (50 loc) · 1.78 KB
/
start.config.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
48
49
50
51
52
53
54
55
import select from '@inquirer/select';
import { execaCommand } from 'execa';
import { bold, greenBright } from 'colorette';
import { operationTypeText } from './config/utils.js';
import { projectList, buildTypeList } from './config/constant.js';
const isStart = process.env.type === 'start';
const isBuild = process.env.type === 'build';
const isPreview = process.env.type === 'preview';
const projectValue = await select({
message: `请选择要${operationTypeText()}的项目`,
choices: projectList.map((item) => ({
name: item.name,
value: item.value,
description: item.description,
disabled: item.disabled
}))
});
const currentProject = projectList.find((item) => item.value === projectValue);
const environmentList = currentProject.environmentList;
const environmentValue = await select({
message: `请选择要${operationTypeText()}的环境`,
choices: environmentList
});
let buildTypeValue = null;
if (isBuild) {
buildTypeValue = await select({
message: '请选择你要构建的类型',
choices: buildTypeList
});
}
switch (process.env.type) {
case 'start': {
const command = `pnpm -F ${projectValue} dev:${environmentValue}`;
execaCommand(command, { stdio: 'inherit' });
break;
}
case 'build':
if (buildTypeValue === 'localBuildUpgradation') {
console.log(bold(greenBright('本地构建并升级项目')));
} else if (buildTypeValue === 'serverBuildUpgradation') {
console.log(bold(greenBright('服务端构建并升级项目')));
}
break;
case 'preview': {
const buildCommand = `pnpm -F ${projectValue} build:${environmentValue}`;
await execaCommand(buildCommand, { stdio: 'inherit' });
const previewCommand = `pnpm -F ${projectValue} preview`;
execaCommand(previewCommand, { stdio: 'inherit' });
}
}