Skip to content

Commit f32fc2a

Browse files
authored
Millora de la sincronització automàtica de versions natives a partir de package.json (#206)
evitarà errors en el futur en el versionat
1 parent b27554a commit f32fc2a

4 files changed

Lines changed: 34 additions & 174 deletions

File tree

ios/App/App.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,12 @@
366366
buildSettings = {
367367
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
368368
CODE_SIGN_STYLE = Automatic;
369-
CURRENT_PROJECT_VERSION = 1;
369+
CURRENT_PROJECT_VERSION = 3002003;
370370
DEVELOPMENT_TEAM = 43J99XDH3E;
371371
INFOPLIST_FILE = App/Info.plist;
372372
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
373373
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
374-
MARKETING_VERSION = 1.0;
374+
MARKETING_VERSION = 3.2.3;
375375
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
376376
PRODUCT_BUNDLE_IDENTIFIER = cat.icgc.catofflinev3;
377377
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -387,12 +387,12 @@
387387
buildSettings = {
388388
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
389389
CODE_SIGN_STYLE = Automatic;
390-
CURRENT_PROJECT_VERSION = 1;
390+
CURRENT_PROJECT_VERSION = 3002003;
391391
DEVELOPMENT_TEAM = 43J99XDH3E;
392392
INFOPLIST_FILE = App/Info.plist;
393393
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
394394
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
395-
MARKETING_VERSION = 1.0;
395+
MARKETING_VERSION = 3.2.3;
396396
PRODUCT_BUNDLE_IDENTIFIER = cat.icgc.catofflinev3;
397397
PRODUCT_NAME = "$(TARGET_NAME)";
398398
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "";

package-lock.json

Lines changed: 0 additions & 165 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@
88
"start": "webpack serve --env dev --host=0.0.0.0",
99
"start:android": "LIVE_RELOAD_IP=`ip route get 1 | awk '{print $(NF-2);exit}'` capacitor run android",
1010
"start:ios": "LIVE_RELOAD_IP=`ipconfig getifaddr en1` capacitor run ios",
11+
"postversion": "node scripts/set-native-version.mjs",
1112
"build": "npm test && webpack --env prod",
12-
"build:android": "npm run build && capacitor sync && capacitor open android",
13-
"build:ios": "npm run build && capacitor sync && capacitor open ios",
13+
"cap:build": "node scripts/set-native-version.mjs && npm run build && capacitor sync",
14+
"build:android": "npm run cap:build && capacitor open android",
15+
"build:ios": "npm run cap:build && capacitor open ios",
1416
"deploy": "npm run build && gh-pages -d dist",
1517
"storybook": "storybook dev -p 6006",
1618
"storybook:build": "storybook build",
1719
"lint": "npm run lint:js && npm run lint:i18n",
1820
"lint:js": "eslint src",
1921
"lint:i18n": "eslint --fix --format node_modules/eslint-plugin-i18n-json/formatter.js src/i18n/*.json",
20-
"prepare": "husky",
21-
"capacitor:copy:before": "capacitor-sync-version"
22+
"prepare": "husky"
2223
},
2324
"repository": {
2425
"type": "git",
@@ -75,7 +76,6 @@
7576
"@typescript-eslint/eslint-plugin": "^8.8.0",
7677
"@typescript-eslint/parser": "^8.8.0",
7778
"babel-loader": "^9.2.1",
78-
"capacitor-sync-version": "^1.0.6",
7979
"chai": "^5.1.1",
8080
"copy-webpack-plugin": "^12.0.2",
8181
"css-loader": "^7.1.2",

scripts/set-native-version.mjs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {readFileSync, writeFileSync} from 'node:fs';
2+
import {dirname, resolve} from 'node:path';
3+
import {fileURLToPath} from 'node:url';
4+
5+
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
6+
7+
const {version} = JSON.parse(readFileSync(resolve(root, 'package.json'), 'utf8'));
8+
const [major, minor, patch] = version.split('.').map(Number);
9+
const buildNumber = (major * 1_000_000) + (minor * 1_000) + patch;
10+
11+
console.log(`Setting version ${version} (build ${buildNumber})`);
12+
13+
// iOS: project.pbxproj
14+
const pbxprojPath = resolve(root, 'ios/App/App.xcodeproj/project.pbxproj');
15+
const pbxproj = readFileSync(pbxprojPath, 'utf8')
16+
.replace(/MARKETING_VERSION = .+;/g, `MARKETING_VERSION = ${version};`)
17+
.replace(/CURRENT_PROJECT_VERSION = .+;/g, `CURRENT_PROJECT_VERSION = ${buildNumber};`);
18+
writeFileSync(pbxprojPath, pbxproj);
19+
20+
// Android: app.properties
21+
const appPropertiesPath = resolve(root, 'android/app/app.properties');
22+
const appProperties = readFileSync(appPropertiesPath, 'utf8')
23+
.replace(/versionCode=\d+/, `versionCode=${buildNumber}`)
24+
.replace(/versionName=.+/, `versionName=${version}`);
25+
writeFileSync(appPropertiesPath, appProperties);

0 commit comments

Comments
 (0)