forked from toolbox-team/reddit-moderator-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.mjs
58 lines (49 loc) · 2.12 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
/* eslint-env node */
import inquirer from 'inquirer';
import fs from 'fs';
import path from 'path';
import {fileURLToPath} from 'url';
const versionNameRegex = /^[\d.]+?: "(.+?)"/;
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const chromeManifestLocation = path.resolve(__dirname, 'extension/chrome_manifest.json');
const firefoxManifestLocation = path.resolve(__dirname, 'extension/firefox_manifest.json');
const manifestContentChrome = JSON.parse(fs.readFileSync(chromeManifestLocation).toString());
const manifestContentFirefox = JSON.parse(fs.readFileSync(firefoxManifestLocation).toString());
const currentVersion = manifestContentChrome.version;
const currentVersionName = manifestContentChrome.version_name.match(versionNameRegex)[1];
console.log('\n--------');
console.log('Update version information');
console.log('--------\n');
inquirer
.prompt([
{
name: 'newVersion',
message: 'New version',
default: currentVersion,
},
{
name: 'newVersionName',
message: 'New version name',
default: currentVersionName,
},
])
.then(answers => {
if (answers.newVersion !== currentVersion || answers.newVersionName !== currentVersionName) {
console.log('Writing update version information to manifest');
manifestContentFirefox.version = answers.newVersion;
manifestContentChrome.version = answers.newVersion;
manifestContentFirefox.version_name = `${answers.newVersion}: "${answers.newVersionName}"`;
manifestContentChrome.version_name = `${answers.newVersion}: "${answers.newVersionName}"`;
fs.writeFileSync(chromeManifestLocation, JSON.stringify(manifestContentChrome, null, 4), 'utf8', err => {
if (err) {
throw err;
}
});
fs.writeFileSync(firefoxManifestLocation, JSON.stringify(manifestContentFirefox, null, 4), 'utf8', err => {
if (err) {
throw err;
}
});
}
});