-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-version.js
More file actions
53 lines (44 loc) · 1.73 KB
/
update-version.js
File metadata and controls
53 lines (44 loc) · 1.73 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
/**
* Version Synchronization Script
* Reads version.json and updates:
* - package.json
* - android/app/build.gradle (if exists)
* - Adds build date
*/
const fs = require('fs');
const path = require('path');
// Read version.json (source of truth)
const versionFile = path.join(__dirname, 'version.json');
const versionData = JSON.parse(fs.readFileSync(versionFile, 'utf8'));
// Update build date
versionData.buildDate = new Date().toISOString().split('T')[0];
fs.writeFileSync(versionFile, JSON.stringify(versionData, null, 2) + '\n');
console.log(`✅ version.json updated: v${versionData.version} (build ${versionData.buildDate})`);
// Update package.json
const packageFile = path.join(__dirname, 'package.json');
if (fs.existsSync(packageFile)) {
const packageData = JSON.parse(fs.readFileSync(packageFile, 'utf8'));
packageData.version = versionData.version;
fs.writeFileSync(packageFile, JSON.stringify(packageData, null, 2) + '\n');
console.log(`✅ package.json updated: v${versionData.version}`);
}
// Update Android build.gradle (if exists)
const gradleFile = path.join(__dirname, 'android', 'app', 'build.gradle');
if (fs.existsSync(gradleFile)) {
let gradle = fs.readFileSync(gradleFile, 'utf8');
// Update versionCode
gradle = gradle.replace(
/versionCode\s+\d+/,
`versionCode ${versionData.versionCode}`
);
// Update versionName
gradle = gradle.replace(
/versionName\s+"[^"]+"/,
`versionName "${versionData.version}"`
);
fs.writeFileSync(gradleFile, gradle);
console.log(`✅ build.gradle updated: v${versionData.version} (code ${versionData.versionCode})`);
} else {
console.log('ℹ️ android/app/build.gradle not found (skip)');
}
console.log('\n✅ Version synchronization complete!');