-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
74 lines (69 loc) · 2.15 KB
/
build.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const chalk = require('chalk');
const { spawn } = require('child_process');
const fs = require('fs-extra');
const path = require('path');
const firstCmd = './node_modules/.bin/rimraf lib';
const secondCmd = './node_modules/.bin/babel src --copy-files --extensions .es6,.es,.jsx,js --out-dir lib';
start();
async function start() {
// 1. clear
await runClear();
// 2. 启动服务/构建
await runServer();
}
// async function runClear() {
// console.log(chalk.blue(`执行clear命令 start`));
// await (function () {
// return new Promise(function (resolve) {
// console.log(chalk.blue(`执行clear命令 ing`));
// rimraf('./lib', function () {
// resolve();
// })
// });
// })();
// console.log(chalk.blue(`执行clear命令 end`));
// successLog();
// }
async function runClear() {
console.log(chalk.blue(`执行clear命令 start`));
await doCommand(firstCmd);
console.log(chalk.blue(`执行clear命令 end`));
successLog();
}
async function runServer() {
await doCommand(secondCmd);
}
/**
*
* @param sign //0 本地 1 测试 2 发布http 3 发布https
* @param message //控制台打印信息
* @returns {Promise}
*/
function doCommand(commanddStr) {
const promiseInstance = new Promise(function (resolve) {
const ls = spawn(commanddStr, [],
{
shell: true
}
);
ls.stdout.on('data', (data) => {
console.log(chalk.green(`${data}`));
});
ls.stderr.on('data', (data) => {
console.log(`错误:${data}`);
});
ls.on('close', (code) => {
resolve();
});
})
return promiseInstance;
}
// twBase打包程序 end
function successLog() {
console.log(chalk.yellow('\n---------------------------------------'))
console.log(chalk.yellow('---------------------------------------'))
console.log(chalk.yellow('------------- 服务配置完成 ---------- '))
console.log(chalk.yellow('---------------------------------------'))
console.log(chalk.yellow('---------------------------------------\n'))
console.log(chalk.blue(`即将执行命令:./node_modules/.bin/babel src --copy-files --source-maps --extensions .es6,.es,.jsx,js --out-dir lib\n`))
}