-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (26 loc) · 861 Bytes
/
index.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
const fs = require('fs');
const path = require('path');
const readline = require('readline');
const filePath = path.join(__dirname, './source/main.json');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Please input cdn domain (start with http | https): ', (replaceUrl) => {
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error('read file content error: ', err);
return;
}
const replacedData = data.replace(/\.\//g, `${replaceUrl}`);
const outputPath = path.join(__dirname, './dist/main.json');
// 将替换后的数据写回文件
fs.writeFile(outputPath, replacedData, 'utf8', (err) => {
if (err) {
console.error('write file content error', err);
return;
}
console.log('task finished!');
});
});
});