UNPKG

react-native-expo-signed

Version:

An Expo config plugin for setting up code signing for Android and iOS builds during Expo prebuild.

11 lines (10 loc) 2.55 kB
"use strict";const g=require("@expo/config-plugins"),n=require("fs"),l=require("path"),S=(o,e)=>g.withGradleProperties(o,s=>(Object.entries(e).forEach(([t,{key:r,value:i}])=>{r&&i&&(s.modResults.find(u=>u.type==="property"&&u.key===r)||s.modResults.push({key:r,type:"property",value:i}))}),s)),P=(o,e)=>{const s=l.resolve(e.app_path,"build.gradle");if(n.existsSync(s)){let t=n.readFileSync(s,"utf8");t=t.replace(/\r\n/g,` `);const r=/signingConfigs\s*\{(?:[^{}]*\{[^}]*\}|[^}])*release\s*\{[^}]*\}[^}]*\}/;let i=t.replace(/(release\s*{[^}]*signingConfig\s+signingConfigs\.)debug/,"$1release");r.test(i)||(i=i.replace(/(signingConfigs\s*{[^}]*debug\s*{[^}]*})/,`$1 release { if (project.hasProperty('${e.store_file.key}')) { storeFile file(${e.store_file.key}) storePassword ${e.store_password.key} keyAlias ${e.key_alias.key} keyPassword ${e.key_password.key} } }`)),i!==t&&n.writeFileSync(s,i,"utf8")}return o},h=(o,e)=>{const s=l.resolve(e.keystorePath,e.store_file.value),t=l.resolve(e.app_path,e.store_file.value);if(!n.existsSync(s))throw new Error(`❌ Keystore file not found at: ${s}`);return n.existsSync(l.dirname(t))&&n.copyFileSync(s,t),o},C=(o,e)=>{["store_file","key_alias","store_password","key_password","keystorePath","app_path"].forEach(i=>{if(!e[i])throw new Error(`Missing required: ${i}`)});const t=l.resolve(e.keystorePath,e.store_file.value);if(!n.existsSync(t))throw new Error(`❌ Keystore missing: ${t}`);return h(P(S(o,e),e),e)},d=(o,e={})=>g.withXcodeProject(o,s=>{const t=s.modResults,r=t.pbxXCBuildConfigurationSection(),i=t.pbxNativeTargetSection(),y=t.pbxXCConfigurationList();for(const u in i){const p=i[u];if(typeof p!="object"||!p)continue;const E=p.buildConfigurationList?.replace(/"/g,"");if(!E)continue;const _=y[E];if(!_?.buildConfigurations)continue;const I=_.buildConfigurations.map(f=>f.value);for(const f in r){if(!I.includes(f))continue;const a=r[f];if(typeof a!="object"||!a)continue;const c=a.buildSettings??{};e.CODE_SIGN_STYLE&&(c.CODE_SIGN_STYLE=e.CODE_SIGN_STYLE),e.CODE_SIGN_IDENTITY&&(c.CODE_SIGN_IDENTITY=e.CODE_SIGN_IDENTITY),e.DEVELOPMENT_TEAM&&(c.DEVELOPMENT_TEAM=e.DEVELOPMENT_TEAM),e.PROVISIONING_PROFILE_SPECIFIER&&(c.PROVISIONING_PROFILE_SPECIFIER=e.PROVISIONING_PROFILE_SPECIFIER),a.buildSettings=c}}return s}),N=(o,{android:e,ios:s}={})=>{let t=o;return e&&(t=C(t,{...e,app_path:e?.app_path??"./android/app",keystorePath:e?.keystorePath??"./"})),s&&(t=d(t,s)),t};module.exports=N;