-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbump-version.js
More file actions
31 lines (25 loc) · 1.17 KB
/
bump-version.js
File metadata and controls
31 lines (25 loc) · 1.17 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
const fs = require('fs');
const version = require('./package.json').version;
const iOSVersionFilePath = 'ios/Constants.m';
const androidVersionFilePath = 'android/src/main/java/com/letscooee/utils/Constants.java';
console.log(`updating to [${version}]`);
const newVersionCode = parseInt(version.split('.').map(v => v.padStart(2, '0')).join(''));
/**************** Write New Version in Constant.java & Constant.swift ***************/
bumpVersion(iOSVersionFilePath);
bumpVersion(androidVersionFilePath);
/**************** End Write New Version in pubspec.yaml ***************/
/**
* Access file at given path and write VERSION_NAME & VERSION_CODE
*
* @param path {string} path of the file
*/
function bumpVersion(path) {
let cooeeMetaData = fs.readFileSync(path, "utf8");
if (path.includes('android')) {
cooeeMetaData = cooeeMetaData.replace(/VERSION_NAME = "[^"]+"/, `VERSION_NAME = "${version}"`);
} else {
cooeeMetaData = cooeeMetaData.replace(/VERSION_NAME = @"[^"]+"/, `VERSION_NAME = @"${version}"`);
}
cooeeMetaData = cooeeMetaData.replace(/VERSION_CODE = [^;]+/, `VERSION_CODE = ${newVersionCode}`);
fs.writeFileSync(path, cooeeMetaData);
}