-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
36 lines (31 loc) · 1.02 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
import { exec } from 'child_process';
import { readFile, writeFile } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
// 使用ncc打包index.js
exec('ncc build index.js -o dist', (err, stdout, stderr) => {
if (err) {
console.error(`构建失败: ${stderr}`);
return;
}
console.log(`构建成功: ${stdout}`);
// 读取打包后的文件
const filePath = join(__dirname, 'dist', 'index.js');
readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error(`读取文件失败: ${err}`);
return;
}
// 替换所有的\033为\x1b
const result = data.replace(/\\033/g, '\\x1b');
// 写回文件
writeFile(filePath, result, 'utf8', (err) => {
if (err) {
console.error(`写入文件失败: ${err}`);
return;
}
console.log('替换完成');
});
});
});