forked from tryforge/ForgeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit.ts
More file actions
54 lines (41 loc) · 1.54 KB
/
commit.ts
File metadata and controls
54 lines (41 loc) · 1.54 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
import { execSync } from "child_process"
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs"
import { argv, stdin, stdout } from "process"
import { createInterface } from "readline"
import prompt from "./functions/prompt"
import { join } from "path"
const path = "./metadata"
if (!existsSync(path)) mkdirSync(path)
const version = require("../package.json").version
async function main() {
let skip = false
const msg = (await prompt("Please write the commit message: ")).replace(
/(--?(\w+))/gim, (match) => {
const name = /(\w+)/.exec(match)![1].toLowerCase()
switch (name) {
case "hide": {
skip = true
break
}
default: {
throw new Error(`--${name} is not a valid flag.`)
}
}
return ""
}
).trim()
const fileName = join(path, "changelogs.json")
const json: Record<string, string[]> = existsSync(fileName) ? JSON.parse(readFileSync(fileName, "utf-8")) : {}
json[version] ??= []
if (!skip) {
json[version].unshift(msg)
writeFileSync(fileName, JSON.stringify(json), "utf-8")
}
const branch = await prompt("Write the branch name to push to (defaults to dev): ") || "dev"
const escapedMsg = msg.replace(/\$/g, "\\$")
execSync("git branch -M " + branch + " && git add . && git commit -m \"" + escapedMsg + "\" && git push -u origin " + branch, {
stdio: "inherit"
})
}
// Nothing
main()