-
Notifications
You must be signed in to change notification settings - Fork 0
/
android-property-updater.js
40 lines (29 loc) · 1.22 KB
/
android-property-updater.js
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
const fs = require('fs');
const path = require('path');
const findModuleBuildGradle= require('./build-gradle-search');
function updateAndroidBuildFileProperty(versionCode, versionName) {
const filePath = findModuleBuildGradle(path.join(process.cwd(), 'android'));
// Read the file line by line
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err);
return;
}
var updatedFileContent = data;
if(versionCode){
updatedFileContent = updatedFileContent.replace(/versionCode\s+\d+/, `versionCode ${versionCode}`);
}
if(versionName){
updatedFileContent = updatedFileContent.replace(/versionName\s+"[^"]*"/, `versionName "${versionName}"`);
}
// Write the updated content back to the file
fs.writeFile(filePath, updatedFileContent, 'utf8', (err) => {
if (err) {
console.error('Error writing to file:', err);
return;
}
console.log(`File ${filePath} updated successfully -versionCode=${versionCode}, versionName=${versionName}`);
});
});
}
module.exports = updateAndroidBuildFileProperty