-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathbump.ts
executable file
·118 lines (106 loc) · 2.97 KB
/
bump.ts
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
import * as fs from "fs";
import * as shell from "shelljs";
import { VERSION } from "../version";
let newVersion = "";
export type SemanticTarget = "major" | "minor" | "patch";
export function bumpVersionFile(version) {
fs.writeFile(
`../version.ts`,
`export const VERSION = '${version}';`,
function (err) {
if (err) {
console.log(err);
process.exit(1);
}
console.log("Version file updated");
}
);
}
export function bumpLibPackageFile(version) {
//
// Read lib package.json
fs.readFile(
`../projects/angular-cropperjs/package.json`,
"utf8",
function (err, contents) {
//
// Parse json
const pkg = JSON.parse(contents);
// update version
pkg.version = version;
//
// Write package.json
fs.writeFile(
`../projects/angular-cropperjs/package.json`,
JSON.stringify(pkg, null, "\t"),
function (err) {
if (err) {
console.log(err);
process.exit(1);
}
console.log(`Frontoose main package updated`);
}
);
}
);
}
export function bumpMainPackageFile(version) {
//
// Read package.json
fs.readFile(`../package.json`, "utf8", function (err, contents) {
//
// Parse json
const pkg = JSON.parse(contents);
// update version
pkg.version = version;
//
// Write package.json
fs.writeFile(
`../package.json`,
JSON.stringify(pkg, null, "\t"),
function (err) {
if (err) {
console.log(err);
process.exit(1);
}
console.log(`Frontoose main package updated`);
}
);
});
}
export function bumpNumber(num: string, target: SemanticTarget) {
let major = parseFloat(num.split(".")[0]);
let minor = parseFloat(num.split(".")[1]);
let patch = parseFloat(num.split(".")[2]);
switch (target) {
case "major":
major += 1;
minor = 0;
patch = 0;
break;
case "minor":
minor += 1;
patch = 0;
break;
case "patch":
patch += 1;
break;
}
return `${major}.${minor}.${patch}`;
}
export function gitTag() {
// re-create tag due to standard-version bug
shell.exec(
`cd ../ && git tag -a v${VERSION} -m "chore(release): ${VERSION}"`
);
shell.exec(`git commit -am "chore(release): ${VERSION}"`);
}
export function bump(target: SemanticTarget = "patch") {
newVersion = bumpNumber(VERSION, target);
bumpVersionFile(newVersion);
bumpLibPackageFile(newVersion);
bumpMainPackageFile(newVersion);
}
//
// test
// console.log(bump());