codeplay-common 4.10.5 → 4.10.6
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/CHANGELOG.md +77 -77
- package/LICENSE +21 -21
- package/README.md +215 -215
- package/RELEASE_NOTES.md +75 -75
- package/files/buildCodeplay/add-splash-screen.js +255 -255
- package/files/buildCodeplay/apk-store-builder.js +97 -97
- package/files/buildCodeplay/codeplayBeforeBuild.js +4660 -4658
- package/files/buildCodeplay/fix-onesignal-plugin.js +96 -96
- package/files/buildCodeplay/ios-emi-admob-modification.js +24 -24
- package/files/buildCodeplay/manifestModification.js +35 -35
- package/files/buildCodeplay/packageidBaseModification.js +445 -445
- package/files/buildCodeplay/project-scripts.cjs +56 -56
- package/files/buildCodeplay/release-sync.config.json +4 -4
- package/files/buildCodeplay/setSplashAnimation.js +226 -226
- package/files/buildCodeplay/sync-admob-nextgen.js +218 -218
- package/files/buildCodeplay/versions.json +27 -27
- package/files/finalrelease +1239 -1239
- package/files/generate-ai-promo-video.js +23 -23
- package/files/ionic.config.json +6 -6
- package/files/scripts-common/run-codeplay-sync-after.js +21 -21
- package/files/scripts-common/screenshot/background-decorations.js +120 -120
- package/files/scripts-common/screenshot/frame-samples.js +117 -117
- package/files/scripts-common/setup-baseline-profile.js +265 -265
- package/files/take-screen-image.js +4304 -4304
- package/files/take-screen-video.js +644 -644
- package/package.json +27 -27
- package/scripts/sync-files.js +110 -110
- package/scripts/uninstall.js +2 -2
|
@@ -1,218 +1,218 @@
|
|
|
1
|
-
// AdMob packages version the folder; filenames inside it stay stable.
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const https = require('https');
|
|
5
|
-
|
|
6
|
-
const PACKAGE_PATTERN = /^admob-nextgen-(\d+(?:\.\d+)*)$/;
|
|
7
|
-
const REQUIRED_FILES = ['admob-emi-nextgen.js', 'app-open-state.js'];
|
|
8
|
-
const SERVER = 'https://htmlcodeplay.com/code-play-plugin/';
|
|
9
|
-
|
|
10
|
-
function compareVersions(a, b) {
|
|
11
|
-
const left = String(a).split('.').map(Number);
|
|
12
|
-
const right = String(b).split('.').map(Number);
|
|
13
|
-
for (let i = 0; i < Math.max(left.length, right.length); i++) {
|
|
14
|
-
const difference = (left[i] || 0) - (right[i] || 0);
|
|
15
|
-
if (difference) return difference;
|
|
16
|
-
}
|
|
17
|
-
return 0;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function isComplete(directory) {
|
|
21
|
-
return REQUIRED_FILES.every(file => fs.existsSync(path.join(directory, file))
|
|
22
|
-
&& fs.statSync(path.join(directory, file)).isFile()
|
|
23
|
-
&& fs.statSync(path.join(directory, file)).size > 0);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function findLatestPackage(adsDirectory) {
|
|
27
|
-
if (!fs.existsSync(adsDirectory)) return null;
|
|
28
|
-
return fs.readdirSync(adsDirectory).filter(name => PACKAGE_PATTERN.test(name)
|
|
29
|
-
&& isComplete(path.join(adsDirectory, name)))
|
|
30
|
-
.sort((a, b) => compareVersions(b.match(PACKAGE_PATTERN)[1], a.match(PACKAGE_PATTERN)[1]))[0] || null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function request(url, redirects = 0) {
|
|
34
|
-
return new Promise((resolve, reject) => {
|
|
35
|
-
const req = https.get(url, { timeout: 10000 }, response => {
|
|
36
|
-
if ([301, 302, 303, 307, 308].includes(response.statusCode) && response.headers.location) {
|
|
37
|
-
response.resume();
|
|
38
|
-
if (redirects >= 3) return reject(new Error('Too many AdMob download redirects.'));
|
|
39
|
-
const target = new URL(response.headers.location, url);
|
|
40
|
-
if (target.protocol !== 'https:') return reject(new Error('AdMob downloads require HTTPS.'));
|
|
41
|
-
resolve(request(target.href, redirects + 1));
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
if (response.statusCode !== 200) {
|
|
45
|
-
response.resume();
|
|
46
|
-
reject(new Error(`AdMob download returned HTTP ${response.statusCode}.`));
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const chunks = [];
|
|
50
|
-
response.on('data', chunk => chunks.push(chunk));
|
|
51
|
-
response.on('error', reject);
|
|
52
|
-
response.on('end', () => resolve(Buffer.concat(chunks)));
|
|
53
|
-
});
|
|
54
|
-
req.on('timeout', () => req.destroy(new Error('AdMob download timed out.')));
|
|
55
|
-
req.on('error', reject);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function extractPackage(buffer, destination, packageName, AdmZip = require('adm-zip')) {
|
|
60
|
-
const zip = new AdmZip(buffer);
|
|
61
|
-
const entries = zip.getEntries();
|
|
62
|
-
const wrapped = entries.some(entry => entry.entryName === `${packageName}/admob-emi-nextgen.js`);
|
|
63
|
-
for (const entry of entries) {
|
|
64
|
-
let name = entry.entryName;
|
|
65
|
-
if (name.includes('\\') || name.startsWith('/') || name.split('/').includes('..')
|
|
66
|
-
|| /^[a-z]:/i.test(name) || ((entry.header.attr >>> 16) & 0xf000) === 0xa000) {
|
|
67
|
-
throw new Error(`Unsafe AdMob ZIP entry: ${name}`);
|
|
68
|
-
}
|
|
69
|
-
if (wrapped) {
|
|
70
|
-
if (name === `${packageName}/`) continue;
|
|
71
|
-
if (!name.startsWith(`${packageName}/`)) throw new Error('Mixed AdMob ZIP roots.');
|
|
72
|
-
name = name.slice(packageName.length + 1);
|
|
73
|
-
}
|
|
74
|
-
if (!name) continue;
|
|
75
|
-
const target = path.resolve(destination, name);
|
|
76
|
-
if (!target.startsWith(path.resolve(destination) + path.sep)) throw new Error('Invalid AdMob ZIP path.');
|
|
77
|
-
if (entry.isDirectory) fs.mkdirSync(target, { recursive: true });
|
|
78
|
-
else {
|
|
79
|
-
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
80
|
-
fs.writeFileSync(target, entry.getData());
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
if (!isComplete(destination)) throw new Error('AdMob ZIP must contain the controller and app-open-state.js.');
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function sourceFiles(directory) {
|
|
87
|
-
if (!fs.existsSync(directory)) return [];
|
|
88
|
-
return fs.readdirSync(directory, { withFileTypes: true }).flatMap(entry => {
|
|
89
|
-
if (['node_modules', '.git', 'android', 'ios', 'www', 'agent-temp'].includes(entry.name)) return [];
|
|
90
|
-
const fullPath = path.join(directory, entry.name);
|
|
91
|
-
if (entry.isDirectory()) return sourceFiles(fullPath);
|
|
92
|
-
return entry.isFile() && /\.(?:js|mjs|cjs|ts|f7|vue|jsx|tsx)$/.test(entry.name) ? [fullPath] : [];
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function syncImports(projectRoot, packageName) {
|
|
97
|
-
const adsDirectory = path.join(projectRoot, 'src', 'js', 'Ads');
|
|
98
|
-
const targetDirectory = path.join(adsDirectory, packageName);
|
|
99
|
-
if (!isComplete(targetDirectory)) throw new Error('Cannot migrate imports to an incomplete AdMob package.');
|
|
100
|
-
const files = sourceFiles(path.join(projectRoot, 'src'));
|
|
101
|
-
for (const name of ['vite.config.js', 'vite.config.mjs', 'vite.config.ts']) {
|
|
102
|
-
const file = path.join(projectRoot, name);
|
|
103
|
-
if (fs.existsSync(file)) files.push(file);
|
|
104
|
-
}
|
|
105
|
-
const updates = [];
|
|
106
|
-
for (const file of files) {
|
|
107
|
-
const original = fs.readFileSync(file, 'utf8');
|
|
108
|
-
const next = original.replace(/(['"`])([^'"`\r\n]+)\1/g, (match, quote, specifier) => {
|
|
109
|
-
if (!/admob-(?:emi-nextgen|app-open-state|nextgen)-/.test(specifier)) return match;
|
|
110
|
-
if (specifier.includes('${')) throw new Error(`Computed AdMob import needs migration before cleanup: ${file}`);
|
|
111
|
-
const suffixIndex = specifier.search(/[?#]/);
|
|
112
|
-
const suffix = suffixIndex < 0 ? '' : specifier.slice(suffixIndex);
|
|
113
|
-
specifier = suffixIndex < 0 ? specifier : specifier.slice(0, suffixIndex);
|
|
114
|
-
let resolved;
|
|
115
|
-
if (specifier.startsWith('@/')) resolved = path.resolve(projectRoot, 'src', specifier.slice(2));
|
|
116
|
-
else if (specifier.startsWith('./') || specifier.startsWith('../')) resolved = path.resolve(path.dirname(file), specifier);
|
|
117
|
-
else return match;
|
|
118
|
-
const relative = path.relative(adsDirectory, resolved).split(path.sep).join('/');
|
|
119
|
-
let name;
|
|
120
|
-
if (/^admob-emi-nextgen-\d+(?:\.\d+)*\.js$/.test(relative)) name = REQUIRED_FILES[0];
|
|
121
|
-
else if (/^admob-app-open-state-\d+(?:\.\d+)*\.js$/.test(relative)) name = REQUIRED_FILES[1];
|
|
122
|
-
else {
|
|
123
|
-
const folderFile = relative.match(/^admob-nextgen-\d+(?:\.\d+)*\/(.+)$/);
|
|
124
|
-
if (!folderFile) return match;
|
|
125
|
-
name = folderFile[1];
|
|
126
|
-
}
|
|
127
|
-
const target = path.join(targetDirectory, name);
|
|
128
|
-
if (!fs.existsSync(target)) throw new Error(`AdMob import target missing: ${target}`);
|
|
129
|
-
let replacement = specifier.startsWith('@/')
|
|
130
|
-
? `@/js/Ads/${packageName}/${name}`
|
|
131
|
-
: path.relative(path.dirname(file), target).split(path.sep).join('/');
|
|
132
|
-
if (!specifier.startsWith('@/') && !replacement.startsWith('.')) replacement = './' + replacement;
|
|
133
|
-
return quote + replacement + suffix + quote;
|
|
134
|
-
});
|
|
135
|
-
if (next !== original) updates.push({ file, next });
|
|
136
|
-
}
|
|
137
|
-
// Plan every replacement before writing or removing any legacy source.
|
|
138
|
-
for (const { file, next } of updates) fs.writeFileSync(file, next, 'utf8');
|
|
139
|
-
return updates.map(update => path.relative(projectRoot, update.file));
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function syncPackageDependencies(projectRoot, packageName) {
|
|
143
|
-
const adsDirectory = path.join(projectRoot, 'src', 'js', 'Ads');
|
|
144
|
-
const controller = path.join(adsDirectory, packageName, REQUIRED_FILES[0]);
|
|
145
|
-
const iapFolders = fs.readdirSync(adsDirectory).filter(name => /^IAP-\d+(?:\.\d+)*$/.test(name)
|
|
146
|
-
&& fs.existsSync(path.join(adsDirectory, name, 'firebase-analytics.js')))
|
|
147
|
-
.sort((a, b) => compareVersions(b.slice(4), a.slice(4)));
|
|
148
|
-
const original = fs.readFileSync(controller, 'utf8');
|
|
149
|
-
let next = original.replace(/(['"])\.\.?\/admob-ad-configuration-nextgen\.json\1/g,
|
|
150
|
-
(match, quote) => `${quote}../admob-ad-configuration-nextgen.json${quote}`);
|
|
151
|
-
if (iapFolders.length) next = next.replace(/(['"])\.\.?\/IAP-\d+(?:\.\d+)*\/(?:firebase-analytics|IAP-state)\.js\1/g,
|
|
152
|
-
(match, quote) => `${quote}../${iapFolders[0]}/${match.includes('IAP-state') ? 'IAP-state.js' : 'firebase-analytics.js'}${quote}`);
|
|
153
|
-
if (next !== original) fs.writeFileSync(controller, next, 'utf8');
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
async function syncAdmobNextgen(options = {}) {
|
|
157
|
-
const projectRoot = path.resolve(options.projectRoot || process.cwd());
|
|
158
|
-
const adsDirectory = path.join(projectRoot, 'src', 'js', 'Ads');
|
|
159
|
-
if (!fs.existsSync(adsDirectory)) return null;
|
|
160
|
-
const log = options.log || console.log;
|
|
161
|
-
const fetch = options.request || request;
|
|
162
|
-
let latest = findLatestPackage(adsDirectory);
|
|
163
|
-
let versions = options.versions;
|
|
164
|
-
if (versions === undefined) {
|
|
165
|
-
try { versions = JSON.parse((await fetch(SERVER + 'versions.json')).toString('utf8')); }
|
|
166
|
-
catch (error) { log(`AdMob: server unavailable; retaining the installed package. ${error.message}`); }
|
|
167
|
-
}
|
|
168
|
-
// New manifests use admob-nextgen. Accept the previous key only at folder versions >= 4.0.
|
|
169
|
-
const advertisedVersion = String(versions?.['admob-nextgen'] || versions?.['admob-emi-nextgen'] || '');
|
|
170
|
-
// IAP 4.6 requires the synchronous ownership gate in AdMob 4.1 or newer.
|
|
171
|
-
const remoteVersion = /^\d+(?:\.\d+)*$/.test(advertisedVersion) && compareVersions(advertisedVersion, '4.1') >= 0
|
|
172
|
-
? advertisedVersion : '4.1';
|
|
173
|
-
const candidates = [];
|
|
174
|
-
if (/^\d+(?:\.\d+)*$/.test(remoteVersion) && compareVersions(remoteVersion, '4.0') >= 0) {
|
|
175
|
-
candidates.push({ version: remoteVersion });
|
|
176
|
-
}
|
|
177
|
-
for (const candidate of candidates) {
|
|
178
|
-
if (latest && compareVersions(latest.match(PACKAGE_PATTERN)[1], candidate.version) >= 0) break;
|
|
179
|
-
const name = `admob-nextgen-${candidate.version}`;
|
|
180
|
-
const temporaryRoot = path.join(projectRoot, 'agent-temp', 'admob-package-sync');
|
|
181
|
-
fs.mkdirSync(temporaryRoot, { recursive: true });
|
|
182
|
-
const staging = fs.mkdtempSync(path.join(temporaryRoot, 'package-'));
|
|
183
|
-
try {
|
|
184
|
-
const buffer = await fetch(SERVER + name + '.zip');
|
|
185
|
-
extractPackage(buffer, staging, name, options.AdmZip);
|
|
186
|
-
const destination = path.join(adsDirectory, name);
|
|
187
|
-
if (fs.existsSync(destination)) throw new Error(`Incomplete AdMob package already exists: ${destination}`);
|
|
188
|
-
fs.renameSync(staging, destination);
|
|
189
|
-
latest = name;
|
|
190
|
-
log(`AdMob: installed ${name}.`);
|
|
191
|
-
} catch (error) {
|
|
192
|
-
log(`AdMob: could not install ${name}: ${error.message}`);
|
|
193
|
-
} finally {
|
|
194
|
-
fs.rmSync(staging, { recursive: true, force: true });
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
if (!latest) throw new Error('No complete AdMob folder package is available. Check admob-nextgen in the live versions.json and its ZIP on htmlcodeplay.com; existing files were preserved.');
|
|
198
|
-
if (compareVersions(latest.match(PACKAGE_PATTERN)[1], '4.1') < 0) throw new Error('Deferred IAP startup requires admob-nextgen-4.1 or newer; existing sources were preserved.');
|
|
199
|
-
syncPackageDependencies(projectRoot, latest);
|
|
200
|
-
const changed = syncImports(projectRoot, latest);
|
|
201
|
-
// Remove only this plugin's superseded files after the new imports are in place.
|
|
202
|
-
for (const entry of fs.readdirSync(adsDirectory, { withFileTypes: true })) {
|
|
203
|
-
if (entry.isFile() && /^admob-(?:emi-nextgen|app-open-state)-\d+(?:\.\d+)*\.js$/.test(entry.name)) {
|
|
204
|
-
fs.unlinkSync(path.join(adsDirectory, entry.name));
|
|
205
|
-
} else if (entry.isDirectory() && PACKAGE_PATTERN.test(entry.name) && entry.name !== latest) {
|
|
206
|
-
fs.rmSync(path.join(adsDirectory, entry.name), { recursive: true });
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
log(`AdMob: ${latest} ready; migrated ${changed.length} file(s).`);
|
|
210
|
-
return latest;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
module.exports = { syncAdmobNextgen, syncImports, findLatestPackage, compareVersions, extractPackage };
|
|
214
|
-
|
|
215
|
-
if (require.main === module) syncAdmobNextgen().catch(error => {
|
|
216
|
-
console.error(error.message);
|
|
217
|
-
process.exitCode = 1;
|
|
218
|
-
});
|
|
1
|
+
// AdMob packages version the folder; filenames inside it stay stable.
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const https = require('https');
|
|
5
|
+
|
|
6
|
+
const PACKAGE_PATTERN = /^admob-nextgen-(\d+(?:\.\d+)*)$/;
|
|
7
|
+
const REQUIRED_FILES = ['admob-emi-nextgen.js', 'app-open-state.js'];
|
|
8
|
+
const SERVER = 'https://htmlcodeplay.com/code-play-plugin/';
|
|
9
|
+
|
|
10
|
+
function compareVersions(a, b) {
|
|
11
|
+
const left = String(a).split('.').map(Number);
|
|
12
|
+
const right = String(b).split('.').map(Number);
|
|
13
|
+
for (let i = 0; i < Math.max(left.length, right.length); i++) {
|
|
14
|
+
const difference = (left[i] || 0) - (right[i] || 0);
|
|
15
|
+
if (difference) return difference;
|
|
16
|
+
}
|
|
17
|
+
return 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function isComplete(directory) {
|
|
21
|
+
return REQUIRED_FILES.every(file => fs.existsSync(path.join(directory, file))
|
|
22
|
+
&& fs.statSync(path.join(directory, file)).isFile()
|
|
23
|
+
&& fs.statSync(path.join(directory, file)).size > 0);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function findLatestPackage(adsDirectory) {
|
|
27
|
+
if (!fs.existsSync(adsDirectory)) return null;
|
|
28
|
+
return fs.readdirSync(adsDirectory).filter(name => PACKAGE_PATTERN.test(name)
|
|
29
|
+
&& isComplete(path.join(adsDirectory, name)))
|
|
30
|
+
.sort((a, b) => compareVersions(b.match(PACKAGE_PATTERN)[1], a.match(PACKAGE_PATTERN)[1]))[0] || null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function request(url, redirects = 0) {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const req = https.get(url, { timeout: 10000 }, response => {
|
|
36
|
+
if ([301, 302, 303, 307, 308].includes(response.statusCode) && response.headers.location) {
|
|
37
|
+
response.resume();
|
|
38
|
+
if (redirects >= 3) return reject(new Error('Too many AdMob download redirects.'));
|
|
39
|
+
const target = new URL(response.headers.location, url);
|
|
40
|
+
if (target.protocol !== 'https:') return reject(new Error('AdMob downloads require HTTPS.'));
|
|
41
|
+
resolve(request(target.href, redirects + 1));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (response.statusCode !== 200) {
|
|
45
|
+
response.resume();
|
|
46
|
+
reject(new Error(`AdMob download returned HTTP ${response.statusCode}.`));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const chunks = [];
|
|
50
|
+
response.on('data', chunk => chunks.push(chunk));
|
|
51
|
+
response.on('error', reject);
|
|
52
|
+
response.on('end', () => resolve(Buffer.concat(chunks)));
|
|
53
|
+
});
|
|
54
|
+
req.on('timeout', () => req.destroy(new Error('AdMob download timed out.')));
|
|
55
|
+
req.on('error', reject);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function extractPackage(buffer, destination, packageName, AdmZip = require('adm-zip')) {
|
|
60
|
+
const zip = new AdmZip(buffer);
|
|
61
|
+
const entries = zip.getEntries();
|
|
62
|
+
const wrapped = entries.some(entry => entry.entryName === `${packageName}/admob-emi-nextgen.js`);
|
|
63
|
+
for (const entry of entries) {
|
|
64
|
+
let name = entry.entryName;
|
|
65
|
+
if (name.includes('\\') || name.startsWith('/') || name.split('/').includes('..')
|
|
66
|
+
|| /^[a-z]:/i.test(name) || ((entry.header.attr >>> 16) & 0xf000) === 0xa000) {
|
|
67
|
+
throw new Error(`Unsafe AdMob ZIP entry: ${name}`);
|
|
68
|
+
}
|
|
69
|
+
if (wrapped) {
|
|
70
|
+
if (name === `${packageName}/`) continue;
|
|
71
|
+
if (!name.startsWith(`${packageName}/`)) throw new Error('Mixed AdMob ZIP roots.');
|
|
72
|
+
name = name.slice(packageName.length + 1);
|
|
73
|
+
}
|
|
74
|
+
if (!name) continue;
|
|
75
|
+
const target = path.resolve(destination, name);
|
|
76
|
+
if (!target.startsWith(path.resolve(destination) + path.sep)) throw new Error('Invalid AdMob ZIP path.');
|
|
77
|
+
if (entry.isDirectory) fs.mkdirSync(target, { recursive: true });
|
|
78
|
+
else {
|
|
79
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
80
|
+
fs.writeFileSync(target, entry.getData());
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (!isComplete(destination)) throw new Error('AdMob ZIP must contain the controller and app-open-state.js.');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function sourceFiles(directory) {
|
|
87
|
+
if (!fs.existsSync(directory)) return [];
|
|
88
|
+
return fs.readdirSync(directory, { withFileTypes: true }).flatMap(entry => {
|
|
89
|
+
if (['node_modules', '.git', 'android', 'ios', 'www', 'agent-temp'].includes(entry.name)) return [];
|
|
90
|
+
const fullPath = path.join(directory, entry.name);
|
|
91
|
+
if (entry.isDirectory()) return sourceFiles(fullPath);
|
|
92
|
+
return entry.isFile() && /\.(?:js|mjs|cjs|ts|f7|vue|jsx|tsx)$/.test(entry.name) ? [fullPath] : [];
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function syncImports(projectRoot, packageName) {
|
|
97
|
+
const adsDirectory = path.join(projectRoot, 'src', 'js', 'Ads');
|
|
98
|
+
const targetDirectory = path.join(adsDirectory, packageName);
|
|
99
|
+
if (!isComplete(targetDirectory)) throw new Error('Cannot migrate imports to an incomplete AdMob package.');
|
|
100
|
+
const files = sourceFiles(path.join(projectRoot, 'src'));
|
|
101
|
+
for (const name of ['vite.config.js', 'vite.config.mjs', 'vite.config.ts']) {
|
|
102
|
+
const file = path.join(projectRoot, name);
|
|
103
|
+
if (fs.existsSync(file)) files.push(file);
|
|
104
|
+
}
|
|
105
|
+
const updates = [];
|
|
106
|
+
for (const file of files) {
|
|
107
|
+
const original = fs.readFileSync(file, 'utf8');
|
|
108
|
+
const next = original.replace(/(['"`])([^'"`\r\n]+)\1/g, (match, quote, specifier) => {
|
|
109
|
+
if (!/admob-(?:emi-nextgen|app-open-state|nextgen)-/.test(specifier)) return match;
|
|
110
|
+
if (specifier.includes('${')) throw new Error(`Computed AdMob import needs migration before cleanup: ${file}`);
|
|
111
|
+
const suffixIndex = specifier.search(/[?#]/);
|
|
112
|
+
const suffix = suffixIndex < 0 ? '' : specifier.slice(suffixIndex);
|
|
113
|
+
specifier = suffixIndex < 0 ? specifier : specifier.slice(0, suffixIndex);
|
|
114
|
+
let resolved;
|
|
115
|
+
if (specifier.startsWith('@/')) resolved = path.resolve(projectRoot, 'src', specifier.slice(2));
|
|
116
|
+
else if (specifier.startsWith('./') || specifier.startsWith('../')) resolved = path.resolve(path.dirname(file), specifier);
|
|
117
|
+
else return match;
|
|
118
|
+
const relative = path.relative(adsDirectory, resolved).split(path.sep).join('/');
|
|
119
|
+
let name;
|
|
120
|
+
if (/^admob-emi-nextgen-\d+(?:\.\d+)*\.js$/.test(relative)) name = REQUIRED_FILES[0];
|
|
121
|
+
else if (/^admob-app-open-state-\d+(?:\.\d+)*\.js$/.test(relative)) name = REQUIRED_FILES[1];
|
|
122
|
+
else {
|
|
123
|
+
const folderFile = relative.match(/^admob-nextgen-\d+(?:\.\d+)*\/(.+)$/);
|
|
124
|
+
if (!folderFile) return match;
|
|
125
|
+
name = folderFile[1];
|
|
126
|
+
}
|
|
127
|
+
const target = path.join(targetDirectory, name);
|
|
128
|
+
if (!fs.existsSync(target)) throw new Error(`AdMob import target missing: ${target}`);
|
|
129
|
+
let replacement = specifier.startsWith('@/')
|
|
130
|
+
? `@/js/Ads/${packageName}/${name}`
|
|
131
|
+
: path.relative(path.dirname(file), target).split(path.sep).join('/');
|
|
132
|
+
if (!specifier.startsWith('@/') && !replacement.startsWith('.')) replacement = './' + replacement;
|
|
133
|
+
return quote + replacement + suffix + quote;
|
|
134
|
+
});
|
|
135
|
+
if (next !== original) updates.push({ file, next });
|
|
136
|
+
}
|
|
137
|
+
// Plan every replacement before writing or removing any legacy source.
|
|
138
|
+
for (const { file, next } of updates) fs.writeFileSync(file, next, 'utf8');
|
|
139
|
+
return updates.map(update => path.relative(projectRoot, update.file));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function syncPackageDependencies(projectRoot, packageName) {
|
|
143
|
+
const adsDirectory = path.join(projectRoot, 'src', 'js', 'Ads');
|
|
144
|
+
const controller = path.join(adsDirectory, packageName, REQUIRED_FILES[0]);
|
|
145
|
+
const iapFolders = fs.readdirSync(adsDirectory).filter(name => /^IAP-\d+(?:\.\d+)*$/.test(name)
|
|
146
|
+
&& fs.existsSync(path.join(adsDirectory, name, 'firebase-analytics.js')))
|
|
147
|
+
.sort((a, b) => compareVersions(b.slice(4), a.slice(4)));
|
|
148
|
+
const original = fs.readFileSync(controller, 'utf8');
|
|
149
|
+
let next = original.replace(/(['"])\.\.?\/admob-ad-configuration-nextgen\.json\1/g,
|
|
150
|
+
(match, quote) => `${quote}../admob-ad-configuration-nextgen.json${quote}`);
|
|
151
|
+
if (iapFolders.length) next = next.replace(/(['"])\.\.?\/IAP-\d+(?:\.\d+)*\/(?:firebase-analytics|IAP-state)\.js\1/g,
|
|
152
|
+
(match, quote) => `${quote}../${iapFolders[0]}/${match.includes('IAP-state') ? 'IAP-state.js' : 'firebase-analytics.js'}${quote}`);
|
|
153
|
+
if (next !== original) fs.writeFileSync(controller, next, 'utf8');
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function syncAdmobNextgen(options = {}) {
|
|
157
|
+
const projectRoot = path.resolve(options.projectRoot || process.cwd());
|
|
158
|
+
const adsDirectory = path.join(projectRoot, 'src', 'js', 'Ads');
|
|
159
|
+
if (!fs.existsSync(adsDirectory)) return null;
|
|
160
|
+
const log = options.log || console.log;
|
|
161
|
+
const fetch = options.request || request;
|
|
162
|
+
let latest = findLatestPackage(adsDirectory);
|
|
163
|
+
let versions = options.versions;
|
|
164
|
+
if (versions === undefined) {
|
|
165
|
+
try { versions = JSON.parse((await fetch(SERVER + 'versions.json')).toString('utf8')); }
|
|
166
|
+
catch (error) { log(`AdMob: server unavailable; retaining the installed package. ${error.message}`); }
|
|
167
|
+
}
|
|
168
|
+
// New manifests use admob-nextgen. Accept the previous key only at folder versions >= 4.0.
|
|
169
|
+
const advertisedVersion = String(versions?.['admob-nextgen'] || versions?.['admob-emi-nextgen'] || '');
|
|
170
|
+
// IAP 4.6 requires the synchronous ownership gate in AdMob 4.1 or newer.
|
|
171
|
+
const remoteVersion = /^\d+(?:\.\d+)*$/.test(advertisedVersion) && compareVersions(advertisedVersion, '4.1') >= 0
|
|
172
|
+
? advertisedVersion : '4.1';
|
|
173
|
+
const candidates = [];
|
|
174
|
+
if (/^\d+(?:\.\d+)*$/.test(remoteVersion) && compareVersions(remoteVersion, '4.0') >= 0) {
|
|
175
|
+
candidates.push({ version: remoteVersion });
|
|
176
|
+
}
|
|
177
|
+
for (const candidate of candidates) {
|
|
178
|
+
if (latest && compareVersions(latest.match(PACKAGE_PATTERN)[1], candidate.version) >= 0) break;
|
|
179
|
+
const name = `admob-nextgen-${candidate.version}`;
|
|
180
|
+
const temporaryRoot = path.join(projectRoot, 'agent-temp', 'admob-package-sync');
|
|
181
|
+
fs.mkdirSync(temporaryRoot, { recursive: true });
|
|
182
|
+
const staging = fs.mkdtempSync(path.join(temporaryRoot, 'package-'));
|
|
183
|
+
try {
|
|
184
|
+
const buffer = await fetch(SERVER + name + '.zip');
|
|
185
|
+
extractPackage(buffer, staging, name, options.AdmZip);
|
|
186
|
+
const destination = path.join(adsDirectory, name);
|
|
187
|
+
if (fs.existsSync(destination)) throw new Error(`Incomplete AdMob package already exists: ${destination}`);
|
|
188
|
+
fs.renameSync(staging, destination);
|
|
189
|
+
latest = name;
|
|
190
|
+
log(`AdMob: installed ${name}.`);
|
|
191
|
+
} catch (error) {
|
|
192
|
+
log(`AdMob: could not install ${name}: ${error.message}`);
|
|
193
|
+
} finally {
|
|
194
|
+
fs.rmSync(staging, { recursive: true, force: true });
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (!latest) throw new Error('No complete AdMob folder package is available. Check admob-nextgen in the live versions.json and its ZIP on htmlcodeplay.com; existing files were preserved.');
|
|
198
|
+
if (compareVersions(latest.match(PACKAGE_PATTERN)[1], '4.1') < 0) throw new Error('Deferred IAP startup requires admob-nextgen-4.1 or newer; existing sources were preserved.');
|
|
199
|
+
syncPackageDependencies(projectRoot, latest);
|
|
200
|
+
const changed = syncImports(projectRoot, latest);
|
|
201
|
+
// Remove only this plugin's superseded files after the new imports are in place.
|
|
202
|
+
for (const entry of fs.readdirSync(adsDirectory, { withFileTypes: true })) {
|
|
203
|
+
if (entry.isFile() && /^admob-(?:emi-nextgen|app-open-state)-\d+(?:\.\d+)*\.js$/.test(entry.name)) {
|
|
204
|
+
fs.unlinkSync(path.join(adsDirectory, entry.name));
|
|
205
|
+
} else if (entry.isDirectory() && PACKAGE_PATTERN.test(entry.name) && entry.name !== latest) {
|
|
206
|
+
fs.rmSync(path.join(adsDirectory, entry.name), { recursive: true });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
log(`AdMob: ${latest} ready; migrated ${changed.length} file(s).`);
|
|
210
|
+
return latest;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
module.exports = { syncAdmobNextgen, syncImports, findLatestPackage, compareVersions, extractPackage };
|
|
214
|
+
|
|
215
|
+
if (require.main === module) syncAdmobNextgen().catch(error => {
|
|
216
|
+
console.error(error.message);
|
|
217
|
+
process.exitCode = 1;
|
|
218
|
+
});
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
{
|
|
2
|
-
"plugins":[
|
|
3
|
-
{"name":"backbutton","pattern":"backbutton-(\\d+\\.\\d+)\\.js$","minVersion":"2.1","baseDir":"js","mandatoryUpdate":true},
|
|
4
|
-
{"name":"common-js","pattern":"common-(\\d+\\.\\d+)(?:-beta-(\\d+))?\\.js$","minVersion":"6.7","baseDir":"js","mandatoryUpdate":true},
|
|
5
|
-
|
|
6
|
-
{"name":"admob-nextgen","pattern":"admob-nextgen-(\\d+(?:\\.\\d+)*)$","minVersion":"4.1","baseDir":"js/Ads","mandatoryUpdate":true,"isFolder":true},
|
|
7
|
-
{"name":"video-player","pattern":"video-player-(\\d+\\.\\d+)\\.js$","minVersion":"1.6","baseDir":"js","mandatoryUpdate":true},
|
|
8
|
-
{"name":"image-cropper","pattern":"image-cropper-(\\d+\\.\\d+)\\.js$","minVersion":"1.1","baseDir":"js","mandatoryUpdate":true},
|
|
9
|
-
{"name":"beautify","pattern":"beautify-(\\d+\\.\\d+)\\.js$","minVersion":"1.1","baseDir":"js","mandatoryUpdate":true},
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
{"name":"localization","pattern":"localization-(\\d+\\.\\d+)$","minVersion":"1.8","baseDir":"js/localization","mandatoryUpdate":true,"isFolder":true},
|
|
13
|
-
{"name": "localization_settings","pattern": "localization_settings-(\\d+\\.\\d+)\\.js$","minVersion": "1.1","required": true,"baseDir": "js/localization","mandatoryUpdate": true},
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
{"name":"editor","pattern":"editor-(\\d+\\.\\d+)$","minVersion":"2.0","baseDir":"js/editor","mandatoryUpdate":true,"isFolder":true},
|
|
17
|
-
{"name":"ffmpeg","pattern":"ffmpeg-(\\d+\\.\\d+)$","minVersion":"1.6","baseDir":"js","mandatoryUpdate":true,"isFolder":true},
|
|
18
|
-
{"name":"theme","pattern":"theme-(\\d+\\.\\d+)$","minVersion":"3.5","baseDir":"theme","destDir":"theme","mandatoryUpdate":true,"isFolder":true},
|
|
19
|
-
{"name":"certificatejs","pattern":"certificatejs-(\\d+\\.\\d+)$","minVersion":"1.9","baseDir":"certificate","destDir":"certificate","mandatoryUpdate":true,"isFolder":true},
|
|
20
|
-
{"name":"IAP","pattern":"IAP-(\\d+\\.\\d+)$","minVersion":"4.6","baseDir":"js/Ads","mandatoryUpdate":true,"isFolder":true},
|
|
21
|
-
{"name":"common-less","pattern":"common-(\\d+\\.\\d+)\\.less$","minVersion":"1.8","baseDir":"assets/css","mandatoryUpdate":true},
|
|
22
|
-
{"name":"localNotification_AppSettings","pattern":"localNotification_AppSettings-(\\d+\\.\\d+)\\.js$","minVersion":"1.0","baseDir":"js","mandatoryUpdate":true},
|
|
23
|
-
{"name":"localNotification","pattern":"localNotification-(\\d+\\.\\d+)\\.js$","minVersion":"2.2","baseDir":"js","mandatoryUpdate":true},
|
|
24
|
-
{"name":"onesignal","pattern":"onesignal-(\\d+\\.\\d+)\\.js$","minVersion":"2.4","baseDir":"js","mandatoryUpdate":true},
|
|
25
|
-
{"name":"saveToGalleryAndSaveAnyFile","pattern":"saveToGalleryAndSaveAnyFile-(\\d+\\.\\d+)(-ios)?\\.js$","minVersion":"3.1","baseDir":"js","mandatoryUpdate":true}
|
|
26
|
-
]
|
|
27
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"plugins":[
|
|
3
|
+
{"name":"backbutton","pattern":"backbutton-(\\d+\\.\\d+)\\.js$","minVersion":"2.1","baseDir":"js","mandatoryUpdate":true},
|
|
4
|
+
{"name":"common-js","pattern":"common-(\\d+\\.\\d+)(?:-beta-(\\d+))?\\.js$","minVersion":"6.7","baseDir":"js","mandatoryUpdate":true},
|
|
5
|
+
|
|
6
|
+
{"name":"admob-nextgen","pattern":"admob-nextgen-(\\d+(?:\\.\\d+)*)$","minVersion":"4.1","baseDir":"js/Ads","mandatoryUpdate":true,"isFolder":true},
|
|
7
|
+
{"name":"video-player","pattern":"video-player-(\\d+\\.\\d+)\\.js$","minVersion":"1.6","baseDir":"js","mandatoryUpdate":true},
|
|
8
|
+
{"name":"image-cropper","pattern":"image-cropper-(\\d+\\.\\d+)\\.js$","minVersion":"1.1","baseDir":"js","mandatoryUpdate":true},
|
|
9
|
+
{"name":"beautify","pattern":"beautify-(\\d+\\.\\d+)\\.js$","minVersion":"1.1","baseDir":"js","mandatoryUpdate":true},
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
{"name":"localization","pattern":"localization-(\\d+\\.\\d+)$","minVersion":"1.8","baseDir":"js/localization","mandatoryUpdate":true,"isFolder":true},
|
|
13
|
+
{"name": "localization_settings","pattern": "localization_settings-(\\d+\\.\\d+)\\.js$","minVersion": "1.1","required": true,"baseDir": "js/localization","mandatoryUpdate": true},
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
{"name":"editor","pattern":"editor-(\\d+\\.\\d+)$","minVersion":"2.0","baseDir":"js/editor","mandatoryUpdate":true,"isFolder":true},
|
|
17
|
+
{"name":"ffmpeg","pattern":"ffmpeg-(\\d+\\.\\d+)$","minVersion":"1.6","baseDir":"js","mandatoryUpdate":true,"isFolder":true},
|
|
18
|
+
{"name":"theme","pattern":"theme-(\\d+\\.\\d+)$","minVersion":"3.5","baseDir":"theme","destDir":"theme","mandatoryUpdate":true,"isFolder":true},
|
|
19
|
+
{"name":"certificatejs","pattern":"certificatejs-(\\d+\\.\\d+)$","minVersion":"1.9","baseDir":"certificate","destDir":"certificate","mandatoryUpdate":true,"isFolder":true},
|
|
20
|
+
{"name":"IAP","pattern":"IAP-(\\d+\\.\\d+)$","minVersion":"4.6","baseDir":"js/Ads","mandatoryUpdate":true,"isFolder":true},
|
|
21
|
+
{"name":"common-less","pattern":"common-(\\d+\\.\\d+)\\.less$","minVersion":"1.8","baseDir":"assets/css","mandatoryUpdate":true},
|
|
22
|
+
{"name":"localNotification_AppSettings","pattern":"localNotification_AppSettings-(\\d+\\.\\d+)\\.js$","minVersion":"1.0","baseDir":"js","mandatoryUpdate":true},
|
|
23
|
+
{"name":"localNotification","pattern":"localNotification-(\\d+\\.\\d+)\\.js$","minVersion":"2.2","baseDir":"js","mandatoryUpdate":true},
|
|
24
|
+
{"name":"onesignal","pattern":"onesignal-(\\d+\\.\\d+)\\.js$","minVersion":"2.4","baseDir":"js","mandatoryUpdate":true},
|
|
25
|
+
{"name":"saveToGalleryAndSaveAnyFile","pattern":"saveToGalleryAndSaveAnyFile-(\\d+\\.\\d+)(-ios)?\\.js$","minVersion":"3.1","baseDir":"js","mandatoryUpdate":true}
|
|
26
|
+
]
|
|
27
|
+
}
|