codeplay-common 4.11.34 → 4.11.37

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +115 -115
  2. package/LICENSE +21 -21
  3. package/README.md +6 -0
  4. package/RELEASE_NOTES.md +110 -110
  5. package/files/buildCodeplay/HUAWEI-PRIVACY.md +9 -9
  6. package/files/buildCodeplay/add-splash-screen.js +256 -256
  7. package/files/buildCodeplay/apk-store-builder.js +97 -97
  8. package/files/buildCodeplay/fix-onesignal-plugin.js +96 -96
  9. package/files/buildCodeplay/fix-optimize-builld/android-r8-rules.cjs +31 -31
  10. package/files/buildCodeplay/fix-optimize-builld/ffmpeg-jni-rules.cjs +28 -28
  11. package/files/buildCodeplay/fix-optimize-builld/fix-optimize-build.gradle +9 -9
  12. package/files/buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs +30 -30
  13. package/files/buildCodeplay/huawei-privacy.cjs +102 -92
  14. package/files/buildCodeplay/iap-alias.cjs +116 -108
  15. package/files/buildCodeplay/ios-emi-admob-modification.js +24 -24
  16. package/files/buildCodeplay/manifestModification.js +38 -38
  17. package/files/buildCodeplay/migrate-system-bars.cjs +122 -122
  18. package/files/buildCodeplay/packageidBaseModification.js +528 -528
  19. package/files/buildCodeplay/project-scripts.cjs +69 -69
  20. package/files/buildCodeplay/ruads.cjs +10 -1
  21. package/files/buildCodeplay/setSplashAnimation.js +228 -228
  22. package/files/buildCodeplay/setup-ruads.cjs +9 -2
  23. package/files/buildCodeplay/splash-setup.cjs +88 -88
  24. package/files/buildCodeplay/splashxml/codeplay_splashScreen.xml +11 -11
  25. package/files/buildCodeplay/sync-admob-nextgen.js +219 -219
  26. package/files/buildCodeplay/tests/huawei-live-reload.test.cjs +60 -0
  27. package/files/buildCodeplay/tests/huawei-multiple-entries.test.cjs +80 -0
  28. package/files/buildCodeplay/tests/huawei-vite.test.cjs +38 -35
  29. package/files/buildCodeplay/versions.json +28 -28
  30. package/files/finalrelease +1365 -1365
  31. package/files/generate-ai-promo-video.js +23 -23
  32. package/files/ionic.config.json +6 -6
  33. package/files/scripts-common/run-codeplay-sync-after.js +21 -21
  34. package/files/scripts-common/screenshot/background-decorations.js +120 -120
  35. package/files/scripts-common/screenshot/frame-samples.js +117 -117
  36. package/files/scripts-common/setup-baseline-profile.js +291 -291
  37. package/files/take-screen-video.js +644 -644
  38. package/package.json +1 -1
  39. package/runtime/splash-ready.mjs +52 -52
  40. package/scripts/iap-alias.test.cjs +117 -78
  41. package/scripts/ruads-install.test.cjs +20 -3
  42. package/scripts/splash-setup.test.cjs +142 -142
  43. package/scripts/sync-files.js +119 -119
  44. package/scripts/system-bars-package.test.cjs +37 -37
  45. package/scripts/system-bars.test.cjs +93 -93
  46. package/scripts/uninstall.js +2 -2
  47. package/scripts/vite-build-settings.test.cjs +1 -0
@@ -1,92 +1,102 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
4
- const generatedEntry = '../buildCodeplay/huawei-privacy-generated.js';
5
- const originalAttribute = 'data-codeplay-original-src';
6
- const analyticsMarker = 'CODEPLAY HUAWEI ANALYTICS ORIGINAL';
7
-
8
- function updateEntry(projectRoot, enabled, appId, appName) {
9
- const indexPath = path.join(projectRoot, 'src/index.html');
10
- if (!fs.existsSync(indexPath)) {
11
- if (enabled) throw new Error('Huawei privacy: src/index.html was not found.');
12
- return false;
13
- }
14
- const original = fs.readFileSync(indexPath, 'utf8');
15
- const scripts = [...original.matchAll(/<script\b(?=[^>]*\btype\s*=\s*["']module["'])[^>]*\bsrc\s*=\s*["']([^"']+)["'][^>]*><\/script>/gi)];
16
- const managed = scripts.filter(match => match[0].includes(originalAttribute));
17
- if (managed.length > 1) throw new Error('Huawei privacy: more than one managed app entry was found.');
18
- let target = managed[0];
19
- if (!target && enabled) {
20
- if (scripts.length !== 1) throw new Error('Huawei privacy: expected exactly one module app entry in src/index.html.');
21
- target = scripts[0];
22
- }
23
- if (!target) return false;
24
- const saved = target[0].match(new RegExp(`${originalAttribute}=["']([^"']+)["']`));
25
- const entry = saved ? saved[1] : target[1];
26
- if (!/^\.\/[\w./-]+\.js$/.test(entry) || entry.includes('..')) {
27
- throw new Error(`Huawei privacy: unsupported app entry ${entry}`);
28
- }
29
- const entryPath = path.resolve(projectRoot, 'src', entry);
30
- if (!fs.existsSync(entryPath)) throw new Error(`Huawei privacy: app entry ${entry} was not found.`);
31
- const tag = enabled
32
- ? target[0].replace(/\ssrc\s*=\s*["'][^"']+["']/, ` src="${generatedEntry}"`)
33
- .replace(/<script\b/, match => saved ? match : `${match} ${originalAttribute}="${entry}"`)
34
- : target[0].replace(/\ssrc\s*=\s*["'][^"']+["']/, ` src="${entry}"`)
35
- .replace(new RegExp(`\\s+${originalAttribute}=["'][^"']+["']`), '');
36
- const next = original.replace(target[0], tag);
37
- if (next !== original) fs.writeFileSync(indexPath, next);
38
- if (enabled) {
39
- const wrapperPath = path.join(projectRoot, 'buildCodeplay/huawei-privacy-generated.js');
40
- const importPath = `../src/${entry.slice(2)}`;
41
- const wrapper = `// Generated by codeplay-common for the Huawei build.\nimport { startHuaweiPrivacy } from './huawei-privacy-entry.js';\nstartHuaweiPrivacy({ appId: ${JSON.stringify(appId)}, appName: ${JSON.stringify(appName)}, startApp: () => import(${JSON.stringify(importPath)}) });\n`;
42
- if (!fs.existsSync(wrapperPath) || fs.readFileSync(wrapperPath, 'utf8') !== wrapper) fs.writeFileSync(wrapperPath, wrapper);
43
- }
44
- return next !== original;
45
- }
46
-
47
- function updateAnalyticsDefault(projectRoot, enabled) {
48
- const manifestPath = path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml');
49
- if (!fs.existsSync(manifestPath)) {
50
- if (enabled) throw new Error('Huawei privacy: AndroidManifest.xml was not found.');
51
- return false;
52
- }
53
- const original = fs.readFileSync(manifestPath, 'utf8');
54
- const newline = original.includes('\r\n') ? '\r\n' : '\n';
55
- const marker = new RegExp(`(\\r?\\n)?[ \\t]*<!-- ${analyticsMarker} ([A-Za-z0-9+/=]*) -->\\r?\\n[ \\t]*<meta-data\\b(?=[^>]*\\bandroid:name=["']firebase_analytics_collection_enabled["'])[^>]*\\/\\s*>\\r?\\n?`);
56
- let next = original;
57
- if (marker.test(next)) {
58
- if (!enabled) next = next.replace(marker, (_, leading, encoded) =>
59
- encoded ? `${leading || ''}${Buffer.from(encoded, 'base64').toString('utf8')}` : '');
60
- else next = next.replace(marker, match => match.replace(/android:value=["'][^"']*["']/, 'android:value="false"'));
61
- } else if (enabled) {
62
- const existing = /[ \t]*<meta-data\b(?=[^>]*\bandroid:name=["']firebase_analytics_collection_enabled["'])[^>]*\/\s*>\r?\n?/;
63
- const prior = next.match(existing)?.[0] || '';
64
- const block = ` <!-- ${analyticsMarker} ${Buffer.from(prior).toString('base64')} -->${newline} <meta-data android:name="firebase_analytics_collection_enabled" android:value="false" />${newline}`;
65
- if (!/<application\b[^>]*>/.test(next)) throw new Error('Huawei privacy: application element was not found in AndroidManifest.xml.');
66
- next = prior ? next.replace(existing, block) : next.replace(/<application\b[^>]*>/, match => `${match}${newline}${block}`);
67
- }
68
- if (next !== original) fs.writeFileSync(manifestPath, next);
69
- return next !== original;
70
- }
71
-
72
- function syncHuaweiPrivacy(projectRoot, storeId, platform = 'android') {
73
- const enabled = platform === 'android' && Number(storeId) === 4;
74
- const config = JSON.parse(fs.readFileSync(path.join(projectRoot, 'capacitor.config.json'), 'utf8'));
75
- const appId = Number(config.android?.APP_UNIQUE_ID);
76
- if (enabled && (!Number.isInteger(appId) || appId < 1)) {
77
- throw new Error('Huawei privacy: capacitor.config.json needs a valid android.APP_UNIQUE_ID.');
78
- }
79
- // Inspect both targets before writing either one, so unsupported app layouts fail early.
80
- const manifestPath = path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml');
81
- if (enabled && !fs.existsSync(manifestPath)) {
82
- throw new Error('Huawei privacy: AndroidManifest.xml was not found.');
83
- }
84
- if (enabled && !/<application\b[^>]*>/.test(fs.readFileSync(manifestPath, 'utf8'))) {
85
- throw new Error('Huawei privacy: application element was not found in AndroidManifest.xml.');
86
- }
87
- updateEntry(projectRoot, enabled, appId, config.appName || 'App');
88
- updateAnalyticsDefault(projectRoot, enabled);
89
- if (enabled) console.log(`Huawei privacy consent enabled. Verify https://htmlcodeplay.com/privacy/ch/${appId} is published before submission.`);
90
- }
91
-
92
- module.exports = { syncHuaweiPrivacy };
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const generatedEntry = '../buildCodeplay/huawei-privacy-generated.js';
5
+ const originalAttribute = 'data-codeplay-original-src';
6
+ const analyticsMarker = 'CODEPLAY HUAWEI ANALYTICS ORIGINAL';
7
+
8
+ function updateEntry(projectRoot, enabled, appId, appName) {
9
+ const indexPath = path.join(projectRoot, 'src/index.html');
10
+ if (!fs.existsSync(indexPath)) {
11
+ if (enabled) throw new Error('Huawei privacy: src/index.html was not found.');
12
+ return false;
13
+ }
14
+ const original = fs.readFileSync(indexPath, 'utf8');
15
+ // Ignore commented examples while retaining offsets into the original HTML.
16
+ const visible = original.replace(/<!--[\s\S]*?-->/g, comment => comment.replace(/[^\r\n]/g, ' '));
17
+ const scripts = [...visible.matchAll(/<script\b(?=[^>]*\stype\s*=\s*["'](?:module|application\/x-codeplay-huawei-module)["'])[^>]*>\s*<\/script>/gi)]
18
+ .filter(match => new RegExp(`\\s(?:src|${originalAttribute})\\s*=`).test(match[0]));
19
+ const targets = enabled ? scripts : scripts.filter(match => match[0].includes(originalAttribute));
20
+ if (enabled && !targets.length) throw new Error('Huawei privacy: expected at least one module app entry in src/index.html.');
21
+ if (!targets.length) return false;
22
+ // Validate every entry before changing either the HTML or the generated wrapper.
23
+ const entries = targets.map(target => {
24
+ const saved = target[0].match(new RegExp(`${originalAttribute}=["']([^"']+)["']`));
25
+ const entry = saved ? saved[1] : target[0].match(/\ssrc\s*=\s*["']([^"']+)["']/i)[1];
26
+ if (!/^\.\/[\w./-]+\.js$/.test(entry) || entry.includes('..')) {
27
+ throw new Error(`Huawei privacy: unsupported app entry ${entry}`);
28
+ }
29
+ if (!fs.existsSync(path.resolve(projectRoot, 'src', entry))) {
30
+ throw new Error(`Huawei privacy: app entry ${entry} was not found.`);
31
+ }
32
+ return { target, saved, entry };
33
+ });
34
+ let next = original;
35
+ for (let i = entries.length - 1; i >= 0; i--) {
36
+ const { target, saved, entry } = entries[i];
37
+ const type = enabled && i > 0 ? 'application/x-codeplay-huawei-module' : 'module';
38
+ let tag = target[0].replace(/\sdata-codeplay-deferred-src\s*=/i, ' src=')
39
+ .replace(/(\btype\s*=\s*["'])[^"']+(["'])/i, `$1${type}$2`)
40
+ .replace(/(\ssrc\s*=\s*["'])[^"']+(["'])/i, `$1${enabled && i === 0 ? generatedEntry : entry}$2`);
41
+ if (enabled && i > 0) tag = tag.replace(/\ssrc\s*=/i, ' data-codeplay-deferred-src=');
42
+ tag = enabled
43
+ ? tag.replace(/<script\b/i, match => saved ? match : `${match} ${originalAttribute}="${entry}"`)
44
+ : tag.replace(new RegExp(`\\s+${originalAttribute}=["'][^"']+["']`), '');
45
+ next = next.slice(0, target.index) + tag + next.slice(target.index + target[0].length);
46
+ }
47
+ if (enabled) {
48
+ const wrapperPath = path.join(projectRoot, 'buildCodeplay/huawei-privacy-generated.js');
49
+ const imports = entries.map(({ entry }) => `await import(${JSON.stringify(`../src/${entry.slice(2)}`)});`).join(' ');
50
+ const wrapper = `// Generated by codeplay-common for the Huawei build.\nimport { startHuaweiPrivacy } from './huawei-privacy-entry.js';\nstartHuaweiPrivacy({ appId: ${JSON.stringify(appId)}, appName: ${JSON.stringify(appName)}, startApp: async () => { ${imports} } });\n`;
51
+ if (!fs.existsSync(wrapperPath) || fs.readFileSync(wrapperPath, 'utf8') !== wrapper) fs.writeFileSync(wrapperPath, wrapper);
52
+ }
53
+ if (next !== original) fs.writeFileSync(indexPath, next);
54
+ return next !== original;
55
+ }
56
+
57
+ function updateAnalyticsDefault(projectRoot, enabled) {
58
+ const manifestPath = path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml');
59
+ if (!fs.existsSync(manifestPath)) {
60
+ if (enabled) throw new Error('Huawei privacy: AndroidManifest.xml was not found.');
61
+ return false;
62
+ }
63
+ const original = fs.readFileSync(manifestPath, 'utf8');
64
+ const newline = original.includes('\r\n') ? '\r\n' : '\n';
65
+ const marker = new RegExp(`(\\r?\\n)?[ \\t]*<!-- ${analyticsMarker} ([A-Za-z0-9+/=]*) -->\\r?\\n[ \\t]*<meta-data\\b(?=[^>]*\\bandroid:name=["']firebase_analytics_collection_enabled["'])[^>]*\\/\\s*>\\r?\\n?`);
66
+ let next = original;
67
+ if (marker.test(next)) {
68
+ if (!enabled) next = next.replace(marker, (_, leading, encoded) =>
69
+ encoded ? `${leading || ''}${Buffer.from(encoded, 'base64').toString('utf8')}` : '');
70
+ else next = next.replace(marker, match => match.replace(/android:value=["'][^"']*["']/, 'android:value="false"'));
71
+ } else if (enabled) {
72
+ const existing = /[ \t]*<meta-data\b(?=[^>]*\bandroid:name=["']firebase_analytics_collection_enabled["'])[^>]*\/\s*>\r?\n?/;
73
+ const prior = next.match(existing)?.[0] || '';
74
+ const block = ` <!-- ${analyticsMarker} ${Buffer.from(prior).toString('base64')} -->${newline} <meta-data android:name="firebase_analytics_collection_enabled" android:value="false" />${newline}`;
75
+ if (!/<application\b[^>]*>/.test(next)) throw new Error('Huawei privacy: application element was not found in AndroidManifest.xml.');
76
+ next = prior ? next.replace(existing, block) : next.replace(/<application\b[^>]*>/, match => `${match}${newline}${block}`);
77
+ }
78
+ if (next !== original) fs.writeFileSync(manifestPath, next);
79
+ return next !== original;
80
+ }
81
+
82
+ function syncHuaweiPrivacy(projectRoot, storeId, platform = 'android') {
83
+ const enabled = platform === 'android' && Number(storeId) === 4;
84
+ const config = JSON.parse(fs.readFileSync(path.join(projectRoot, 'capacitor.config.json'), 'utf8'));
85
+ const appId = Number(config.android?.APP_UNIQUE_ID);
86
+ if (enabled && (!Number.isInteger(appId) || appId < 1)) {
87
+ throw new Error('Huawei privacy: capacitor.config.json needs a valid android.APP_UNIQUE_ID.');
88
+ }
89
+ // Inspect both targets before writing either one, so unsupported app layouts fail early.
90
+ const manifestPath = path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml');
91
+ if (enabled && !fs.existsSync(manifestPath)) {
92
+ throw new Error('Huawei privacy: AndroidManifest.xml was not found.');
93
+ }
94
+ if (enabled && !/<application\b[^>]*>/.test(fs.readFileSync(manifestPath, 'utf8'))) {
95
+ throw new Error('Huawei privacy: application element was not found in AndroidManifest.xml.');
96
+ }
97
+ updateEntry(projectRoot, enabled, appId, config.appName || 'App');
98
+ updateAnalyticsDefault(projectRoot, enabled);
99
+ if (enabled) console.log(`Huawei privacy consent enabled. Verify https://htmlcodeplay.com/privacy/ch/${appId} is published before submission.`);
100
+ }
101
+
102
+ module.exports = { syncHuaweiPrivacy };
@@ -1,108 +1,116 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
4
- function findLatestIapDirectory(projectRoot = process.cwd()) {
5
- const ads = path.join(projectRoot, 'src/js/Ads');
6
- if (!fs.existsSync(ads)) return null;
7
- const folder = fs.readdirSync(ads, { withFileTypes: true })
8
- .filter(entry => entry.isDirectory() && /^IAP-\d+(?:\.\d+)*$/.test(entry.name)
9
- && fs.existsSync(path.join(ads, entry.name, 'IAP-state.js'))
10
- && fs.statSync(path.join(ads, entry.name, 'IAP-state.js')).isFile())
11
- .map(entry => entry.name).sort((a, b) => b.localeCompare(a, undefined, { numeric: true }))[0];
12
- return folder ? path.join(ads, folder) : null;
13
- }
14
-
15
- // Resolve old protected controllers without rewriting their source or version.
16
- function legacyIapPlugin(projectRoot = process.cwd()) {
17
- return {
18
- name: 'codeplay-legacy-iap-imports',
19
- enforce: 'pre',
20
- async resolveId(source, importer) {
21
- const match = /^(?:(?:\.\.?\/)+|@\/|\/src\/)(?:[^?#]*\/)?IAP-\d+(?:\.\d+)*\/([^?#]+)([?#].*)?$/.exec(source);
22
- if (!match) return null;
23
- const directory = findLatestIapDirectory(projectRoot);
24
- if (!directory) throw new Error('Cannot resolve legacy IAP import: no installed IAP-state.js.');
25
- const target = path.resolve(directory, match[1]);
26
- if (!target.startsWith(directory + path.sep) || !fs.existsSync(target) || !fs.statSync(target).isFile()) throw new Error(`Missing IAP module: ${source}`);
27
- return this.resolve(target + (match[2] || ''), importer, { skipSelf: true });
28
- },
29
- };
30
- }
31
-
32
- // Reuse the before-build source inventory and gallery migration's import scanner.
33
- // Only module specifiers are changed; comments, text and F7 markup are preserved.
34
- function syncIapAliases(projectRoot = process.cwd(), files = []) {
35
- const directory = findLatestIapDirectory(projectRoot);
36
- const plans = [];
37
- for (const file of files) {
38
- if (file.split(path.sep).some(part => /^admob-nextgen-\d+(?:\.\d+)*$/.test(part)) || /^admob-emi-nextgen-\d+(?:\.\d+)*\.js$/.test(path.basename(file))) continue;
39
- if (!/\.(?:js|mjs|cjs|ts|tsx|jsx|f7|vue)$/.test(file) || file.endsWith('.min.js')) continue;
40
- const original = fs.readFileSync(file, 'utf8');
41
- let script = original;
42
- if (/\.(f7|vue)$/.test(file)) {
43
- script = original.replace(/[^\r\n]/g, ' ');
44
- for (const match of original.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script\s*>/gi)) {
45
- const start = match.index + match[0].indexOf('>') + 1;
46
- script = script.slice(0, start) + match[1] + script.slice(start + match[1].length);
47
- }
48
- }
49
- const code = script.replace(/\/\/[^\r\n]*|\/\*[\s\S]*?\*\/|(['"`])(?:\\[\s\S]|(?!\1)[^\\])*\1/g,
50
- (match, quote) => quote ? match : match.replace(/[^\r\n]/g, ' '));
51
- const imports = /(['"`])(?:\\[\s\S]|(?!\1)[^\\])*\1|\b(?:import\s+(?:[^;'"`]*?\s+from\s*)?|export\s+[^;'"`]*?\s+from\s*|(?:import|require)\s*\(\s*)(['"])([^'"\r\n]+)\2/g;
52
- const replacements = [];
53
- for (const match of code.matchAll(imports)) {
54
- const specifier = match[3];
55
- if (!specifier) continue;
56
- const versioned = /^(?:(?:\.\.?\/)+|@\/|\/src\/)(?:[^?#]*\/)?IAP-\d+(?:\.\d+)*\/([^?#]+)([?#].*)?$/.exec(specifier);
57
- const aliased = /^@iap\/([^?#]+)([?#].*)?$/.exec(specifier);
58
- if (!versioned && !aliased) continue;
59
- if (!directory) throw new Error(`Cannot configure @iap: no installed IAP folder with IAP-state.js (${file}).`);
60
- const module = (versioned || aliased)[1];
61
- const target = path.resolve(directory, module);
62
- if (!target.startsWith(directory + path.sep) || !fs.existsSync(target) || !fs.statSync(target).isFile()) throw new Error(`Missing @iap/${module} in ${directory}; update the compatible IAP package first.`);
63
- if (versioned) {
64
- const start = match.index + match[0].lastIndexOf(specifier);
65
- replacements.push({ start, length: specifier.length, value: `@iap/${module}${versioned[2] || ''}` });
66
- }
67
- }
68
- let updated = original;
69
- for (const edit of replacements.reverse()) updated = updated.slice(0, edit.start) + edit.value + updated.slice(edit.start + edit.length);
70
- if (updated !== original) plans.push({ file, updated });
71
- }
72
- const vite = ['vite.config.mjs', 'vite.config.js'].map(name => path.join(projectRoot, name)).find(file => fs.existsSync(file));
73
- if (directory && vite) {
74
- let original = fs.readFileSync(vite, 'utf8');
75
- const saved = original;
76
- if (!original.includes('codeplayIapAliases.findLatestIapDirectory(')) {
77
- const code = original.replace(/\/\/[^\r\n]*|\/\*[\s\S]*?\*\/|(['"`])(?:\\[\s\S]|(?!\1)[^\\])*\1/g,
78
- (match, quote) => quote ? match : match.replace(/[^\r\n]/g, ' '));
79
- const header = /\balias\s*:\s*([\[{])/.exec(code);
80
- if (!header) throw new Error('Cannot configure @iap: Vite needs a resolve.alias object or array.');
81
- if (/['"]@iap['"]\s*[:,]/.test(code)) throw new Error('Cannot replace a custom @iap alias automatically; use codeplayIapAliases.findLatestIapDirectory().');
82
- const entry = header[1] === '{'
83
- ? "'@iap': codeplayIapAliases.findLatestIapDirectory(),"
84
- : "{ find: '@iap', replacement: codeplayIapAliases.findLatestIapDirectory() },";
85
- const offset = header.index + header[0].length;
86
- const newline = original.includes('\r\n') ? '\r\n' : '\n';
87
- const updated = original.slice(0, offset) + newline + ' ' + entry + original.slice(offset);
88
- original = `import codeplayIapAliases from './buildCodeplay/iap-alias.cjs';${newline}${updated}`;
89
- }
90
- if (!original.includes('codeplayIapAliases.legacyIapPlugin(')) {
91
- const plugins = /\bplugins\s*:\s*\[/.exec(original);
92
- if (plugins) {
93
- const offset = plugins.index + plugins[0].length;
94
- original = original.slice(0, offset) + '\n codeplayIapAliases.legacyIapPlugin(),' + original.slice(offset);
95
- } else {
96
- const resolve = /\bresolve\s*:/.exec(original);
97
- if (!resolve) throw new Error('Cannot configure legacy IAP resolution: Vite resolve settings missing.');
98
- original = original.slice(0, resolve.index) + 'plugins: [codeplayIapAliases.legacyIapPlugin()],\n' + original.slice(resolve.index);
99
- }
100
- }
101
- if (saved !== original) plans.push({ file: vite, updated: original });
102
- }
103
- // Validate the complete migration before writing. No confirmation is needed.
104
- for (const plan of plans) fs.writeFileSync(plan.file, plan.updated);
105
- return plans.map(plan => path.relative(projectRoot, plan.file));
106
- }
107
-
108
- module.exports = { findLatestIapDirectory, legacyIapPlugin, syncIapAliases };
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ function findLatestIapDirectory(projectRoot = process.cwd()) {
5
+ const ads = path.join(projectRoot, 'src/js/Ads');
6
+ if (!fs.existsSync(ads)) return null;
7
+ const folder = fs.readdirSync(ads, { withFileTypes: true })
8
+ .filter(entry => entry.isDirectory() && /^IAP-\d+(?:\.\d+)*$/.test(entry.name)
9
+ && fs.existsSync(path.join(ads, entry.name, 'IAP-state.js'))
10
+ && fs.statSync(path.join(ads, entry.name, 'IAP-state.js')).isFile())
11
+ .map(entry => entry.name).sort((a, b) => b.localeCompare(a, undefined, { numeric: true }))[0];
12
+ return folder ? path.join(ads, folder) : null;
13
+ }
14
+
15
+ // Resolve old protected controllers without rewriting their source or version.
16
+ function legacyIapPlugin(projectRoot = process.cwd()) {
17
+ return {
18
+ name: 'codeplay-legacy-iap-imports',
19
+ enforce: 'pre',
20
+ async resolveId(source, importer) {
21
+ const match = /^(?:(?:\.\.?\/)+|@\/|\/src\/)(?:[^?#]*\/)?IAP-\d+(?:\.\d+)*\/([^?#]+)([?#].*)?$/.exec(source);
22
+ if (!match) return null;
23
+ const directory = findLatestIapDirectory(projectRoot);
24
+ if (!directory) throw new Error('Cannot resolve legacy IAP import: no installed IAP-state.js.');
25
+ const target = path.resolve(directory, match[1]);
26
+ if (!target.startsWith(directory + path.sep) || !fs.existsSync(target) || !fs.statSync(target).isFile()) throw new Error(`Missing IAP module: ${source}`);
27
+ return this.resolve(target + (match[2] || ''), importer, { skipSelf: true });
28
+ },
29
+ };
30
+ }
31
+
32
+ // Reuse the before-build source inventory and gallery migration's import scanner.
33
+ // Only module specifiers are changed; comments, text and F7 markup are preserved.
34
+ function syncIapAliases(projectRoot = process.cwd(), files = []) {
35
+ const directory = findLatestIapDirectory(projectRoot);
36
+ const plans = [];
37
+ for (const file of files) {
38
+ if (file.split(path.sep).some(part => /^admob-nextgen-\d+(?:\.\d+)*$/.test(part)) || /^admob-emi-nextgen-\d+(?:\.\d+)*\.js$/.test(path.basename(file))) continue;
39
+ if (!/\.(?:js|mjs|cjs|ts|tsx|jsx|f7|vue)$/.test(file) || file.endsWith('.min.js')) continue;
40
+ const original = fs.readFileSync(file, 'utf8');
41
+ let script = original;
42
+ if (/\.(f7|vue)$/.test(file)) {
43
+ script = original.replace(/[^\r\n]/g, ' ');
44
+ for (const match of original.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script\s*>/gi)) {
45
+ const start = match.index + match[0].indexOf('>') + 1;
46
+ script = script.slice(0, start) + match[1] + script.slice(start + match[1].length);
47
+ }
48
+ }
49
+ const code = script.replace(/\/\/[^\r\n]*|\/\*[\s\S]*?\*\/|(['"`])(?:\\[\s\S]|(?!\1)[^\\])*\1/g,
50
+ (match, quote) => quote ? match : match.replace(/[^\r\n]/g, ' '));
51
+ const imports = /(['"`])(?:\\[\s\S]|(?!\1)[^\\])*\1|\b(?:import\s+(?:[^;'"`]*?\s+from\s*)?|export\s+[^;'"`]*?\s+from\s*|(?:import|require)\s*\(\s*)(['"])([^'"\r\n]+)\2/g;
52
+ const replacements = [];
53
+ for (const match of code.matchAll(imports)) {
54
+ const specifier = match[3];
55
+ if (!specifier) continue;
56
+ const versioned = /^(?:(?:\.\.?\/)+|@\/|\/src\/)(?:[^?#]*\/)?IAP-\d+(?:\.\d+)*\/([^?#]+)([?#].*)?$/.exec(specifier);
57
+ const aliased = /^@iap\/([^?#]+)([?#].*)?$/.exec(specifier);
58
+ if (!versioned && !aliased) continue;
59
+ if (!directory) throw new Error(`Cannot configure @iap: no installed IAP folder with IAP-state.js (${file}).`);
60
+ const module = (versioned || aliased)[1];
61
+ const target = path.resolve(directory, module);
62
+ if (!target.startsWith(directory + path.sep) || !fs.existsSync(target) || !fs.statSync(target).isFile()) throw new Error(`Missing @iap/${module} in ${directory}; update the compatible IAP package first.`);
63
+ if (versioned) {
64
+ const start = match.index + match[0].lastIndexOf(specifier);
65
+ replacements.push({ start, length: specifier.length, value: `@iap/${module}${versioned[2] || ''}` });
66
+ }
67
+ }
68
+ let updated = original;
69
+ for (const edit of replacements.reverse()) updated = updated.slice(0, edit.start) + edit.value + updated.slice(edit.start + edit.length);
70
+ if (updated !== original) plans.push({ file, updated });
71
+ }
72
+ const vite = ['vite.config.mjs', 'vite.config.js'].map(name => path.join(projectRoot, name)).find(file => fs.existsSync(file));
73
+ if (directory && vite) {
74
+ let original = fs.readFileSync(vite, 'utf8');
75
+ const saved = original;
76
+ if (!original.includes('codeplayIapAliases.findLatestIapDirectory(')) {
77
+ const code = original.replace(/\/\/[^\r\n]*|\/\*[\s\S]*?\*\/|(['"`])(?:\\[\s\S]|(?!\1)[^\\])*\1/g,
78
+ (match, quote) => quote ? match : match.replace(/[^\r\n]/g, ' '));
79
+ const header = /\balias\s*:\s*([\[{])/.exec(code);
80
+ if (!header) throw new Error('Cannot configure @iap: Vite needs a resolve.alias object or array.');
81
+ // Migrate only the standard versioned app directory; never evaluate config code.
82
+ const existing = /['"]@iap['"]\s*[:,]/.test(code);
83
+ const standard = /(['"]@iap['"]\s*:\s*|\bfind\s*:\s*['"]@iap['"]\s*,\s*replacement\s*:\s*)((?:path\.)?resolve\s*\(\s*__dirname\s*,\s*(['"])(?:\.\/)?src\/js\/Ads\/IAP-\d+(?:\.\d+)*\/?\3\s*\))(?=\s*[,}])/g;
84
+ const matches = [...code.matchAll(standard)];
85
+ if (existing && matches.length !== 1) throw new Error('Cannot replace a custom @iap alias automatically; use codeplayIapAliases.findLatestIapDirectory().');
86
+ const entry = header[1] === '{'
87
+ ? "'@iap': codeplayIapAliases.findLatestIapDirectory(),"
88
+ : "{ find: '@iap', replacement: codeplayIapAliases.findLatestIapDirectory() },";
89
+ const offset = header.index + header[0].length;
90
+ const newline = original.includes('\r\n') ? '\r\n' : '\n';
91
+ const match = matches[0];
92
+ const start = match && match.index + match[1].length;
93
+ const updated = existing
94
+ ? original.slice(0, start) + 'codeplayIapAliases.findLatestIapDirectory()' + original.slice(start + match[2].length)
95
+ : original.slice(0, offset) + newline + ' ' + entry + original.slice(offset);
96
+ original = `import codeplayIapAliases from './buildCodeplay/iap-alias.cjs';${newline}${updated}`;
97
+ }
98
+ if (!original.includes('codeplayIapAliases.legacyIapPlugin(')) {
99
+ const plugins = /\bplugins\s*:\s*\[/.exec(original);
100
+ if (plugins) {
101
+ const offset = plugins.index + plugins[0].length;
102
+ original = original.slice(0, offset) + '\n codeplayIapAliases.legacyIapPlugin(),' + original.slice(offset);
103
+ } else {
104
+ const resolve = /\bresolve\s*:/.exec(original);
105
+ if (!resolve) throw new Error('Cannot configure legacy IAP resolution: Vite resolve settings missing.');
106
+ original = original.slice(0, resolve.index) + 'plugins: [codeplayIapAliases.legacyIapPlugin()],\n' + original.slice(resolve.index);
107
+ }
108
+ }
109
+ if (saved !== original) plans.push({ file: vite, updated: original });
110
+ }
111
+ // Validate the complete migration before writing. No confirmation is needed.
112
+ for (const plan of plans) fs.writeFileSync(plan.file, plan.updated);
113
+ return plans.map(plan => path.relative(projectRoot, plan.file));
114
+ }
115
+
116
+ module.exports = { findLatestIapDirectory, legacyIapPlugin, syncIapAliases };
@@ -9,30 +9,30 @@ const replaceEmiPluginCode=()=>
9
9
 
10
10
 
11
11
  if (fs.existsSync(filePath)) {
12
- let fileContent = fs.readFileSync(filePath, 'utf8');
13
-
14
- // match the hideBannerAd method
15
- const methodRegex = /(- \(void\)hideBannerAd:[\s\S]*?\{)([\s\S]*?)(^\})/m;
16
-
17
- const match = fileContent.match(methodRegex);
18
-
19
- if (match) {
20
- const methodBody = match[2];
21
-
22
- // replace only if the line is not already commented
23
- const modifiedMethodBody = methodBody.replace(
24
- /^(\s*)(?!\/\/)\[self\s+resetWebViewHeight\];/m,
25
- '$1//[self resetWebViewHeight];'
26
- );
27
-
28
- const updatedFileContent =
29
- fileContent.slice(0, match.index) +
30
- match[1] +
31
- modifiedMethodBody +
32
- match[3] +
33
- fileContent.slice(match.index + match[0].length);
34
-
35
- fs.writeFileSync(filePath, updatedFileContent, 'utf8');
12
+ let fileContent = fs.readFileSync(filePath, 'utf8');
13
+
14
+ // match the hideBannerAd method
15
+ const methodRegex = /(- \(void\)hideBannerAd:[\s\S]*?\{)([\s\S]*?)(^\})/m;
16
+
17
+ const match = fileContent.match(methodRegex);
18
+
19
+ if (match) {
20
+ const methodBody = match[2];
21
+
22
+ // replace only if the line is not already commented
23
+ const modifiedMethodBody = methodBody.replace(
24
+ /^(\s*)(?!\/\/)\[self\s+resetWebViewHeight\];/m,
25
+ '$1//[self resetWebViewHeight];'
26
+ );
27
+
28
+ const updatedFileContent =
29
+ fileContent.slice(0, match.index) +
30
+ match[1] +
31
+ modifiedMethodBody +
32
+ match[3] +
33
+ fileContent.slice(match.index + match[0].length);
34
+
35
+ fs.writeFileSync(filePath, updatedFileContent, 'utf8');
36
36
  console.log(
37
37
  '✅ Successfully ensured [self resetWebViewHeight]; is commented only inside hideBannerAd in emiAdmobPlugin.m'
38
38
  );
@@ -1,38 +1,38 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const plist = require('plist');
4
- const { syncAndroidR8Rules } = require('./fix-optimize-builld/restore-android-r8-rules.cjs');
5
-
6
- syncAndroidR8Rules(process.cwd(), { installGradleHook: true });
7
-
8
- const { readFileSync } = require("fs");
9
-
10
-
11
-
12
-
13
-
14
-
15
- const addToolAttribute=()=>{
16
- //const platformRoot = path.join(context.opts.projectRoot, 'android');
17
- //const manifestPath = path.join(platformRoot, 'capacitor-cordova-android-plugins/src/main/AndroidManifest.xml');
18
-
19
- const manifestPath = path.resolve(process.cwd(), 'android/capacitor-cordova-android-plugins/src/main/AndroidManifest.xml');
20
-
21
- if (fs.existsSync(manifestPath)) {
22
- let manifest = fs.readFileSync(manifestPath, 'utf8');
23
-
24
- // Check if xmlns:tools exists
25
- if (!manifest.includes('xmlns:tools="http://schemas.android.com/tools"')) {
26
- // Add the tools namespace to the <manifest> tag.
27
- manifest = manifest.replace('<manifest', '<manifest xmlns:tools="http://schemas.android.com/tools"');
28
- fs.writeFileSync(manifestPath, manifest, 'utf8');
29
- console.log('✅ Added xmlns:tools to AndroidManifest.xml');
30
- } else {
31
- console.log('ℹ️ xmlns:tools already exists, skipping...');
32
- }
33
- } else {
34
- console.log('ℹ️ capacitor-cordova-android-plugins AndroidManifest.xml not found, skipping tools namespace update.');
35
- }
36
- };
37
-
38
- addToolAttribute()
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const plist = require('plist');
4
+ const { syncAndroidR8Rules } = require('./fix-optimize-builld/restore-android-r8-rules.cjs');
5
+
6
+ syncAndroidR8Rules(process.cwd(), { installGradleHook: true });
7
+
8
+ const { readFileSync } = require("fs");
9
+
10
+
11
+
12
+
13
+
14
+
15
+ const addToolAttribute=()=>{
16
+ //const platformRoot = path.join(context.opts.projectRoot, 'android');
17
+ //const manifestPath = path.join(platformRoot, 'capacitor-cordova-android-plugins/src/main/AndroidManifest.xml');
18
+
19
+ const manifestPath = path.resolve(process.cwd(), 'android/capacitor-cordova-android-plugins/src/main/AndroidManifest.xml');
20
+
21
+ if (fs.existsSync(manifestPath)) {
22
+ let manifest = fs.readFileSync(manifestPath, 'utf8');
23
+
24
+ // Check if xmlns:tools exists
25
+ if (!manifest.includes('xmlns:tools="http://schemas.android.com/tools"')) {
26
+ // Add the tools namespace to the <manifest> tag.
27
+ manifest = manifest.replace('<manifest', '<manifest xmlns:tools="http://schemas.android.com/tools"');
28
+ fs.writeFileSync(manifestPath, manifest, 'utf8');
29
+ console.log('✅ Added xmlns:tools to AndroidManifest.xml');
30
+ } else {
31
+ console.log('ℹ️ xmlns:tools already exists, skipping...');
32
+ }
33
+ } else {
34
+ console.log('ℹ️ capacitor-cordova-android-plugins AndroidManifest.xml not found, skipping tools namespace update.');
35
+ }
36
+ };
37
+
38
+ addToolAttribute()