forked from Pax1601/DCSOlympus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
increase_version.js
73 lines (62 loc) · 2.38 KB
/
increase_version.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const path = require("path");
const fs = require("fs");
let files = [];
const revision = require('child_process').execSync('git rev-parse --short HEAD').toString().trim();
function throughDirectory(directory) {
fs.readdirSync(directory).forEach(file => {
const absolute = path.join(directory, file);
if (!file.includes("increase_version.js") && !file.includes("node_modules")) {
if (fs.statSync(absolute).isDirectory())
{
return throughDirectory(absolute);
}
else {
return files.push(absolute);
}
}
});
}
fs.readFile("./version.json", "utf8", (error, data) => {
if (error) {
console.log(error);
return;
}
const versionJSON = JSON.parse(data);
var version = versionJSON["version"];
console.log(`Setting version number to ${version}`);
version = version.replace("v", "");
var arr = version.split(".");
const major = arr[0];
const minor = arr[1];
const minorminor = arr[2];
throughDirectory(".");
files.forEach((file) => {
fs.readFile(file, 'utf8', function (err,data) {
var fileChanged = false;
if (err) {
return console.log(err);
}
if (data.search(/{{OLYMPUS_VERSION_NUMBER}}/g) >= 0) {
console.log(`Replacing version in ${file}`);
data = data.replace(/{{OLYMPUS_VERSION_NUMBER}}/g, `v${major}.${minor}.${minorminor}`);
data = data.replace(/{{OLYMPUS_COMMIT_HASH}}/g, revision);
fileChanged = true;
}
if (data.search(/{{OLYMPUS_VS_VERSION_NUMBER_1}}/g) >= 0) {
console.log(`Replacing version in ${file}`);
var data = data.replace(/{{OLYMPUS_VS_VERSION_NUMBER_1}}/g, `${major},${minor},${minorminor}`);
fileChanged = true;
}
if (data.search(/{{OLYMPUS_VS_VERSION_NUMBER_2}}/g) >= 0) {
console.log(`Replacing version in ${file}`);
data = data.replace(/{{OLYMPUS_VS_VERSION_NUMBER_2}}/g, `${major}.${minor}.${minorminor}`);
fileChanged = true;
}
if (fileChanged) {
fs.writeFile(file, data, 'utf8', (err) => {
if (err) return console.log(err);
});
}
});
});
});