-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-version.js
102 lines (78 loc) · 3.84 KB
/
update-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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Script to update the version number
// Usage: node update-version.js A.B.C
"use strict";
const FS = require("fs");
const Path = require("path");
function updateFile(file, callback) {
const contents = FS.readFileSync(file).toString();
const newContents = callback(contents);
FS.writeFileSync(file, newContents);
console.log("UPDATED: " + file);
}
function main() {
const arg = process.argv[2] || "";
if (!arg) {
console.log("Usage: node update-version.js A.B.C");
return 1;
}
const parts = arg.split(".");
if (parts.length !== 3) {
console.log("Usage: node update-version.js A.B.C");
return 1;
}
const MAJOR = parseInt(parts[0], 10);
const MINOR = parseInt(parts[1], 10);
const REVISION = parseInt(parts[2], 10);
if (isNaN(MAJOR) || isNaN(MINOR) || isNaN(REVISION) || MAJOR < 0 || MINOR < 0 || REVISION < 0) {
console.log("Usage: node update-version.js A.B.C");
return 1;
}
const VERSION = MAJOR + "." + MINOR + "." + REVISION;
const DATE = (new Date()).toISOString().split("T")[0];
console.log(`Changing version to ${VERSION} | Date: ${DATE}`);
updateFile(Path.resolve(__dirname, "frontend", ".env"), contents => {
return contents
.replace(/VITE\_\_VERSION=[0-9]+\.[0-9]+\.[0-9]+/, `VITE__VERSION=${VERSION}`)
.replace(/VITE\_\_VERSION\_DATE=[0-9]+\-[0-9]+\-[0-9]+/, `VITE__VERSION_DATE=${DATE}`);
});
updateFile(Path.resolve(__dirname, "frontend", "package.json"), contents => {
return contents
.replace(/\"version\"\: \"[0-9]+\.[0-9]+\.[0-9]+\"/, `"version": "${VERSION}"`);
});
updateFile(Path.resolve(__dirname, "backend", "main.go"), contents => {
return contents
.replace(/BACKEND_VERSION = \"[0-9]+\.[0-9]+\.[0-9]+\"/, `BACKEND_VERSION = "${VERSION}"`);
});
updateFile(Path.resolve(__dirname, "backend", "doc", "api-docs.yml"), contents => {
return contents
.replace(/version\: [0-9]+\.[0-9]+\.[0-9]+/, `version: ${VERSION}`);
});
updateFile(Path.resolve(__dirname, "launcher", "main.go"), contents => {
return contents
.replace(/VERSION = \"[0-9]+\.[0-9]+\.[0-9]+\"/, `VERSION = "${VERSION}"`);
});
updateFile(Path.resolve(__dirname, "launcher", "winres", "winres.json"), contents => {
return contents
.replace(/\"version\":\s\"[0-9]+\.[0-9]+\.[0-9]+\"/, `"version": "${VERSION}"`)
.replace(/\"ProductVersion\":\s\"[0-9]+\.[0-9]+\.[0-9]+\"/, `"ProductVersion": "${VERSION}"`)
.replace(/\"file_version\":\s\"[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\"/, `"file_version": "${VERSION}.0"`)
.replace(/\"product_version\":\s\"[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\"/, `"product_version": "${VERSION}.0"`);
});
updateFile(Path.resolve(__dirname, "packages", "windows-msi", "make-wix.bat"), contents => {
return contents
.replace(/PersonalMediaVault\-[0-9]+\.[0-9]+\.[0-9]+\-x64\.msi/, `PersonalMediaVault-${VERSION}-x64.msi`)
.replace(/PersonalMediaVault\-[0-9]+\.[0-9]+\.[0-9]+\-x64\-es\.msi/, `PersonalMediaVault-${VERSION}-x64-es.msi`);
});
updateFile(Path.resolve(__dirname, "packages", "windows-msi", "Product.wxs"), contents => {
return contents
.replace(/Name=\"PersonalMediaVault\" Version=\"[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\"/, `Name="PersonalMediaVault" Version="${VERSION}.0"`);
});
updateFile(Path.resolve(__dirname, "packages", "dpkg-deb", "build.sh"), contents => {
return contents
.replace(/PMV\_VERSION\_MAJOR=[0-9]+/, `PMV_VERSION_MAJOR=${MAJOR}`)
.replace(/PMV\_VERSION\_MINOR=[0-9]+/, `PMV_VERSION_MINOR=${MINOR}`)
.replace(/PMV\_VERSION\_REVISION=[0-9]+/, `PMV_VERSION_REVISION=${REVISION}`);
});
console.log("DONE!");
}
process.exit(main() || 0);