-
Notifications
You must be signed in to change notification settings - Fork 5
/
version.ts
50 lines (40 loc) 路 1.45 KB
/
version.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
import { resolve } from "https://deno.land/std@0.129.0/path/mod.ts"
import { log } from "./src/utils.ts"
const VERSION = "0.20.2"
function hasBumpFlag() {
return (
Deno.args.includes("patch") ||
Deno.args.includes("minor") ||
Deno.args.includes("major")
)
}
function getNextVersionNumber(actualVersion: string): string | undefined {
const [major, minor, patch] = actualVersion
.split(".")
.map((n) => parseInt(n, 10))
if (Deno.args.includes("patch")) {
return [major, minor, patch + 1].map((n) => n.toString()).join(".")
} else if (Deno.args.includes("minor")) {
return [major, minor + 1, 0].map((n) => n.toString()).join(".")
} else if (Deno.args.includes("major")) {
return [major + 1, 0, 0].map((n) => n.toString()).join(".")
}
}
function bumpVersion() {
const nextVersionNumber = getNextVersionNumber(VERSION) as string
const versionFileStr = Deno.readTextFileSync("./version.ts").split("\n")
const newVersionFileStr = versionFileStr
.map((line: string) => {
if (line.startsWith("const VERSION")) {
line = line.replace(VERSION, nextVersionNumber ?? VERSION)
}
return line
})
.join("\n")
Deno.writeTextFileSync("./version.ts", newVersionFileStr)
log.success(`Version bumped from ${VERSION} to ${nextVersionNumber}`)
}
// can be ran as Deno script to bump version
if (hasBumpFlag()) bumpVersion()
// can be imported as a module to display version number
export default () => VERSION