forked from tonyantony300/alt-sendme
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.js
More file actions
executable file
·83 lines (70 loc) · 1.96 KB
/
release.js
File metadata and controls
executable file
·83 lines (70 loc) · 1.96 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
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
#!/usr/bin/env node
import fs from 'node:fs'
import path from 'node:path'
import { execSync } from 'node:child_process'
import { fileURLToPath } from 'node:url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const rootPackageJsonPath = path.join(__dirname, '../package.json')
const syncVersionScript = path.join(__dirname, 'sync-version.js')
const validateVersionScript = path.join(__dirname, 'validate-version.js')
const rootPackageJson = JSON.parse(fs.readFileSync(rootPackageJsonPath, 'utf8'))
const currentVersion = rootPackageJson.version
if (!currentVersion) {
console.error('Error: No version found in package.json')
process.exit(1)
}
const versionArg = process.argv[2]
if (!versionArg) {
console.error(
'Error: Please specify version bump type (patch/minor/major) or exact version (e.g., 0.3.0)'
)
process.exit(1)
}
let newVersion
if (
versionArg === 'patch' ||
versionArg === 'minor' ||
versionArg === 'major'
) {
const [major, minor, patch] = currentVersion.split('.').map(Number)
switch (versionArg) {
case 'patch':
newVersion = `${major}.${minor}.${patch + 1}`
break
case 'minor':
newVersion = `${major}.${minor + 1}.0`
break
case 'major':
newVersion = `${major + 1}.0.0`
break
}
} else {
if (!/^\d+\.\d+\.\d+$/.test(versionArg)) {
console.error(
`Error: Invalid version format "${versionArg}". Expected format: X.Y.Z (e.g., 0.3.0)`
)
process.exit(1)
}
newVersion = versionArg
}
rootPackageJson.version = newVersion
fs.writeFileSync(
rootPackageJsonPath,
`${JSON.stringify(rootPackageJson, null, 2)}\n`
)
try {
execSync(`node "${syncVersionScript}"`, { stdio: 'inherit' })
} catch (_error) {
console.error('Failed to sync versions')
process.exit(1)
}
try {
execSync(`node "${validateVersionScript}"`, { stdio: 'inherit' })
} catch (_error) {
console.error('Version validation failed')
process.exit(1)
}
try {
execSync('git status --short', { stdio: 'inherit' })
} catch (_error) {}