-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion-bump.js
More file actions
55 lines (46 loc) · 1.44 KB
/
Copy pathversion-bump.js
File metadata and controls
55 lines (46 loc) · 1.44 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
54
55
import fs from 'fs';
import commandLineArgs from 'command-line-args';
const optionDefinitions = [{ name: 'type', alias: 't', type: String }]; // major, minor, patch
const options = commandLineArgs(optionDefinitions);
if (!options.type) {
console.log('No symantic versioning type supplied: --type');
process.exit(1);
}
const increaseVersion = () => {
let parts = currentVersion.split('.');
switch (options.type) {
case 'major':
parts[0] = parseInt(parts[0]) + 1;
break;
case 'minor':
parts[1] = parseInt(parts[1]) + 1;
break;
case 'patch':
parts[2] = parseInt(parts[2]) + 1;
break;
}
return parts.join('.');
};
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8')),
currentVersion = pkg.version,
newVersion = increaseVersion();
if (currentVersion == newVersion) {
process.exit(1);
}
// package.json
pkg.version = newVersion;
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 4), {
encoding: 'utf8',
});
// version.ts
let ts = fs.readFileSync('./src/lib/version.ts', 'utf8');
ts = ts.replace(`'${currentVersion}'`, `'${newVersion}'`);
fs.writeFileSync('./src/lib/version.ts', ts, {
encoding: 'utf8',
});
// README.md
let rm = fs.readFileSync('./README.md', 'utf8');
rm = rm.replace(`version-${currentVersion}`, `version-${newVersion}`);
fs.writeFileSync('./README.md', rm, {
encoding: 'utf8',
});