-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathbump-version.cjs
57 lines (48 loc) · 1.63 KB
/
bump-version.cjs
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
#!/usr/bin/env node
const fs = require('fs').promises
const path = require('path')
// Replace the ESM import with CommonJS require
const packageJson = require('./package.json')
const OLD_VERSION = packageJson.version
async function updateVersion() {
// Check if version argument is provided
const newVersion = process.argv[2]
if (!newVersion) {
console.error('Please provide a version number as argument')
console.error('Usage: node bump-version.js VERSION')
process.exit(1)
}
// Function to update file if it exists
async function updateFile(filename, searchPattern, replacement) {
try {
const filePath = path.join(process.cwd(), filename)
const fileContent = await fs.readFile(filePath, 'utf8')
// Create the replacement pattern based on the file type
const updatedContent = fileContent.replace(searchPattern(OLD_VERSION), replacement(newVersion))
await fs.writeFile(filePath, updatedContent)
console.log(`Updated ${filename} version to ${newVersion}`)
} catch (error) {
if (error.code === 'ENOENT') {
console.log(`Warning: ${filename} not found`)
} else {
console.error(`Error updating ${filename}:`, error.message)
}
}
}
await updateFile(
'package.json',
oldVer => `"version": "${oldVer}"`,
newVer => `"version": "${newVer}"`
)
await updateFile(
'src-tauri/tauri.conf.json',
oldVer => `"version": "${oldVer}"`,
newVer => `"version": "${newVer}"`
)
await updateFile(
'src-tauri/Cargo.toml',
oldVer => `version = "${oldVer}"`,
newVer => `version = "${newVer}"`
)
}
updateVersion().catch(console.error)