codeplay-common 4.11.21 → 4.11.23

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.
@@ -0,0 +1,111 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { execFileSync } = require('child_process');
4
+
5
+ const VK_PACKAGE = 'capacitor-codeplay-rustore-ads';
6
+ const ADMOB_PACKAGE = 'capacitor-admob-nextgen';
7
+
8
+ // A missing RuAds section preserves the existing provider on every store.
9
+ function getAdProvider(config, storeId, platform = 'android') {
10
+ const id = Number(storeId || 1);
11
+ const ru = config.plugins?.RuAds;
12
+ const assigned = platform !== 'ios' && [4, 10].includes(id)
13
+ && (ru?.STORE_IDS || []).map(Number).includes(id);
14
+ if (assigned) return ru.VK_ADS_ENABLED === true ? 'vk' : 'none';
15
+ return config.plugins?.AdMob?.ADMOB_ENABLED === false ? 'none' : 'admob';
16
+ }
17
+
18
+ function findLatestVkController(projectRoot = process.cwd()) {
19
+ const ads = path.join(projectRoot, 'src/js/Ads');
20
+ const pattern = /^vk-ads-(\d+(?:\.\d+)*)$/;
21
+ if (!fs.existsSync(ads)) return null;
22
+ const folders = fs.readdirSync(ads, { withFileTypes: true }).filter(entry => entry.isDirectory() && pattern.test(entry.name))
23
+ .map(entry => entry.name).sort((a, b) => b.match(pattern)[1].localeCompare(a.match(pattern)[1], undefined, { numeric: true }));
24
+ const folder = folders.find(name => {
25
+ const file = path.join(ads, name, 'vk-ads.js');
26
+ return fs.existsSync(file) && fs.statSync(file).isFile() && fs.statSync(file).size > 0;
27
+ });
28
+ return folder ? `./src/js/Ads/${folder}/vk-ads.js` : null;
29
+ }
30
+
31
+ function controllerPath(config, storeId, platform, admobPath, projectRoot = process.cwd()) {
32
+ const provider = getAdProvider(config, storeId, platform);
33
+ if (provider === 'admob') return admobPath;
34
+ if (provider === 'none') return './buildCodeplay/disabled-ads.mjs';
35
+ const controller = findLatestVkController(projectRoot);
36
+ if (!controller) throw new Error('VK ads is enabled but no complete src/js/Ads/vk-ads-<version>/vk-ads.js exists. Copy the versioned VK folder manually first; later updates use the server versions.json entry "vk-ads".');
37
+ return controller;
38
+ }
39
+
40
+ function prepareReleaseAds(projectRoot, storeId, platform = 'android', warn = console.warn) {
41
+ const capacitorConfig = JSON.parse(fs.readFileSync(path.join(projectRoot, 'capacitor.config.json')));
42
+ if (getAdProvider(capacitorConfig, storeId, platform) !== 'vk') return false;
43
+ const file = path.join(projectRoot, 'src/js/Ads/vk-ad-configuration.json');
44
+ const original = fs.readFileSync(file, 'utf8');
45
+ const configuration = JSON.parse(original);
46
+ if (configuration.config?.isTesting !== true) return false;
47
+ warn('\x1b[33m⚠️ VK test ads are enabled. Automatically setting config.isTesting to false in src/js/Ads/vk-ad-configuration.json before release.\x1b[0m');
48
+ configuration.config.isTesting = false;
49
+ const newline = original.includes('\r\n') ? '\r\n' : '\n';
50
+ fs.writeFileSync(file, (JSON.stringify(configuration, null, 2) + '\n').replaceAll('\n', newline));
51
+ return true;
52
+ }
53
+
54
+ function includedPackages(config, pkg, platform, provider) {
55
+ const existing = config[platform]?.includePlugins ?? config.includePlugins;
56
+ const packages = existing || [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.devDependencies || {})];
57
+ return [...new Set(packages.filter(name => ![VK_PACKAGE, ADMOB_PACKAGE].includes(name))
58
+ .concat(provider === 'vk' ? [VK_PACKAGE] : provider === 'admob' ? [ADMOB_PACKAGE] : []))];
59
+ }
60
+
61
+ function syncAdProviderPackages(projectRoot = process.cwd(), run) {
62
+ const config = JSON.parse(fs.readFileSync(path.join(projectRoot, 'capacitor.config.json')));
63
+ const provider = getAdProvider(config, process.env.VITE_STORE_ID, process.env.CODEPLAY_BUILD_PLATFORM);
64
+ const selected = provider === 'vk' ? VK_PACKAGE : provider === 'admob' ? ADMOB_PACKAGE : null;
65
+ const readPackage = () => JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json')));
66
+ const installed = name => fs.existsSync(path.join(projectRoot, 'node_modules', name, 'package.json'));
67
+ const execute = args => {
68
+ if (run) run(`npm ${args.join(' ')}`);
69
+ else execFileSync(process.platform === 'win32' ? 'npm.cmd' : 'npm', args,
70
+ { cwd: projectRoot, stdio: 'inherit', shell: process.platform === 'win32' });
71
+ };
72
+ let changed = false;
73
+ for (const name of [ADMOB_PACKAGE, VK_PACKAGE]) {
74
+ const pkg = readPackage();
75
+ if (name !== selected && (pkg.dependencies?.[name] || pkg.devDependencies?.[name] || installed(name))) {
76
+ execute(['uninstall', name]);
77
+ changed = true;
78
+ }
79
+ }
80
+ const pkg = readPackage();
81
+ const vkVersion = selected === VK_PACKAGE && installed(selected)
82
+ ? JSON.parse(fs.readFileSync(path.join(projectRoot, 'node_modules', selected, 'package.json'))).version : null;
83
+ const [major, minor, patch] = String(vkVersion || '').split('.').map(Number);
84
+ const oldVk = vkVersion && major === 0 && (minor < 1 || (minor === 1 && patch < 1));
85
+ if (selected && (!pkg.dependencies?.[selected] || !installed(selected) || oldVk)) {
86
+ const version = oldVk ? '^0.1.1' : pkg.dependencies?.[selected] || (selected === VK_PACKAGE ? '^0.1.1' : '');
87
+ execute(['install', version ? `${selected}@${version}` : selected, '--save']);
88
+ changed = true;
89
+ }
90
+ return changed;
91
+ }
92
+
93
+ // includePlugins is scoped to cap sync; always restore the caller's configuration.
94
+ // Filtering affects both Capacitor and Cordova discovery without uninstalling other providers.
95
+ function withNativeAdProvider(projectRoot, storeId, platform, action) {
96
+ const configPath = path.join(projectRoot, 'capacitor.config.json');
97
+ const original = fs.readFileSync(configPath, 'utf8');
98
+ const config = JSON.parse(original);
99
+ const pkg = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json')));
100
+ const provider = getAdProvider(config, storeId, platform);
101
+ const targets = platform ? [platform] : ['android', 'ios'];
102
+ for (const target of targets) {
103
+ config[target] = { ...config[target], includePlugins: includedPackages(config, pkg, target,
104
+ getAdProvider(config, storeId, target)) };
105
+ }
106
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n');
107
+ try { return action(provider); }
108
+ finally { fs.writeFileSync(configPath, original); }
109
+ }
110
+
111
+ module.exports = { getAdProvider, controllerPath, findLatestVkController, prepareReleaseAds, includedPackages, syncAdProviderPackages, withNativeAdProvider };
@@ -0,0 +1,49 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ function syncRuAdsSetup(projectRoot, { runtimeRoot } = {}) {
5
+ const config = JSON.parse(fs.readFileSync(path.join(projectRoot, 'capacitor.config.json')));
6
+ const vite = ['vite.config.mjs', 'vite.config.js'].map(name => path.join(projectRoot, name)).find(file => fs.existsSync(file));
7
+ if (vite) {
8
+ const source = fs.readFileSync(vite, 'utf8');
9
+ if (!source.includes('ruAdsBuild.controllerPath(') && !source.includes('codeplayOriginalViteConfig')) {
10
+ if (!/^[ \t]*export\s+default\s+/m.test(source)) throw new Error('Cannot configure RuAds: Vite must have a default configuration export.');
11
+ const wrapped = source.replace(/^[ \t]*export\s+default\s+/m, 'const codeplayOriginalViteConfig = ');
12
+ fs.writeFileSync(vite, `import ruAdsBuild from './buildCodeplay/ruads.cjs';
13
+ import { readFileSync as codeplayReadConfig } from 'node:fs';
14
+ import { resolve as codeplayResolve } from 'node:path';
15
+ ${wrapped}
16
+ export default async (environment) => {
17
+ const base = await (typeof codeplayOriginalViteConfig === 'function'
18
+ ? codeplayOriginalViteConfig(environment) : codeplayOriginalViteConfig);
19
+ const settings = JSON.parse(codeplayReadConfig(codeplayResolve('capacitor.config.json'), 'utf8'));
20
+ const storeId = process.env.VITE_STORE_ID || '1';
21
+ const platform = process.env.CODEPLAY_BUILD_PLATFORM || (storeId === '6' ? 'ios' : 'android');
22
+ const aliases = base.resolve?.alias || {};
23
+ const current = Array.isArray(aliases) ? aliases.find(item => item.find === '@admob')?.replacement : aliases['@admob'];
24
+ const provider = ruAdsBuild.getAdProvider(settings, storeId, platform);
25
+ if (!current && provider === 'vk') {
26
+ throw new Error('VK ads requires the shared @admob alias. Update this app integration first.');
27
+ }
28
+ const selected = current && (provider === 'admob' ? current : codeplayResolve(ruAdsBuild.controllerPath(settings, storeId, platform, current)));
29
+ const alias = !selected ? aliases : Array.isArray(aliases)
30
+ ? aliases.map(item => item.find === '@admob' ? { ...item, replacement: selected } : item)
31
+ : { ...aliases, '@admob': selected };
32
+ return { ...base, resolve: { ...base.resolve, alias }, define: { ...base.define,
33
+ 'import.meta.env.VITE_STORE_ID': JSON.stringify(storeId),
34
+ 'import.meta.env.VITE_RUADS_ENABLED': JSON.stringify(provider === 'vk') } };
35
+ };
36
+ `);
37
+ }
38
+ }
39
+ const ru = config.plugins?.RuAds;
40
+ if (ru?.VK_ADS_ENABLED !== true || !(ru.STORE_IDS || []).some(id => [4, 10].includes(Number(id)))) return;
41
+ const ads = path.join(projectRoot, 'src/js/Ads');
42
+ const configuration = path.join(ads, 'vk-ad-configuration.json');
43
+ if (fs.existsSync(configuration)) return;
44
+ const runtime = runtimeRoot || path.join(projectRoot, 'node_modules/codeplay-common/runtime/vk-ads');
45
+ fs.mkdirSync(ads, { recursive: true });
46
+ fs.copyFileSync(path.join(runtime, 'vk-ad-configuration.json'), configuration);
47
+ }
48
+
49
+ module.exports = { syncRuAdsSetup };
@@ -0,0 +1,43 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const start = '// BEGIN CODEPLAY NON-GOOGLE STORE BILLING';
5
+ const end = '// END CODEPLAY NON-GOOGLE STORE BILLING';
6
+ const block = `${start}
7
+ configurations.configureEach {
8
+ exclude group: 'com.android.billingclient'
9
+ }
10
+ android.buildTypes.configureEach {
11
+ proguardFile file('../../buildCodeplay/non-google-billing.pro')
12
+ }
13
+ ${end}`;
14
+
15
+ function syncStoreBillingPolicy(projectRoot, storeId, platform = 'android') {
16
+ if (platform !== 'android') return false;
17
+ const excluded = [4, 10].includes(Number(storeId));
18
+ const gradle = path.join(projectRoot, 'android/app/build.gradle');
19
+ if (!fs.existsSync(gradle)) return false;
20
+ const original = fs.readFileSync(gradle, 'utf8');
21
+ const newline = original.includes('\r\n') ? '\r\n' : '\n';
22
+ const clean = original.replace(new RegExp(`${start}[\\s\\S]*?${end}\\r?\\n?`, 'g'), '');
23
+ const updated = excluded
24
+ ? `${clean.trimEnd()}${newline}${newline}${block.replaceAll('\n', newline)}${newline}`
25
+ : clean;
26
+ let changed = updated !== original;
27
+ if (changed) fs.writeFileSync(gradle, updated);
28
+
29
+ // The excluded library supplies its own permission. Also remove any explicit
30
+ // app declaration; other permissions and supported-store billing stay intact.
31
+ const manifest = path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml');
32
+ if (excluded && fs.existsSync(manifest)) {
33
+ const current = fs.readFileSync(manifest, 'utf8');
34
+ const next = current.replace(/^[ \t]*<uses-permission\b(?=[^>]*\bandroid:name\s*=\s*(['"])com\.android\.vending\.BILLING\1)[^>]*\/\s*>[ \t]*(?:\r?\n)?/gm, '');
35
+ if (next !== current) {
36
+ fs.writeFileSync(manifest, next);
37
+ changed = true;
38
+ }
39
+ }
40
+ return changed;
41
+ }
42
+
43
+ module.exports = { syncStoreBillingPolicy };
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "plugins":[
3
+ {"name":"vk-ads","pattern":"vk-ads-(\\d+(?:\\.\\d+)*)$","minVersion":"1.0","baseDir":"js/Ads","mandatoryUpdate":true,"isFolder":true},
3
4
  {"name":"backbutton","pattern":"backbutton-(\\d+\\.\\d+)\\.js$","minVersion":"2.1","baseDir":"js","mandatoryUpdate":true},
4
5
  {"name":"common-js","pattern":"common-(\\d+\\.\\d+)(?:-beta-(\\d+))?\\.js$","minVersion":"6.7","baseDir":"js","mandatoryUpdate":true},
5
6
 
@@ -3,6 +3,7 @@ Can be run like
3
3
  node finalrelease
4
4
  node finalrelease 1
5
5
  node finalrelease "1,2,7"
6
+ node finalrelease 10 // RuStore signed AAB (9 is reserved for desktop)
6
7
  */
7
8
 
8
9
  import { existsSync, readFileSync, readdirSync, promises, constants, writeFileSync, unlinkSync, mkdirSync, renameSync } from 'fs';
@@ -18,6 +19,7 @@ import { syncAndroidR8Rules } from './buildCodeplay/fix-optimize-builld/restore-
18
19
  const fs = require('fs'); */
19
20
 
20
21
  import fs from 'fs';
22
+ import ruAdsBuild from './buildCodeplay/ruads.cjs';
21
23
  import path from 'path';
22
24
 
23
25
  const __filename = fileURLToPath(import.meta.url);
@@ -179,6 +181,9 @@ function checkProductionAdmobAlias() {
179
181
  }
180
182
 
181
183
  const activeAlias = activeAliases[0];
184
+ if (capacitorConfig.plugins?.RuAds && !viteConfigContent.includes('ruAdsBuild.controllerPath(')) {
185
+ throw new Error('RuAds requires the store-aware controller selector in Vite.');
186
+ }
182
187
  if (!productionAliasPattern.test(activeAlias)) {
183
188
  console.error(`❌ FINAL RELEASE BLOCKED: @admob currently points to '${activeAlias}'.`);
184
189
  console.error(" It must point to './src/js/Ads/admob-nextgen-x.x/admob-emi-nextgen.js', not a test AdMob file.");
@@ -216,11 +221,12 @@ const storeNames = {
216
221
  "4": "HuaweiStore",
217
222
  "5": "OppoStore",
218
223
  //"6": "iOSStore",
219
- "8": "VivoStore"
224
+ "8": "VivoStore",
225
+ "10": "RuStore"
220
226
  };
221
227
 
222
228
 
223
- //1=> PlayStore 2=> SamsungStore 3=>MiStore 4=>HuaweiStore 5=>OppoStore 6=>iOSStore 7=> AmazonStore 8=> VivoStore
229
+ //1=> PlayStore 2=> SamsungStore 3=>MiStore 4=>HuaweiStore 5=>OppoStore 6=>iOSStore 7=> AmazonStore 8=> VivoStore 9=> Desktop (not built here) 10=> RuStore
224
230
 
225
231
 
226
232
 
@@ -254,9 +260,16 @@ if (existsSync(releaseSyncConfigPath)) {
254
260
  }
255
261
  const RELEASE_SYNC_URL = process.env.CODEPLAY_RELEASE_SYNC_URL || releaseSyncConfig.url || 'https://htmlcodeplay.com/codeplay/api/v1/release/sync';
256
262
  const RELEASE_SYNC_TOKEN = process.env.CODEPLAY_RELEASE_SYNC_TOKEN || releaseSyncConfig.token || '';
263
+ // RuStore is resolved by name on the server; numeric IDs remain server-owned.
257
264
  const RELEASE_PLATFORM_IDS = { PlayStore: 1, SamsungStore: 13, AmazonStore: 17, MiStore: 15, HuaweiStore: 12, OppoStore: 14, VivoStore: 16 };
258
265
 
259
266
  function syncReleaseToCodeplay(storeName, finalVersionName, finalVersionCode, releasedDate) {
267
+ const platformId = RELEASE_PLATFORM_IDS[storeName];
268
+ const platformName = storeName === 'RuStore' ? 'RuStore' : null;
269
+ if (!platformName && (!Number.isInteger(platformId) || platformId <= 0)) {
270
+ console.warn(`⚠️ Codeplay release sync skipped for unknown store ${storeName}.`);
271
+ return;
272
+ }
260
273
  if (!RELEASE_SYNC_TOKEN) {
261
274
  console.warn(`⚠️ Codeplay release sync skipped: add a token to ${releaseSyncConfigPath}.`);
262
275
  return;
@@ -273,7 +286,7 @@ function syncReleaseToCodeplay(storeName, finalVersionName, finalVersionCode, re
273
286
  status: 1,
274
287
  folder_name: path.basename(process.cwd()),
275
288
  app_unique_id: String(_appUniqueId || ''),
276
- platform_id: RELEASE_PLATFORM_IDS[storeName],
289
+ ...(platformName ? { platform_name: platformName } : { platform_id: platformId }),
277
290
  });
278
291
  try {
279
292
  const response = execFileSync('curl.exe', ['-sS', '--fail-with-body', '-X', 'POST', RELEASE_SYNC_URL,
@@ -922,11 +935,11 @@ function setAmazonWindowExtensionsDependency(enabled, { cleanup = false } = {})
922
935
  writeFileSync(gradleFilePath, nextGradleContent, 'utf8');
923
936
  }
924
937
 
925
- console.log(enabled
926
- ? '✅ Added Amazon Fire WebView compatibility dependency for Store ID 7.'
927
- : cleanup
928
- ? 'ℹ️ Removed temporary Amazon Fire WebView compatibility dependency after build cleanup.'
929
- : 'ℹ️ Amazon Fire WebView compatibility dependency is not included for this build.');
938
+ if (enabled) {
939
+ console.log('✅ Added Amazon Fire WebView compatibility dependency for Store ID 7.');
940
+ } else if (cleanup && nextGradleContent !== currentGradleContent) {
941
+ console.log('ℹ️ Removed temporary Amazon Fire WebView compatibility dependency after build cleanup.');
942
+ }
930
943
  }
931
944
 
932
945
  const versionCodeMatch = gradleContent.match(/versionCode\s+(\d+)/);
@@ -1168,8 +1181,15 @@ rl.question('Enter new versionCode (press enter to keep current): ', (newVersion
1168
1181
  console.log("\x1b[33m%s\x1b[0m", "Seems to Pro Version [No ads found]");
1169
1182
  }
1170
1183
 
1184
+ const releaseAdConfig = JSON.parse(readFileSync(capacitorConfigPath, 'utf8'));
1185
+ const provider = ruAdsBuild.getAdProvider(releaseAdConfig, id, 'android');
1186
+ console.log(`Advertising provider for ${storeName}: ${provider}`);
1187
+ ruAdsBuild.prepareReleaseAds(__dirname, id, 'android');
1188
+ if (provider === 'vk') ruAdsBuild.controllerPath(releaseAdConfig, id, 'android', null, __dirname);
1189
+
1171
1190
  // Run the Vite build
1172
- execSync(`npm run build:storeid${id}`, { stdio: 'inherit' });
1191
+ execSync(`npm run build:storeid${id}`, { stdio: 'inherit',
1192
+ env: { ...process.env, VITE_STORE_ID: String(id), CODEPLAY_BUILD_PLATFORM: 'android' } });
1173
1193
 
1174
1194
 
1175
1195
 
@@ -1209,7 +1229,9 @@ rl.question('Enter new versionCode (press enter to keep current): ', (newVersion
1209
1229
  execSync(`npx cap build android --androidreleasetype=${buildType}`, { stdio: 'inherit' }); */
1210
1230
 
1211
1231
 
1212
- execSync('npx cap sync android', { stdio: 'inherit' });
1232
+ ruAdsBuild.withNativeAdProvider(__dirname, id, 'android', () =>
1233
+ execSync('npx cap sync android', { stdio: 'inherit',
1234
+ env: { ...process.env, VITE_STORE_ID: String(id), CODEPLAY_BUILD_PLATFORM: 'android' } }));
1213
1235
 
1214
1236
  if (!baselineProfileChecked) {
1215
1237
  await checkBaselineProfileBeforeRelease();
package/package.json CHANGED
@@ -1,28 +1,28 @@
1
- {
2
- "name": "codeplay-common",
3
- "version": "4.11.21",
4
- "description": "Common build scripts and files",
5
- "scripts": {
6
- "postinstall": "node scripts/sync-files.js",
7
- "preinstall": "node scripts/uninstall.js"
8
- },
9
- "dependencies": {
10
- "adm-zip": "^0.6.1",
11
- "plist": "^3.1.0"
12
- },
13
- "repository": {
14
- "type": "git",
15
- "url": "https://github.com/merbin2012/codeplay-common.git"
16
- },
17
- "author": "Codeplay Technologies",
18
- "license": "MIT",
19
- "files": [
20
- "files/",
21
- "scripts/",
22
- "README.md",
23
- "CHANGELOG.md",
24
- "RELEASE_NOTES.md",
25
- "LICENSE",
26
- "runtime/"
27
- ]
28
- }
1
+ {
2
+ "name": "codeplay-common",
3
+ "version": "4.11.23",
4
+ "description": "Common build scripts and files",
5
+ "scripts": {
6
+ "postinstall": "node scripts/sync-files.js",
7
+ "preinstall": "node scripts/uninstall.js"
8
+ },
9
+ "dependencies": {
10
+ "adm-zip": "^0.6.1",
11
+ "plist": "^3.1.0"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/merbin2012/codeplay-common.git"
16
+ },
17
+ "author": "Codeplay Technologies",
18
+ "license": "MIT",
19
+ "files": [
20
+ "files/",
21
+ "scripts/",
22
+ "README.md",
23
+ "CHANGELOG.md",
24
+ "RELEASE_NOTES.md",
25
+ "LICENSE",
26
+ "runtime/"
27
+ ]
28
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "VERSION": "1.2",
3
+ "android": {
4
+ "HuaweiStore": {
5
+ "appId": 0,
6
+ "bannerSlotId": 0,
7
+ "interstitialSlotId": 0,
8
+ "rewardedSlotId": 0
9
+ },
10
+ "RuStore": {
11
+ "appId": 0,
12
+ "bannerSlotId": 0,
13
+ "interstitialSlotId": 0,
14
+ "rewardedSlotId": 0
15
+ }
16
+ },
17
+ "config": {
18
+ "isTesting": false,
19
+ "bannerEnabled": true,
20
+ "bannerSize": "320x50",
21
+ "bannerDisabledPages": [],
22
+ "bannerStartupDelayMs": 3000,
23
+ "interstitialEnabled": true,
24
+ "interstitialStartupDelayMs": 30000,
25
+ "minimumClick": 2,
26
+ "interstitialFirstTimeOutMs": 252000,
27
+ "interstitialTimeOutMs": 360000,
28
+ "interstitialPerSession": 8,
29
+ "rewardVideoEnabled": true,
30
+ "userAgeRestricted": false,
31
+ "retryDelayMs": 30000,
32
+ "debug": false
33
+ },
34
+ "testid": {
35
+ "bannerSlotId": 794557,
36
+ "interstitialSlotId": 6481,
37
+ "rewardedSlotId": 45101
38
+ }
39
+ }
@@ -0,0 +1,78 @@
1
+ const { test } = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
5
+ const { pathToFileURL } = require('node:url');
6
+ const { syncIapAliases, findLatestIapDirectory, legacyIapPlugin } = require('../files/buildCodeplay/iap-alias.cjs');
7
+
8
+ function fixture(alias = '{}') {
9
+ const base = path.resolve(process.env.CODEPLAY_TEST_ROOT || path.join(__dirname, '../agent-temp'));
10
+ fs.mkdirSync(base, { recursive: true });
11
+ const root = fs.mkdtempSync(path.join(base, 'iap-alias-'));
12
+ const write = (name, value) => { const file = path.join(root, name); fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, value); return file; };
13
+ write('buildCodeplay/iap-alias.cjs', fs.readFileSync(path.join(__dirname, '../files/buildCodeplay/iap-alias.cjs')));
14
+ write('src/js/Ads/IAP-4.8/IAP-state.js', 'export const shouldBlockIapAds = () => false;');
15
+ write('src/js/Ads/IAP-4.8/IAP-bootstrap.js', 'export const initIAP = () => {};');
16
+ write('vite.config.mjs', `export default async () => ({ resolve: { alias: ${alias} }, define: { preserved: true } });`);
17
+ return { root, write };
18
+ }
19
+
20
+ test('migrates imports and re-exports without changing comments, text or F7 templates; repeat is stable', () => {
21
+ const f = fixture();
22
+ const file = f.write('src/pages/home.f7', `<template><div>import '../IAP-4.9/IAP-state.js'</div></template>\n<script>\n// import '../IAP-4.9/IAP-state.js'\nconst text = "../IAP-4.9/IAP-state.js";\nimport { shouldBlockIapAds } from '../js/Ads/IAP-4.9/IAP-state.js';\nconst module = import('@/js/Ads/IAP-4.9/IAP-bootstrap.js');\nexport { initIAP } from '../js/Ads/IAP-4.9/IAP-bootstrap.js';\n</script>`);
23
+ assert.equal(syncIapAliases(f.root, [file]).length, 2);
24
+ const result = fs.readFileSync(file, 'utf8');
25
+ assert.ok(result.includes("from '@iap/IAP-state.js'"));
26
+ assert.ok(result.includes("import('@iap/IAP-bootstrap.js')"));
27
+ assert.ok(result.includes("from '@iap/IAP-bootstrap.js'"));
28
+ assert.ok(result.includes('// import \'../IAP-4.9/IAP-state.js\''));
29
+ assert.ok(result.includes('const text = "../IAP-4.9/IAP-state.js"'));
30
+ assert.ok(result.includes('<div>import \'../IAP-4.9/IAP-state.js\'</div>'));
31
+ assert.deepEqual(syncIapAliases(f.root, [file]), []);
32
+ });
33
+
34
+ test('Vite object and array aliases resolve IAP 4.8 and change automatically when a newer folder appears', async () => {
35
+ const previous = process.cwd();
36
+ try {
37
+ for (const aliases of ["{'@existing':'/unchanged'}", "[{ find: '@existing', replacement: '/unchanged' }]"]) {
38
+ const f = fixture(aliases); syncIapAliases(f.root); process.chdir(f.root);
39
+ const { default: configure } = await import(pathToFileURL(path.join(f.root, 'vite.config.mjs')).href);
40
+ const selected = config => Array.isArray(config.resolve.alias) ? config.resolve.alias.find(a => a.find === '@iap').replacement : config.resolve.alias['@iap'];
41
+ assert.equal(selected(await configure({})), path.join(f.root, 'src/js/Ads/IAP-4.8'));
42
+ f.write('src/js/Ads/IAP-4.10/IAP-state.js', '// newest state');
43
+ f.write('src/js/Ads/IAP-5.0/README.txt', 'incomplete');
44
+ assert.equal(selected(await configure({})), path.join(f.root, 'src/js/Ads/IAP-4.10'));
45
+ assert.equal((await configure({})).define.preserved, true);
46
+ assert.equal(findLatestIapDirectory(f.root), path.join(f.root, 'src/js/Ads/IAP-4.10'));
47
+ }
48
+ } finally { process.chdir(previous); }
49
+ });
50
+
51
+ test('missing IAP modules fail before any source or Vite changes', () => {
52
+ const f = fixture();
53
+ const source = "import { x } from '../IAP-4.9/missing.js';";
54
+ const file = f.write('src/caller.js', source);
55
+ const vite = fs.readFileSync(path.join(f.root, 'vite.config.mjs'), 'utf8');
56
+ assert.throws(() => syncIapAliases(f.root, [file]), /Missing @iap\/missing.js/);
57
+ assert.equal(fs.readFileSync(file, 'utf8'), source);
58
+ assert.equal(fs.readFileSync(path.join(f.root, 'vite.config.mjs'), 'utf8'), vite);
59
+ });
60
+
61
+ test('apps without IAP are left unchanged', () => {
62
+ const f = fixture(); fs.unlinkSync(path.join(f.root, 'src/js/Ads/IAP-4.8/IAP-state.js'));
63
+ assert.equal(findLatestIapDirectory(f.root), null);
64
+ assert.deepEqual(syncIapAliases(f.root), []);
65
+ });
66
+
67
+ test('protected AdMob source stays unchanged and legacy imports resolve to installed IAP', async () => {
68
+ const f = fixture();
69
+ const original = "import { shouldBlockIapAds } from '../IAP-4.9/IAP-state.js';";
70
+ const file = f.write('src/js/Ads/admob-nextgen-4.7/admob-emi-nextgen.js', original);
71
+ syncIapAliases(f.root, [file]);
72
+ assert.equal(fs.readFileSync(file, 'utf8'), original);
73
+ const plugin = legacyIapPlugin(f.root);
74
+ const resolver = { resolve: async target => ({ id: target }) };
75
+ const result = await plugin.resolveId.call(resolver, '../IAP-4.9/IAP-state.js', file);
76
+ assert.equal(result.id, path.join(f.root, 'src/js/Ads/IAP-4.8/IAP-state.js'));
77
+ assert.equal(await plugin.resolveId.call(resolver, '@capacitor/core', file), null);
78
+ });