-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrelease.js
79 lines (67 loc) · 1.84 KB
/
release.js
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
import { exec } from 'node:child_process'
import {
readFileSync,
writeFileSync,
} from 'node:fs'
import { createRequire } from 'node:module'
import process from 'node:process'
const require = createRequire(import.meta.url)
const PluginInfo = require('./plugin.json')
const {
version,
} = PluginInfo
let [major, minor, patch] = version.split('.').map(Number)
const args = process.argv.slice(2)
const mode = args.find((arg) => arg.startsWith('--mode='))?.split('=')[1] || 'patch'
const isManual = mode === 'manual'
console.log(`Update mode: ${mode}`)
switch (mode) {
case 'manual':
break
case 'major':
major++
minor = 0
patch = 0
break
case 'minor':
minor++
patch = 0
break
case 'patch':
patch++
break
default:
console.log()
console.error('\x1B[31m%s\x1B[0m', `Invalid [mode] arg. Use major, minor, or patch`)
console.log()
process.exit(1)
}
const newVersion = `${major}.${minor}.${patch}`
PluginInfo.version = newVersion
if (isManual) {
console.log(`Ready to release => v${newVersion}`)
} else {
console.log(`Ready to release: v${version} => v${newVersion}`)
const content = readFileSync('./plugin.json', 'utf8')
const updated = content.replace(
/"version"\s*:\s*"[^"]+"/,
`"version": "${newVersion}"`,
)
writeFileSync('./plugin.json', updated, 'utf8')
}
exec(
`git add ./plugin.json && git commit -m "chore: update version to ${newVersion}" && git push && git tag v${newVersion}`,
(err, stdout) => {
if (err) {
console.error('\x1B[31m%s\x1B[0m', 'Error:', err)
process.exit(1)
}
exec(`git push origin v${newVersion}`, (err) => {
if (err) {
console.error('\x1B[31m%s\x1B[0m', 'Error pushing tag:', err)
process.exit(1)
}
console.log('\x1B[32m%s\x1B[0m', `✨ Version ${newVersion} released successfully`)
})
},
)