2022-12-09 23:18:35 -05:00
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
const argv = process.argv.slice(2);
|
|
|
|
|
2022-12-15 00:30:43 -05:00
|
|
|
async function rewrite(filename) {
|
|
|
|
const content = fs.readFileSync(filename, 'utf8').split('\n');
|
2022-12-09 23:18:35 -05:00
|
|
|
const startRe = /<!-- download start -->/;
|
|
|
|
const endRe = /<!-- download end -->/;
|
|
|
|
|
|
|
|
let flag = false;
|
|
|
|
for (let i = 0; i < content.length; i++) {
|
|
|
|
if (startRe.test(content[i])) {
|
|
|
|
flag = true;
|
|
|
|
}
|
|
|
|
if (flag) {
|
2023-01-15 03:21:34 -05:00
|
|
|
if (!/winget install --id=lencx.ChatGPT -e --version/.test(content[i])) {
|
|
|
|
content[i] = content[i].replace(/(\d+).(\d+).(\d+)/g, argv[0]);
|
|
|
|
}
|
2022-12-09 23:18:35 -05:00
|
|
|
}
|
|
|
|
if (endRe.test(content[i])) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-15 00:30:43 -05:00
|
|
|
fs.writeFileSync(filename, content.join('\n'), 'utf8');
|
|
|
|
}
|
|
|
|
|
|
|
|
async function init() {
|
|
|
|
rewrite('README.md');
|
2022-12-17 04:39:10 -05:00
|
|
|
rewrite('README-ZH_CN.md');
|
2022-12-09 23:18:35 -05:00
|
|
|
}
|
|
|
|
|
2022-12-09 23:20:40 -05:00
|
|
|
init().catch(console.error);
|