@webority/mobile-tools 0.177.0 → 0.178.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -60,6 +60,17 @@ npx mobile-tools prebuild --same-env [--platform android|ios]
60
60
  | Staging | `.staging` | `staging` |
61
61
  | Production | none | `production` |
62
62
 
63
+ ### `settings`
64
+
65
+ ```bash
66
+ npx mobile-tools settings --env <Development|Staging|Production>
67
+ npx mobile-tools settings --same-env
68
+ ```
69
+
70
+ - Writes `appsettings.Compiled.json` exactly as `prebuild` does, with the same checks and build stamp, and touches no native file. `prebuild` writes the file through the same code.
71
+ - Use it where only the app's JavaScript needs the compiled settings, such as a type check on a clean checkout.
72
+ - Fails when `appsettings.Compiled.json` is not git-ignored.
73
+
63
74
  ### `sync`
64
75
 
65
76
  ```bash
package/lib/cli.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{parseArgs}from"node:util";import{build}from"./build.js";import{cache}from"./cache.js";import{parseEnvironment}from"./config.js";import{devices}from"./devices.js";import{doctor}from"./doctor.js";import{installHooks}from"./hooks.js";import{icons}from"./icons.js";import{initKeystore}from"./keystore.js";import{restartMetro}from"./metro.js";import{CliError,fail,reportFailure,say,setJsonOutput,warn}from"./output.js";import{parseAndroidAbis}from"./platform.js";import{prebuild}from"./prebuild.js";import{run}from"./run.js";import{uploadSymbols}from"./symbols.js";import{checkSync,sync,writeStamp}from"./sync.js";import{SIMULATOR_ARCHS}from"./xos.js";const COMMAND_USAGE={prebuild:" prebuild --env <Development|Staging|Production> [--platform android|ios]\n prebuild --same-env [--platform android|ios]\n Compile appsettings into appsettings.Compiled.json and stamp the native projects.",sync:" sync [--check | --stamp]\n --check: exit 1 with the fix command when node_modules (or ios/Pods) is stale.\n --stamp: record that node_modules matches the lockfile now (run it from postinstall).\n Without either: install from the lockfile, stamp, and reset native codegen when needed.",hooks:" hooks install\n Add git post-merge and post-checkout hooks that run sync --check.",run:" run --env <Environment> [--platform android|ios] [--device <serial|name>] [--rebuild] [--profiling] [--app <path.app>]\n Build for one device's ABI (or install the cached build with the same native fingerprint), install it there, reuse or start Metro, and launch. --rebuild skips the cache.\n iOS (macOS): installs the simulator app --app names on a booted simulator, starts Metro and launches it; it never builds.\n --profiling serves production JavaScript with React's profiling renderer; a Metro serving development JavaScript must be stopped first.",build:" build --env <Environment> --artifact apk|aab|ios-sim [--debug] [--debug-signed] [--ota-test] [--arch <value>] [--json] [-- <gradle args>]\n Prebuild, then build a release APK or App Bundle (Android, every ABI unless --arch) or an iOS simulator app through xOS Tools (xos on PATH).\n --arch for ios-sim: x86_64 (the default) or arm64. For apk and aab: arm64-v8a, armeabi-v7a, x86_64 or x86, as one value or a comma list; arm64 means arm64-v8a.\n --debug builds the debug variant (apk or ios-sim only).\n --debug-signed builds a staging test apk signed with the debug keystore, named *-debugsigned.apk (apk only; not with --debug or Production).\n --ota-test suffixes the OTA runtime version with -otatest, so only this build receives an update published for it.\n Arguments after -- go to Gradle unchanged (apk and aab only), for example -- --no-daemon --max-workers=3.",devices:" devices [--platform android|ios] [--json]\n Connect local MuMu emulators, then list every ready device once (simulators for iOS).",doctor:" doctor [--platform android|ios] [--fix] [--json]\n Check the toolchain and the app tree; exit 1 while a problem remains. --fix removes a stale autolinking cache.",cache:" cache list|clear [--json]\n List or remove this app's cached builds.",metro:" metro restart\n Stop the Metro mobile-tools started for this app and start it again on the same port.",icons:" icons [--source <png|svg>]\n Render per-environment launcher icons for Android flavors and iOS AppIcon-<Env> sets.",symbols:" symbols upload --env <Environment> --dsym <path>\n Upload an iOS build's dSYM folder or zip to Firebase Crashlytics, with the app id from that environment's GoogleService-Info plist; needs the Firebase CLI.",keystore:' keystore init --out <file.jks> [--alias upload] [--dname "CN=Android Upload Key"] [--validity-days 10000]\n Create the Android upload keystore with the password from MOBILE_TOOLS_KEYSTORE_PASSWORD and print its SHA-256 for store.json.'},USAGE=`mobile-tools <command> [options] (run from the app's root folder)\n\n${Object.values(COMMAND_USAGE).join("\n\n")}`,knownCommand=e=>Object.hasOwn(COMMAND_USAGE,e),commandUsage=e=>`usage:\n${COMMAND_USAGE[e]}`,parse=(e,o,t,a=!1)=>{try{const{values:e,positionals:n}=parseArgs({args:o,options:t,allowPositionals:a,strict:!0});return{values:e,positionals:n}}catch(o){return fail("badInput",`${o instanceof Error?o.message:String(o)}\n\n${commandUsage(e)}`)}},envOption=e=>"string"==typeof e?parseEnvironment(e):void 0,platformOption=e=>{if(void 0!==e)return"android"!==e&&"ios"!==e?fail("badInput",`--platform must be android or ios, not ${String(e)}`):e},JSON_COMMANDS=new Set(["build","cache","devices","doctor"]),artifactOption=e=>"apk"===e||"aab"===e||"ios-sim"===e?e:fail("badInput","build needs --artifact apk, aab or ios-sim"),main=async e=>{const[o,...t]=e,a=process.cwd(),n=t.indexOf("--"),s=n<0?t:t.slice(0,n);if(void 0!==o&&knownCommand(o)&&(s.includes("--help")||s.includes("-h")))say(commandUsage(o));else switch(setJsonOutput(JSON_COMMANDS.has(o??"")&&s.includes("--json")),o){case"prebuild":{const{values:e}=parse(o,t,{env:{type:"string"},"same-env":{type:"boolean"},platform:{type:"string"}});return void prebuild({appRoot:a,env:envOption(e.env),sameEnv:!0===e["same-env"],platform:platformOption(e.platform)})}case"sync":{const{values:e}=parse(o,t,{check:{type:"boolean"},stamp:{type:"boolean"}});if(e.check&&e.stamp&&fail("badInput","use --check or --stamp, not both"),e.stamp)return writeStamp(a),void say("sync --stamp: recorded node_modules as matching the lockfile");if(e.check){const e=checkSync(a,process.platform);return e.length>0&&fail("installStale",e.join("\n")),void say("sync --check: node_modules matches the lockfile")}return void sync(a,process.platform)}case"hooks":{const{positionals:e}=parse(o,t,{},!0);return"install"===e[0]&&1===e.length||fail("badInput",`usage: mobile-tools hooks install\n\n${USAGE}`),void installHooks(a)}case"run":{const{values:e}=parse(o,t,{env:{type:"string"},platform:{type:"string"},device:{type:"string"},rebuild:{type:"boolean"},profiling:{type:"boolean"},app:{type:"string"}}),n=envOption(e.env)??fail("badInput","run needs --env <Development|Staging|Production>");return void await run({appRoot:a,env:n,platform:platformOption(e.platform)??"android",device:"string"==typeof e.device?e.device:void 0,rebuild:!0===e.rebuild,profiling:!0===e.profiling,app:"string"==typeof e.app?e.app:void 0})}case"build":{const e=t.indexOf("--"),n=e<0?t:t.slice(0,e),s=e<0?[]:t.slice(e+1),{values:i}=parse(o,n,{env:{type:"string"},artifact:{type:"string"},debug:{type:"boolean"},"debug-signed":{type:"boolean"},"ota-test":{type:"boolean"},json:{type:"boolean"},arch:{type:"string"}}),r=envOption(i.env)??fail("badInput","build needs --env <Development|Staging|Production>"),p=artifactOption(i.artifact);!0===i.debug&&"aab"===p&&fail("badInput","--debug builds an apk or an ios-sim app; an App Bundle is release only"),"ios-sim"===p&&s.length>0&&fail("badInput","Gradle arguments after -- apply to apk and aab builds only");const l="string"==typeof i.arch?i.arch:void 0,d="ios-sim"===p?SIMULATOR_ARCHS.find(e=>e===(l??"x86_64"))??fail("badInput","--arch must be x86_64 or arm64"):void 0,c="ios-sim"===p||void 0===l?void 0:parseAndroidAbis(l);return void await build({appRoot:a,env:r,artifact:p,debug:!0===i.debug,debugSigned:!0===i["debug-signed"],otaTest:!0===i["ota-test"],gradleArgs:s,arch:d,abis:c})}case"devices":{const{values:e}=parse(o,t,{platform:{type:"string"},json:{type:"boolean"}});return void await devices({appRoot:a,platform:platformOption(e.platform)??"android"})}case"doctor":{const{values:e}=parse(o,t,{platform:{type:"string"},fix:{type:"boolean"},json:{type:"boolean"}});return void await doctor({appRoot:a,platform:platformOption(e.platform),fix:!0===e.fix})}case"cache":{const{positionals:e}=parse(o,t,{json:{type:"boolean"}},!0),n=e[0];return 1!==e.length||"list"!==n&&"clear"!==n?fail("badInput",`usage: mobile-tools cache list|clear\n\n${USAGE}`):void await cache({appRoot:a,action:n})}case"metro":{const{positionals:e}=parse(o,t,{},!0);return"restart"===e[0]&&1===e.length||fail("badInput",`usage: mobile-tools metro restart\n\n${USAGE}`),void await restartMetro(a)}case"icons":{const{values:e}=parse(o,t,{source:{type:"string"}});return void await icons({appRoot:a,source:"string"==typeof e.source?e.source:void 0})}case"symbols":{const{values:e,positionals:n}=parse(o,t,{env:{type:"string"},dsym:{type:"string"}},!0);"upload"===n[0]&&1===n.length||fail("badInput",`usage: mobile-tools symbols upload --env <Environment> --dsym <path>\n\n${USAGE}`);const s=envOption(e.env)??fail("badInput","symbols upload needs --env <Development|Staging|Production>"),i="string"==typeof e.dsym?e.dsym:fail("badInput","symbols upload needs --dsym <path>");return void await uploadSymbols({appRoot:a,env:s,dsym:i})}case"keystore":{const{values:e,positionals:a}=parse(o,t,{out:{type:"string"},alias:{type:"string"},dname:{type:"string"},"validity-days":{type:"string"}},!0);"init"===a[0]&&1===a.length||fail("badInput",`usage: mobile-tools keystore init --out <file.jks>\n\n${USAGE}`);const n="string"==typeof e.out?e.out:fail("badInput","keystore init needs --out <file.jks>"),s="string"==typeof e["validity-days"]?e["validity-days"]:"10000";return/^[1-9][0-9]*$/.test(s)||fail("badInput",`--validity-days must be a positive whole number, not ${s}`),void await initKeystore({out:n,alias:"string"==typeof e.alias?e.alias:"upload",dname:"string"==typeof e.dname?e.dname:"CN=Android Upload Key",validityDays:Number(s)})}case"help":{const e=t[0];return void 0===e?void say(USAGE):(knownCommand(e)||fail("badInput",`unknown command "${e}"\n\n${USAGE}`),void say(commandUsage(e)))}case void 0:case"--help":case"-h":return void say(USAGE);default:fail("badInput",`unknown command "${o}"\n\n${USAGE}`)}};main(process.argv.slice(2)).catch(e=>{e instanceof CliError&&(reportFailure(e),process.exit(e.exitCode)),warn(e instanceof Error?e.stack??e.message:String(e)),process.exit(1)});
2
+ import{parseArgs}from"node:util";import{build}from"./build.js";import{cache}from"./cache.js";import{parseEnvironment}from"./config.js";import{devices}from"./devices.js";import{doctor}from"./doctor.js";import{installHooks}from"./hooks.js";import{icons}from"./icons.js";import{initKeystore}from"./keystore.js";import{restartMetro}from"./metro.js";import{CliError,fail,reportFailure,say,setJsonOutput,warn}from"./output.js";import{parseAndroidAbis}from"./platform.js";import{compileSettings,prebuild}from"./prebuild.js";import{run}from"./run.js";import{uploadSymbols}from"./symbols.js";import{checkSync,sync,writeStamp}from"./sync.js";import{SIMULATOR_ARCHS}from"./xos.js";const COMMAND_USAGE={prebuild:" prebuild --env <Development|Staging|Production> [--platform android|ios]\n prebuild --same-env [--platform android|ios]\n Compile appsettings into appsettings.Compiled.json and stamp the native projects.",settings:" settings --env <Development|Staging|Production>\n settings --same-env\n Compile appsettings into appsettings.Compiled.json only; no native file is touched.",sync:" sync [--check | --stamp]\n --check: exit 1 with the fix command when node_modules (or ios/Pods) is stale.\n --stamp: record that node_modules matches the lockfile now (run it from postinstall).\n Without either: install from the lockfile, stamp, and reset native codegen when needed.",hooks:" hooks install\n Add git post-merge and post-checkout hooks that run sync --check.",run:" run --env <Environment> [--platform android|ios] [--device <serial|name>] [--rebuild] [--profiling] [--app <path.app>]\n Build for one device's ABI (or install the cached build with the same native fingerprint), install it there, reuse or start Metro, and launch. --rebuild skips the cache.\n iOS (macOS): installs the simulator app --app names on a booted simulator, starts Metro and launches it; it never builds.\n --profiling serves production JavaScript with React's profiling renderer; a Metro serving development JavaScript must be stopped first.",build:" build --env <Environment> --artifact apk|aab|ios-sim [--debug] [--debug-signed] [--ota-test] [--arch <value>] [--json] [-- <gradle args>]\n Prebuild, then build a release APK or App Bundle (Android, every ABI unless --arch) or an iOS simulator app through xOS Tools (xos on PATH).\n --arch for ios-sim: x86_64 (the default) or arm64. For apk and aab: arm64-v8a, armeabi-v7a, x86_64 or x86, as one value or a comma list; arm64 means arm64-v8a.\n --debug builds the debug variant (apk or ios-sim only).\n --debug-signed builds a staging test apk signed with the debug keystore, named *-debugsigned.apk (apk only; not with --debug or Production).\n --ota-test suffixes the OTA runtime version with -otatest, so only this build receives an update published for it.\n Arguments after -- go to Gradle unchanged (apk and aab only), for example -- --no-daemon --max-workers=3.",devices:" devices [--platform android|ios] [--json]\n Connect local MuMu emulators, then list every ready device once (simulators for iOS).",doctor:" doctor [--platform android|ios] [--fix] [--json]\n Check the toolchain and the app tree; exit 1 while a problem remains. --fix removes a stale autolinking cache.",cache:" cache list|clear [--json]\n List or remove this app's cached builds.",metro:" metro restart\n Stop the Metro mobile-tools started for this app and start it again on the same port.",icons:" icons [--source <png|svg>]\n Render per-environment launcher icons for Android flavors and iOS AppIcon-<Env> sets.",symbols:" symbols upload --env <Environment> --dsym <path>\n Upload an iOS build's dSYM folder or zip to Firebase Crashlytics, with the app id from that environment's GoogleService-Info plist; needs the Firebase CLI.",keystore:' keystore init --out <file.jks> [--alias upload] [--dname "CN=Android Upload Key"] [--validity-days 10000]\n Create the Android upload keystore with the password from MOBILE_TOOLS_KEYSTORE_PASSWORD and print its SHA-256 for store.json.'},USAGE=`mobile-tools <command> [options] (run from the app's root folder)\n\n${Object.values(COMMAND_USAGE).join("\n\n")}`,knownCommand=e=>Object.hasOwn(COMMAND_USAGE,e),commandUsage=e=>`usage:\n${COMMAND_USAGE[e]}`,parse=(e,o,t,n=!1)=>{try{const{values:e,positionals:a}=parseArgs({args:o,options:t,allowPositionals:n,strict:!0});return{values:e,positionals:a}}catch(o){return fail("badInput",`${o instanceof Error?o.message:String(o)}\n\n${commandUsage(e)}`)}},envOption=e=>"string"==typeof e?parseEnvironment(e):void 0,platformOption=e=>{if(void 0!==e)return"android"!==e&&"ios"!==e?fail("badInput",`--platform must be android or ios, not ${String(e)}`):e},JSON_COMMANDS=new Set(["build","cache","devices","doctor"]),artifactOption=e=>"apk"===e||"aab"===e||"ios-sim"===e?e:fail("badInput","build needs --artifact apk, aab or ios-sim"),main=async e=>{const[o,...t]=e,n=process.cwd(),a=t.indexOf("--"),s=a<0?t:t.slice(0,a);if(void 0!==o&&knownCommand(o)&&(s.includes("--help")||s.includes("-h")))say(commandUsage(o));else switch(setJsonOutput(JSON_COMMANDS.has(o??"")&&s.includes("--json")),o){case"prebuild":{const{values:e}=parse(o,t,{env:{type:"string"},"same-env":{type:"boolean"},platform:{type:"string"}});return void prebuild({appRoot:n,env:envOption(e.env),sameEnv:!0===e["same-env"],platform:platformOption(e.platform)})}case"settings":{const{values:e}=parse(o,t,{env:{type:"string"},"same-env":{type:"boolean"}});return void compileSettings({appRoot:n,env:envOption(e.env),sameEnv:!0===e["same-env"]})}case"sync":{const{values:e}=parse(o,t,{check:{type:"boolean"},stamp:{type:"boolean"}});if(e.check&&e.stamp&&fail("badInput","use --check or --stamp, not both"),e.stamp)return writeStamp(n),void say("sync --stamp: recorded node_modules as matching the lockfile");if(e.check){const e=checkSync(n,process.platform);return e.length>0&&fail("installStale",e.join("\n")),void say("sync --check: node_modules matches the lockfile")}return void sync(n,process.platform)}case"hooks":{const{positionals:e}=parse(o,t,{},!0);return"install"===e[0]&&1===e.length||fail("badInput",`usage: mobile-tools hooks install\n\n${USAGE}`),void installHooks(n)}case"run":{const{values:e}=parse(o,t,{env:{type:"string"},platform:{type:"string"},device:{type:"string"},rebuild:{type:"boolean"},profiling:{type:"boolean"},app:{type:"string"}}),a=envOption(e.env)??fail("badInput","run needs --env <Development|Staging|Production>");return void await run({appRoot:n,env:a,platform:platformOption(e.platform)??"android",device:"string"==typeof e.device?e.device:void 0,rebuild:!0===e.rebuild,profiling:!0===e.profiling,app:"string"==typeof e.app?e.app:void 0})}case"build":{const e=t.indexOf("--"),a=e<0?t:t.slice(0,e),s=e<0?[]:t.slice(e+1),{values:i}=parse(o,a,{env:{type:"string"},artifact:{type:"string"},debug:{type:"boolean"},"debug-signed":{type:"boolean"},"ota-test":{type:"boolean"},json:{type:"boolean"},arch:{type:"string"}}),r=envOption(i.env)??fail("badInput","build needs --env <Development|Staging|Production>"),p=artifactOption(i.artifact);!0===i.debug&&"aab"===p&&fail("badInput","--debug builds an apk or an ios-sim app; an App Bundle is release only"),"ios-sim"===p&&s.length>0&&fail("badInput","Gradle arguments after -- apply to apk and aab builds only");const l="string"==typeof i.arch?i.arch:void 0,d="ios-sim"===p?SIMULATOR_ARCHS.find(e=>e===(l??"x86_64"))??fail("badInput","--arch must be x86_64 or arm64"):void 0,c="ios-sim"===p||void 0===l?void 0:parseAndroidAbis(l);return void await build({appRoot:n,env:r,artifact:p,debug:!0===i.debug,debugSigned:!0===i["debug-signed"],otaTest:!0===i["ota-test"],gradleArgs:s,arch:d,abis:c})}case"devices":{const{values:e}=parse(o,t,{platform:{type:"string"},json:{type:"boolean"}});return void await devices({appRoot:n,platform:platformOption(e.platform)??"android"})}case"doctor":{const{values:e}=parse(o,t,{platform:{type:"string"},fix:{type:"boolean"},json:{type:"boolean"}});return void await doctor({appRoot:n,platform:platformOption(e.platform),fix:!0===e.fix})}case"cache":{const{positionals:e}=parse(o,t,{json:{type:"boolean"}},!0),a=e[0];return 1!==e.length||"list"!==a&&"clear"!==a?fail("badInput",`usage: mobile-tools cache list|clear\n\n${USAGE}`):void await cache({appRoot:n,action:a})}case"metro":{const{positionals:e}=parse(o,t,{},!0);return"restart"===e[0]&&1===e.length||fail("badInput",`usage: mobile-tools metro restart\n\n${USAGE}`),void await restartMetro(n)}case"icons":{const{values:e}=parse(o,t,{source:{type:"string"}});return void await icons({appRoot:n,source:"string"==typeof e.source?e.source:void 0})}case"symbols":{const{values:e,positionals:a}=parse(o,t,{env:{type:"string"},dsym:{type:"string"}},!0);"upload"===a[0]&&1===a.length||fail("badInput",`usage: mobile-tools symbols upload --env <Environment> --dsym <path>\n\n${USAGE}`);const s=envOption(e.env)??fail("badInput","symbols upload needs --env <Development|Staging|Production>"),i="string"==typeof e.dsym?e.dsym:fail("badInput","symbols upload needs --dsym <path>");return void await uploadSymbols({appRoot:n,env:s,dsym:i})}case"keystore":{const{values:e,positionals:n}=parse(o,t,{out:{type:"string"},alias:{type:"string"},dname:{type:"string"},"validity-days":{type:"string"}},!0);"init"===n[0]&&1===n.length||fail("badInput",`usage: mobile-tools keystore init --out <file.jks>\n\n${USAGE}`);const a="string"==typeof e.out?e.out:fail("badInput","keystore init needs --out <file.jks>"),s="string"==typeof e["validity-days"]?e["validity-days"]:"10000";return/^[1-9][0-9]*$/.test(s)||fail("badInput",`--validity-days must be a positive whole number, not ${s}`),void await initKeystore({out:a,alias:"string"==typeof e.alias?e.alias:"upload",dname:"string"==typeof e.dname?e.dname:"CN=Android Upload Key",validityDays:Number(s)})}case"help":{const e=t[0];return void 0===e?void say(USAGE):(knownCommand(e)||fail("badInput",`unknown command "${e}"\n\n${USAGE}`),void say(commandUsage(e)))}case void 0:case"--help":case"-h":return void say(USAGE);default:fail("badInput",`unknown command "${o}"\n\n${USAGE}`)}};main(process.argv.slice(2)).catch(e=>{e instanceof CliError&&(reportFailure(e),process.exit(e.exitCode)),warn(e instanceof Error?e.stack??e.message:String(e)),process.exit(1)});
package/lib/prebuild.d.ts CHANGED
@@ -69,5 +69,12 @@ export interface PrebuildOptions {
69
69
  /** Only `build --ota-test` sets it: the OTA runtime version gets the `-otatest` suffix. */
70
70
  otaTest?: boolean;
71
71
  }
72
+ export interface CompileSettingsOptions {
73
+ appRoot: string;
74
+ env?: Environment | undefined;
75
+ sameEnv?: boolean;
76
+ }
77
+ /** Compiles appsettings into appsettings.Compiled.json and writes no other file. Returns the settings it compiled. */
78
+ export declare const compileSettings: (options: CompileSettingsOptions) => AppSettings;
72
79
  /** Compiles appsettings and stamps the native layers. Returns the settings it compiled. */
73
80
  export declare const prebuild: (options: PrebuildOptions) => AppSettings;
package/lib/prebuild.js CHANGED
@@ -1 +1 @@
1
- import{copyFileSync,existsSync,mkdirSync,readFileSync,rmSync,writeFileSync}from"node:fs";import path from"node:path";import{checkAppSettings}from"./appSettingsRules.js";import{applicationId,COMPILED_FILE,ENVIRONMENTS,flavorOf,lastCompiledEnvironment,loadAppSettings,loadToolsConfig,resolveIosProjectName}from"./config.js";import{capture}from"./exec.js";import{androidOtaManifest,expoPlist,otaNativeSettings}from"./otaNative.js";import{fail,say}from"./output.js";import{findOnPath}from"./platform.js";export const IOS_COMPILED_XCCONFIG="ios/appsettings.Compiled.xcconfig";export const androidFlavorManifest=e=>`android/app/src/${flavorOf(e)}/AndroidManifest.xml`;export const expoPlistPath=e=>`ios/${e}/Supporting/Expo.plist`;export const usesExpoUpdates=e=>dependsOn(e,"expo-updates");export const generatedNativeFiles=(e,t,i,o)=>{if("android"===o)return usesExpoUpdates(e)?[androidFlavorManifest(i)]:[];const n=[IOS_COMPILED_XCCONFIG];if(void 0!==t){const o=path.join(e,loadToolsConfig(e).firebasePlistDir,`GoogleService-Info.${i}.plist`);existsSync(o)&&n.push(`ios/${t}/GoogleService-Info.plist`),usesExpoUpdates(e)&&n.push(expoPlistPath(t))}return n};export const nativeBuildInputs=(e,t)=>{const i=path.join(e,COMPILED_FILE);if(!existsSync(i))return fail("appConfigInvalid",`${COMPILED_FILE} is missing: run npx mobile-tools prebuild --env <Development|Staging|Production> first`);const o=JSON.parse(readFileSync(i,"utf8")),n=resolveIosProjectName(e,loadToolsConfig(e)),s=generatedNativeFiles(e,n,o.ENVIRONMENT,t).filter(t=>existsSync(path.join(e,t)));return[...["APP_ID","APP_NAME","VERSION_DISPLAY","VERSION_INTERNAL"].map(e=>`${e}=${JSON.stringify(o[e])}`),...s.map(t=>`${t}=${JSON.stringify(readFileSync(path.join(e,t),"utf8"))}`)].join("\n")};const requiredGroup=(e,t)=>{const i=e[t];if(void 0===i)throw new Error(`the pattern did not capture group ${t}`);return i},objectsOf=(e,t)=>[...e.matchAll(new RegExp(`\\n\\s*(\\w+)(?: /\\*([^\\n]*?)\\*/)? = \\{\\s*isa = ${t};`,"g"))].map(e=>({id:requiredGroup(e,1),name:(e[2]??"").trim()})),pbxObject=(e,t)=>{const i=new RegExp(`\\n\\s*${t}(?: /\\*[^\\n]*?\\*/)? = \\{`).exec(e);if(!i)return;let o=0;for(let t=i.index+i[0].length-1;t<e.length;t++)if(e.startsWith("/*",t)){if(t=e.indexOf("*/",t+2)+1,0===t)return}else if('"'===e[t])for(t++;t<e.length&&'"'!==e[t];t++)"\\"===e[t]&&t++;else if("{"===e[t])o++;else if("}"===e[t]&&0===--o)return e.slice(i.index,t+1)},configurationsOf=(e,t)=>[...(/buildConfigurations = \(([^)]*)\)/.exec(pbxObject(e,t)??"")?.[1]??"").matchAll(/(\w+)(?: \/\* ([^*]*?) \*\/)?,/g)].map(e=>({id:requiredGroup(e,1),name:e[2]??""})),unquote=e=>e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1).replace(/\\"/g,'"'):e,shipsInfoPlist=e=>/^com\.apple\.product-type\.(application|.*extension)/.test(e);export const shippedInfoPlists=e=>{const t=new Map,i=/\n\s*(\w+)(?: \/\*[^\n]*?\*\/)? = \{\s*isa = PBXNativeTarget;/g;for(const o of e.matchAll(i)){const i=requiredGroup(o,1),n=pbxObject(e,i)??"",s=unquote(/\sproductType = ([^;\n]*);/.exec(n)?.[1]??"");if(!shipsInfoPlist(s))continue;const r=unquote(/\sname = ([^;\n]*);/.exec(n)?.[1]??i),a=/\sbuildConfigurationList = (\w+)/.exec(n)?.[1],p=a&&pbxObject(e,a)||"",c=/buildConfigurations = \(([^)]*)\)/.exec(p)?.[1]??"";for(const i of c.matchAll(/\w+(?= \/\*|,)/g)){const o=requiredGroup(i,0),n=/\sINFOPLIST_FILE = ([^;\n]*);/.exec(pbxObject(e,o)??"")?.[1];n&&!t.has(unquote(n))&&t.set(unquote(n),r)}}return[...t].map(([e,t])=>({target:t,file:e}))};const BUILD_SETTING_KEYS=[["CFBundleIdentifier","PRODUCT_BUNDLE_IDENTIFIER"],["CFBundleShortVersionString","MARKETING_VERSION"],["CFBundleVersion","CURRENT_PROJECT_VERSION"]];export const fixedInfoPlistValues=e=>BUILD_SETTING_KEYS.flatMap(([t,i])=>{const o=new RegExp(`<key>${t}</key>\\s*(<[^>]*>)?([^<]*)`).exec(e);if(!o)return[];const n=requiredGroup(o,2),s=o[1],r="<string>"===s?n.trim():s??n.trim();return r===`$(${i})`||r===`\${${i}}`?[]:[{key:t,value:r,setting:i}]});export const checkInfoPlistReferences=(e,t)=>{const i=path.join(e,"ios"),o=readFileSync(path.join(i,`${t}.xcodeproj`,"project.pbxproj"),"utf8"),n=[{target:t,file:`${t}/Info.plist`},...shippedInfoPlists(o)],s=path.resolve(i,`${t}/Info.plist`),r=[],a=new Set;for(const{target:t,file:o}of n){const n=o.replace(/^(\$\(SRCROOT\)|\$\{SRCROOT\}|\$\(PROJECT_DIR\))\//,"");if(/\$[({]/.test(n)){r.push(`target ${t}: INFOPLIST_FILE ${o} uses a build setting prebuild cannot resolve`);continue}const p=path.resolve(i,n);if(a.has(p))continue;a.add(p);const c=path.relative(e,p).replace(/\\/g,"/");if(!existsSync(p)){r.push(`${c} not found (INFOPLIST_FILE of target ${t})`);continue}const d=readFileSync(p,"utf8");for(const{key:e,value:t,setting:i}of fixedInfoPlistValues(d))r.push(`${c}: ${e} is "${t}", must be $(${i})`);p!==s||/<key>CFBundleDisplayName<\/key>\s*<string>\$\(APP_NAME\)<\/string>/.test(d)||r.push(`${c}: CFBundleDisplayName must be $(APP_NAME), which ios/appsettings.Compiled.xcconfig sets`)}r.length>0&&fail("appConfigInvalid",`Info.plist values that ignore what prebuild writes into appsettings.Compiled.xcconfig:\n ${r.join("\n ")}`)};const XCCONFIG_BASE=/baseConfigurationReference = \w+ \/\* appsettings\.Compiled\.xcconfig \*\//,MANAGED_BUILD_SETTINGS=["PRODUCT_BUNDLE_IDENTIFIER","MARKETING_VERSION","CURRENT_PROJECT_VERSION"];export const checkPbxprojSettings=(e,t)=>{const i=[],o=objectsOf(e,"PBXProject")[0];void 0===o&&i.push("project.pbxproj has no PBXProject object to carry the base configuration");const n=o?/\sbuildConfigurationList = (\w+)/.exec(pbxObject(e,o.id)??"")?.[1]:void 0;for(const{id:t,name:o}of n?configurationsOf(e,n):[])XCCONFIG_BASE.test(pbxObject(e,t)??"")||i.push(`project configuration ${t} /* ${o} */ does not use appsettings.Compiled.xcconfig as its base configuration: set the project-level configurations' base configuration to appsettings.Compiled.xcconfig`);const s=t?[...MANAGED_BUILD_SETTINGS,"ASSETCATALOG_COMPILER_APPICON_NAME"]:MANAGED_BUILD_SETTINGS;for(const{id:t,name:o}of objectsOf(e,"XCBuildConfiguration")){const n=pbxObject(e,t)??"";for(const e of s)new RegExp(`\\s${e} = `).test(n)&&i.push(`configuration ${t} /* ${o} */ sets ${e}: remove it; ios/appsettings.Compiled.xcconfig sets it`);/\sINFOPLIST_KEY_CFBundleDisplayName = /.test(n)&&i.push(`configuration ${t} /* ${o} */ sets INFOPLIST_KEY_CFBundleDisplayName: remove it; Info.plist reads $(APP_NAME), which ios/appsettings.Compiled.xcconfig sets`)}i.length>0&&fail("appConfigInvalid",`project.pbxproj sets values that ios/appsettings.Compiled.xcconfig owns:\n ${i.join("\n ")}`)};const XCCONFIG_UNSAFE=/\/\/|[$";]/,xcconfigText=(e,t,i)=>{const o=[["APP_NAME",String(e.APP_NAME)],["PRODUCT_BUNDLE_IDENTIFIER",applicationId(String(e.APP_ID),t)],["MARKETING_VERSION",String(e.VERSION_DISPLAY)],["CURRENT_PROJECT_VERSION",String(e.VERSION_INTERNAL)],...i?[["ASSETCATALOG_COMPILER_APPICON_NAME",`AppIcon-${t}`]]:[]];for(const[e,t]of o)XCCONFIG_UNSAFE.test(t)&&fail("appConfigInvalid",`${e} must not contain // $ " or ;: it is written unquoted into ios/appsettings.Compiled.xcconfig`);return["// Written by mobile-tools prebuild from appsettings.Compiled.json for one environment. Not tracked: run prebuild to change it.",...o.map(([e,t])=>`${e} = ${t}`)].map(e=>`${e}\n`).join("")};export const buildCommit=e=>{const t=findOnPath("git",process.env,process.platform);if(!t)return"nogit";const i=capture({file:t,args:["rev-parse","--short","HEAD"]},e);if(0!==i.status)return"nogit";const o=capture({file:t,args:["status","--porcelain","--","."]},e);return 0!==o.status?fail("toolFailed",`git status failed in ${e}: ${o.stderr.trim()}`):""===o.stdout.trim()?i.stdout.trim():`${i.stdout.trim()}-dirty`};export const requireIgnored=(e,t)=>{const i=findOnPath("git",process.env,process.platform);if(!i||0!==capture({file:i,args:["rev-parse","--is-inside-work-tree"]},e).status)return;const o=t.filter(t=>{const o=capture({file:i,args:["check-ignore","-q","--",t]},e);return 0!==o.status&&1!==o.status&&fail("toolFailed",`git check-ignore failed for ${t}: ${o.stderr.trim()}`),1===o.status});o.length>0&&fail("appConfigInvalid",`add these lines to ${path.basename(e)}/.gitignore; prebuild writes them per environment:\n${o.join("\n")}`)};const writeIfChanged=(e,t)=>(!existsSync(e)||readFileSync(e,"utf8")!==t)&&(writeFileSync(e,t,"utf8"),!0),report=(e,t,i)=>{say(`prebuild: ${i?"wrote":"unchanged"} ${path.relative(e,t)}`)},dependsOn=(e,t)=>{const i=path.join(e,"package.json");if(!existsSync(i))return!1;const o=JSON.parse(readFileSync(i,"utf8"));return Boolean(o.dependencies?.[t])};export const usesFirebase=e=>dependsOn(e,"@react-native-firebase/app");export const checkNdkHook=e=>{const t=path.join(e,"android","build.gradle");if(!existsSync(t))return;const i=readFileSync(t,"utf8");/withId\(\s*["']com\.android\.library["']\s*\)/.test(i)&&/\.ndkVersion\s*=\s*rootProject\.ext\.ndkVersion/.test(i)||fail("appConfigInvalid",'android/build.gradle does not hand the app NDK to library modules; add after apply plugin "com.facebook.react.rootproject": subprojects { project -> project.plugins.withId("com.android.library") { project.android.ndkVersion = rootProject.ext.ndkVersion } }')};const MANAGED_GRADLE_KEYS=/^\s*(APP_NAME|APP_ID|VERSION_DISPLAY|VERSION_INTERNAL)\s*[=:]/gm;export const stampAndroid=(e,t,i,o,n)=>{const s=path.join(e,"android","gradle.properties");existsSync(s)||fail("appConfigInvalid",`android/gradle.properties not found in ${e}`),usesFirebase(e)&&!existsSync(path.join(e,"android","app","google-services.json"))&&fail("appConfigInvalid","android/app/google-services.json is missing; the app uses @react-native-firebase, whose Gradle plugin needs it"),checkNdkHook(e);const r=[...new Set([...readFileSync(s,"utf8").matchAll(MANAGED_GRADLE_KEYS)].map(([,e])=>e))];r.length>0&&fail("appConfigInvalid",`android/gradle.properties sets ${r.join(", ")}: remove them; android/app/build.gradle reads them from appsettings.Compiled.json`);const a=path.join(e,"android","app","build.gradle");if(existsSync(a)&&readFileSync(a,"utf8").includes("appsettings.Compiled.json")||fail("appConfigInvalid","android/app/build.gradle does not read appsettings.Compiled.json; add the compiledSettings loader (mobile-tools README, prebuild)"),usesExpoUpdates(e)){o.flavors||fail("appConfigInvalid",'expo-updates settings go into the flavor\'s manifest; set "flavors": true');const s=path.join(e,"android","app","src","main","AndroidManifest.xml");existsSync(s)||fail("appConfigInvalid","android/app/src/main/AndroidManifest.xml not found");const r=[...readFileSync(s,"utf8").matchAll(/android:name="(expo\.modules\.updates\.[^"]*)"/g)].map(([,e])=>e);r.length>0&&fail("appConfigInvalid",`android/app/src/main/AndroidManifest.xml sets ${r.join(", ")}: remove them from android/app/src/main/AndroidManifest.xml; prebuild writes them into ${androidFlavorManifest(i)}`);const a=otaNativeSettings(e,t,i,"android",n),p=path.join(e,androidFlavorManifest(i));mkdirSync(path.dirname(p),{recursive:!0}),report(e,p,writeIfChanged(p,androidOtaManifest(a)))}};export const stampIos=(e,t,i,o,n,s)=>{const r=path.join(e,"ios",n),a=path.join(r,"Info.plist"),p=path.join(e,"ios",`${n}.xcodeproj`,"project.pbxproj");for(const t of[a,p])existsSync(t)||fail("appConfigInvalid",`${path.relative(e,t)} not found: check "iosProjectName"`);checkInfoPlistReferences(e,n);const c=`AppIcon-${i}`,d=path.join(r,"Images.xcassets"),l=existsSync(path.join(d,`${c}.appiconset`)),f=ENVIRONMENTS.filter(e=>e!==i&&existsSync(path.join(d,`AppIcon-${e}.appiconset`)));!l&&f.length>0&&fail("appConfigInvalid",`ios/${n}/Images.xcassets has AppIcon-${f[0]} but no ${c}: run mobile-tools icons`),checkPbxprojSettings(readFileSync(p,"utf8"),l);const u=path.join(e,IOS_COMPILED_XCCONFIG);report(e,u,writeIfChanged(u,xcconfigText(t,i,l))),l||say(`prebuild: no AppIcon-${i} set, so ios/appsettings.Compiled.xcconfig sets no app icon name`);const g=path.join(r,"GoogleService-Info.plist"),I=path.join(e,o.firebasePlistDir,`GoogleService-Info.${i}.plist`);if(!existsSync(I)&&usesFirebase(e)&&fail("appConfigInvalid",`${path.relative(e,I)} is missing; the app uses @react-native-firebase, and an iOS build without it reports no crashes`),existsSync(I)){const t=!existsSync(g)||!readFileSync(I).equals(readFileSync(g));t&&copyFileSync(I,g),report(e,g,t)}else existsSync(g)&&(rmSync(g),say(`prebuild: removed ${path.relative(e,g)}, no ${path.relative(e,I)}`));if(usesExpoUpdates(e)){readFileSync(p,"utf8").includes("Expo.plist in Resources")||fail("appConfigInvalid","add Supporting/Expo.plist to the Xcode project's Copy Bundle Resources; prebuild writes its contents");const o=otaNativeSettings(e,t,i,"ios",s),r=path.join(e,expoPlistPath(n));mkdirSync(path.dirname(r),{recursive:!0}),report(e,r,writeIfChanged(r,expoPlist(o)))}};export const prebuild=e=>{const{appRoot:t,sameEnv:i,platform:o}=e,n=!0===e.otaTest;i&&e.env&&fail("badInput","pass --env or --same-env, not both");const s=i?lastCompiledEnvironment(t):e.env;if(!s)return fail("badInput","prebuild needs --env <Development|Staging|Production> or --same-env");const r=loadToolsConfig(t),a=resolveIosProjectName(t,r),p=loadAppSettings(t,s,r.requiredSettings);checkAppSettings(t,p,s);const c="android"===o||!o&&existsSync(path.join(t,"android")),d="android"===o?void 0:a;if("ios"===o&&void 0===d)return fail("appConfigInvalid",`no ios/ folder in ${t}`);const l=[...c?generatedNativeFiles(t,d,s,"android"):[],...void 0!==d?generatedNativeFiles(t,d,s,"ios"):[]];requireIgnored(t,[COMPILED_FILE,...l]);const f={...p,COMMIT:buildCommit(t),BUILD_TIME:(new Date).toISOString()};return writeFileSync(path.join(t,COMPILED_FILE),`${JSON.stringify(f,null,2)}\n`,"utf8"),say(`prebuild: wrote ${COMPILED_FILE} (${s}, ${f.COMMIT})`),c&&stampAndroid(t,f,s,r,n),void 0!==d&&stampIos(t,f,s,r,d,n),f};
1
+ import{copyFileSync,existsSync,mkdirSync,readFileSync,rmSync,writeFileSync}from"node:fs";import path from"node:path";import{checkAppSettings}from"./appSettingsRules.js";import{applicationId,COMPILED_FILE,ENVIRONMENTS,flavorOf,lastCompiledEnvironment,loadAppSettings,loadToolsConfig,resolveIosProjectName}from"./config.js";import{capture}from"./exec.js";import{androidOtaManifest,expoPlist,otaNativeSettings}from"./otaNative.js";import{fail,say}from"./output.js";import{findOnPath}from"./platform.js";export const IOS_COMPILED_XCCONFIG="ios/appsettings.Compiled.xcconfig";export const androidFlavorManifest=e=>`android/app/src/${flavorOf(e)}/AndroidManifest.xml`;export const expoPlistPath=e=>`ios/${e}/Supporting/Expo.plist`;export const usesExpoUpdates=e=>dependsOn(e,"expo-updates");export const generatedNativeFiles=(e,t,i,o)=>{if("android"===o)return usesExpoUpdates(e)?[androidFlavorManifest(i)]:[];const n=[IOS_COMPILED_XCCONFIG];if(void 0!==t){const o=path.join(e,loadToolsConfig(e).firebasePlistDir,`GoogleService-Info.${i}.plist`);existsSync(o)&&n.push(`ios/${t}/GoogleService-Info.plist`),usesExpoUpdates(e)&&n.push(expoPlistPath(t))}return n};export const nativeBuildInputs=(e,t)=>{const i=path.join(e,COMPILED_FILE);if(!existsSync(i))return fail("appConfigInvalid",`${COMPILED_FILE} is missing: run npx mobile-tools prebuild --env <Development|Staging|Production> first`);const o=JSON.parse(readFileSync(i,"utf8")),n=resolveIosProjectName(e,loadToolsConfig(e)),s=generatedNativeFiles(e,n,o.ENVIRONMENT,t).filter(t=>existsSync(path.join(e,t)));return[...["APP_ID","APP_NAME","VERSION_DISPLAY","VERSION_INTERNAL"].map(e=>`${e}=${JSON.stringify(o[e])}`),...s.map(t=>`${t}=${JSON.stringify(readFileSync(path.join(e,t),"utf8"))}`)].join("\n")};const requiredGroup=(e,t)=>{const i=e[t];if(void 0===i)throw new Error(`the pattern did not capture group ${t}`);return i},objectsOf=(e,t)=>[...e.matchAll(new RegExp(`\\n\\s*(\\w+)(?: /\\*([^\\n]*?)\\*/)? = \\{\\s*isa = ${t};`,"g"))].map(e=>({id:requiredGroup(e,1),name:(e[2]??"").trim()})),pbxObject=(e,t)=>{const i=new RegExp(`\\n\\s*${t}(?: /\\*[^\\n]*?\\*/)? = \\{`).exec(e);if(!i)return;let o=0;for(let t=i.index+i[0].length-1;t<e.length;t++)if(e.startsWith("/*",t)){if(t=e.indexOf("*/",t+2)+1,0===t)return}else if('"'===e[t])for(t++;t<e.length&&'"'!==e[t];t++)"\\"===e[t]&&t++;else if("{"===e[t])o++;else if("}"===e[t]&&0===--o)return e.slice(i.index,t+1)},configurationsOf=(e,t)=>[...(/buildConfigurations = \(([^)]*)\)/.exec(pbxObject(e,t)??"")?.[1]??"").matchAll(/(\w+)(?: \/\* ([^*]*?) \*\/)?,/g)].map(e=>({id:requiredGroup(e,1),name:e[2]??""})),unquote=e=>e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1).replace(/\\"/g,'"'):e,shipsInfoPlist=e=>/^com\.apple\.product-type\.(application|.*extension)/.test(e);export const shippedInfoPlists=e=>{const t=new Map,i=/\n\s*(\w+)(?: \/\*[^\n]*?\*\/)? = \{\s*isa = PBXNativeTarget;/g;for(const o of e.matchAll(i)){const i=requiredGroup(o,1),n=pbxObject(e,i)??"",s=unquote(/\sproductType = ([^;\n]*);/.exec(n)?.[1]??"");if(!shipsInfoPlist(s))continue;const r=unquote(/\sname = ([^;\n]*);/.exec(n)?.[1]??i),a=/\sbuildConfigurationList = (\w+)/.exec(n)?.[1],p=a&&pbxObject(e,a)||"",c=/buildConfigurations = \(([^)]*)\)/.exec(p)?.[1]??"";for(const i of c.matchAll(/\w+(?= \/\*|,)/g)){const o=requiredGroup(i,0),n=/\sINFOPLIST_FILE = ([^;\n]*);/.exec(pbxObject(e,o)??"")?.[1];n&&!t.has(unquote(n))&&t.set(unquote(n),r)}}return[...t].map(([e,t])=>({target:t,file:e}))};const BUILD_SETTING_KEYS=[["CFBundleIdentifier","PRODUCT_BUNDLE_IDENTIFIER"],["CFBundleShortVersionString","MARKETING_VERSION"],["CFBundleVersion","CURRENT_PROJECT_VERSION"]];export const fixedInfoPlistValues=e=>BUILD_SETTING_KEYS.flatMap(([t,i])=>{const o=new RegExp(`<key>${t}</key>\\s*(<[^>]*>)?([^<]*)`).exec(e);if(!o)return[];const n=requiredGroup(o,2),s=o[1],r="<string>"===s?n.trim():s??n.trim();return r===`$(${i})`||r===`\${${i}}`?[]:[{key:t,value:r,setting:i}]});export const checkInfoPlistReferences=(e,t)=>{const i=path.join(e,"ios"),o=readFileSync(path.join(i,`${t}.xcodeproj`,"project.pbxproj"),"utf8"),n=[{target:t,file:`${t}/Info.plist`},...shippedInfoPlists(o)],s=path.resolve(i,`${t}/Info.plist`),r=[],a=new Set;for(const{target:t,file:o}of n){const n=o.replace(/^(\$\(SRCROOT\)|\$\{SRCROOT\}|\$\(PROJECT_DIR\))\//,"");if(/\$[({]/.test(n)){r.push(`target ${t}: INFOPLIST_FILE ${o} uses a build setting prebuild cannot resolve`);continue}const p=path.resolve(i,n);if(a.has(p))continue;a.add(p);const c=path.relative(e,p).replace(/\\/g,"/");if(!existsSync(p)){r.push(`${c} not found (INFOPLIST_FILE of target ${t})`);continue}const d=readFileSync(p,"utf8");for(const{key:e,value:t,setting:i}of fixedInfoPlistValues(d))r.push(`${c}: ${e} is "${t}", must be $(${i})`);p!==s||/<key>CFBundleDisplayName<\/key>\s*<string>\$\(APP_NAME\)<\/string>/.test(d)||r.push(`${c}: CFBundleDisplayName must be $(APP_NAME), which ios/appsettings.Compiled.xcconfig sets`)}r.length>0&&fail("appConfigInvalid",`Info.plist values that ignore what prebuild writes into appsettings.Compiled.xcconfig:\n ${r.join("\n ")}`)};const XCCONFIG_BASE=/baseConfigurationReference = \w+ \/\* appsettings\.Compiled\.xcconfig \*\//,MANAGED_BUILD_SETTINGS=["PRODUCT_BUNDLE_IDENTIFIER","MARKETING_VERSION","CURRENT_PROJECT_VERSION"];export const checkPbxprojSettings=(e,t)=>{const i=[],o=objectsOf(e,"PBXProject")[0];void 0===o&&i.push("project.pbxproj has no PBXProject object to carry the base configuration");const n=o?/\sbuildConfigurationList = (\w+)/.exec(pbxObject(e,o.id)??"")?.[1]:void 0;for(const{id:t,name:o}of n?configurationsOf(e,n):[])XCCONFIG_BASE.test(pbxObject(e,t)??"")||i.push(`project configuration ${t} /* ${o} */ does not use appsettings.Compiled.xcconfig as its base configuration: set the project-level configurations' base configuration to appsettings.Compiled.xcconfig`);const s=t?[...MANAGED_BUILD_SETTINGS,"ASSETCATALOG_COMPILER_APPICON_NAME"]:MANAGED_BUILD_SETTINGS;for(const{id:t,name:o}of objectsOf(e,"XCBuildConfiguration")){const n=pbxObject(e,t)??"";for(const e of s)new RegExp(`\\s${e} = `).test(n)&&i.push(`configuration ${t} /* ${o} */ sets ${e}: remove it; ios/appsettings.Compiled.xcconfig sets it`);/\sINFOPLIST_KEY_CFBundleDisplayName = /.test(n)&&i.push(`configuration ${t} /* ${o} */ sets INFOPLIST_KEY_CFBundleDisplayName: remove it; Info.plist reads $(APP_NAME), which ios/appsettings.Compiled.xcconfig sets`)}i.length>0&&fail("appConfigInvalid",`project.pbxproj sets values that ios/appsettings.Compiled.xcconfig owns:\n ${i.join("\n ")}`)};const XCCONFIG_UNSAFE=/\/\/|[$";]/,xcconfigText=(e,t,i)=>{const o=[["APP_NAME",String(e.APP_NAME)],["PRODUCT_BUNDLE_IDENTIFIER",applicationId(String(e.APP_ID),t)],["MARKETING_VERSION",String(e.VERSION_DISPLAY)],["CURRENT_PROJECT_VERSION",String(e.VERSION_INTERNAL)],...i?[["ASSETCATALOG_COMPILER_APPICON_NAME",`AppIcon-${t}`]]:[]];for(const[e,t]of o)XCCONFIG_UNSAFE.test(t)&&fail("appConfigInvalid",`${e} must not contain // $ " or ;: it is written unquoted into ios/appsettings.Compiled.xcconfig`);return["// Written by mobile-tools prebuild from appsettings.Compiled.json for one environment. Not tracked: run prebuild to change it.",...o.map(([e,t])=>`${e} = ${t}`)].map(e=>`${e}\n`).join("")};export const buildCommit=e=>{const t=findOnPath("git",process.env,process.platform);if(!t)return"nogit";const i=capture({file:t,args:["rev-parse","--short","HEAD"]},e);if(0!==i.status)return"nogit";const o=capture({file:t,args:["status","--porcelain","--","."]},e);return 0!==o.status?fail("toolFailed",`git status failed in ${e}: ${o.stderr.trim()}`):""===o.stdout.trim()?i.stdout.trim():`${i.stdout.trim()}-dirty`};export const requireIgnored=(e,t)=>{const i=findOnPath("git",process.env,process.platform);if(!i||0!==capture({file:i,args:["rev-parse","--is-inside-work-tree"]},e).status)return;const o=t.filter(t=>{const o=capture({file:i,args:["check-ignore","-q","--",t]},e);return 0!==o.status&&1!==o.status&&fail("toolFailed",`git check-ignore failed for ${t}: ${o.stderr.trim()}`),1===o.status});o.length>0&&fail("appConfigInvalid",`add these lines to ${path.basename(e)}/.gitignore; prebuild writes them per environment:\n${o.join("\n")}`)};const writeIfChanged=(e,t)=>(!existsSync(e)||readFileSync(e,"utf8")!==t)&&(writeFileSync(e,t,"utf8"),!0),report=(e,t,i)=>{say(`prebuild: ${i?"wrote":"unchanged"} ${path.relative(e,t)}`)},dependsOn=(e,t)=>{const i=path.join(e,"package.json");if(!existsSync(i))return!1;const o=JSON.parse(readFileSync(i,"utf8"));return Boolean(o.dependencies?.[t])};export const usesFirebase=e=>dependsOn(e,"@react-native-firebase/app");export const checkNdkHook=e=>{const t=path.join(e,"android","build.gradle");if(!existsSync(t))return;const i=readFileSync(t,"utf8");/withId\(\s*["']com\.android\.library["']\s*\)/.test(i)&&/\.ndkVersion\s*=\s*rootProject\.ext\.ndkVersion/.test(i)||fail("appConfigInvalid",'android/build.gradle does not hand the app NDK to library modules; add after apply plugin "com.facebook.react.rootproject": subprojects { project -> project.plugins.withId("com.android.library") { project.android.ndkVersion = rootProject.ext.ndkVersion } }')};const MANAGED_GRADLE_KEYS=/^\s*(APP_NAME|APP_ID|VERSION_DISPLAY|VERSION_INTERNAL)\s*[=:]/gm;export const stampAndroid=(e,t,i,o,n)=>{const s=path.join(e,"android","gradle.properties");existsSync(s)||fail("appConfigInvalid",`android/gradle.properties not found in ${e}`),usesFirebase(e)&&!existsSync(path.join(e,"android","app","google-services.json"))&&fail("appConfigInvalid","android/app/google-services.json is missing; the app uses @react-native-firebase, whose Gradle plugin needs it"),checkNdkHook(e);const r=[...new Set([...readFileSync(s,"utf8").matchAll(MANAGED_GRADLE_KEYS)].map(([,e])=>e))];r.length>0&&fail("appConfigInvalid",`android/gradle.properties sets ${r.join(", ")}: remove them; android/app/build.gradle reads them from appsettings.Compiled.json`);const a=path.join(e,"android","app","build.gradle");if(existsSync(a)&&readFileSync(a,"utf8").includes("appsettings.Compiled.json")||fail("appConfigInvalid","android/app/build.gradle does not read appsettings.Compiled.json; add the compiledSettings loader (mobile-tools README, prebuild)"),usesExpoUpdates(e)){o.flavors||fail("appConfigInvalid",'expo-updates settings go into the flavor\'s manifest; set "flavors": true');const s=path.join(e,"android","app","src","main","AndroidManifest.xml");existsSync(s)||fail("appConfigInvalid","android/app/src/main/AndroidManifest.xml not found");const r=[...readFileSync(s,"utf8").matchAll(/android:name="(expo\.modules\.updates\.[^"]*)"/g)].map(([,e])=>e);r.length>0&&fail("appConfigInvalid",`android/app/src/main/AndroidManifest.xml sets ${r.join(", ")}: remove them from android/app/src/main/AndroidManifest.xml; prebuild writes them into ${androidFlavorManifest(i)}`);const a=otaNativeSettings(e,t,i,"android",n),p=path.join(e,androidFlavorManifest(i));mkdirSync(path.dirname(p),{recursive:!0}),report(e,p,writeIfChanged(p,androidOtaManifest(a)))}};export const stampIos=(e,t,i,o,n,s)=>{const r=path.join(e,"ios",n),a=path.join(r,"Info.plist"),p=path.join(e,"ios",`${n}.xcodeproj`,"project.pbxproj");for(const t of[a,p])existsSync(t)||fail("appConfigInvalid",`${path.relative(e,t)} not found: check "iosProjectName"`);checkInfoPlistReferences(e,n);const c=`AppIcon-${i}`,d=path.join(r,"Images.xcassets"),l=existsSync(path.join(d,`${c}.appiconset`)),f=ENVIRONMENTS.filter(e=>e!==i&&existsSync(path.join(d,`AppIcon-${e}.appiconset`)));!l&&f.length>0&&fail("appConfigInvalid",`ios/${n}/Images.xcassets has AppIcon-${f[0]} but no ${c}: run mobile-tools icons`),checkPbxprojSettings(readFileSync(p,"utf8"),l);const u=path.join(e,IOS_COMPILED_XCCONFIG);report(e,u,writeIfChanged(u,xcconfigText(t,i,l))),l||say(`prebuild: no AppIcon-${i} set, so ios/appsettings.Compiled.xcconfig sets no app icon name`);const g=path.join(r,"GoogleService-Info.plist"),I=path.join(e,o.firebasePlistDir,`GoogleService-Info.${i}.plist`);if(!existsSync(I)&&usesFirebase(e)&&fail("appConfigInvalid",`${path.relative(e,I)} is missing; the app uses @react-native-firebase, and an iOS build without it reports no crashes`),existsSync(I)){const t=!existsSync(g)||!readFileSync(I).equals(readFileSync(g));t&&copyFileSync(I,g),report(e,g,t)}else existsSync(g)&&(rmSync(g),say(`prebuild: removed ${path.relative(e,g)}, no ${path.relative(e,I)}`));if(usesExpoUpdates(e)){readFileSync(p,"utf8").includes("Expo.plist in Resources")||fail("appConfigInvalid","add Supporting/Expo.plist to the Xcode project's Copy Bundle Resources; prebuild writes its contents");const o=otaNativeSettings(e,t,i,"ios",s),r=path.join(e,expoPlistPath(n));mkdirSync(path.dirname(r),{recursive:!0}),report(e,r,writeIfChanged(r,expoPlist(o)))}};const resolveEnvironment=(e,t,i,o)=>{o&&i&&fail("badInput","pass --env or --same-env, not both");return(o?lastCompiledEnvironment(t):i)??fail("badInput",`${e} needs --env <Development|Staging|Production> or --same-env`)},checkedSettings=(e,t,i)=>{const o=loadAppSettings(e,t,i.requiredSettings);return checkAppSettings(e,o,t),o},writeCompiledSettings=(e,t,i,o)=>{const n={...i,COMMIT:buildCommit(t),BUILD_TIME:(new Date).toISOString()};return writeFileSync(path.join(t,COMPILED_FILE),`${JSON.stringify(n,null,2)}\n`,"utf8"),say(`${e}: wrote ${COMPILED_FILE} (${o}, ${n.COMMIT})`),n};export const compileSettings=e=>{const{appRoot:t}=e,i=resolveEnvironment("settings",t,e.env,e.sameEnv),o=checkedSettings(t,i,loadToolsConfig(t));return requireIgnored(t,[COMPILED_FILE]),writeCompiledSettings("settings",t,o,i)};export const prebuild=e=>{const{appRoot:t,platform:i}=e,o=!0===e.otaTest,n=resolveEnvironment("prebuild",t,e.env,e.sameEnv),s=loadToolsConfig(t),r=resolveIosProjectName(t,s),a=checkedSettings(t,n,s),p="android"===i||!i&&existsSync(path.join(t,"android")),c="android"===i?void 0:r;if("ios"===i&&void 0===c)return fail("appConfigInvalid",`no ios/ folder in ${t}`);const d=[...p?generatedNativeFiles(t,c,n,"android"):[],...void 0!==c?generatedNativeFiles(t,c,n,"ios"):[]];requireIgnored(t,[COMPILED_FILE,...d]);const l=writeCompiledSettings("prebuild",t,a,n);return p&&stampAndroid(t,l,n,s,o),void 0!==c&&stampIos(t,l,n,s,c,o),l};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/mobile-tools",
3
- "version": "0.177.0",
3
+ "version": "0.178.1",
4
4
  "description": "Dev-time CLI for Webority React Native apps: one prebuild, a dependency guard, a device-aware run and per-environment launcher icons, the same on Windows and macOS.",
5
5
  "keywords": [
6
6
  "react-native",