-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwin-update.js
56 lines (47 loc) · 1.34 KB
/
win-update.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
const {
createReadStream,
createWriteStream,
unlinkSync,
renameSync
} = require('node:fs');
const path = require('node:path');
const readline = require('readline');
const pkg = require('./package.json');
const APP_VERSION = JSON.stringify(pkg.version);
const FILENAME = 'winx64-installer.iss';
const inputPath = path.normalize(`./${FILENAME}`);
const outputPath = path.normalize(`./${FILENAME}.lock`);
const readStream = createReadStream(inputPath);
const writeStream = createWriteStream(outputPath);
const lineReader = readline.createInterface({
input: readStream,
output: writeStream,
crlfDelay: Infinity
});
lineReader.on('line', line => {
if (line.includes('#define MyAppVersion')) {
const updatedLine = line.replace(/"(.*?)"/g, `${APP_VERSION}`);
writeStream.write(updatedLine + '\n');
} else {
writeStream.write(line + '\n');
}
});
lineReader.on('close', () => {
lineReader.close();
readStream.close();
writeStream.close();
});
writeStream.on('close', () => {
try {
unlinkSync(inputPath);
} catch (error) {
console.error(`Error occurred while trying to delete: ${inputPath}. Error: `, error);
process.exit(-1);
}
try {
renameSync(outputPath, inputPath);
} catch (error) {
console.error(`Error occurred while trying to rename: ${outputPath}. Error: `, error);
process.exit(-1);
}
});