codeplay-common 4.10.8 → 4.11.0

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.
@@ -1,3 +1,4 @@
1
+ // Version 6.8: preserve Capacitor permission annotations for Love Calculator Android builds.
1
2
  // Version 6.7: deferred IAP startup, ownership-safe ads, and unified store preparation.
2
3
  // Version 6.7: migrate AdMob files to ZIP-distributed folder packages.
3
4
  // Version 6.7: recreate failed WebViews, defer background recovery, and suppress foreground recovery toasts.
@@ -4521,8 +4522,30 @@ function findAndroidBuildBlock(content, name) {
4521
4522
  return null;
4522
4523
  }
4523
4524
 
4525
+ function syncAndroidCapacitorPermissionRules() {
4526
+ if (buildPlatform !== 'android' || !fs.existsSync(androidAppBuildGradlePath)) return;
4527
+ const capacitorConfig = JSON.parse(fs.readFileSync(configPath, 'utf8'));
4528
+ if (capacitorConfig.appId !== 'codeplay.love.calculator') return;
4529
+
4530
+ const rulesPath = path.join(androidPlatformPath, 'app', 'proguard-rules.pro');
4531
+ const original = fs.existsSync(rulesPath) ? fs.readFileSync(rulesPath, 'utf8') : '';
4532
+ const newline = original.includes('\r\n') ? '\r\n' : '\n';
4533
+ const rules = [
4534
+ '-keepattributes RuntimeVisibleAnnotations,AnnotationDefault',
4535
+ '-keep @interface com.getcapacitor.annotation.CapacitorPlugin { *; }',
4536
+ '-keep @interface com.getcapacitor.annotation.Permission { *; }'
4537
+ ];
4538
+ const existingRules = original.split(/\r?\n/).map(line => line.trim());
4539
+ const missingRules = rules.filter(rule => !existingRules.includes(rule));
4540
+ if (!missingRules.length) return;
4541
+
4542
+ const next = `${original.trimEnd()}${newline}${newline}# Preserve Capacitor permission metadata used at runtime.${newline}${missingRules.join(newline)}${newline}`;
4543
+ fs.writeFileSync(rulesPath, next, 'utf8');
4544
+ }
4545
+
4524
4546
  function syncAndroidBuildOptimization() {
4525
4547
  if (buildPlatform !== 'android' || !fs.existsSync(androidAppBuildGradlePath)) return;
4548
+ syncAndroidCapacitorPermissionRules();
4526
4549
 
4527
4550
  const original = fs.readFileSync(androidAppBuildGradlePath, 'utf8');
4528
4551
  const newline = original.includes('\r\n') ? '\r\n' : '\n';
@@ -38,7 +38,9 @@ function updateBuildScripts(scripts) {
38
38
  next['ionic:build'] = next['ionic:build'] || 'npm run build';
39
39
  next['ionic:serve'] = next['ionic:serve'] || 'cross-env NODE_ENV=development vite';
40
40
  next['baseline-profile:setup'] = next['baseline-profile:setup'] || 'node scripts-common/setup-baseline-profile.js';
41
- next['baseline-profile:generate'] = next['baseline-profile:generate'] || 'cd android && gradlew.bat :app:generateBaselineProfile --console=plain';
41
+ if (!next['baseline-profile:generate'] || next['baseline-profile:generate'] === 'cd android && gradlew.bat :app:generateBaselineProfile --console=plain') {
42
+ next['baseline-profile:generate'] = 'node scripts-common/generate-baseline-profile.js';
43
+ }
42
44
  next.release = next.release || 'node finalrelease';
43
45
  return next;
44
46
  }
@@ -0,0 +1,42 @@
1
+ const { execFileSync, spawnSync } = require('child_process');
2
+ const path = require('path');
3
+
4
+ function main() {
5
+ const devices = execFileSync('adb', ['devices'], { encoding: 'utf8' })
6
+ .split(/\r?\n/)
7
+ .map(line => line.match(/^(.+?)\tdevice\s*$/))
8
+ .filter(Boolean)
9
+ .map(match => match[1]);
10
+ const requestedSerial = process.env.ANDROID_SERIAL?.trim();
11
+ if (requestedSerial?.includes(',')) {
12
+ throw new Error('Set ANDROID_SERIAL to one device connection for Baseline Profile generation.');
13
+ }
14
+ const serial = requestedSerial || devices[0];
15
+ if (!serial || !devices.includes(serial)) {
16
+ throw new Error(requestedSerial
17
+ ? `ADB device is not online: ${requestedSerial}`
18
+ : 'No online ADB device. Connect an Android device before generating a Baseline Profile.');
19
+ }
20
+
21
+ console.log(`Generating Baseline Profile using one ADB connection: ${serial}`);
22
+ const args = [':app:generateBaselineProfile', '--console=plain'];
23
+ const result = spawnSync(
24
+ process.platform === 'win32' ? 'cmd.exe' : './gradlew',
25
+ process.platform === 'win32' ? ['/d', '/s', '/c', `gradlew.bat ${args.join(' ')}`] : args,
26
+ {
27
+ cwd: path.resolve(__dirname, '..', 'android'),
28
+ env: { ...process.env, ANDROID_SERIAL: serial },
29
+ stdio: 'inherit',
30
+ }
31
+ );
32
+ if (result.error) throw result.error;
33
+ if (result.signal) throw new Error(`Baseline Profile generation stopped by ${result.signal}.`);
34
+ process.exitCode = result.status ?? 1;
35
+ }
36
+
37
+ try {
38
+ main();
39
+ } catch (error) {
40
+ console.error(`Baseline Profile generation failed: ${error.message}`);
41
+ process.exitCode = 1;
42
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeplay-common",
3
- "version": "4.10.8",
3
+ "version": "4.11.0",
4
4
  "description": "Common build scripts and files",
5
5
  "scripts": {
6
6
  "postinstall": "node scripts/sync-files.js",