-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion-change.mjs
More file actions
53 lines (45 loc) · 1.68 KB
/
version-change.mjs
File metadata and controls
53 lines (45 loc) · 1.68 KB
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
import { execSync } from 'child_process';
import { readFileSync, writeFileSync } from 'fs';
import { valid } from 'semver';
const newVersion = process.argv.find(value => value.startsWith('--new_version'));
if (!newVersion) {
throw Error('Param --new_version is missing!');
}
const targetVersion = newVersion.split('=')[1];
if (!targetVersion) {
throw Error('Param --new_version is empty!');
}
if (!valid(targetVersion)) {
throw Error('New version is invalid!')
}
// read minAppVersion from manifest.json
let manifestFile = JSON.parse(readFileSync('manifest.json', 'utf8'));
const { minAppVersion } = manifestFile;
if (!minAppVersion || minAppVersion === '') {
throw Error(`Missing minAppVersion in 'manifest.json'`);
}
// update version to target version
manifestFile.version = targetVersion;
writeFileSync('manifest.json', JSON.stringify(manifestFile, null, '\t'));
// update version in package
let packageFile = JSON.parse(readFileSync('package.json', 'utf8'));
packageFile.version = targetVersion;
writeFileSync('package.json', JSON.stringify(packageFile, null, '\t'));
// update version in package-lock
try {
execSync('npm install', { stdio: 'inherit' });
} catch (error) {
throw Error('npm installed failed: ' + error);
}
// read versions file
let versionsFile = JSON.parse(readFileSync('versions.json', 'utf8'));
let keys = Object.keys(versionsFile);
// remove existing versions with same minAppVersion
keys.forEach(key => {
if (minAppVersion === versionsFile[key]) {
delete versionsFile[key];
}
});
// update versions.json with target version and minAppVersion from manifest.json
versionsFile[targetVersion] = minAppVersion;
writeFileSync('versions.json', JSON.stringify(versionsFile, null, '\t'));