|
1 | 1 | import fs from 'fs'; |
2 | 2 | import path from 'path'; |
3 | 3 | import { fileURLToPath } from 'url'; |
4 | | -import { execSync } from 'child_process'; |
5 | 4 |
|
6 | 5 | const __filename = fileURLToPath(import.meta.url); |
7 | 6 | const __dirname = path.dirname(__filename); |
8 | 7 |
|
9 | | -// Get commits since last mobile version bump |
10 | | -function getCommitsSinceLastMobileBump() { |
11 | | - try { |
12 | | - // Find the last commit that changed mobile package.json version |
13 | | - // This is typically a "chore(mobile): bump mobile app version" commit |
14 | | - const lastBumpCommit = execSync( |
15 | | - 'git log -1 --format=%H --grep="chore(mobile): bump mobile app version" -- apps/mobile/v1/package.json', |
16 | | - { encoding: 'utf8' } |
17 | | - ).trim(); |
| 8 | +/** |
| 9 | + * Unified Versioning Script for Mobile App |
| 10 | + * |
| 11 | + * This script syncs the mobile app version to match the main app version. |
| 12 | + * Both main and mobile use the SAME version number for simplicity. |
| 13 | + * |
| 14 | + * Usage: Called by semantic-release with the new version as argument |
| 15 | + */ |
18 | 16 |
|
19 | | - if (lastBumpCommit) { |
20 | | - // Get commits since that bump commit |
21 | | - const commits = execSync( |
22 | | - `git log ${lastBumpCommit}..HEAD --pretty=format:"%s"`, |
23 | | - { encoding: 'utf8' } |
24 | | - ); |
25 | | - return commits.split('\n').filter(Boolean); |
26 | | - } |
| 17 | +const version = process.argv[2]; |
27 | 18 |
|
28 | | - // If no bump commit found, just get the last commit |
29 | | - const lastCommit = execSync('git log -1 --pretty=format:"%s"', { encoding: 'utf8' }); |
30 | | - return lastCommit ? [lastCommit] : []; |
31 | | - } catch (error) { |
32 | | - // Fallback to last commit |
33 | | - try { |
34 | | - const lastCommit = execSync('git log -1 --pretty=format:"%s"', { encoding: 'utf8' }); |
35 | | - return lastCommit ? [lastCommit] : []; |
36 | | - } catch { |
37 | | - return []; |
38 | | - } |
39 | | - } |
| 19 | +if (!version) { |
| 20 | + console.error('Version not provided'); |
| 21 | + process.exit(1); |
40 | 22 | } |
41 | 23 |
|
42 | | -// Check if there are mobile commits |
43 | | -function hasMobileCommits(commits) { |
44 | | - return commits.some(commit => commit.includes('(mobile)')); |
45 | | -} |
46 | | - |
47 | | -// Determine version bump type for mobile based on the HIGHEST priority commit |
48 | | -function getMobileVersionBump(commits) { |
49 | | - const mobileCommits = commits.filter(commit => commit.includes('(mobile)')); |
50 | | - |
51 | | - // Check for breaking changes (highest priority) |
52 | | - if (mobileCommits.some(commit => commit.includes('BREAKING CHANGE') || commit.startsWith('feat(mobile)!'))) { |
53 | | - return 'major'; |
54 | | - } |
55 | | - |
56 | | - // Check for features (medium priority) |
57 | | - if (mobileCommits.some(commit => commit.startsWith('feat(mobile)'))) { |
58 | | - return 'minor'; |
59 | | - } |
60 | | - |
61 | | - // Check for fixes (low priority) |
62 | | - if (mobileCommits.some(commit => commit.startsWith('fix(mobile)'))) { |
63 | | - return 'patch'; |
64 | | - } |
65 | | - |
66 | | - // For chore, style, refactor, etc. - still bump patch |
67 | | - if (mobileCommits.length > 0) { |
68 | | - return 'patch'; |
69 | | - } |
70 | | - |
71 | | - return null; |
72 | | -} |
73 | | - |
74 | | -// Bump version |
75 | | -function bumpVersion(version, type) { |
76 | | - const parts = version.split('.').map(Number); |
77 | | - |
78 | | - switch (type) { |
79 | | - case 'major': |
80 | | - return `${parts[0] + 1}.0.0`; |
81 | | - case 'minor': |
82 | | - return `${parts[0]}.${parts[1] + 1}.0`; |
83 | | - case 'patch': |
84 | | - return `${parts[0]}.${parts[1]}.${parts[2] + 1}`; |
85 | | - default: |
86 | | - return version; |
87 | | - } |
88 | | -} |
89 | | - |
90 | | -// Main execution |
91 | | -const commits = getCommitsSinceLastMobileBump(); |
92 | | - |
93 | | -if (!hasMobileCommits(commits)) { |
94 | | - console.log('No mobile commits found, skipping mobile version bump'); |
95 | | - process.exit(0); |
96 | | -} |
97 | | - |
98 | | -const bumpType = getMobileVersionBump(commits); |
99 | | -if (!bumpType) { |
100 | | - console.log('No mobile version bump needed'); |
101 | | - process.exit(0); |
102 | | -} |
| 24 | +console.log(`\n📱 Syncing mobile app to version ${version}...`); |
103 | 25 |
|
104 | 26 | // Update mobile app package.json |
105 | 27 | const mobilePackagePath = path.join(__dirname, '../apps/mobile/v1/package.json'); |
106 | 28 | const mobilePackage = JSON.parse(fs.readFileSync(mobilePackagePath, 'utf8')); |
107 | 29 | const oldVersion = mobilePackage.version; |
108 | | -const newVersion = bumpVersion(oldVersion, bumpType); |
109 | | -mobilePackage.version = newVersion; |
| 30 | +mobilePackage.version = version; |
110 | 31 | fs.writeFileSync(mobilePackagePath, JSON.stringify(mobilePackage, null, 2) + '\n'); |
111 | | -console.log(`Updated mobile package.json from ${oldVersion} to ${newVersion} (${bumpType})`); |
| 32 | +console.log(`✓ Updated apps/mobile/v1/package.json: ${oldVersion} → ${version}`); |
112 | 33 |
|
113 | 34 | // Update mobile app.json |
114 | 35 | const mobileAppJsonPath = path.join(__dirname, '../apps/mobile/v1/app.json'); |
115 | 36 | const mobileAppJson = JSON.parse(fs.readFileSync(mobileAppJsonPath, 'utf8')); |
116 | | -mobileAppJson.expo.version = newVersion; |
| 37 | +mobileAppJson.expo.version = version; |
117 | 38 |
|
118 | | -// Also bump build numbers for iOS and Android |
| 39 | +// Bump build numbers for iOS and Android |
119 | 40 | if (mobileAppJson.expo.ios) { |
120 | 41 | const currentBuildNumber = parseInt(mobileAppJson.expo.ios.buildNumber || '1', 10); |
121 | 42 | mobileAppJson.expo.ios.buildNumber = String(currentBuildNumber + 1); |
122 | | - console.log(`Updated iOS buildNumber to ${mobileAppJson.expo.ios.buildNumber}`); |
| 43 | + console.log(`✓ Bumped iOS buildNumber to ${mobileAppJson.expo.ios.buildNumber}`); |
123 | 44 | } |
124 | 45 |
|
125 | 46 | if (mobileAppJson.expo.android) { |
126 | 47 | const currentVersionCode = parseInt(mobileAppJson.expo.android.versionCode || 1, 10); |
127 | 48 | mobileAppJson.expo.android.versionCode = currentVersionCode + 1; |
128 | | - console.log(`Updated Android versionCode to ${mobileAppJson.expo.android.versionCode}`); |
| 49 | + console.log(`✓ Bumped Android versionCode to ${mobileAppJson.expo.android.versionCode}`); |
129 | 50 | } |
130 | 51 |
|
131 | 52 | fs.writeFileSync(mobileAppJsonPath, JSON.stringify(mobileAppJson, null, 2) + '\n'); |
132 | | -console.log(`Updated mobile app.json to version ${newVersion}`); |
| 53 | +console.log(`✓ Updated apps/mobile/v1/app.json`); |
133 | 54 |
|
134 | 55 | // Update mobile version.ts |
135 | 56 | const mobileVersionPath = path.join(__dirname, '../apps/mobile/v1/src/constants/version.ts'); |
136 | | -const mobileVersionContent = `export const APP_VERSION = '${newVersion}';\n`; |
| 57 | +const mobileVersionContent = `export const APP_VERSION = '${version}';\n`; |
137 | 58 | fs.writeFileSync(mobileVersionPath, mobileVersionContent); |
138 | | -console.log(`Updated mobile version.ts to ${newVersion}`); |
| 59 | +console.log(`✓ Updated apps/mobile/v1/src/constants/version.ts`); |
139 | 60 |
|
140 | | -console.log(`\n✅ Mobile app version bumped: ${oldVersion} → ${newVersion} (${bumpType})`); |
| 61 | +console.log(`\n✅ Mobile app synced to version ${version}`); |
| 62 | +console.log(` (Unified versioning: main and mobile always match)\n`); |
0 commit comments