This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
forked from ringcentral/slate
-
Notifications
You must be signed in to change notification settings - Fork 28
/
increment_version.js
128 lines (112 loc) · 3.2 KB
/
increment_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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const fs = require('fs');
const path = require("path");
const commandLineArgs = process.argv.slice(2);
const langSettings = {
ruby: {
path: '../client_libraries/ruby-asana',
replacements: [
{
file: "lib/asana/version.rb",
regex: "{{version}}"
}
]
},
node: {
path: '../client_libraries/node-asana',
replacements: [
{
file: "package.json",
regex: "\"asana\",\n \"version\": \"{{version}}\""
},
{
file: "package-lock.json",
regex: "\"asana\",\n \"version\": \"{{version}}\""
}
]
},
php: {
path: '../client_libraries/php-asana',
replacements: [
{
file: "README.md",
regex: "\"asana\/asana\": \"\^{{version}}\""
}
]
},
java: {
path: '../client_libraries/java-asana',
replacements: [
{
file: "pom.xml",
regex: "<version>{{version}}<\/version><\!--lib_version-->"
},
{
file: "README.md",
regex: "<version>{{version}}</version>"
}
]
},
python: {
path: '../client_libraries/python-asana',
replacements: [
{
file: "asana/version.py",
regex: "{{version}}"
}
]
}
};
let promises = [];
for (let i = 0; i < commandLineArgs.length; i++) {
promises.push(new Promise((resolve, reject) => {
fs.readFile(path.resolve(__dirname, langSettings[commandLineArgs[i]].path + '/VERSION'), 'utf8', function (err, data) {
if (err) {
return console.log('Unable to read: ' + err);
}
data = data.trim();
let prevVersion = data;
let versionParts = data.split(".");
versionParts[versionParts.length - 1] = parseInt(versionParts[versionParts.length - 1]) + 1;
let nextVersion = versionParts.join('.');
fs.writeFile(path.resolve(__dirname, langSettings[commandLineArgs[i]].path + '/VERSION'), nextVersion, function (err) {
if (err) {
return console.log('Unable to write: ' + err);
}
incrementVersion(commandLineArgs[i], prevVersion, nextVersion, resolve);
});
});
}));
}
Promise.all(promises).then(() => {
console.log("All Done!");
});
function incrementVersion(lang, prevVersion, nextVersion, callback) {
let promises = [];
let replacements = langSettings[lang].replacements;
for (let i = 0; i < replacements.length; i++) {
promises.push(new Promise((resolve, reject) => {
let filepath = langSettings[lang].path + '/' + replacements[i].file;
fs.readFile(path.resolve(__dirname, filepath), 'utf8', function (err, data) {
if (err) {
console.log("Failed to read: " + err);
}
console.log(data);
let newData = data.replace(
replacements[i].regex.replace("{{version}}", prevVersion),
replacements[i].regex.replace("{{version}}", nextVersion)
);
console.log(newData);
fs.writeFile(path.resolve(__dirname, filepath), newData, function (err) {
if (err) {
console.log("Failed to write: " + err);
}
resolve();
});
});
}));
}
Promise.all(promises).then((values) => {
console.log("Completed incrementing: " + lang);
callback();
});
}