codeplay-common 4.5.8 → 4.5.9

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.
@@ -1278,7 +1278,10 @@ let _admobConfig;
1278
1278
 
1279
1279
  const androidPlatformPath = path.join(process.cwd(), 'android');
1280
1280
  const iosPlatformPath = path.join(process.cwd(), 'ios');
1281
- const androidManifestPath = path.join(process.cwd(), 'android', 'app', 'src', 'main', 'AndroidManifest.xml');
1281
+ const androidManifestPath = path.join(process.cwd(), 'android', 'app', 'src', 'main', 'AndroidManifest.xml');
1282
+ const androidAppBuildGradlePath = path.join(process.cwd(), 'android', 'app', 'build.gradle');
1283
+ const AMAZON_WINDOW_EXTENSIONS_DEPENDENCY = 'implementation "androidx.window.extensions.core:core:1.0.0"';
1284
+ const AMAZON_WINDOW_EXTENSIONS_DEPENDENCY_PATTERN = /^[ \t]*implementation\s+["']androidx\.window\.extensions\.core:core:[^"']+["'][ \t]*(?:\r?\n)?/gm;
1282
1285
  const infoPlistPath = path.join(process.cwd(), 'ios', 'App', 'App', 'Info.plist');
1283
1286
  const resourcesPath = path.join(process.cwd(), 'resources', 'res');
1284
1287
  const androidResPath = path.join(process.cwd(), 'android', 'app', 'src', 'main', 'res');
@@ -3665,12 +3668,19 @@ const getCurrentStoreId = () => {
3665
3668
  if (!fs.existsSync(commonFilePath)) return 1;
3666
3669
 
3667
3670
  const commonFileContent = fs.readFileSync(commonFilePath, "utf8");
3668
- const storeIdMatch = commonFileContent.match(/export\s+let\s+_storeid\s*=\s*import\.meta\.env\.VITE_STORE_ID\s*\|\|\s*(\d+)\s*;/);
3669
-
3670
- return storeIdMatch ? Number(storeIdMatch[1]) : 1;
3671
- };
3671
+ const environmentStoreIdMatch = commonFileContent.match(
3672
+ /^[ \t]*export\s+let\s+_storeid\s*=\s*import\.meta\.env\.VITE_STORE_ID\s*\|\|\s*(\d+)\s*;/m
3673
+ );
3674
+ if (environmentStoreIdMatch) return Number(environmentStoreIdMatch[1]);
3675
+
3676
+ const directStoreIdMatch = commonFileContent.match(
3677
+ /^[ \t]*export\s+let\s+_storeid\s*=\s*(\d+)\s*;/m
3678
+ );
3679
+
3680
+ return directStoreIdMatch ? Number(directStoreIdMatch[1]) : 1;
3681
+ };
3672
3682
 
3673
- const getRevenueCatStoreState = (iapConfig) => {
3683
+ const getRevenueCatStoreState = (iapConfig) => {
3674
3684
  const storeId = getCurrentStoreId();
3675
3685
  const configuration = iapConfig.configuration || {};
3676
3686
  const storeMap = {
@@ -3700,10 +3710,43 @@ const getRevenueCatStoreState = (iapConfig) => {
3700
3710
  return {
3701
3711
  storeId,
3702
3712
  store: storeMap[storeId] || null
3703
- };
3704
- };
3705
-
3706
- const ensureAndroidPermission = (permission, enabled) => {
3713
+ };
3714
+ };
3715
+
3716
+ const syncAmazonFireWebViewDependency = (enabled) => {
3717
+ if (!fs.existsSync(androidAppBuildGradlePath)) {
3718
+ console.error(`❌ Android app build.gradle not found: ${androidAppBuildGradlePath}`);
3719
+ process.exit(1);
3720
+ }
3721
+
3722
+ const currentContent = fs.readFileSync(androidAppBuildGradlePath, "utf8");
3723
+ let nextContent = currentContent.replace(AMAZON_WINDOW_EXTENSIONS_DEPENDENCY_PATTERN, "");
3724
+
3725
+ if (enabled) {
3726
+ const newline = nextContent.includes("\r\n") ? "\r\n" : "\n";
3727
+ const dependenciesHeaderPattern = /(^dependencies[ \t]*\{[ \t]*\r?\n)/m;
3728
+
3729
+ if (!dependenciesHeaderPattern.test(nextContent)) {
3730
+ console.error(`❌ dependencies block not found in ${androidAppBuildGradlePath}`);
3731
+ process.exit(1);
3732
+ }
3733
+
3734
+ nextContent = nextContent.replace(
3735
+ dependenciesHeaderPattern,
3736
+ `$1 ${AMAZON_WINDOW_EXTENSIONS_DEPENDENCY}${newline}`
3737
+ );
3738
+ }
3739
+
3740
+ if (nextContent !== currentContent) {
3741
+ fs.writeFileSync(androidAppBuildGradlePath, nextContent, "utf8");
3742
+ }
3743
+
3744
+ console.log(enabled
3745
+ ? "✅ Amazon Fire WebView compatibility dependency enabled for Store ID 7."
3746
+ : "ℹ️ Amazon Fire WebView compatibility dependency disabled for this store.");
3747
+ };
3748
+
3749
+ const ensureAndroidPermission = (permission, enabled) => {
3707
3750
  if (!fs.existsSync(androidManifestPath)) return false;
3708
3751
 
3709
3752
  let manifestContent = fs.readFileSync(androidManifestPath, "utf8");
@@ -3730,14 +3773,15 @@ const ensureAndroidPermission = (permission, enabled) => {
3730
3773
  return true;
3731
3774
  };
3732
3775
 
3733
- const syncRevenueCatIapSetup = () => {
3734
- const admobConfig = getAdmobIapConfig();
3735
- const iapConfig = admobConfig?.IAP;
3736
-
3737
- if (!iapConfig) {
3738
- console.log("ℹ️ IAP configuration not found. Skipping RevenueCat package sync.");
3739
- return;
3740
- }
3776
+ const syncRevenueCatIapSetup = () => {
3777
+ const admobConfig = getAdmobIapConfig();
3778
+ const iapConfig = admobConfig?.IAP;
3779
+
3780
+ if (!iapConfig) {
3781
+ syncAmazonFireWebViewDependency(false);
3782
+ console.log("ℹ️ IAP configuration not found. Skipping RevenueCat package sync.");
3783
+ return;
3784
+ }
3741
3785
 
3742
3786
  ensureIapDesignInCapacitorConfig(iapConfig);
3743
3787
 
@@ -3745,8 +3789,9 @@ const syncRevenueCatIapSetup = () => {
3745
3789
  iapConfig.playstore === true ||
3746
3790
  iapConfig.ios === true ||
3747
3791
  iapConfig.amazon === true;
3748
- const { storeId, store } = getRevenueCatStoreState(iapConfig);
3749
- const revenueCatEnabledForCurrentStore = store?.enabled === true;
3792
+ const { storeId, store } = getRevenueCatStoreState(iapConfig);
3793
+ const revenueCatEnabledForCurrentStore = store?.enabled === true;
3794
+ syncAmazonFireWebViewDependency(storeId === 7 && iapConfig.amazon === true);
3750
3795
 
3751
3796
  if (revenueCatEnabledForCurrentStore && !store.apiKey) {
3752
3797
  console.error(`❌ RevenueCat IAP is enabled for ${store.name} but ${store.apiKeyName} is missing.`);
@@ -679,7 +679,7 @@ const gradleFilePath = join("android", "app", "build.gradle");
679
679
  const gradleContent = readFileSync(gradleFilePath, 'utf8');
680
680
 
681
681
  // Return the character range of a Gradle block, allowing nested blocks inside it.
682
- function findGradleBlock(content, headerPattern) {
682
+ function findGradleBlock(content, headerPattern) {
683
683
  const headerMatch = content.match(headerPattern);
684
684
  if (!headerMatch) return null;
685
685
  const openingBrace = content.indexOf('{', headerMatch.index + headerMatch[0].length);
@@ -697,10 +697,41 @@ function findGradleBlock(content, headerPattern) {
697
697
  else if (character === '{') depth += 1;
698
698
  else if (character === '}' && --depth === 0) return { start: openingBrace + 1, end: index };
699
699
  }
700
- return null;
701
- }
702
-
703
- const versionCodeMatch = gradleContent.match(/versionCode\s+(\d+)/);
700
+ return null;
701
+ }
702
+
703
+ const amazonWindowExtensionsDependency = 'implementation "androidx.window.extensions.core:core:1.0.0"';
704
+ const amazonWindowExtensionsDependencyPattern = /^[ \t]*implementation\s+["']androidx\.window\.extensions\.core:core:[^"']+["'][ \t]*(?:\r?\n)?/gm;
705
+
706
+ function setAmazonWindowExtensionsDependency(enabled) {
707
+ const currentGradleContent = readFileSync(gradleFilePath, 'utf8');
708
+ let nextGradleContent = currentGradleContent.replace(amazonWindowExtensionsDependencyPattern, '');
709
+
710
+ if (enabled) {
711
+ const dependenciesBlock = findGradleBlock(nextGradleContent, /^\s*dependencies\s*/m);
712
+ if (!dependenciesBlock) {
713
+ throw new Error(`The dependencies block was not found in ${gradleFilePath}.`);
714
+ }
715
+
716
+ const newline = nextGradleContent.includes('\r\n') ? '\r\n' : '\n';
717
+ const contentBeforeClosingBrace = nextGradleContent.slice(0, dependenciesBlock.end);
718
+ const linePrefix = contentBeforeClosingBrace.endsWith('\n') ? '' : newline;
719
+ nextGradleContent = contentBeforeClosingBrace
720
+ + linePrefix
721
+ + ` ${amazonWindowExtensionsDependency}${newline}`
722
+ + nextGradleContent.slice(dependenciesBlock.end);
723
+ }
724
+
725
+ if (nextGradleContent !== currentGradleContent) {
726
+ writeFileSync(gradleFilePath, nextGradleContent, 'utf8');
727
+ }
728
+
729
+ console.log(enabled
730
+ ? '✅ Added Amazon Fire WebView compatibility dependency for Store ID 7.'
731
+ : 'ℹ️ Amazon Fire WebView compatibility dependency is not included for this build.');
732
+ }
733
+
734
+ const versionCodeMatch = gradleContent.match(/versionCode\s+(\d+)/);
704
735
  const versionNameMatch = gradleContent.match(/versionName\s+"([^"]+)"/);
705
736
 
706
737
  const versionCode = versionCodeMatch ? versionCodeMatch[1] : '';
@@ -854,6 +885,8 @@ rl.question('Enter new versionCode (press enter to keep current): ', (newVersion
854
885
  }
855
886
  try {
856
887
  applyFlowchartStoreApi(id);
888
+ const shouldIncludeAmazonWindowExtensions = String(id) === '7' && amazon === true;
889
+ setAmazonWindowExtensionsDependency(shouldIncludeAmazonWindowExtensions);
857
890
  // Modify the minSdkVersion based on the store
858
891
 
859
892
 
@@ -969,9 +1002,11 @@ rl.question('Enter new versionCode (press enter to keep current): ', (newVersion
969
1002
  } catch (error) {
970
1003
  console.error(`❌ Error during build for Store ID ${id}:`, error);
971
1004
  restoreFlowchartStoreApi();
1005
+ setAmazonWindowExtensionsDependency(false);
972
1006
  process.exit(1);
973
1007
  } finally {
974
1008
  restoreFlowchartStoreApi();
1009
+ setAmazonWindowExtensionsDependency(false);
975
1010
  }
976
1011
  });
977
1012
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeplay-common",
3
- "version": "4.5.8",
3
+ "version": "4.5.9",
4
4
  "description": "Common build scripts and files",
5
5
  "scripts": {
6
6
  "postinstall": "node scripts/sync-files.js",