forked from mxx1111/mdlook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbump-desktop-version.mjs
More file actions
65 lines (53 loc) · 1.83 KB
/
Copy pathbump-desktop-version.mjs
File metadata and controls
65 lines (53 loc) · 1.83 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
import fs from 'node:fs'
import path from 'node:path'
import process from 'node:process'
const root = path.resolve(import.meta.dirname, '..')
const tauriConfigPath = path.join(root, 'apps/web/src-tauri/tauri.conf.json')
const cargoTomlPath = path.join(root, 'apps/web/src-tauri/Cargo.toml')
const cargoLockPath = path.join(root, 'apps/web/src-tauri/Cargo.lock')
function read(file) {
return fs.readFileSync(file, 'utf8')
}
function write(file, content) {
fs.writeFileSync(file, content)
}
function parseVersion(version) {
const match = version.match(/^(\d+)\.(\d+)\.(\d+)$/)
if (!match)
throw new Error(`Unsupported version format: ${version}`)
return match.slice(1).map(Number)
}
function nextVersion(current, bump) {
if (/^\d+\.\d+\.\d+$/.test(bump))
return bump
const [major, minor, patch] = parseVersion(current)
switch (bump) {
case 'major':
return `${major + 1}.0.0`
case 'minor':
return `${major}.${minor + 1}.0`
case 'patch':
return `${major}.${minor}.${patch + 1}`
default:
throw new Error(`Usage: node scripts/bump-desktop-version.mjs [patch|minor|major|x.y.z]`)
}
}
function updateCargoLock(content, version) {
return content.replace(
/(\[\[package\]\]\nname = "mdlook"\nversion = ")([^"]+)(")/,
`$1${version}$3`,
)
}
const bump = process.argv[2] ?? 'patch'
const tauriConfig = JSON.parse(read(tauriConfigPath))
const current = tauriConfig.version
const version = nextVersion(current, bump)
tauriConfig.version = version
write(`${tauriConfigPath}`, `${JSON.stringify(tauriConfig, null, 2)}\n`)
write(
cargoTomlPath,
read(cargoTomlPath).replace(/^version = "([^"]+)"/m, `version = "${version}"`),
)
if (fs.existsSync(cargoLockPath))
write(cargoLockPath, updateCargoLock(read(cargoLockPath), version))
console.log(`mdlook desktop version: ${current} -> ${version}`)