codeplay-common 4.11.38 → 4.11.40
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.
- package/README.md +1 -1
- package/RELEASE_NOTES.md +13 -13
- package/files/buildCodeplay/add-splash-screen.js +1 -1
- package/files/buildCodeplay/codeplayBeforeBuild.js +2 -2
- package/files/buildCodeplay/ensure-current-build.cjs +32 -4
- package/files/buildCodeplay/fix-optimize-builld/android-r8-rules.cjs +31 -31
- package/files/buildCodeplay/fix-optimize-builld/ffmpeg-jni-rules.cjs +28 -28
- package/files/buildCodeplay/fix-optimize-builld/fix-optimize-build.gradle +9 -9
- package/files/buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs +30 -30
- package/files/buildCodeplay/huawei-privacy-entry.js +135 -135
- package/files/buildCodeplay/huawei-privacy.css +22 -22
- package/files/buildCodeplay/ios-ad-consent.cjs +56 -56
- package/files/buildCodeplay/ios-emi-admob-modification.js +25 -25
- package/files/buildCodeplay/newly added.txt +89 -89
- package/files/buildCodeplay/non-google-billing.pro +3 -3
- package/files/buildCodeplay/release-sync.config.json +4 -4
- package/files/buildCodeplay/remove-force-kotlin-disable.js +43 -43
- package/files/buildCodeplay/ruads.cjs +220 -220
- package/files/buildCodeplay/saf-mediastore-dependency.cjs +21 -21
- package/files/buildCodeplay/setSplashAnimation.js +2 -2
- package/files/buildCodeplay/setup-ruads.cjs +62 -62
- package/files/buildCodeplay/splash-setup.cjs +88 -88
- package/files/buildCodeplay/store-billing.cjs +43 -43
- package/files/buildCodeplay/tests/huawei-live-reload.test.cjs +60 -60
- package/files/buildCodeplay/tests/huawei-privacy.test.cjs +49 -49
- package/files/scripts-common/collect-startup-profile.js +134 -134
- package/files/scripts-common/generate-baseline-profile.js +218 -218
- package/files/take-screen-image.js +4552 -4414
- package/package.json +1 -1
- package/runtime/splash-ready.mjs +52 -52
- package/runtime/vk-ads/vk-ad-configuration.json +39 -39
- package/scripts/baseline-profile.test.cjs +189 -189
- package/scripts/ensure-current-build.test.cjs +128 -28
- package/scripts/ios-ad-consent.test.cjs +99 -99
- package/scripts/ruads-install.test.cjs +197 -197
- package/scripts/ruads-policy.test.cjs +174 -174
- package/scripts/saf-mediastore-dependency.test.cjs +44 -44
- package/scripts/splash-setup.test.cjs +142 -142
- package/scripts/sync-files.js +1 -1
- package/scripts/vite-build-settings.test.cjs +93 -93
|
@@ -1,220 +1,220 @@
|
|
|
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
|
-
const noAdmobStart = '// BEGIN CODEPLAY EXCLUDE ADMOB';
|
|
8
|
-
const noAdmobEnd = '// END CODEPLAY EXCLUDE ADMOB';
|
|
9
|
-
|
|
10
|
-
// HTML resolves ../buildCodeplay to /buildCodeplay when Vite serves src as root.
|
|
11
|
-
function withBuildCodeplayAlias(aliases, directory) {
|
|
12
|
-
if (Array.isArray(aliases)) {
|
|
13
|
-
return aliases.some(item => item.find === '/buildCodeplay') ? aliases
|
|
14
|
-
: [...aliases, { find: '/buildCodeplay', replacement: directory }];
|
|
15
|
-
}
|
|
16
|
-
return { '/buildCodeplay': directory, ...aliases };
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function removeAdmobPluginConfig(config) {
|
|
20
|
-
for (const name of Object.keys(config.plugins || {})) {
|
|
21
|
-
if (/admob/i.test(name)) delete config.plugins[name];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// IAP shares this JSON with AdMob. Keep purchase settings but omit ad IDs from
|
|
26
|
-
// non-AdMob web bundles, without editing the app's protected source config.
|
|
27
|
-
function admobConfigPlugin(provider) {
|
|
28
|
-
return {
|
|
29
|
-
name: 'codeplay-store-admob-config',
|
|
30
|
-
enforce: 'pre',
|
|
31
|
-
transform(source, id) {
|
|
32
|
-
if (provider === 'admob' || !/(?:^|[\\/])admob-ad-configuration(?:-nextgen)?\.json$/.test(id)) return null;
|
|
33
|
-
const scrub = value => {
|
|
34
|
-
if (typeof value === 'string') return value.startsWith('ca-app-pub-') ? '' : value;
|
|
35
|
-
if (Array.isArray(value)) return value.map(scrub);
|
|
36
|
-
if (value && typeof value === 'object') return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, scrub(item)]));
|
|
37
|
-
return value;
|
|
38
|
-
};
|
|
39
|
-
const config = scrub(JSON.parse(source));
|
|
40
|
-
for (const key of ['bannerEnabled', 'interstitialEnabled', 'appOpenEnabled', 'rewardVideoEnabled', 'rewardInterstitialEnabled']) {
|
|
41
|
-
if (config.config) config.config[key] = false;
|
|
42
|
-
}
|
|
43
|
-
return { code: JSON.stringify(config), map: null };
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Run after sync as well as before builds: old app-owned entries survive cap sync.
|
|
49
|
-
// Keep ads-identifier/appset: VK and analytics use them independently of AdMob.
|
|
50
|
-
function syncAndroidAdmobPolicy(projectRoot, storeId, platform = 'android') {
|
|
51
|
-
if (platform !== 'android') return false;
|
|
52
|
-
const config = JSON.parse(fs.readFileSync(path.join(projectRoot, 'capacitor.config.json'), 'utf8'));
|
|
53
|
-
const excluded = getAdProvider(config, storeId, platform) !== 'admob';
|
|
54
|
-
let changed = false;
|
|
55
|
-
const update = (file, transform) => {
|
|
56
|
-
if (!fs.existsSync(file)) return;
|
|
57
|
-
const original = fs.readFileSync(file, 'utf8');
|
|
58
|
-
const next = transform(original);
|
|
59
|
-
if (next === original) return;
|
|
60
|
-
fs.writeFileSync(file, next);
|
|
61
|
-
changed = true;
|
|
62
|
-
};
|
|
63
|
-
update(path.join(projectRoot, 'android/app/build.gradle'), original => {
|
|
64
|
-
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
65
|
-
const clean = original.replace(new RegExp(`^${noAdmobStart}[\\s\\S]*?${noAdmobEnd}\\r?\\n?`, 'gm'), '');
|
|
66
|
-
if (!excluded) return clean;
|
|
67
|
-
const modules = ['play-services-ads', 'play-services-ads-lite', 'play-services-ads-base',
|
|
68
|
-
'play-services-ads-api', 'play-services-ads-fullscreen', 'play-services-ads-mobile-sdk'];
|
|
69
|
-
const block = [noAdmobStart, 'configurations.configureEach {',
|
|
70
|
-
...modules.map(name => ` exclude group: 'com.google.android.gms', module: '${name}'`),
|
|
71
|
-
" exclude group: 'com.google.ads.mediation'",
|
|
72
|
-
" exclude group: 'com.google.android.ump', module: 'user-messaging-platform'",
|
|
73
|
-
'}', noAdmobEnd, ''].join(newline);
|
|
74
|
-
return `${clean.trimEnd()}${newline}${newline}${block}`;
|
|
75
|
-
});
|
|
76
|
-
if (!excluded) {
|
|
77
|
-
const readJson = file => fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8')) : {};
|
|
78
|
-
const adSettings = readJson(path.join(projectRoot, 'src/js/Ads/admob-ad-configuration-nextgen.json'));
|
|
79
|
-
const pkg = readJson(path.join(projectRoot, 'package.json'));
|
|
80
|
-
const appId = adSettings.androidAppId || pkg.admob?.androidAppId || config.plugins?.AdMob?.APP_ID_ANDROID;
|
|
81
|
-
update(path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml'), original => {
|
|
82
|
-
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
83
|
-
let next = original;
|
|
84
|
-
const ensureMeta = (name, value) => {
|
|
85
|
-
const escapedName = name.replace(/\./g, '\\.');
|
|
86
|
-
// Stop at a self-closing tag before considering a later closing tag.
|
|
87
|
-
const existing = new RegExp(`<meta-data\\b(?=[^>]*\\bandroid:name\\s*=\\s*(['"])${escapedName}\\1)[^>]*?(?:/\\s*>|>[\\s\\S]*?</meta-data\\s*>)`);
|
|
88
|
-
const tag = `<meta-data android:name="${name}" android:value="${value}" />`;
|
|
89
|
-
next = existing.test(next) ? next.replace(existing, tag)
|
|
90
|
-
: next.replace(/<application\b[^>]*>/, match => `${match}${newline} ${tag}`);
|
|
91
|
-
};
|
|
92
|
-
if (appId) ensureMeta('com.google.android.gms.ads.APPLICATION_ID', appId);
|
|
93
|
-
if (!next.includes('com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING')) {
|
|
94
|
-
ensureMeta('com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING', 'true');
|
|
95
|
-
}
|
|
96
|
-
if (adSettings.config?.isKidsApp !== true && !next.includes('com.google.android.gms.permission.AD_ID')) {
|
|
97
|
-
next = next.replace('</manifest>', ` <uses-permission android:name="com.google.android.gms.permission.AD_ID" />${newline}</manifest>`);
|
|
98
|
-
}
|
|
99
|
-
return next;
|
|
100
|
-
});
|
|
101
|
-
return changed;
|
|
102
|
-
}
|
|
103
|
-
update(path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml'), original =>
|
|
104
|
-
original.replace(/^[ \t]*<(meta-data|activity|service|provider|receiver|uses-library)\b(?=[^>]*\bandroid:name\s*=\s*(['"])(?:com\.google\.android\.gms\.ads\.|com\.google\.ads\.|com\.google\.android\.ump\.)[^'"]*\2)[^>]*?(?:\/\s*>|>[\s\S]*?<\/\1\s*>)[ \t]*(?:\r?\n)?/gm, ''));
|
|
105
|
-
update(path.join(projectRoot, 'android/app/src/main/assets/capacitor.config.json'), original => {
|
|
106
|
-
const generated = JSON.parse(original);
|
|
107
|
-
removeAdmobPluginConfig(generated);
|
|
108
|
-
return JSON.stringify(generated, null, 2) + '\n';
|
|
109
|
-
});
|
|
110
|
-
return changed;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// A missing RuAds section preserves the existing provider on every store.
|
|
114
|
-
function getAdProvider(config, storeId, platform = 'android') {
|
|
115
|
-
const id = Number(storeId || 1);
|
|
116
|
-
const ru = config.plugins?.RuAds;
|
|
117
|
-
const assigned = platform !== 'ios' && [4, 10].includes(id)
|
|
118
|
-
&& (ru?.STORE_IDS || []).map(Number).includes(id);
|
|
119
|
-
if (assigned) return ru.VK_ADS_ENABLED === true ? 'vk' : 'none';
|
|
120
|
-
return config.plugins?.AdMob?.ADMOB_ENABLED === false ? 'none' : 'admob';
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function findLatestVkController(projectRoot = process.cwd()) {
|
|
124
|
-
const ads = path.join(projectRoot, 'src/js/Ads');
|
|
125
|
-
const pattern = /^vk-ads-(\d+(?:\.\d+)*)$/;
|
|
126
|
-
if (!fs.existsSync(ads)) return null;
|
|
127
|
-
const folders = fs.readdirSync(ads, { withFileTypes: true }).filter(entry => entry.isDirectory() && pattern.test(entry.name))
|
|
128
|
-
.map(entry => entry.name).sort((a, b) => b.match(pattern)[1].localeCompare(a.match(pattern)[1], undefined, { numeric: true }));
|
|
129
|
-
const folder = folders.find(name => {
|
|
130
|
-
const file = path.join(ads, name, 'vk-ads.js');
|
|
131
|
-
return fs.existsSync(file) && fs.statSync(file).isFile() && fs.statSync(file).size > 0;
|
|
132
|
-
});
|
|
133
|
-
return folder ? `./src/js/Ads/${folder}/vk-ads.js` : null;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function controllerPath(config, storeId, platform, admobPath, projectRoot = process.cwd()) {
|
|
137
|
-
const provider = getAdProvider(config, storeId, platform);
|
|
138
|
-
if (provider === 'admob') return admobPath;
|
|
139
|
-
if (provider === 'none') return './buildCodeplay/disabled-ads.mjs';
|
|
140
|
-
const controller = findLatestVkController(projectRoot);
|
|
141
|
-
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".');
|
|
142
|
-
return controller;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function prepareReleaseAds(projectRoot, storeId, platform = 'android', warn = console.warn) {
|
|
146
|
-
const capacitorConfig = JSON.parse(fs.readFileSync(path.join(projectRoot, 'capacitor.config.json')));
|
|
147
|
-
if (getAdProvider(capacitorConfig, storeId, platform) !== 'vk') return false;
|
|
148
|
-
const file = path.join(projectRoot, 'src/js/Ads/vk-ad-configuration.json');
|
|
149
|
-
const original = fs.readFileSync(file, 'utf8');
|
|
150
|
-
const configuration = JSON.parse(original);
|
|
151
|
-
if (configuration.config?.isTesting !== true) return false;
|
|
152
|
-
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');
|
|
153
|
-
configuration.config.isTesting = false;
|
|
154
|
-
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
155
|
-
fs.writeFileSync(file, (JSON.stringify(configuration, null, 2) + '\n').replaceAll('\n', newline));
|
|
156
|
-
return true;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function includedPackages(config, pkg, platform, provider) {
|
|
160
|
-
const existing = config[platform]?.includePlugins ?? config.includePlugins;
|
|
161
|
-
const packages = existing || [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.devDependencies || {})];
|
|
162
|
-
return [...new Set(packages.filter(name => ![VK_PACKAGE, ADMOB_PACKAGE].includes(name))
|
|
163
|
-
.concat(provider === 'vk' ? [VK_PACKAGE] : provider === 'admob' ? [ADMOB_PACKAGE] : []))];
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function syncAdProviderPackages(projectRoot = process.cwd(), run) {
|
|
167
|
-
const config = JSON.parse(fs.readFileSync(path.join(projectRoot, 'capacitor.config.json')));
|
|
168
|
-
const provider = getAdProvider(config, process.env.VITE_STORE_ID, process.env.CODEPLAY_BUILD_PLATFORM);
|
|
169
|
-
const selected = provider === 'vk' ? VK_PACKAGE : provider === 'admob' ? ADMOB_PACKAGE : null;
|
|
170
|
-
const readPackage = () => JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json')));
|
|
171
|
-
const installed = name => fs.existsSync(path.join(projectRoot, 'node_modules', name, 'package.json'));
|
|
172
|
-
const execute = args => {
|
|
173
|
-
if (run) run(`npm ${args.join(' ')}`);
|
|
174
|
-
else execFileSync(process.platform === 'win32' ? 'npm.cmd' : 'npm', args,
|
|
175
|
-
{ cwd: projectRoot, stdio: 'inherit', shell: process.platform === 'win32' });
|
|
176
|
-
};
|
|
177
|
-
let changed = false;
|
|
178
|
-
for (const name of [ADMOB_PACKAGE, VK_PACKAGE]) {
|
|
179
|
-
const pkg = readPackage();
|
|
180
|
-
if (name !== selected && (pkg.dependencies?.[name] || pkg.devDependencies?.[name] || installed(name))) {
|
|
181
|
-
execute(['uninstall', name]);
|
|
182
|
-
changed = true;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
const pkg = readPackage();
|
|
186
|
-
const vkVersion = selected === VK_PACKAGE && installed(selected)
|
|
187
|
-
? JSON.parse(fs.readFileSync(path.join(projectRoot, 'node_modules', selected, 'package.json'))).version : null;
|
|
188
|
-
const [major, minor, patch] = String(vkVersion || '').split('.').map(Number);
|
|
189
|
-
const oldVk = vkVersion && major === 0 && (minor < 1 || (minor === 1 && patch < 1));
|
|
190
|
-
if (selected && (!pkg.dependencies?.[selected] || !installed(selected) || oldVk)) {
|
|
191
|
-
const version = oldVk ? '^0.1.1' : pkg.dependencies?.[selected] || (selected === VK_PACKAGE ? '^0.1.1' : '');
|
|
192
|
-
execute(['install', version ? `${selected}@${version}` : selected, '--save']);
|
|
193
|
-
changed = true;
|
|
194
|
-
}
|
|
195
|
-
return changed;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// includePlugins is scoped to cap sync; always restore the caller's configuration.
|
|
199
|
-
// Filtering affects both Capacitor and Cordova discovery without uninstalling other providers.
|
|
200
|
-
function withNativeAdProvider(projectRoot, storeId, platform, action) {
|
|
201
|
-
const configPath = path.join(projectRoot, 'capacitor.config.json');
|
|
202
|
-
const original = fs.readFileSync(configPath, 'utf8');
|
|
203
|
-
const config = JSON.parse(original);
|
|
204
|
-
const pkg = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json')));
|
|
205
|
-
const provider = getAdProvider(config, storeId, platform);
|
|
206
|
-
const targets = platform ? [platform] : ['android', 'ios'];
|
|
207
|
-
for (const target of targets) {
|
|
208
|
-
config[target] = { ...config[target], includePlugins: includedPackages(config, pkg, target,
|
|
209
|
-
getAdProvider(config, storeId, target)) };
|
|
210
|
-
}
|
|
211
|
-
if (provider !== 'admob') removeAdmobPluginConfig(config);
|
|
212
|
-
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n');
|
|
213
|
-
let result;
|
|
214
|
-
try { result = action(provider); }
|
|
215
|
-
finally { fs.writeFileSync(configPath, original); }
|
|
216
|
-
syncAndroidAdmobPolicy(projectRoot, storeId, platform);
|
|
217
|
-
return result;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
module.exports = { getAdProvider, controllerPath, findLatestVkController, prepareReleaseAds, includedPackages, syncAdProviderPackages, withNativeAdProvider, syncAndroidAdmobPolicy, admobConfigPlugin, withBuildCodeplayAlias };
|
|
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
|
+
const noAdmobStart = '// BEGIN CODEPLAY EXCLUDE ADMOB';
|
|
8
|
+
const noAdmobEnd = '// END CODEPLAY EXCLUDE ADMOB';
|
|
9
|
+
|
|
10
|
+
// HTML resolves ../buildCodeplay to /buildCodeplay when Vite serves src as root.
|
|
11
|
+
function withBuildCodeplayAlias(aliases, directory) {
|
|
12
|
+
if (Array.isArray(aliases)) {
|
|
13
|
+
return aliases.some(item => item.find === '/buildCodeplay') ? aliases
|
|
14
|
+
: [...aliases, { find: '/buildCodeplay', replacement: directory }];
|
|
15
|
+
}
|
|
16
|
+
return { '/buildCodeplay': directory, ...aliases };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function removeAdmobPluginConfig(config) {
|
|
20
|
+
for (const name of Object.keys(config.plugins || {})) {
|
|
21
|
+
if (/admob/i.test(name)) delete config.plugins[name];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// IAP shares this JSON with AdMob. Keep purchase settings but omit ad IDs from
|
|
26
|
+
// non-AdMob web bundles, without editing the app's protected source config.
|
|
27
|
+
function admobConfigPlugin(provider) {
|
|
28
|
+
return {
|
|
29
|
+
name: 'codeplay-store-admob-config',
|
|
30
|
+
enforce: 'pre',
|
|
31
|
+
transform(source, id) {
|
|
32
|
+
if (provider === 'admob' || !/(?:^|[\\/])admob-ad-configuration(?:-nextgen)?\.json$/.test(id)) return null;
|
|
33
|
+
const scrub = value => {
|
|
34
|
+
if (typeof value === 'string') return value.startsWith('ca-app-pub-') ? '' : value;
|
|
35
|
+
if (Array.isArray(value)) return value.map(scrub);
|
|
36
|
+
if (value && typeof value === 'object') return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, scrub(item)]));
|
|
37
|
+
return value;
|
|
38
|
+
};
|
|
39
|
+
const config = scrub(JSON.parse(source));
|
|
40
|
+
for (const key of ['bannerEnabled', 'interstitialEnabled', 'appOpenEnabled', 'rewardVideoEnabled', 'rewardInterstitialEnabled']) {
|
|
41
|
+
if (config.config) config.config[key] = false;
|
|
42
|
+
}
|
|
43
|
+
return { code: JSON.stringify(config), map: null };
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Run after sync as well as before builds: old app-owned entries survive cap sync.
|
|
49
|
+
// Keep ads-identifier/appset: VK and analytics use them independently of AdMob.
|
|
50
|
+
function syncAndroidAdmobPolicy(projectRoot, storeId, platform = 'android') {
|
|
51
|
+
if (platform !== 'android') return false;
|
|
52
|
+
const config = JSON.parse(fs.readFileSync(path.join(projectRoot, 'capacitor.config.json'), 'utf8'));
|
|
53
|
+
const excluded = getAdProvider(config, storeId, platform) !== 'admob';
|
|
54
|
+
let changed = false;
|
|
55
|
+
const update = (file, transform) => {
|
|
56
|
+
if (!fs.existsSync(file)) return;
|
|
57
|
+
const original = fs.readFileSync(file, 'utf8');
|
|
58
|
+
const next = transform(original);
|
|
59
|
+
if (next === original) return;
|
|
60
|
+
fs.writeFileSync(file, next);
|
|
61
|
+
changed = true;
|
|
62
|
+
};
|
|
63
|
+
update(path.join(projectRoot, 'android/app/build.gradle'), original => {
|
|
64
|
+
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
65
|
+
const clean = original.replace(new RegExp(`^${noAdmobStart}[\\s\\S]*?${noAdmobEnd}\\r?\\n?`, 'gm'), '');
|
|
66
|
+
if (!excluded) return clean;
|
|
67
|
+
const modules = ['play-services-ads', 'play-services-ads-lite', 'play-services-ads-base',
|
|
68
|
+
'play-services-ads-api', 'play-services-ads-fullscreen', 'play-services-ads-mobile-sdk'];
|
|
69
|
+
const block = [noAdmobStart, 'configurations.configureEach {',
|
|
70
|
+
...modules.map(name => ` exclude group: 'com.google.android.gms', module: '${name}'`),
|
|
71
|
+
" exclude group: 'com.google.ads.mediation'",
|
|
72
|
+
" exclude group: 'com.google.android.ump', module: 'user-messaging-platform'",
|
|
73
|
+
'}', noAdmobEnd, ''].join(newline);
|
|
74
|
+
return `${clean.trimEnd()}${newline}${newline}${block}`;
|
|
75
|
+
});
|
|
76
|
+
if (!excluded) {
|
|
77
|
+
const readJson = file => fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8')) : {};
|
|
78
|
+
const adSettings = readJson(path.join(projectRoot, 'src/js/Ads/admob-ad-configuration-nextgen.json'));
|
|
79
|
+
const pkg = readJson(path.join(projectRoot, 'package.json'));
|
|
80
|
+
const appId = adSettings.androidAppId || pkg.admob?.androidAppId || config.plugins?.AdMob?.APP_ID_ANDROID;
|
|
81
|
+
update(path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml'), original => {
|
|
82
|
+
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
83
|
+
let next = original;
|
|
84
|
+
const ensureMeta = (name, value) => {
|
|
85
|
+
const escapedName = name.replace(/\./g, '\\.');
|
|
86
|
+
// Stop at a self-closing tag before considering a later closing tag.
|
|
87
|
+
const existing = new RegExp(`<meta-data\\b(?=[^>]*\\bandroid:name\\s*=\\s*(['"])${escapedName}\\1)[^>]*?(?:/\\s*>|>[\\s\\S]*?</meta-data\\s*>)`);
|
|
88
|
+
const tag = `<meta-data android:name="${name}" android:value="${value}" />`;
|
|
89
|
+
next = existing.test(next) ? next.replace(existing, tag)
|
|
90
|
+
: next.replace(/<application\b[^>]*>/, match => `${match}${newline} ${tag}`);
|
|
91
|
+
};
|
|
92
|
+
if (appId) ensureMeta('com.google.android.gms.ads.APPLICATION_ID', appId);
|
|
93
|
+
if (!next.includes('com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING')) {
|
|
94
|
+
ensureMeta('com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING', 'true');
|
|
95
|
+
}
|
|
96
|
+
if (adSettings.config?.isKidsApp !== true && !next.includes('com.google.android.gms.permission.AD_ID')) {
|
|
97
|
+
next = next.replace('</manifest>', ` <uses-permission android:name="com.google.android.gms.permission.AD_ID" />${newline}</manifest>`);
|
|
98
|
+
}
|
|
99
|
+
return next;
|
|
100
|
+
});
|
|
101
|
+
return changed;
|
|
102
|
+
}
|
|
103
|
+
update(path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml'), original =>
|
|
104
|
+
original.replace(/^[ \t]*<(meta-data|activity|service|provider|receiver|uses-library)\b(?=[^>]*\bandroid:name\s*=\s*(['"])(?:com\.google\.android\.gms\.ads\.|com\.google\.ads\.|com\.google\.android\.ump\.)[^'"]*\2)[^>]*?(?:\/\s*>|>[\s\S]*?<\/\1\s*>)[ \t]*(?:\r?\n)?/gm, ''));
|
|
105
|
+
update(path.join(projectRoot, 'android/app/src/main/assets/capacitor.config.json'), original => {
|
|
106
|
+
const generated = JSON.parse(original);
|
|
107
|
+
removeAdmobPluginConfig(generated);
|
|
108
|
+
return JSON.stringify(generated, null, 2) + '\n';
|
|
109
|
+
});
|
|
110
|
+
return changed;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// A missing RuAds section preserves the existing provider on every store.
|
|
114
|
+
function getAdProvider(config, storeId, platform = 'android') {
|
|
115
|
+
const id = Number(storeId || 1);
|
|
116
|
+
const ru = config.plugins?.RuAds;
|
|
117
|
+
const assigned = platform !== 'ios' && [4, 10].includes(id)
|
|
118
|
+
&& (ru?.STORE_IDS || []).map(Number).includes(id);
|
|
119
|
+
if (assigned) return ru.VK_ADS_ENABLED === true ? 'vk' : 'none';
|
|
120
|
+
return config.plugins?.AdMob?.ADMOB_ENABLED === false ? 'none' : 'admob';
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function findLatestVkController(projectRoot = process.cwd()) {
|
|
124
|
+
const ads = path.join(projectRoot, 'src/js/Ads');
|
|
125
|
+
const pattern = /^vk-ads-(\d+(?:\.\d+)*)$/;
|
|
126
|
+
if (!fs.existsSync(ads)) return null;
|
|
127
|
+
const folders = fs.readdirSync(ads, { withFileTypes: true }).filter(entry => entry.isDirectory() && pattern.test(entry.name))
|
|
128
|
+
.map(entry => entry.name).sort((a, b) => b.match(pattern)[1].localeCompare(a.match(pattern)[1], undefined, { numeric: true }));
|
|
129
|
+
const folder = folders.find(name => {
|
|
130
|
+
const file = path.join(ads, name, 'vk-ads.js');
|
|
131
|
+
return fs.existsSync(file) && fs.statSync(file).isFile() && fs.statSync(file).size > 0;
|
|
132
|
+
});
|
|
133
|
+
return folder ? `./src/js/Ads/${folder}/vk-ads.js` : null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function controllerPath(config, storeId, platform, admobPath, projectRoot = process.cwd()) {
|
|
137
|
+
const provider = getAdProvider(config, storeId, platform);
|
|
138
|
+
if (provider === 'admob') return admobPath;
|
|
139
|
+
if (provider === 'none') return './buildCodeplay/disabled-ads.mjs';
|
|
140
|
+
const controller = findLatestVkController(projectRoot);
|
|
141
|
+
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".');
|
|
142
|
+
return controller;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function prepareReleaseAds(projectRoot, storeId, platform = 'android', warn = console.warn) {
|
|
146
|
+
const capacitorConfig = JSON.parse(fs.readFileSync(path.join(projectRoot, 'capacitor.config.json')));
|
|
147
|
+
if (getAdProvider(capacitorConfig, storeId, platform) !== 'vk') return false;
|
|
148
|
+
const file = path.join(projectRoot, 'src/js/Ads/vk-ad-configuration.json');
|
|
149
|
+
const original = fs.readFileSync(file, 'utf8');
|
|
150
|
+
const configuration = JSON.parse(original);
|
|
151
|
+
if (configuration.config?.isTesting !== true) return false;
|
|
152
|
+
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');
|
|
153
|
+
configuration.config.isTesting = false;
|
|
154
|
+
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
155
|
+
fs.writeFileSync(file, (JSON.stringify(configuration, null, 2) + '\n').replaceAll('\n', newline));
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function includedPackages(config, pkg, platform, provider) {
|
|
160
|
+
const existing = config[platform]?.includePlugins ?? config.includePlugins;
|
|
161
|
+
const packages = existing || [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.devDependencies || {})];
|
|
162
|
+
return [...new Set(packages.filter(name => ![VK_PACKAGE, ADMOB_PACKAGE].includes(name))
|
|
163
|
+
.concat(provider === 'vk' ? [VK_PACKAGE] : provider === 'admob' ? [ADMOB_PACKAGE] : []))];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function syncAdProviderPackages(projectRoot = process.cwd(), run) {
|
|
167
|
+
const config = JSON.parse(fs.readFileSync(path.join(projectRoot, 'capacitor.config.json')));
|
|
168
|
+
const provider = getAdProvider(config, process.env.VITE_STORE_ID, process.env.CODEPLAY_BUILD_PLATFORM);
|
|
169
|
+
const selected = provider === 'vk' ? VK_PACKAGE : provider === 'admob' ? ADMOB_PACKAGE : null;
|
|
170
|
+
const readPackage = () => JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json')));
|
|
171
|
+
const installed = name => fs.existsSync(path.join(projectRoot, 'node_modules', name, 'package.json'));
|
|
172
|
+
const execute = args => {
|
|
173
|
+
if (run) run(`npm ${args.join(' ')}`);
|
|
174
|
+
else execFileSync(process.platform === 'win32' ? 'npm.cmd' : 'npm', args,
|
|
175
|
+
{ cwd: projectRoot, stdio: 'inherit', shell: process.platform === 'win32' });
|
|
176
|
+
};
|
|
177
|
+
let changed = false;
|
|
178
|
+
for (const name of [ADMOB_PACKAGE, VK_PACKAGE]) {
|
|
179
|
+
const pkg = readPackage();
|
|
180
|
+
if (name !== selected && (pkg.dependencies?.[name] || pkg.devDependencies?.[name] || installed(name))) {
|
|
181
|
+
execute(['uninstall', name]);
|
|
182
|
+
changed = true;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const pkg = readPackage();
|
|
186
|
+
const vkVersion = selected === VK_PACKAGE && installed(selected)
|
|
187
|
+
? JSON.parse(fs.readFileSync(path.join(projectRoot, 'node_modules', selected, 'package.json'))).version : null;
|
|
188
|
+
const [major, minor, patch] = String(vkVersion || '').split('.').map(Number);
|
|
189
|
+
const oldVk = vkVersion && major === 0 && (minor < 1 || (minor === 1 && patch < 1));
|
|
190
|
+
if (selected && (!pkg.dependencies?.[selected] || !installed(selected) || oldVk)) {
|
|
191
|
+
const version = oldVk ? '^0.1.1' : pkg.dependencies?.[selected] || (selected === VK_PACKAGE ? '^0.1.1' : '');
|
|
192
|
+
execute(['install', version ? `${selected}@${version}` : selected, '--save']);
|
|
193
|
+
changed = true;
|
|
194
|
+
}
|
|
195
|
+
return changed;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// includePlugins is scoped to cap sync; always restore the caller's configuration.
|
|
199
|
+
// Filtering affects both Capacitor and Cordova discovery without uninstalling other providers.
|
|
200
|
+
function withNativeAdProvider(projectRoot, storeId, platform, action) {
|
|
201
|
+
const configPath = path.join(projectRoot, 'capacitor.config.json');
|
|
202
|
+
const original = fs.readFileSync(configPath, 'utf8');
|
|
203
|
+
const config = JSON.parse(original);
|
|
204
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json')));
|
|
205
|
+
const provider = getAdProvider(config, storeId, platform);
|
|
206
|
+
const targets = platform ? [platform] : ['android', 'ios'];
|
|
207
|
+
for (const target of targets) {
|
|
208
|
+
config[target] = { ...config[target], includePlugins: includedPackages(config, pkg, target,
|
|
209
|
+
getAdProvider(config, storeId, target)) };
|
|
210
|
+
}
|
|
211
|
+
if (provider !== 'admob') removeAdmobPluginConfig(config);
|
|
212
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n');
|
|
213
|
+
let result;
|
|
214
|
+
try { result = action(provider); }
|
|
215
|
+
finally { fs.writeFileSync(configPath, original); }
|
|
216
|
+
syncAndroidAdmobPolicy(projectRoot, storeId, platform);
|
|
217
|
+
return result;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
module.exports = { getAdProvider, controllerPath, findLatestVkController, prepareReleaseAds, includedPackages, syncAdProviderPackages, withNativeAdProvider, syncAndroidAdmobPolicy, admobConfigPlugin, withBuildCodeplayAlias };
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
function syncSafMediastoreDependency(projectRoot = process.cwd()) {
|
|
5
|
-
const file = path.join(projectRoot, 'node_modules', 'cordova-plugin-saf-mediastore', 'plugin.xml');
|
|
6
|
-
if (!fs.existsSync(file)) return false;
|
|
7
|
-
const original = fs.readFileSync(file, 'utf8');
|
|
8
|
-
// Mask comments without changing offsets so commented declarations do not count.
|
|
9
|
-
const active = original.replace(/<!--[\s\S]*?-->/g, comment => comment.replace(/[^\r\n]/g, ' '));
|
|
10
|
-
const android = /<platform\b[^>]*\bname\s*=\s*(['"])android\1[^>]*>[\s\S]*?<\/platform\s*>/.exec(active);
|
|
11
|
-
if (!android) throw new Error('SAF plugin.xml has no Android platform; cannot declare DocumentFile dependency.');
|
|
12
|
-
if (/<framework\b[^>]*\bsrc\s*=\s*(['"])androidx\.documentfile:documentfile:[^'"]+\1/.test(android[0])) return false;
|
|
13
|
-
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
14
|
-
const offset = android.index + android[0].indexOf('>') + 1;
|
|
15
|
-
const dependency = `${newline}\t\t<framework src="androidx.documentfile:documentfile:1.1.0" />`;
|
|
16
|
-
fs.writeFileSync(file, original.slice(0, offset) + dependency + original.slice(offset), 'utf8');
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
module.exports = { syncSafMediastoreDependency };
|
|
21
|
-
if (require.main === module) syncSafMediastoreDependency();
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
function syncSafMediastoreDependency(projectRoot = process.cwd()) {
|
|
5
|
+
const file = path.join(projectRoot, 'node_modules', 'cordova-plugin-saf-mediastore', 'plugin.xml');
|
|
6
|
+
if (!fs.existsSync(file)) return false;
|
|
7
|
+
const original = fs.readFileSync(file, 'utf8');
|
|
8
|
+
// Mask comments without changing offsets so commented declarations do not count.
|
|
9
|
+
const active = original.replace(/<!--[\s\S]*?-->/g, comment => comment.replace(/[^\r\n]/g, ' '));
|
|
10
|
+
const android = /<platform\b[^>]*\bname\s*=\s*(['"])android\1[^>]*>[\s\S]*?<\/platform\s*>/.exec(active);
|
|
11
|
+
if (!android) throw new Error('SAF plugin.xml has no Android platform; cannot declare DocumentFile dependency.');
|
|
12
|
+
if (/<framework\b[^>]*\bsrc\s*=\s*(['"])androidx\.documentfile:documentfile:[^'"]+\1/.test(android[0])) return false;
|
|
13
|
+
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
14
|
+
const offset = android.index + android[0].indexOf('>') + 1;
|
|
15
|
+
const dependency = `${newline}\t\t<framework src="androidx.documentfile:documentfile:1.1.0" />`;
|
|
16
|
+
fs.writeFileSync(file, original.slice(0, offset) + dependency + original.slice(offset), 'utf8');
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = { syncSafMediastoreDependency };
|
|
21
|
+
if (require.main === module) syncSafMediastoreDependency();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const readline = require('readline');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const { readSplashOptions } = require('./splash-setup.cjs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { readSplashOptions } = require('./splash-setup.cjs');
|
|
5
5
|
const splashOptions = readSplashOptions(JSON.parse(fs.readFileSync('capacitor.config.json', 'utf8')));
|
|
6
6
|
|
|
7
7
|
// Define the root directory of the project (adjust if needed)
|
|
@@ -1,62 +1,62 @@
|
|
|
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 = ruAdsBuild.withBuildCodeplayAlias(base.resolve?.alias || {}, codeplayResolve('buildCodeplay'));
|
|
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, plugins: [...(base.plugins || []), ruAdsBuild.admobConfigPlugin(provider)], 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
|
-
let current = fs.readFileSync(vite, 'utf8');
|
|
39
|
-
if (current.includes('codeplayOriginalViteConfig') && !current.includes('ruAdsBuild.withBuildCodeplayAlias(')) {
|
|
40
|
-
const updated = current.replace('const aliases = base.resolve?.alias || {};',
|
|
41
|
-
"const aliases = ruAdsBuild.withBuildCodeplayAlias(base.resolve?.alias || {}, codeplayResolve('buildCodeplay'));");
|
|
42
|
-
if (updated === current) throw new Error('Cannot install Huawei Live Reload path mapping in the Vite wrapper.');
|
|
43
|
-
fs.writeFileSync(vite, updated);
|
|
44
|
-
current = updated;
|
|
45
|
-
}
|
|
46
|
-
if (current.includes('codeplayOriginalViteConfig') && !current.includes('ruAdsBuild.admobConfigPlugin(')) {
|
|
47
|
-
const updated = current.replace('return { ...base, resolve:', 'return { ...base, plugins: [...(base.plugins || []), ruAdsBuild.admobConfigPlugin(provider)], resolve:');
|
|
48
|
-
if (updated === current) throw new Error('Cannot install store AdMob config filtering in the Vite wrapper.');
|
|
49
|
-
fs.writeFileSync(vite, updated);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
const ru = config.plugins?.RuAds;
|
|
53
|
-
if (ru?.VK_ADS_ENABLED !== true || !(ru.STORE_IDS || []).some(id => [4, 10].includes(Number(id)))) return;
|
|
54
|
-
const ads = path.join(projectRoot, 'src/js/Ads');
|
|
55
|
-
const configuration = path.join(ads, 'vk-ad-configuration.json');
|
|
56
|
-
if (fs.existsSync(configuration)) return;
|
|
57
|
-
const runtime = runtimeRoot || path.join(projectRoot, 'node_modules/codeplay-common/runtime/vk-ads');
|
|
58
|
-
fs.mkdirSync(ads, { recursive: true });
|
|
59
|
-
fs.copyFileSync(path.join(runtime, 'vk-ad-configuration.json'), configuration);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
module.exports = { syncRuAdsSetup };
|
|
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 = ruAdsBuild.withBuildCodeplayAlias(base.resolve?.alias || {}, codeplayResolve('buildCodeplay'));
|
|
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, plugins: [...(base.plugins || []), ruAdsBuild.admobConfigPlugin(provider)], 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
|
+
let current = fs.readFileSync(vite, 'utf8');
|
|
39
|
+
if (current.includes('codeplayOriginalViteConfig') && !current.includes('ruAdsBuild.withBuildCodeplayAlias(')) {
|
|
40
|
+
const updated = current.replace('const aliases = base.resolve?.alias || {};',
|
|
41
|
+
"const aliases = ruAdsBuild.withBuildCodeplayAlias(base.resolve?.alias || {}, codeplayResolve('buildCodeplay'));");
|
|
42
|
+
if (updated === current) throw new Error('Cannot install Huawei Live Reload path mapping in the Vite wrapper.');
|
|
43
|
+
fs.writeFileSync(vite, updated);
|
|
44
|
+
current = updated;
|
|
45
|
+
}
|
|
46
|
+
if (current.includes('codeplayOriginalViteConfig') && !current.includes('ruAdsBuild.admobConfigPlugin(')) {
|
|
47
|
+
const updated = current.replace('return { ...base, resolve:', 'return { ...base, plugins: [...(base.plugins || []), ruAdsBuild.admobConfigPlugin(provider)], resolve:');
|
|
48
|
+
if (updated === current) throw new Error('Cannot install store AdMob config filtering in the Vite wrapper.');
|
|
49
|
+
fs.writeFileSync(vite, updated);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const ru = config.plugins?.RuAds;
|
|
53
|
+
if (ru?.VK_ADS_ENABLED !== true || !(ru.STORE_IDS || []).some(id => [4, 10].includes(Number(id)))) return;
|
|
54
|
+
const ads = path.join(projectRoot, 'src/js/Ads');
|
|
55
|
+
const configuration = path.join(ads, 'vk-ad-configuration.json');
|
|
56
|
+
if (fs.existsSync(configuration)) return;
|
|
57
|
+
const runtime = runtimeRoot || path.join(projectRoot, 'node_modules/codeplay-common/runtime/vk-ads');
|
|
58
|
+
fs.mkdirSync(ads, { recursive: true });
|
|
59
|
+
fs.copyFileSync(path.join(runtime, 'vk-ad-configuration.json'), configuration);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = { syncRuAdsSetup };
|