Skip to content

Commit f59e651

Browse files
committed
πŸ§‘β€πŸ’» Add scripts to bump versions
1 parent 127ad57 commit f59e651

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

β€Žbin/sync_config_version.jsβ€Ž

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env node
2+
// Syncs config.xml's version/versionCode with package.json's version.
3+
// Invoked automatically by `npm version <major|minor|patch>` via the "version" npm script.
4+
const fs = require('fs');
5+
const path = require('path');
6+
7+
const rootDir = path.join(__dirname, '..');
8+
const pkg = require(path.join(rootDir, 'package.json'));
9+
const configPath = path.join(rootDir, 'config.xml');
10+
11+
let config = fs.readFileSync(configPath, 'utf8');
12+
13+
const versionCodeMatch = config.match(/android-versionCode="(\d+)"/);
14+
if (!versionCodeMatch) {
15+
throw new Error('Could not find android-versionCode in config.xml');
16+
}
17+
const newVersionCode = String(Number(versionCodeMatch[1]) + 1);
18+
19+
config = config
20+
.replace(/android-versionCode="\d+"/, `android-versionCode="${newVersionCode}"`)
21+
.replace(/ios-CFBundleVersion="\d+"/, `ios-CFBundleVersion="${newVersionCode}"`)
22+
.replace(/version="[^"]+"/, `version="${pkg.version}"`);
23+
24+
fs.writeFileSync(configPath, config);
25+
console.log(`Updated config.xml to version ${pkg.version} (versionCode ${newVersionCode})`);

β€Žpackage.jsonβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"build-prod-android": "npm run export-prod && npx cordova build android",
2020
"build-prod-ios": "npm run export-prod && npx cordova build ios",
2121
"build-prod-android-release": "npm run export-prod && npx cordova build android --release",
22-
"test": "npx jest"
22+
"test": "npx jest",
23+
"version": "node bin/sync_config_version.js && git add config.xml"
2324
},
2425
"devDependencies": {
2526
"@babel/core": "^7.21.3",

0 commit comments

Comments
Β (0)