release.js
1.45 KB
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
const fs = require('fs');
const ora = require('ora');
const path = require('path');
const { exec } = require('child_process');
const outputPath = path.resolve(__dirname, '../lib');
// 删除文件夹
const delPath = path => {
if (!path.includes(process.cwd())) {
console.log('只能操作当前项目');
throw path;
}
const info = fs.statSync(path);
if (info.isDirectory()) {
// 目录
const data = fs.readdirSync(path);
if (data.length > 0) {
data.forEach((f, i) => {
delPath(`${path}/${f}`); // 使用递归
if (i == data.length - 1) {
// 删了目录里的内容就删掉这个目录
delPath(`${path}`);
}
});
} else {
fs.rmdirSync(path); // 删除空目录
}
} else if (info.isFile()) {
fs.unlinkSync(path); // 删除文件
}
};
// 清除输出目录
if (fs.existsSync(outputPath)) {
delPath(outputPath);
}
const cmd = 'vue-cli-service build --target lib --name eagle --dest lib packages/index.js';
const spinner = ora('编译中...').start();
exec(cmd, function(error, stdout, stderr) {
if (error) {
throw error;
}
fs.readdirSync(outputPath).forEach(file => {
if (file !== 'eagle.css') {
if (file === 'eagle.umd.min.js') {
fs.renameSync(path.resolve(outputPath, file), path.resolve(outputPath, 'eagle.js'));
} else {
fs.unlinkSync(path.resolve(outputPath, file));
}
}
});
spinner.succeed('编译完成');
});