-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSetVersionNumber.js
82 lines (70 loc) · 2.29 KB
/
SetVersionNumber.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
"use strict";
var USAGE =
"Updates or queries the version number embedded in this solution.\n" +
"\n" +
"Usage: node SetVersionNumber.js <new-version>\n" +
" or: node SetVersionNumber.js -q | --query\n" +
"\n" +
"Options:\n" +
" -q, --query display current versions without making any changes\n" +
" <new-version> a four-component version number to set, e.g. 1.2.3.4";
var fs = require('fs');
var Path = require('path');
var AppRoot = __dirname;
function updateVersionNumberInFile(newVersion, fileRelPath, regexps) {
console.log("%s", fileRelPath);
var filePath = Path.join(AppRoot, fileRelPath);
var originalContent = fs.readFileSync(filePath, 'utf8');
var newContent = originalContent;
regexps.forEach(function(regexp) {
newContent = newContent.replace(regexp, function(original, prefix, oldVersion, suffix) {
if (newVersion != null) {
if (newVersion == oldVersion) {
console.log(" * %s", oldVersion);
return original;
} else {
console.log(" * %s ==> %s", oldVersion, newVersion);
return prefix + newVersion + suffix;
}
} else {
console.log(" * %s", oldVersion);
return original;
}
});
});
if (newContent != originalContent) {
console.log(" * file updated");
fs.writeFileSync(filePath, newContent);
}
}
function updateVersionNumber(newVersion) {
updateVersionNumberInFile(newVersion, "LiveReload.csproj", [
/(<ApplicationVersion>)(\d+\.\d+\.\d+\.\d+)(<\/ApplicationVersion>)/
]);
updateVersionNumberInFile(newVersion, "Properties/AssemblyInfo.cs", [
/(assembly: AssemblyVersion\(")(\d+\.\d+\.\d+\.\d+)("\))/,
/(assembly: AssemblyFileVersion\(")(\d+\.\d+\.\d+\.\d+)("\))/
]);
}
function usage() {
process.exit(0)
}
function main(args) {
if (args.indexOf('--help') >= 0) {
console.log(USAGE);
return;
}
if (args.length != 1) {
console.error("** Exactly one argument required. Run with --help for usage.");
process.exit(1);
}
var newVersion = args.shift();
if (newVersion == "-q" || newVersion == "--query") {
newVersion = null;
} else if (!newVersion.match(/^\d+\.\d+\.\d+\.\d+$/)) {
console.error("** Incorrect <new-version> specified: %s; it must have exactly 4 numeric components. Run with --help for usage.", newVersion);
process.exit(1);
}
updateVersionNumber(newVersion);
}
main(process.argv.slice(2));