codeplay-common 4.11.22 → 4.11.24
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 +75 -0
- package/files/buildCodeplay/codeplayBeforeBuild.js +71 -34
- package/files/buildCodeplay/disabled-ads.mjs +45 -0
- package/files/buildCodeplay/iap-alias.cjs +108 -0
- package/files/buildCodeplay/non-google-billing.pro +3 -0
- package/files/buildCodeplay/project-scripts.cjs +1 -1
- package/files/buildCodeplay/release-sync.config.json +4 -4
- package/files/buildCodeplay/ruads.cjs +210 -0
- package/files/buildCodeplay/setup-ruads.cjs +55 -0
- package/files/buildCodeplay/store-billing.cjs +43 -0
- package/files/buildCodeplay/versions.json +1 -0
- package/files/finalrelease +35 -10
- package/package.json +1 -1
- package/runtime/vk-ads/vk-ad-configuration.json +39 -0
- package/scripts/iap-alias.test.cjs +78 -0
- package/scripts/ruads-install.test.cjs +180 -0
- package/scripts/ruads-policy.test.cjs +130 -0
- package/scripts/sync-files.js +4 -0
- package/scripts/vite-build-settings.test.cjs +92 -0
|
@@ -0,0 +1,210 @@
|
|
|
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
|
+
function removeAdmobPluginConfig(config) {
|
|
11
|
+
for (const name of Object.keys(config.plugins || {})) {
|
|
12
|
+
if (/admob/i.test(name)) delete config.plugins[name];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// IAP shares this JSON with AdMob. Keep purchase settings but omit ad IDs from
|
|
17
|
+
// non-AdMob web bundles, without editing the app's protected source config.
|
|
18
|
+
function admobConfigPlugin(provider) {
|
|
19
|
+
return {
|
|
20
|
+
name: 'codeplay-store-admob-config',
|
|
21
|
+
enforce: 'pre',
|
|
22
|
+
transform(source, id) {
|
|
23
|
+
if (provider === 'admob' || !/(?:^|[\\/])admob-ad-configuration(?:-nextgen)?\.json$/.test(id)) return null;
|
|
24
|
+
const scrub = value => {
|
|
25
|
+
if (typeof value === 'string') return value.startsWith('ca-app-pub-') ? '' : value;
|
|
26
|
+
if (Array.isArray(value)) return value.map(scrub);
|
|
27
|
+
if (value && typeof value === 'object') return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, scrub(item)]));
|
|
28
|
+
return value;
|
|
29
|
+
};
|
|
30
|
+
const config = scrub(JSON.parse(source));
|
|
31
|
+
for (const key of ['bannerEnabled', 'interstitialEnabled', 'appOpenEnabled', 'rewardVideoEnabled', 'rewardInterstitialEnabled']) {
|
|
32
|
+
if (config.config) config.config[key] = false;
|
|
33
|
+
}
|
|
34
|
+
return { code: JSON.stringify(config), map: null };
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Run after sync as well as before builds: old app-owned entries survive cap sync.
|
|
40
|
+
// Keep ads-identifier/appset: VK and analytics use them independently of AdMob.
|
|
41
|
+
function syncAndroidAdmobPolicy(projectRoot, storeId, platform = 'android') {
|
|
42
|
+
if (platform !== 'android') return false;
|
|
43
|
+
const config = JSON.parse(fs.readFileSync(path.join(projectRoot, 'capacitor.config.json'), 'utf8'));
|
|
44
|
+
const excluded = getAdProvider(config, storeId, platform) !== 'admob';
|
|
45
|
+
let changed = false;
|
|
46
|
+
const update = (file, transform) => {
|
|
47
|
+
if (!fs.existsSync(file)) return;
|
|
48
|
+
const original = fs.readFileSync(file, 'utf8');
|
|
49
|
+
const next = transform(original);
|
|
50
|
+
if (next === original) return;
|
|
51
|
+
fs.writeFileSync(file, next);
|
|
52
|
+
changed = true;
|
|
53
|
+
};
|
|
54
|
+
update(path.join(projectRoot, 'android/app/build.gradle'), original => {
|
|
55
|
+
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
56
|
+
const clean = original.replace(new RegExp(`^${noAdmobStart}[\\s\\S]*?${noAdmobEnd}\\r?\\n?`, 'gm'), '');
|
|
57
|
+
if (!excluded) return clean;
|
|
58
|
+
const modules = ['play-services-ads', 'play-services-ads-lite', 'play-services-ads-base',
|
|
59
|
+
'play-services-ads-api', 'play-services-ads-fullscreen', 'play-services-ads-mobile-sdk'];
|
|
60
|
+
const block = [noAdmobStart, 'configurations.configureEach {',
|
|
61
|
+
...modules.map(name => ` exclude group: 'com.google.android.gms', module: '${name}'`),
|
|
62
|
+
" exclude group: 'com.google.ads.mediation'",
|
|
63
|
+
" exclude group: 'com.google.android.ump', module: 'user-messaging-platform'",
|
|
64
|
+
'}', noAdmobEnd, ''].join(newline);
|
|
65
|
+
return `${clean.trimEnd()}${newline}${newline}${block}`;
|
|
66
|
+
});
|
|
67
|
+
if (!excluded) {
|
|
68
|
+
const readJson = file => fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8')) : {};
|
|
69
|
+
const adSettings = readJson(path.join(projectRoot, 'src/js/Ads/admob-ad-configuration-nextgen.json'));
|
|
70
|
+
const pkg = readJson(path.join(projectRoot, 'package.json'));
|
|
71
|
+
const appId = adSettings.androidAppId || pkg.admob?.androidAppId || config.plugins?.AdMob?.APP_ID_ANDROID;
|
|
72
|
+
update(path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml'), original => {
|
|
73
|
+
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
74
|
+
let next = original;
|
|
75
|
+
const ensureMeta = (name, value) => {
|
|
76
|
+
const escapedName = name.replace(/\./g, '\\.');
|
|
77
|
+
const existing = new RegExp(`<meta-data\\b(?=[^>]*\\bandroid:name\\s*=\\s*(['"])${escapedName}\\1)[^>]*(?:/\\s*>|>[\\s\\S]*?</meta-data\\s*>)`);
|
|
78
|
+
const tag = `<meta-data android:name="${name}" android:value="${value}" />`;
|
|
79
|
+
next = existing.test(next) ? next.replace(existing, tag)
|
|
80
|
+
: next.replace(/<application\b[^>]*>/, match => `${match}${newline} ${tag}`);
|
|
81
|
+
};
|
|
82
|
+
if (appId) ensureMeta('com.google.android.gms.ads.APPLICATION_ID', appId);
|
|
83
|
+
if (!next.includes('com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING')) {
|
|
84
|
+
ensureMeta('com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING', 'true');
|
|
85
|
+
}
|
|
86
|
+
if (adSettings.config?.isKidsApp !== true && !next.includes('com.google.android.gms.permission.AD_ID')) {
|
|
87
|
+
next = next.replace('</manifest>', ` <uses-permission android:name="com.google.android.gms.permission.AD_ID" />${newline}</manifest>`);
|
|
88
|
+
}
|
|
89
|
+
return next;
|
|
90
|
+
});
|
|
91
|
+
return changed;
|
|
92
|
+
}
|
|
93
|
+
update(path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml'), original =>
|
|
94
|
+
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, ''));
|
|
95
|
+
update(path.join(projectRoot, 'android/app/src/main/assets/capacitor.config.json'), original => {
|
|
96
|
+
const generated = JSON.parse(original);
|
|
97
|
+
removeAdmobPluginConfig(generated);
|
|
98
|
+
return JSON.stringify(generated, null, 2) + '\n';
|
|
99
|
+
});
|
|
100
|
+
return changed;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// A missing RuAds section preserves the existing provider on every store.
|
|
104
|
+
function getAdProvider(config, storeId, platform = 'android') {
|
|
105
|
+
const id = Number(storeId || 1);
|
|
106
|
+
const ru = config.plugins?.RuAds;
|
|
107
|
+
const assigned = platform !== 'ios' && [4, 10].includes(id)
|
|
108
|
+
&& (ru?.STORE_IDS || []).map(Number).includes(id);
|
|
109
|
+
if (assigned) return ru.VK_ADS_ENABLED === true ? 'vk' : 'none';
|
|
110
|
+
return config.plugins?.AdMob?.ADMOB_ENABLED === false ? 'none' : 'admob';
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function findLatestVkController(projectRoot = process.cwd()) {
|
|
114
|
+
const ads = path.join(projectRoot, 'src/js/Ads');
|
|
115
|
+
const pattern = /^vk-ads-(\d+(?:\.\d+)*)$/;
|
|
116
|
+
if (!fs.existsSync(ads)) return null;
|
|
117
|
+
const folders = fs.readdirSync(ads, { withFileTypes: true }).filter(entry => entry.isDirectory() && pattern.test(entry.name))
|
|
118
|
+
.map(entry => entry.name).sort((a, b) => b.match(pattern)[1].localeCompare(a.match(pattern)[1], undefined, { numeric: true }));
|
|
119
|
+
const folder = folders.find(name => {
|
|
120
|
+
const file = path.join(ads, name, 'vk-ads.js');
|
|
121
|
+
return fs.existsSync(file) && fs.statSync(file).isFile() && fs.statSync(file).size > 0;
|
|
122
|
+
});
|
|
123
|
+
return folder ? `./src/js/Ads/${folder}/vk-ads.js` : null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function controllerPath(config, storeId, platform, admobPath, projectRoot = process.cwd()) {
|
|
127
|
+
const provider = getAdProvider(config, storeId, platform);
|
|
128
|
+
if (provider === 'admob') return admobPath;
|
|
129
|
+
if (provider === 'none') return './buildCodeplay/disabled-ads.mjs';
|
|
130
|
+
const controller = findLatestVkController(projectRoot);
|
|
131
|
+
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".');
|
|
132
|
+
return controller;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function prepareReleaseAds(projectRoot, storeId, platform = 'android', warn = console.warn) {
|
|
136
|
+
const capacitorConfig = JSON.parse(fs.readFileSync(path.join(projectRoot, 'capacitor.config.json')));
|
|
137
|
+
if (getAdProvider(capacitorConfig, storeId, platform) !== 'vk') return false;
|
|
138
|
+
const file = path.join(projectRoot, 'src/js/Ads/vk-ad-configuration.json');
|
|
139
|
+
const original = fs.readFileSync(file, 'utf8');
|
|
140
|
+
const configuration = JSON.parse(original);
|
|
141
|
+
if (configuration.config?.isTesting !== true) return false;
|
|
142
|
+
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');
|
|
143
|
+
configuration.config.isTesting = false;
|
|
144
|
+
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
145
|
+
fs.writeFileSync(file, (JSON.stringify(configuration, null, 2) + '\n').replaceAll('\n', newline));
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function includedPackages(config, pkg, platform, provider) {
|
|
150
|
+
const existing = config[platform]?.includePlugins ?? config.includePlugins;
|
|
151
|
+
const packages = existing || [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.devDependencies || {})];
|
|
152
|
+
return [...new Set(packages.filter(name => ![VK_PACKAGE, ADMOB_PACKAGE].includes(name))
|
|
153
|
+
.concat(provider === 'vk' ? [VK_PACKAGE] : provider === 'admob' ? [ADMOB_PACKAGE] : []))];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function syncAdProviderPackages(projectRoot = process.cwd(), run) {
|
|
157
|
+
const config = JSON.parse(fs.readFileSync(path.join(projectRoot, 'capacitor.config.json')));
|
|
158
|
+
const provider = getAdProvider(config, process.env.VITE_STORE_ID, process.env.CODEPLAY_BUILD_PLATFORM);
|
|
159
|
+
const selected = provider === 'vk' ? VK_PACKAGE : provider === 'admob' ? ADMOB_PACKAGE : null;
|
|
160
|
+
const readPackage = () => JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json')));
|
|
161
|
+
const installed = name => fs.existsSync(path.join(projectRoot, 'node_modules', name, 'package.json'));
|
|
162
|
+
const execute = args => {
|
|
163
|
+
if (run) run(`npm ${args.join(' ')}`);
|
|
164
|
+
else execFileSync(process.platform === 'win32' ? 'npm.cmd' : 'npm', args,
|
|
165
|
+
{ cwd: projectRoot, stdio: 'inherit', shell: process.platform === 'win32' });
|
|
166
|
+
};
|
|
167
|
+
let changed = false;
|
|
168
|
+
for (const name of [ADMOB_PACKAGE, VK_PACKAGE]) {
|
|
169
|
+
const pkg = readPackage();
|
|
170
|
+
if (name !== selected && (pkg.dependencies?.[name] || pkg.devDependencies?.[name] || installed(name))) {
|
|
171
|
+
execute(['uninstall', name]);
|
|
172
|
+
changed = true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const pkg = readPackage();
|
|
176
|
+
const vkVersion = selected === VK_PACKAGE && installed(selected)
|
|
177
|
+
? JSON.parse(fs.readFileSync(path.join(projectRoot, 'node_modules', selected, 'package.json'))).version : null;
|
|
178
|
+
const [major, minor, patch] = String(vkVersion || '').split('.').map(Number);
|
|
179
|
+
const oldVk = vkVersion && major === 0 && (minor < 1 || (minor === 1 && patch < 1));
|
|
180
|
+
if (selected && (!pkg.dependencies?.[selected] || !installed(selected) || oldVk)) {
|
|
181
|
+
const version = oldVk ? '^0.1.1' : pkg.dependencies?.[selected] || (selected === VK_PACKAGE ? '^0.1.1' : '');
|
|
182
|
+
execute(['install', version ? `${selected}@${version}` : selected, '--save']);
|
|
183
|
+
changed = true;
|
|
184
|
+
}
|
|
185
|
+
return changed;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// includePlugins is scoped to cap sync; always restore the caller's configuration.
|
|
189
|
+
// Filtering affects both Capacitor and Cordova discovery without uninstalling other providers.
|
|
190
|
+
function withNativeAdProvider(projectRoot, storeId, platform, action) {
|
|
191
|
+
const configPath = path.join(projectRoot, 'capacitor.config.json');
|
|
192
|
+
const original = fs.readFileSync(configPath, 'utf8');
|
|
193
|
+
const config = JSON.parse(original);
|
|
194
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json')));
|
|
195
|
+
const provider = getAdProvider(config, storeId, platform);
|
|
196
|
+
const targets = platform ? [platform] : ['android', 'ios'];
|
|
197
|
+
for (const target of targets) {
|
|
198
|
+
config[target] = { ...config[target], includePlugins: includedPackages(config, pkg, target,
|
|
199
|
+
getAdProvider(config, storeId, target)) };
|
|
200
|
+
}
|
|
201
|
+
if (provider !== 'admob') removeAdmobPluginConfig(config);
|
|
202
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n');
|
|
203
|
+
let result;
|
|
204
|
+
try { result = action(provider); }
|
|
205
|
+
finally { fs.writeFileSync(configPath, original); }
|
|
206
|
+
syncAndroidAdmobPolicy(projectRoot, storeId, platform);
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
module.exports = { getAdProvider, controllerPath, findLatestVkController, prepareReleaseAds, includedPackages, syncAdProviderPackages, withNativeAdProvider, syncAndroidAdmobPolicy, admobConfigPlugin };
|
|
@@ -0,0 +1,55 @@
|
|
|
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, 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
|
+
const current = fs.readFileSync(vite, 'utf8');
|
|
39
|
+
if (current.includes('codeplayOriginalViteConfig') && !current.includes('ruAdsBuild.admobConfigPlugin(')) {
|
|
40
|
+
const updated = current.replace('return { ...base, resolve:', 'return { ...base, plugins: [...(base.plugins || []), ruAdsBuild.admobConfigPlugin(provider)], resolve:');
|
|
41
|
+
if (updated === current) throw new Error('Cannot install store AdMob config filtering in the Vite wrapper.');
|
|
42
|
+
fs.writeFileSync(vite, updated);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const ru = config.plugins?.RuAds;
|
|
46
|
+
if (ru?.VK_ADS_ENABLED !== true || !(ru.STORE_IDS || []).some(id => [4, 10].includes(Number(id)))) return;
|
|
47
|
+
const ads = path.join(projectRoot, 'src/js/Ads');
|
|
48
|
+
const configuration = path.join(ads, 'vk-ad-configuration.json');
|
|
49
|
+
if (fs.existsSync(configuration)) return;
|
|
50
|
+
const runtime = runtimeRoot || path.join(projectRoot, 'node_modules/codeplay-common/runtime/vk-ads');
|
|
51
|
+
fs.mkdirSync(ads, { recursive: true });
|
|
52
|
+
fs.copyFileSync(path.join(runtime, 'vk-ad-configuration.json'), configuration);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
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
|
|
package/files/finalrelease
CHANGED
|
@@ -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:
|
|
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
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
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,12 @@ 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
|
-
|
|
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' } }));
|
|
1235
|
+
|
|
1236
|
+
// Reapply after sync so stale settings cannot leak from another store.
|
|
1237
|
+
ruAdsBuild.syncAndroidAdmobPolicy(__dirname, id, 'android');
|
|
1213
1238
|
|
|
1214
1239
|
if (!baselineProfileChecked) {
|
|
1215
1240
|
await checkBaselineProfileBeforeRelease();
|
package/package.json
CHANGED
|
@@ -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
|
+
});
|