-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.mjs
90 lines (72 loc) · 2.63 KB
/
release.mjs
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
/*
* Copyright (c) 2025 Marcos Talau <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http:www.gnu.org/licenses/>.
*/
import * as fs from "fs";
import readline from "readline";
import { execSync } from "child_process";
const JSON_SPACE = 4;
function _getAnswer(question, rl) {
const ret = new Promise(r => rl.question(question, r));
return ret;
}
async function getAnswer(question) {
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
const answer = await _getAnswer(question, rl);
rl.close();
return answer;
}
function readJSONFile(fname) {
return JSON.parse(fs.readFileSync(fname, "utf-8"));
}
function saveJSONFile(fname, data, space) {
fs.writeFileSync(fname, JSON.stringify(data, null, space) + "\n");
}
function checkUncommited() {
const out = execSync("git diff");
if (out.length !== 0) {
console.log("Please, commit changes before");
process.exit(1);
}
}
// main
checkUncommited();
let update_files = true;
const pkg = readJSONFile("package.json");
const cur_version = pkg["version"];
console.log(`Current version: ${cur_version}`);
const new_version = await getAnswer(" New version: ");
if (cur_version > new_version) {
console.log("cur_version > new_version, aborting");
process.exit(1);
} else if (cur_version == new_version) {
await getAnswer("cur_version == new_version, continue? [C-c to abort] ");
update_files = false;
}
if (update_files) {
pkg["version"] = new_version;
saveJSONFile("package.json", pkg, JSON_SPACE);
const manifest = readJSONFile("manifest.json");
manifest["version"] = new_version;
saveJSONFile("manifest.json", manifest, JSON_SPACE);
const versions = readJSONFile("versions.json");
versions[new_version] = manifest["minAppVersion"];
saveJSONFile("versions.json", versions, JSON_SPACE);
execSync("git add package.json manifest.json versions.json");
execSync(`git commit -m "release version ${new_version}"`);
}
execSync(`git tag ${new_version}`);
execSync("git push");
execSync("git push --tags");