-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathbump-version.js
More file actions
executable file
·84 lines (69 loc) · 2.53 KB
/
Copy pathbump-version.js
File metadata and controls
executable file
·84 lines (69 loc) · 2.53 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
84
#!/usr/bin/env node
import { execSync } from 'child_process'
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
// Read package.json
const packageJsonPath = path.join(__dirname, 'package.json')
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
// Get current version
const currentVersion = packageJson.version
console.log(`Current version: ${currentVersion}`)
// Parse version (assuming semver format: major.minor.patch)
const versionParts = currentVersion.split('.').map(Number)
const [major, minor, patch] = versionParts
// Bump patch version by default (can be modified to accept arguments for major/minor)
const bumpType = process.argv[2] || 'patch'
let newVersion
switch (bumpType) {
case 'major':
newVersion = `${major + 1}.0.0`
break
case 'minor':
newVersion = `${major}.${minor + 1}.0`
break
case 'patch':
default:
newVersion = `${major}.${minor}.${patch + 1}`
break
}
console.log(`New version: ${newVersion}`)
// Update package.json
packageJson.version = newVersion
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n')
console.log('✓ Updated package.json')
// Read Android build.gradle to get current versionCode
const buildGradlePath = path.join(__dirname, 'android', 'app', 'build.gradle')
let buildGradle = fs.readFileSync(buildGradlePath, 'utf8')
// Extract current versionCode
const versionCodeMatch = buildGradle.match(/versionCode\s+(\d+)/)
const currentVersionCode = versionCodeMatch ? parseInt(versionCodeMatch[1]) : 1
const newVersionCode = currentVersionCode + 1
console.log(`Android versionCode: ${currentVersionCode} → ${newVersionCode}`)
// Use capacitor-set-version to update both iOS and Android
try {
console.log('\nUpdating iOS and Android versions...')
// Set version and build number for both platforms
execSync(
`npx capacitor-set-version set -v ${newVersion} -b ${newVersionCode}`,
{
stdio: 'inherit',
},
)
console.log('\n✓ Successfully bumped version to', newVersion)
console.log(`✓ Build number: ${newVersionCode}`)
console.log('\nNext steps:')
console.log('1. Review the changes')
console.log(
'2. Commit: git add . && git commit -m "Bump version to ' +
newVersion +
'"',
)
console.log('3. Tag: git tag v' + newVersion)
console.log('4. Push: git push origin develop --tags')
} catch (error) {
console.error('Error updating versions:', error.message)
process.exit(1)
}