codeplay-common 3.2.0 → 3.2.2

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.
@@ -1,2236 +1,2561 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const plist = require('plist');
4
-
5
-
6
-
7
- const { execSync } = require("child_process");
8
-
9
-
10
-
11
-
12
- const { readFileSync } = require("fs");
13
-
14
- const ENABLE_AUTO_UPDATE = true;
15
- const USE_LIVE_SERVER_VERSION = true;
16
-
17
- const configPath = path.join(process.cwd(), 'capacitor.config.json');
18
- const updateLogFile = path.join(process.cwd(), "", "plugin-update-log.txt");
19
-
20
- // Expected plugin list with minimum versions
21
- /* const requiredPlugins = [
22
-
23
- { pattern: /backbutton-(\d+\.\d+)\.js$/, minVersion: '2.0', required: true, baseDir: 'js',mandatoryUpdate: true},
24
-
25
-
26
- { pattern: /common-(\d+\.\d+)(?:-beta-(\d+))?\.js$/, minVersion: '6.0', required: true, baseDir: 'js',mandatoryUpdate: true },
27
-
28
- { pattern: /localization_settings-(\d+\.\d+)\.js$/, minVersion: '1.1', required: true, baseDir: 'js',mandatoryUpdate: false },
29
- { pattern: /localization-(\d+\.\d+)\.js$/, minVersion: '1.5', required: true, baseDir: 'js',mandatoryUpdate: true },
30
- { pattern: /localNotification-(\d+\.\d+)\.js$/, minVersion: '2.2', required: true, baseDir: 'js',mandatoryUpdate: false },
31
- { pattern: /localNotification_AppSettings-(\d+\.\d+)\.js$/, minVersion: '1.0', required: true, baseDir: 'js',mandatoryUpdate: false },
32
- { pattern: /onesignal-(\d+\.\d+)\.js$/, minVersion: '2.3', required: true, baseDir: 'js',mandatoryUpdate: false },
33
- { pattern: /saveToGalleryAndSaveAnyFile-(\d+\.\d+)(-ios)?\.js$/, minVersion: '3.1', required: true, baseDir: 'js',mandatoryUpdate: true },
34
- { pattern: /Ads[\/\\]admob-emi-(\d+\.\d+)\.js$/, minVersion: '3.7', required: true, baseDir: 'js',mandatoryUpdate: true },
35
-
36
- // New added plugins
37
- { pattern: /video-player-(\d+\.\d+)\.js$/, minVersion: '1.5', required: true, baseDir: 'js',mandatoryUpdate: false },
38
- { pattern: /image-cropper-(\d+\.\d+)\.js$/, minVersion: '1.1', required: true, baseDir: 'js',mandatoryUpdate: false },
39
- { pattern: /common-(\d+\.\d+)\.less$/, minVersion: '1.6', required: true, baseDir: 'assets/css',mandatoryUpdate: false },
40
-
41
-
42
- // New folders
43
- { pattern: /IAP-(\d+\.\d+)$/, minVersion: '2.8', isFolder: true , required: true, baseDir: 'js/Ads',mandatoryUpdate: true },
44
- { pattern: /editor-(\d+\.\d+)$/, minVersion: '1.9', isFolder: true, required: true, baseDir: 'js',mandatoryUpdate: true },
45
- { pattern: /ffmpeg-(\d+\.\d+)$/, minVersion: '1.6', isFolder: true, required: true, baseDir: 'js',mandatoryUpdate: true },
46
- { pattern: /theme-(\d+\.\d+)$/, minVersion: '3.3', isFolder: true , required: true, baseDir: 'theme',mandatoryUpdate: true },
47
-
48
-
49
- { pattern: /certificatejs-(\d+\.\d+)$/, minVersion: '1.6', isFolder: true , required: true, baseDir: 'certificate',mandatoryUpdate: true }
50
-
51
- ]; */
52
-
53
-
54
- function requireOrInstall(packageName) {
55
- try {
56
- return require(packageName);
57
- } catch (err) {
58
-
59
- console.log(`📦 "${packageName}" not found. Installing automatically...`);
60
-
61
- try {
62
- execSync(`npm install ${packageName}`, { stdio: "inherit" });
63
- console.log(`✅ "${packageName}" installed successfully.`);
64
- } catch (installErr) {
65
- console.error(`❌ Failed to install "${packageName}".`);
66
- process.exit(1);
67
- }
68
-
69
- // Try loading again
70
- return require(packageName);
71
- }
72
- }
73
-
74
- const AdmZip = requireOrInstall("adm-zip");
75
-
76
-
77
-
78
- const pkg = require(path.join(process.cwd(), 'node_modules', 'codeplay-common', 'package.json'));
79
-
80
- const pluginName = pkg.name;
81
- const pluginVersion = pkg.version;
82
-
83
- let updateLogs = [];
84
-
85
- function writeUpdateLine(message) {
86
- updateLogs.push(message);
87
- }
88
-
89
- const MAX_LOG_BLOCKS = 50;
90
-
91
- function saveUpdateLogs() {
92
-
93
- if (updateLogs.length === 0) return;
94
-
95
- const logDir = path.dirname(updateLogFile);
96
-
97
- if (!fs.existsSync(logDir)) {
98
- fs.mkdirSync(logDir, { recursive: true });
99
- }
100
-
101
- const now = new Date();
102
-
103
- const formattedTime = now.toLocaleString('en-GB', {
104
- day: '2-digit',
105
- month: '2-digit',
106
- year: 'numeric',
107
- hour: '2-digit',
108
- minute: '2-digit',
109
- hour12: true
110
- }).replace(',', '').replace(/\//g, '-');
111
-
112
- let newBlock = `${pluginName}: ${pluginVersion}\n[${formattedTime}]\n`;
113
-
114
- updateLogs.forEach(line => {
115
- newBlock += `${line}\n`;
116
- });
117
-
118
- newBlock += "\n";
119
-
120
- let existingLog = "";
121
-
122
- if (fs.existsSync(updateLogFile)) {
123
- existingLog = fs.readFileSync(updateLogFile, "utf8");
124
- }
125
-
126
- let combinedLog = newBlock + existingLog;
127
-
128
- // Split blocks by plugin header
129
- const blocks = combinedLog.split(/\n(?=codeplay-common:)/);
130
-
131
- // Keep only latest 50
132
- const trimmed = blocks.slice(0, MAX_LOG_BLOCKS).join("\n");
133
-
134
- fs.writeFileSync(updateLogFile, trimmed);
135
-
136
- }
137
-
138
-
139
-
140
-
141
-
142
- const versionsFile = path.join(__dirname, "versions.json");
143
-
144
- function loadRequiredPlugins() {
145
-
146
- if (!fs.existsSync(versionsFile)) {
147
- console.error("❌ versions.json not found");
148
- process.exit(1);
149
- }
150
-
151
- const json = JSON.parse(fs.readFileSync(versionsFile, "utf8"));
152
-
153
- return json.plugins.map(p => ({
154
- ...p,
155
- pattern: new RegExp(p.pattern)
156
- }));
157
-
158
- }
159
-
160
- let requiredPlugins = loadRequiredPlugins();
161
-
162
-
163
-
164
-
165
-
166
-
167
- async function downloadAndExtractZip(url, destFolder) {
168
-
169
- const zipPath = destFolder + ".zip";
170
-
171
- await downloadFile(url, zipPath);
172
-
173
- const zip = new AdmZip(zipPath);
174
- zip.extractAllTo(destFolder, true);
175
-
176
- fs.unlinkSync(zipPath);
177
-
178
- }
179
-
180
-
181
-
182
-
183
-
184
-
185
-
186
- //Check codeplay-common latest version installed or not Start
187
- //const { execSync } = require('child_process');
188
-
189
-
190
- function getInstalledVersion(packageName) {
191
- try {
192
- const packageJsonPath = path.join(process.cwd(), 'node_modules', packageName, 'package.json');
193
- if (fs.existsSync(packageJsonPath)) {
194
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
195
- return packageJson.version;
196
- }
197
- } catch (error) {
198
- return null;
199
- }
200
- return null;
201
- }
202
-
203
- function getLatestVersion(packageName) {
204
- try {
205
- return execSync(`npm view ${packageName} version`).toString().trim();
206
- } catch (error) {
207
- console.error(`Failed to fetch latest version for ${packageName}`);
208
- return null;
209
- }
210
- }
211
-
212
- function checkPackageVersion() {
213
- const packageName = 'codeplay-common';
214
- const installedVersion = getInstalledVersion(packageName);
215
- const latestVersion = getLatestVersion(packageName);
216
-
217
- if (!installedVersion) {
218
- console.error(`${packageName} is not installed. Please install it using "npm install ${packageName}".`);
219
- process.exit(1);
220
- }
221
-
222
- if (installedVersion !== latestVersion) {
223
- console.error(`\x1b[31m${packageName} is outdated (installed: ${installedVersion}, latest: ${latestVersion}). Please update it.\x1b[0m\n\x1b[33mUse 'npm uninstall codeplay-common ; npm i codeplay-common'\x1b[0m`);
224
- process.exit(1);
225
- }
226
-
227
- console.log(`${packageName} is up to date (version ${installedVersion}).`);
228
- }
229
-
230
- // Run package version check before executing the main script
231
- try {
232
- checkPackageVersion();
233
- } catch (error) {
234
- console.error(error.message);
235
- process.exit(1);
236
- }
237
-
238
- //Check codeplay-common latest version installed or not END
239
-
240
-
241
-
242
- function compareWithBeta(installedVersion, minVersion, isBeta) {
243
- const baseCompare = compareVersions(installedVersion, minVersion);
244
-
245
- if (!isBeta) {
246
- // Stable version → normal compare
247
- return baseCompare;
248
- }
249
-
250
- // Beta version logic
251
- if (baseCompare > 0) return 1; // 5.3-beta > 5.2
252
- if (baseCompare < 0) return -1; // 5.1-beta < 5.2
253
-
254
- // Same version but beta LOWER than stable
255
- return -1; // 5.2-beta < 5.2
256
- }
257
-
258
-
259
-
260
-
261
- const checkAppUniqueId=()=>{
262
-
263
- const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
264
-
265
- const appUniqueId = config.android?.APP_UNIQUE_ID;
266
- const RESIZEABLE_ACTIVITY = config.android?.RESIZEABLE_ACTIVITY;
267
- const orientation = config.android?.ORIENTATION;
268
-
269
-
270
- let logErrorMessage="";
271
-
272
- // 1️⃣ Check if it’s missing
273
- if (RESIZEABLE_ACTIVITY === undefined) {
274
- logErrorMessage+='❌ Missing android.RESIZEABLE_ACTIVITY option in capacitor.config.json.\n';
275
- }
276
-
277
- // 2️⃣ Check if it’s not boolean (true/false only)
278
- else if (typeof RESIZEABLE_ACTIVITY !== 'boolean') {
279
- logErrorMessage+='❌ Invalid android.RESIZEABLE_ACTIVITY value. Please use only true or false (without quotes).\n';
280
- }
281
-
282
-
283
-
284
- if (!orientation) {
285
- logErrorMessage+='❌ Missing android.ORIENTATION option in capacitor.config.json.\n';
286
- }
287
-
288
- else if(orientation!="portrait" && orientation!="landscape" && orientation!="auto")
289
- {
290
- logErrorMessage+='❌ Spelling mistake in android.ORIENTATION option in capacitor.config.json. Please use only ["portrait" "landscape" "auto"]\n';
291
- }
292
-
293
-
294
- if (!appUniqueId) {
295
- logErrorMessage+='❌ APP_UNIQUE_ID is missing in capacitor.config.json.';
296
- }
297
-
298
- else if (!Number.isInteger(appUniqueId)) {
299
- logErrorMessage+='❌ APP_UNIQUE_ID must be an integer. Example: 1, 2, 3, etc.';
300
- }
301
-
302
-
303
-
304
- if(logErrorMessage!="")
305
- {
306
- console.error(logErrorMessage);
307
- process.exit(1)
308
- }
309
-
310
-
311
- console.log(`✅ APP_UNIQUE_ID is valid: ${appUniqueId}`);
312
-
313
- }
314
-
315
- checkAppUniqueId();
316
-
317
-
318
-
319
-
320
-
321
-
322
-
323
- //@Codemirror check and install/uninstall the packages START
324
- //const fs = require("fs");
325
- //const path = require("path");
326
- //const { execSync } = require("child_process");
327
-
328
- const jsDir = path.join(__dirname, "..", "src", "js");
329
-
330
- // 🔍 Detect OLD structure
331
- const oldEditorDirs = fs.readdirSync(jsDir)
332
- .filter(name => /^editor-\d+\.\d+$/.test(name));
333
-
334
- // 📁 New structure path (optional, not mandatory)
335
- const newEditorBaseDir = path.join(jsDir, "editor");
336
-
337
- // ======================================================
338
- // CASE 1: OLD STRUCTURE FOUND → STOP
339
- // ======================================================
340
- if (oldEditorDirs.length > 0) {
341
-
342
- console.error(`
343
- ❌ OLD EDITOR STRUCTURE DETECTED
344
-
345
- You are using outdated folder structure:
346
- src/js/editor-x.x/
347
-
348
- 🚨 This is no longer supported.
349
-
350
- 📦 Found folders:
351
- ${oldEditorDirs.map(d => " - " + d).join("\n")}
352
-
353
- 👉 Please move them manually:
354
-
355
- src/js/editor-1.6
356
-
357
- src/js/editor/editor-1.6
358
-
359
- ⚠️ Also ensure:
360
- src/js/editor/configuration.json exists
361
-
362
- ❌ Build stopped.
363
- `);
364
-
365
- process.exit(1);
366
- }
367
-
368
- // ======================================================
369
- // ✅ CASE 2: NEW STRUCTURE EXISTS → VALIDATE
370
- // ======================================================
371
- if (fs.existsSync(newEditorBaseDir)) {
372
-
373
- // 🔍 Find editor-x.x inside new folder
374
- const editorDirs = fs.readdirSync(newEditorBaseDir)
375
- .filter(name => /^editor-\d+\.\d+$/.test(name));
376
-
377
- // 👉 If editor folder exists but no versions → skip safely
378
- if (editorDirs.length === 0) {
379
- console.log("ℹ️ No editor-x.x folders found inside src/js/editor/");
380
- return;
381
- }
382
-
383
- // ======================================================
384
- // Validate configuration.json (NEW RULE)
385
- // ======================================================
386
-
387
- const editorConfigPath = path.join(newEditorBaseDir, "configuration.json");
388
-
389
- // ❌ Missing config
390
- if (!fs.existsSync(editorConfigPath)) {
391
- console.error(`
392
- ❌ MISSING EDITOR CONFIGURATION FILE
393
-
394
- Required:
395
- src/js/editor/configuration.json
396
-
397
- ❌ Build stopped.
398
- `);
399
- process.exit(1);
400
- }
401
-
402
- // Check wrong placement
403
- const invalidConfigs = [];
404
-
405
- editorDirs.forEach(dir => {
406
- const wrongPath = path.join(newEditorBaseDir, dir, "configuration.json");
407
- if (fs.existsSync(wrongPath)) {
408
- invalidConfigs.push(`src/js/editor/${dir}/configuration.json`);
409
- }
410
- });
411
-
412
- if (invalidConfigs.length > 0) {
413
- console.error(`
414
- INVALID CONFIGURATION LOCATION
415
-
416
- 🚫 configuration.json must NOT be inside version folders.
417
-
418
- Found:
419
- ${invalidConfigs.map(p => " - " + p).join("\n")}
420
-
421
- ✅ Correct:
422
- src/js/editor/configuration.json
423
-
424
- ❌ Build stopped.
425
- `);
426
- process.exit(1);
427
- }
428
-
429
- console.log("✅ Editor structure validated.");
430
-
431
- // ======================================================
432
- // 🚀 Continue execution (run.js)
433
- // ======================================================
434
-
435
- const latestEditorDir = editorDirs.sort((a, b) => {
436
- const vA = parseFloat(a.split('-')[1]);
437
- const vB = parseFloat(b.split('-')[1]);
438
- return vB - vA;
439
- })[0];
440
-
441
- const runJsPath = path.join(newEditorBaseDir, latestEditorDir, "run.js");
442
-
443
- if (!fs.existsSync(runJsPath)) {
444
- console.error(`❌ run.js not found in ${latestEditorDir}`);
445
- process.exit(1);
446
- }
447
-
448
- console.log(`🚀 Executing ${runJsPath}...`);
449
- execSync(`node "${runJsPath}"`, { stdio: "inherit" });
450
- }
451
-
452
- // ======================================================
453
- // CASE 3: NOTHING EXISTS → DO NOTHING
454
- // ======================================================
455
- else {
456
- console.log("ℹ️ Editor not used in this project. Skipping...");
457
- }
458
-
459
- //@Codemirror check and install/uninstall the packages END
460
-
461
-
462
-
463
-
464
-
465
-
466
-
467
-
468
-
469
-
470
-
471
-
472
- // saveToGalleryAndSaveAnyFile-x.x-ios.js file check for android and return error if exists START
473
-
474
- const os = require('os');
475
-
476
- const saveToGalleryAndSaveFileCheck_iOS = () => {
477
-
478
- // List of paths to scan
479
- const SCAN_PATHS = [
480
- path.resolve(__dirname, '../src/certificate'),
481
- path.resolve(__dirname, '../src/pages'),
482
- path.resolve(__dirname, '../src/js'),
483
- path.resolve(__dirname, '../src/app.f7')
484
- ];
485
-
486
- // Directory to exclude
487
- const EXCLUDED_DIR = path.resolve(__dirname, '../src/js/Ads');
488
-
489
- const ANDROID_MANIFEST_PATH = path.resolve(__dirname, '../android/app/src/main/AndroidManifest.xml');
490
-
491
-
492
- // Match iOS-specific imports (e.g., saveToGalleryAndSaveAnyFile-2.5-ios.js) not in comments
493
- const IOS_FILE_REGEX = /^(?!\s*\/\/).*['"](?:.*\/)?saveToGalleryAndSaveAnyFile-\d+(\.\d+)*-ios\.js['"]/m;
494
-
495
- // Match Android-specific imports (e.g., saveToGalleryAndSaveAnyFile-2.5.js) not in comments
496
- const ANDROID_FILE_REGEX = /^(?!\s*\/\/).*['"](?:.*\/)?saveToGalleryAndSaveAnyFile-\d+(\.\d+)*\.js['"]/m;
497
-
498
-
499
-
500
-
501
-
502
- const ALLOWED_EXTENSIONS = ['.js', '.f7'];
503
- const isMac = os.platform() === 'darwin';
504
-
505
- let iosImportFound = false;
506
- let androidImportFound = false;
507
-
508
- // Files to skip completely (full or partial match)
509
- const SKIP_FILES = [
510
- 'pdf-3.11.174.min.js',
511
- 'pdf.worker-3.11.174.min.js'
512
- ,'index.browser.js'
513
- ];
514
-
515
-
516
- function scanDirectory(dir) {
517
-
518
- /*
519
- //######################### DO NOT DELETE THIS - START [Appid base validation] #####################################
520
- const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
521
- const appUniqueId = config.android?.APP_UNIQUE_ID;
522
- if (appUniqueId == "206") return;
523
- //######################### DO NOT DELETE THIS - END [Appid base validation] #####################################
524
- */
525
-
526
- const stat = fs.statSync(dir);
527
-
528
- if (stat.isFile()) {
529
-
530
- // 🔥 Skip files in SKIP_FILES array
531
- const baseName = path.basename(dir);
532
- if (SKIP_FILES.includes(baseName)) {
533
- // Just skip silently
534
- return;
535
- }
536
-
537
- // Only scan allowed file extensions
538
- if (ALLOWED_EXTENSIONS.some(ext => dir.endsWith(ext))) {
539
- process.stdout.write(`\r🔍 Scanning: ${dir} `);
540
-
541
- const content = fs.readFileSync(dir, 'utf8');
542
-
543
- if (IOS_FILE_REGEX.test(content)) {
544
- iosImportFound = true;
545
- if (!isMac) {
546
- console.error(`\n❌ ERROR: iOS-specific import detected in: ${dir}`);
547
- console.error(`🚫 STOPPED: This file should not be imported in Android/Windows/Linux builds.\n`);
548
- process.exit(1);
549
- }
550
- }
551
- else if (ANDROID_FILE_REGEX.test(content) && !content.includes('-ios.js')) {
552
- androidImportFound = true;
553
- }
554
- }
555
- }
556
- else if (stat.isDirectory()) {
557
- if (dir === EXCLUDED_DIR || path.basename(dir) === 'node_modules') return;
558
-
559
- const entries = fs.readdirSync(dir, { withFileTypes: true });
560
- for (let entry of entries) {
561
- scanDirectory(path.join(dir, entry.name));
562
- }
563
- }
564
- }
565
-
566
-
567
- // Run scan on all specified paths
568
- for (let scanPath of SCAN_PATHS) {
569
- if (fs.existsSync(scanPath)) {
570
- scanDirectory(scanPath);
571
- }
572
- }
573
-
574
-
575
-
576
- /* // Check src folder
577
- if (!fs.existsSync(ROOT_DIR)) {
578
- console.warn(`⚠️ Warning: 'src' directory not found at: ${ROOT_DIR}`);
579
- return;
580
- } */
581
-
582
- //scanDirectory(ROOT_DIR);
583
-
584
- // iOS Checks
585
- if (isMac && !iosImportFound) {
586
- console.warn(`⚠️ WARNING: You're on macOS but no iOS version (saveToGalleryAndSaveAnyFile-x.x-ios.js) found.`);
587
- process.exit(1);
588
- } else if (isMac && iosImportFound) {
589
- console.log('✅ iOS version detected for macOS build.');
590
- } else if (!iosImportFound) {
591
- console.log('✅ No iOS-specific imports detected for non-macOS.');
592
- }
593
-
594
- // Android Checks
595
- if (androidImportFound) {
596
- console.log("📱 Android version of saveToGalleryAndSaveAnyFile detected. Checking AndroidManifest.xml...");
597
-
598
- if (!fs.existsSync(ANDROID_MANIFEST_PATH)) {
599
- console.error("❌ AndroidManifest.xml not found. Cannot add requestLegacyExternalStorage attribute.");
600
- return;
601
- }
602
-
603
- let manifestContent = fs.readFileSync(ANDROID_MANIFEST_PATH, 'utf8');
604
-
605
- if (!manifestContent.includes('android:requestLegacyExternalStorage="true"')) {
606
- console.log("Adding android:requestLegacyExternalStorage=\"true\" to <application> tag...");
607
-
608
- manifestContent = manifestContent.replace(
609
- /<application([^>]*)>/,
610
- (match, attrs) => {
611
- if (attrs.includes('android:requestLegacyExternalStorage')) return match;
612
- return `<application${attrs} android:requestLegacyExternalStorage="true">`;
613
- }
614
- );
615
-
616
- fs.writeFileSync(ANDROID_MANIFEST_PATH, manifestContent, 'utf8');
617
- console.log("✅ android:requestLegacyExternalStorage=\"true\" added successfully.");
618
- } else {
619
- console.log("ℹ️ android:requestLegacyExternalStorage already exists in AndroidManifest.xml.");
620
- }
621
- } else {
622
- console.log("✅ No Android saveToGalleryAndSaveAnyFile imports detected.");
623
- }
624
- };
625
-
626
- saveToGalleryAndSaveFileCheck_iOS();
627
- // saveToGalleryAndSaveAnyFile-x.x-ios.js file check for android and return error if exists END
628
-
629
-
630
-
631
-
632
-
633
-
634
-
635
-
636
-
637
-
638
-
639
-
640
-
641
- /*
642
- // Clean up AppleDouble files (._*) created by macOS START
643
- if (process.platform === 'darwin') {
644
- try {
645
- console.log('🧹 Cleaning up AppleDouble files (._*)...');
646
- execSync(`find . -name '._*' -delete`);
647
- console.log('✅ AppleDouble files removed.');
648
- } catch (err) {
649
- console.warn('⚠️ Failed to remove AppleDouble files:', err.message);
650
- }
651
- } else {
652
- console.log('ℹ️ Skipping AppleDouble cleanup — not a macOS machine.');
653
- }
654
-
655
- // Clean up AppleDouble files (._*) created by macOS END
656
- */
657
-
658
-
659
-
660
-
661
-
662
-
663
- //In routes.js file check static import START
664
-
665
- const routesPath = path.join(process.cwd(), 'src', 'js', 'routes.js');
666
- const routesContent = fs.readFileSync(routesPath, 'utf-8');
667
-
668
- let inBlockComment = false;
669
- const lines = routesContent.split('\n');
670
-
671
- const allowedImport = `import HomePage from '../pages/home.f7';`;
672
- const badImportRegex = /^[ \t]*import\s+[\w{}*,\s]*\s+from\s+['"].+\.f7['"]\s*;/;
673
- const badImports = [];
674
-
675
- lines.forEach((line, index) => {
676
- const trimmed = line.trim();
677
-
678
- // Handle block comment start and end
679
- if (trimmed.startsWith('/*')) inBlockComment = true;
680
- if (inBlockComment && trimmed.endsWith('*/')) {
681
- inBlockComment = false;
682
- return;
683
- }
684
-
685
- // Skip if inside block comment or line comment
686
- if (inBlockComment || trimmed.startsWith('//')) return;
687
-
688
- // Match static .f7 import
689
- if (badImportRegex.test(trimmed) && trimmed !== allowedImport) {
690
- badImports.push({ line: trimmed, number: index + 1 });
691
- }
692
- });
693
-
694
- if (badImports.length > 0) {
695
- console.error('\n❌ ERROR: Detected disallowed static imports of .f7 files in routes.js\n');
696
- console.error(`⚠️ Only this static import is allowed:\n ${allowedImport}\n`);
697
- console.error(`🔧 Please convert other imports to async dynamic imports like this:\n`);
698
- console.error(`
699
-
700
- import HomePage from '../pages/home.f7';
701
-
702
- const routes = [
703
- {
704
- path: '/',
705
- component:HomePage,
706
- },
707
- {
708
- path: '/ProfilePage/',
709
- async async({ resolve }) {
710
- const page = await import('../pages/profile.f7');
711
- resolve({ component: page.default });
712
- },
713
- }]
714
- `);
715
-
716
- badImports.forEach(({ line, number }) => {
717
- console.error(`${number}: ${line}`);
718
- });
719
-
720
- process.exit(1);
721
- } else {
722
- console.log('✅ routes.js passed the .f7 import check.');
723
- }
724
-
725
- //In routes.js file check static import END
726
-
727
-
728
-
729
-
730
-
731
-
732
-
733
-
734
-
735
-
736
-
737
-
738
-
739
- // Check and change the "BridgeWebViewClient.java" file START
740
- /*
741
- For crash issue due to low memory problem, we need to modify the onRenderProcessGone method in BridgeWebViewClient.java.
742
- */
743
-
744
-
745
- const bridgeWebViewClientFilePath = path.join(process.cwd(), 'node_modules', '@capacitor/android/capacitor/src/main/java/com/getcapacitor', 'BridgeWebViewClient.java');
746
-
747
- // Read the file
748
- if (!fs.existsSync(bridgeWebViewClientFilePath)) {
749
- console.error('❌ Error: BridgeWebViewClient.java not found.');
750
- process.exit(1);
751
- }
752
-
753
- let fileContent = fs.readFileSync(bridgeWebViewClientFilePath, 'utf8');
754
-
755
- // Define old and new code
756
- const oldCodeStart = `@Override
757
- public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) {
758
- super.onRenderProcessGone(view, detail);
759
- boolean result = false;
760
-
761
- List<WebViewListener> webViewListeners = bridge.getWebViewListeners();
762
- if (webViewListeners != null) {
763
- for (WebViewListener listener : bridge.getWebViewListeners()) {
764
- result = listener.onRenderProcessGone(view, detail) || result;
765
- }
766
- }
767
-
768
- return result;
769
- }`;
770
-
771
- const newCode = `@Override
772
- public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) {
773
- super.onRenderProcessGone(view, detail);
774
-
775
- boolean result = false;
776
-
777
- List<WebViewListener> webViewListeners = bridge.getWebViewListeners();
778
- if (webViewListeners != null) {
779
- for (WebViewListener listener : bridge.getWebViewListeners()) {
780
- result = listener.onRenderProcessGone(view, detail) || result;
781
- }
782
- }
783
-
784
- if (!result) {
785
- // If no one handled it, handle it ourselves!
786
-
787
- /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
788
- if (detail.didCrash()) {
789
- //Log.e("CapacitorWebView", "WebView crashed internally!");
790
- } else {
791
- //Log.w("CapacitorWebView", "WebView was killed by system (low memory) internally!");
792
- }
793
- }*/
794
-
795
- view.post(() -> {
796
- Toast.makeText(view.getContext(), "Reloading due to low memory issue", Toast.LENGTH_SHORT).show();
797
- });
798
-
799
- view.reload(); // Safely reload WebView
800
-
801
- return true; // We handled it
802
- }
803
-
804
- return result;
805
- }`;
806
-
807
- // Step 1: Update method if needed
808
- let updated = false;
809
-
810
- if (fileContent.includes(oldCodeStart)) {
811
- console.log('✅ Found old onRenderProcessGone method. Replacing it...');
812
- fileContent = fileContent.replace(oldCodeStart, newCode);
813
- updated = true;
814
- } else if (fileContent.includes(newCode)) {
815
- console.log('ℹ️ Method already updated. No changes needed in "BridgeWebViewClient.java".');
816
- } else {
817
- console.error('❌ Error: Neither old nor new code found. Unexpected content.');
818
- process.exit(1);
819
- }
820
-
821
- // Step 2: Check and add import if missing
822
- const importToast = 'import android.widget.Toast;';
823
- if (!fileContent.includes(importToast)) {
824
- console.log('✅ Adding missing import for Toast...');
825
- const importRegex = /import\s+[^;]+;/g;
826
- const matches = [...fileContent.matchAll(importRegex)];
827
-
828
- if (matches.length > 0) {
829
- const lastImport = matches[matches.length - 1];
830
- const insertPosition = lastImport.index + lastImport[0].length;
831
- fileContent = fileContent.slice(0, insertPosition) + `\n${importToast}` + fileContent.slice(insertPosition);
832
- updated = true;
833
- } else {
834
- console.error('❌ Error: No import section found in file.');
835
- process.exit(1);
836
- }
837
- } else {
838
- console.log('ℹ️ Import for Toast already exists. No changes needed.');
839
- }
840
-
841
- // Step 3: Save if updated
842
- if (updated) {
843
- fs.writeFileSync(bridgeWebViewClientFilePath, fileContent, 'utf8');
844
- console.log('✅ File updated successfully.');
845
- } else {
846
- console.log('ℹ️ No changes needed.');
847
- }
848
-
849
-
850
-
851
-
852
- // Check and change the "BridgeWebViewClient.java" file END
853
-
854
-
855
-
856
-
857
-
858
-
859
-
860
-
861
- /*
862
- // To resolve the kotlin version issue, we need to update the kotlin version in the build.gradle file START
863
-
864
- // Build the path dynamically like you requested
865
- const gradlePath = path.join(
866
- process.cwd(),
867
- 'android',
868
- 'build.gradle'
869
- );
870
-
871
- // Read the existing build.gradle
872
- let gradleContent = fs.readFileSync(gradlePath, 'utf8');
873
-
874
- // Add `ext.kotlin_version` if it's not already there
875
- if (!gradleContent.includes('ext.kotlin_version')) {
876
- gradleContent = gradleContent.replace(
877
- /buildscript\s*{/,
878
- `buildscript {\n ext.kotlin_version = '2.1.0'`
879
- );
880
- }
881
-
882
- // Add Kotlin classpath if it's not already there
883
- if (!gradleContent.includes('org.jetbrains.kotlin:kotlin-gradle-plugin')) {
884
- gradleContent = gradleContent.replace(
885
- /dependencies\s*{([\s\S]*?)classpath 'com.android.tools.build:gradle:8.7.2'/,
886
- `dependencies {\n classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")\n$1classpath 'com.android.tools.build:gradle:8.7.2'`
887
- );
888
- }
889
-
890
- // Write back the modified content
891
- fs.writeFileSync(gradlePath, gradleContent, 'utf8');
892
-
893
- console.log('✅ Kotlin version updated in build.gradle.');
894
-
895
- // To resolve the kotlin version issue, we need to update the kotlin version in the build.gradle file END
896
- */
897
-
898
-
899
-
900
-
901
-
902
-
903
-
904
-
905
- let _admobConfig;
906
-
907
-
908
-
909
- const androidPlatformPath = path.join(process.cwd(), 'android');
910
- const iosPlatformPath = path.join(process.cwd(), 'ios');
911
- const pluginPath = path.join(process.cwd(), 'node_modules', 'emi-indo-cordova-plugin-admob', 'plugin.xml');
912
- const infoPlistPath = path.join(process.cwd(), 'ios', 'App', 'App', 'Info.plist');
913
- const resourcesPath = path.join(process.cwd(), 'resources', 'res');
914
- const androidResPath = path.join(process.cwd(), 'android', 'app', 'src', 'main', 'res');
915
- const localNotificationsPluginPath = path.join(process.cwd(), 'node_modules', '@capacitor', 'local-notifications');
916
-
917
- function fileExists(filePath) {
918
- return fs.existsSync(filePath);
919
- }
920
-
921
- function copyFolderSync(source, target) {
922
- if (!fs.existsSync(target)) {
923
- fs.mkdirSync(target, { recursive: true });
924
- }
925
-
926
- fs.readdirSync(source).forEach(file => {
927
- const sourceFile = path.join(source, file);
928
- const targetFile = path.join(target, file);
929
-
930
- if (fs.lstatSync(sourceFile).isDirectory()) {
931
- copyFolderSync(sourceFile, targetFile);
932
- } else {
933
- fs.copyFileSync(sourceFile, targetFile);
934
- }
935
- });
936
- }
937
-
938
- function checkAndCopyResources() {
939
- if (fileExists(resourcesPath)) {
940
- copyFolderSync(resourcesPath, androidResPath);
941
- console.log('✅ Successfully copied resources/res to android/app/src/main/res.');
942
- } else {
943
- console.log('resources/res folder not found.');
944
-
945
- if (fileExists(localNotificationsPluginPath)) {
946
- throw new Error('❌ resources/res is required for @capacitor/local-notifications. Stopping execution.');
947
- }
948
- }
949
- }
950
-
951
-
952
-
953
-
954
-
955
-
956
-
957
-
958
- function getAdMobConfig() {
959
- if (!fileExists(configPath)) {
960
- throw new Error('❌ capacitor.config.json not found. Ensure this is a Capacitor project.');
961
- }
962
-
963
- const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
964
- const admobConfig = config.plugins?.AdMob;
965
-
966
- if (!admobConfig) {
967
- throw new Error('❌ AdMob configuration is missing in capacitor.config.json.');
968
- }
969
-
970
- // Default to true if ADMOB_ENABLED is not specified
971
- const isEnabled = admobConfig.ADMOB_ENABLED !== false;
972
-
973
- if (!isEnabled) {
974
- return { ADMOB_ENABLED: false }; // Skip further validation
975
- }
976
-
977
- if (!admobConfig.APP_ID_ANDROID || !admobConfig.APP_ID_IOS) {
978
- throw new Error(' ❌ AdMob configuration is incomplete. Ensure APP_ID_ANDROID and APP_ID_IOS are defined.');
979
- }
980
-
981
- return {
982
- ADMOB_ENABLED: true,
983
- APP_ID_ANDROID: admobConfig.APP_ID_ANDROID,
984
- APP_ID_IOS: admobConfig.APP_ID_IOS,
985
- USE_LITE_ADS: admobConfig.USE_LITE_ADS === "lite",
986
- };
987
- }
988
-
989
- function validateAndroidBuildOptions() {
990
-
991
-
992
- if (!fileExists(configPath)) {
993
- console.log('❌ capacitor.config.json not found. Ensure this is a Capacitor project.');
994
- process.exit(1);
995
- }
996
-
997
- const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
998
-
999
- const targetAppId=config.appId
1000
-
1001
- const buildOptions = config.android?.buildOptions;
1002
-
1003
- if (!buildOptions) {
1004
- console.log(' Missing android.buildOptions in capacitor.config.json.');
1005
- process.exit(1);
1006
- }
1007
-
1008
- const requiredProps = [
1009
- 'keystorePath',
1010
- 'keystorePassword',
1011
- 'keystoreAlias',
1012
- 'keystoreAliasPassword',
1013
- 'releaseType',
1014
- 'signingType'
1015
- ];
1016
-
1017
- const missing = requiredProps.filter(prop => !buildOptions[prop]);
1018
-
1019
- if (missing.length > 0) {
1020
- console.log('❌ Missing properties android.buildOptions in capacitor.config.json.');
1021
- process.exit(1);
1022
- }
1023
-
1024
-
1025
- const keystorePath=buildOptions.keystorePath
1026
- const keyFileName = path.basename(keystorePath);
1027
-
1028
-
1029
-
1030
- const keystoreMap = {
1031
- "gameskey.jks": [
1032
- "com.cube.blaster",
1033
- ],
1034
- "htmleditorkeystoke.jks": [
1035
- "com.HTML.AngularJS.Codeplay",
1036
- "com.html.codeplay.pro",
1037
- "com.bootstrap.code.play",
1038
- "com.kids.learning.master",
1039
- "com.Simple.Barcode.Scanner",
1040
- "com.FAShtmlcssjs.editor"
1041
- ]
1042
- };
1043
-
1044
- // find which keystore is required for the given targetAppId
1045
- let requiredKey = "newappskey.jks"; // default
1046
- for (const [keyFile, appIds] of Object.entries(keystoreMap)) {
1047
- if (appIds.includes(targetAppId)) {
1048
- requiredKey = keyFile;
1049
- break;
1050
- }
1051
- }
1052
-
1053
- // validate
1054
- if (keyFileName !== requiredKey) {
1055
- console.log(`❌ The keystore path is mismatched. Expected ${requiredKey} for ${targetAppId}, but got ${keyFileName}`);
1056
- process.exit(1);
1057
- }
1058
-
1059
-
1060
-
1061
-
1062
-
1063
- // optionally return them
1064
- //return buildOptions;
1065
- }
1066
-
1067
- function updatePluginXml(admobConfig) {
1068
- if (!fileExists(pluginPath)) {
1069
- console.error(' ❌ plugin.xml not found. Ensure the plugin is installed.');
1070
- return;
1071
- }
1072
-
1073
- let pluginContent = fs.readFileSync(pluginPath, 'utf8');
1074
-
1075
- pluginContent = pluginContent
1076
- .replace(/<preference name="APP_ID_ANDROID" default=".*?" \/>/, `<preference name="APP_ID_ANDROID" default="${admobConfig.APP_ID_ANDROID}" />`)
1077
- .replace(/<preference name="APP_ID_IOS" default=".*?" \/>/, `<preference name="APP_ID_IOS" default="${admobConfig.APP_ID_IOS}" />`);
1078
-
1079
- fs.writeFileSync(pluginPath, pluginContent, 'utf8');
1080
- console.log('✅ AdMob IDs successfully updated in plugin.xml');
1081
- }
1082
-
1083
- function updateInfoPlist(admobConfig) {
1084
- if (!fileExists(infoPlistPath)) {
1085
- console.error(' ❌ Info.plist not found. Ensure you have built the iOS project.');
1086
- return;
1087
- }
1088
-
1089
- const plistContent = fs.readFileSync(infoPlistPath, 'utf8');
1090
- const plistData = plist.parse(plistContent);
1091
-
1092
- plistData.GADApplicationIdentifier = admobConfig.APP_ID_IOS;
1093
- plistData.NSUserTrackingUsageDescription = 'This identifier will be used to deliver personalized ads to you.';
1094
- plistData.GADDelayAppMeasurementInit = true;
1095
-
1096
- const updatedPlistContent = plist.build(plistData);
1097
- fs.writeFileSync(infoPlistPath, updatedPlistContent, 'utf8');
1098
- console.log('AdMob IDs and additional configurations successfully updated in Info.plist');
1099
- }
1100
-
1101
-
1102
- try {
1103
- if (!fileExists(configPath)) {
1104
- throw new Error(' capacitor.config.json not found. Skipping setup.');
1105
- }
1106
-
1107
- if (!fileExists(androidPlatformPath) && !fileExists(iosPlatformPath)) {
1108
- throw new Error('Neither Android nor iOS platforms are found. Ensure platforms are added to your Capacitor project.');
1109
- }
1110
-
1111
- checkAndCopyResources();
1112
-
1113
-
1114
-
1115
- _admobConfig = getAdMobConfig();
1116
-
1117
-
1118
-
1119
-
1120
-
1121
- // Proceed only if ADMOB_ENABLED is true
1122
- if (_admobConfig.ADMOB_ENABLED) {
1123
- if (fileExists(androidPlatformPath)) {
1124
- updatePluginXml(_admobConfig);
1125
- }
1126
-
1127
- if (fileExists(iosPlatformPath)) {
1128
- updateInfoPlist(_admobConfig);
1129
- }
1130
- }
1131
-
1132
-
1133
- } catch (error) {
1134
- console.error(error.message);
1135
- process.exit(1); // Stop execution if there's a critical error
1136
- }
1137
-
1138
-
1139
-
1140
- validateAndroidBuildOptions();
1141
-
1142
-
1143
-
1144
-
1145
-
1146
-
1147
- // Check all the codeplays plugins version START
1148
-
1149
-
1150
- const readline = require('readline');
1151
-
1152
-
1153
- //const srcDir = path.join(__dirname, 'src');
1154
- const srcDir = path.join(process.cwd(), 'src');
1155
- let outdatedPlugins = [];
1156
-
1157
- function parseVersion(ver) {
1158
- return ver.split('.').map(n => parseInt(n, 10));
1159
- }
1160
-
1161
- function compareVersions(v1, v2) {
1162
- const [a1, b1] = parseVersion(v1);
1163
- const [a2, b2] = parseVersion(v2);
1164
- if (a1 !== a2) return a1 - a2;
1165
- return b1 - b2;
1166
- }
1167
-
1168
- function walkSync(dir, filelist = []) {
1169
- fs.readdirSync(dir).forEach(file => {
1170
- const fullPath = path.join(dir, file);
1171
- const stat = fs.statSync(fullPath);
1172
- if (stat.isDirectory()) {
1173
- walkSync(fullPath, filelist);
1174
- } else {
1175
- filelist.push(fullPath);
1176
- }
1177
- });
1178
- return filelist;
1179
- }
1180
-
1181
-
1182
-
1183
- function getSearchRoot(plugin) {
1184
- return path.join(srcDir, plugin.baseDir || 'js');
1185
- }
1186
-
1187
-
1188
-
1189
-
1190
-
1191
-
1192
-
1193
-
1194
-
1195
-
1196
-
1197
-
1198
-
1199
-
1200
-
1201
-
1202
-
1203
-
1204
-
1205
-
1206
- /*############################################## AUTO DOWNLOAD FROM SERVER START #####################################*/
1207
-
1208
- // ============================================================
1209
- // 🔥 AUTO PLUGIN UPDATE SYSTEM (MANDATORY UPDATES)
1210
- // ============================================================
1211
-
1212
- const https = require("https");
1213
-
1214
- /**
1215
- * Check if file exists on server using HEAD request
1216
- */
1217
- function urlExists(url) {
1218
- return new Promise(resolve => {
1219
- const req = https.request(url, { method: "HEAD" }, res => {
1220
- resolve(res.statusCode === 200);
1221
- });
1222
-
1223
- req.on("error", () => resolve(false));
1224
- req.end();
1225
- });
1226
- }
1227
-
1228
- /**
1229
- * Download file from server
1230
- */
1231
- function downloadFile(url, dest) {
1232
- return new Promise((resolve, reject) => {
1233
- const file = fs.createWriteStream(dest);
1234
-
1235
- https.get(url, response => {
1236
- if (response.statusCode !== 200) {
1237
- reject("Download failed");
1238
- return;
1239
- }
1240
-
1241
- response.pipe(file);
1242
-
1243
- file.on("finish", () => {
1244
- file.close(resolve);
1245
- });
1246
- }).on("error", err => {
1247
- fs.unlink(dest, () => {});
1248
- reject(err);
1249
- });
1250
- });
1251
- }
1252
-
1253
- /**
1254
- * Update imports across src folder
1255
- * Replaces old filename → new filename
1256
- */
1257
- /**
1258
- * Update imports across project
1259
- * Replaces old filename → new filename
1260
- */
1261
-
1262
- const VITE_ALIAS_ONLY = [
1263
- "common",
1264
- "admob-emi",
1265
- "localization",
1266
- "theme",
1267
- "certificatejs",
1268
- "ffmpeg"
1269
- ];
1270
-
1271
- function updateImports(oldName, newName) {
1272
-
1273
- const projectRoot = process.cwd();
1274
-
1275
- const filesToScan = [
1276
- path.join(projectRoot, "vite.config.js"),
1277
- path.join(projectRoot, "vite.config.mjs")
1278
- ];
1279
-
1280
- const srcDir = path.join(projectRoot, "src");
1281
-
1282
- // scan vite config
1283
- filesToScan.forEach(file => {
1284
-
1285
- if (!fs.existsSync(file)) return;
1286
-
1287
- let content = fs.readFileSync(file, "utf8");
1288
-
1289
- if (content.includes(oldName)) {
1290
-
1291
- content = content.split(oldName).join(newName);
1292
-
1293
- fs.writeFileSync(file, content);
1294
-
1295
- console.log(`✏️ Updated alias in ${path.basename(file)}`);
1296
- }
1297
-
1298
- });
1299
-
1300
- // scan src files
1301
- function walk(dir) {
1302
-
1303
- fs.readdirSync(dir).forEach(file => {
1304
-
1305
- if (["node_modules","android","ios","dist",".git"].includes(file))
1306
- return;
1307
-
1308
- const full = path.join(dir, file);
1309
- const stat = fs.statSync(full);
1310
-
1311
- if (stat.isDirectory()) {
1312
- walk(full);
1313
- }
1314
-
1315
- else if (
1316
- (full.endsWith(".js") ||
1317
- full.endsWith(".f7") ||
1318
- full.endsWith(".mjs")) &&
1319
- !full.endsWith(".min.js")
1320
- ) {
1321
-
1322
- let content = fs.readFileSync(full, "utf8");
1323
-
1324
- if (content.includes(oldName)) {
1325
-
1326
- content = content.split(oldName).join(newName);
1327
-
1328
- fs.writeFileSync(full, content);
1329
-
1330
- console.log(`✏️ Updated import in ${path.relative(projectRoot, full)}`);
1331
- }
1332
-
1333
- }
1334
-
1335
- });
1336
-
1337
- }
1338
-
1339
- if (fs.existsSync(srcDir)) {
1340
- walk(srcDir);
1341
- }
1342
-
1343
- }
1344
-
1345
-
1346
- /**
1347
- * Auto-update a plugin file
1348
- * Returns TRUE if success
1349
- * Returns FALSE if fallback to manual needed
1350
- */
1351
-
1352
-
1353
- let _serverVersions = null;
1354
- async function fetchVersions() {
1355
-
1356
- if (_serverVersions) return _serverVersions;
1357
-
1358
- return new Promise((resolve) => {
1359
-
1360
- https.get(
1361
- "https://htmlcodeplay.com/code-play-plugin/versions.json",
1362
- { timeout: 5000 },
1363
- res => {
1364
-
1365
- let data = "";
1366
-
1367
- res.on("data", chunk => data += chunk);
1368
-
1369
- res.on("end", () => {
1370
-
1371
- try {
1372
-
1373
- _serverVersions = JSON.parse(data);
1374
-
1375
- resolve(_serverVersions);
1376
-
1377
- } catch {
1378
-
1379
- resolve(null);
1380
-
1381
- }
1382
-
1383
- });
1384
-
1385
- }
1386
-
1387
- ).on("error", () => resolve(null));
1388
-
1389
- });
1390
-
1391
- }
1392
-
1393
-
1394
-
1395
- async function autoUpdatePlugin(pluginDef, pluginInfo) {
1396
-
1397
- const versions = await fetchVersions();
1398
-
1399
- if (!versions) {
1400
- console.log("⚠️ versions.json not reachable");
1401
- return false;
1402
- }
1403
-
1404
- const oldFullPath = path.join(srcDir, pluginInfo.name);
1405
- const oldFileName = path.basename(oldFullPath);
1406
-
1407
- //const oldFileName = path.basename(oldFullPath);
1408
- const oldVersionFile = oldFileName;
1409
-
1410
-
1411
- const ext = path.extname(oldFileName); // .js or .less
1412
- //const baseName = oldFileName.replace(/-\d+\.\d+.*$/, "");
1413
- const baseName = oldFileName.replace(/-\d+\.\d+.*$/, '').replace(/\.(js|less)$/, '');
1414
-
1415
- // version lookup key
1416
- let pluginKey = baseName;
1417
-
1418
-
1419
- // Only common plugin has js and less variants
1420
- if (baseName === "common") {
1421
- if (ext === ".js") pluginKey = "common-js";
1422
- if (ext === ".less") pluginKey = "common-less";
1423
- }
1424
-
1425
- const latestVersion = versions[pluginKey];
1426
-
1427
- if (!latestVersion) {
1428
- console.log(`❌ No version entry for ${baseName}`);
1429
- return false;
1430
- }
1431
-
1432
- // ===============================
1433
- // FOLDER PLUGIN UPDATE
1434
- // ===============================
1435
- if (pluginDef.isFolder) {
1436
-
1437
- const zipName = `${baseName}-${latestVersion}.zip`;
1438
- const url = `https://htmlcodeplay.com/code-play-plugin/${zipName}`;
1439
-
1440
- const destRoot = path.join(srcDir, pluginDef.destDir || pluginDef.baseDir || '');
1441
- const oldPath = path.join(destRoot, pluginInfo.name);
1442
- const newPath = path.join(destRoot, `${baseName}-${latestVersion}`);
1443
-
1444
- if (!(await urlExists(url))) return false;
1445
-
1446
- fs.rmSync(oldPath, { recursive: true, force: true });
1447
-
1448
- await downloadAndExtractZip(url, newPath);
1449
-
1450
- updateImports(pluginInfo.name, `${baseName}-${latestVersion}`);
1451
-
1452
- // ADD THIS
1453
- writeUpdateLine(`${pluginInfo.name} -> ${baseName}-${latestVersion}`);
1454
-
1455
- console.log(`✅ Folder updated → ${baseName}-${latestVersion}`);
1456
-
1457
- return true;
1458
- }
1459
- // ===============================
1460
- // FILE PLUGIN UPDATE
1461
- // ===============================
1462
-
1463
- const pluginDir = path.dirname(oldFullPath);
1464
-
1465
- // Only this plugin has ios variant
1466
- const IOS_VARIANT_PLUGINS = [
1467
- "saveToGalleryAndSaveAnyFile"
1468
- ];
1469
-
1470
- /* let variants = [
1471
- `${baseName}-${latestVersion}.js`
1472
- ]; */
1473
-
1474
- //const ext = path.extname(oldFileName);
1475
- const variants = [`${baseName.replace(ext,'')}-${latestVersion}${ext}`];
1476
-
1477
-
1478
- if (IOS_VARIANT_PLUGINS.includes(baseName)) {
1479
- variants.push(`${baseName}-${latestVersion}-ios.js`);
1480
- }
1481
-
1482
- let downloaded = [];
1483
-
1484
- // Download files
1485
- for (const fileName of variants) {
1486
-
1487
- const url = `https://htmlcodeplay.com/code-play-plugin/${fileName}`;
1488
-
1489
- console.log(`🔍 Checking latest: ${fileName}`);
1490
-
1491
- if (await urlExists(url)) {
1492
-
1493
- const destPath = path.join(pluginDir, fileName);
1494
-
1495
- await downloadFile(url, destPath);
1496
-
1497
- downloaded.push(fileName);
1498
-
1499
- console.log(`⬇ Downloaded → ${fileName}`);
1500
-
1501
- //writeUpdateLine(`Downloaded: ${fileName}`);
1502
-
1503
- }
1504
- }
1505
-
1506
- if (downloaded.length === 0) {
1507
- console.log(`❌ No files downloaded for ${baseName}`);
1508
- return false;
1509
- }
1510
-
1511
- // Remove ONLY versioned files (safe)
1512
- //const versionPattern = new RegExp(`^${baseName}-\\d+\\.\\d+(-ios)?\\.js$`);
1513
- const versionPattern = new RegExp(`^${baseName}-\\d+\\.\\d+(-ios)?\\${ext}$`);
1514
-
1515
- const existingFiles = fs.readdirSync(pluginDir);
1516
-
1517
- existingFiles.forEach(file => {
1518
-
1519
- if (
1520
- versionPattern.test(file) &&
1521
- !downloaded.includes(file)
1522
- ) {
1523
-
1524
- const oldPath = path.join(pluginDir, file);
1525
-
1526
- fs.unlinkSync(oldPath);
1527
-
1528
- console.log(`🗑 Removed old file → ${file}`);
1529
- //writeUpdateLine(`Removed old file: ${file}`);
1530
- }
1531
-
1532
- });
1533
-
1534
- //const newFileName = `${baseName}-${latestVersion}.js`;
1535
- const newFileName = `${baseName}-${latestVersion}${ext}`;
1536
-
1537
- writeUpdateLine(`${oldVersionFile} -> ${newFileName}`);
1538
-
1539
- updateImports(oldFileName, newFileName);
1540
- //updateImports(baseName, `${baseName}-${latestVersion}.js`);
1541
- //updateImports(pluginInfo.name, `${baseName}-${latestVersion}`);
1542
-
1543
- //console.log(`✅ Updated → ${newFileName}`);
1544
- //console.log(`✅ Updated ${baseName}-${latestVersion}`);
1545
-
1546
- return true;
1547
- }
1548
-
1549
-
1550
-
1551
-
1552
- /*############################################## AUTO DOWNLOAD FROM SERVER END #####################################*/
1553
-
1554
-
1555
-
1556
-
1557
-
1558
-
1559
-
1560
-
1561
-
1562
-
1563
-
1564
-
1565
-
1566
-
1567
-
1568
-
1569
-
1570
-
1571
- async function loadPluginVersions() {
1572
-
1573
- if (!USE_LIVE_SERVER_VERSION) {
1574
- console.log("ℹ️ Using local plugin versions (offline mode).");
1575
- return;
1576
- }
1577
-
1578
- console.log("🌐 Fetching plugin versions from server...");
1579
-
1580
- const versions = await fetchVersions();
1581
-
1582
- if (!versions || typeof versions !== "object") {
1583
- console.log("⚠️ Server unavailable or invalid versions.json. Falling back to local versions.");
1584
- return;
1585
- }
1586
-
1587
- requiredPlugins.forEach(plugin => {
1588
-
1589
- if (!plugin.name) return;
1590
-
1591
- if (versions[plugin.name]) {
1592
- plugin.minVersion = versions[plugin.name];
1593
- }
1594
-
1595
- });
1596
-
1597
- console.log("✅ Plugin versions loaded from server.");
1598
-
1599
- }
1600
-
1601
-
1602
-
1603
- let hasMandatoryUpdate = false;
1604
- function checkPlugins() {
1605
- return new Promise(async (resolve, reject) => {
1606
- const files = walkSync(srcDir);
1607
- const outdatedPlugins = [];
1608
- let hasMandatoryUpdate = false;
1609
-
1610
- for (const plugin of requiredPlugins) {
1611
- const searchRoot = getSearchRoot(plugin);
1612
-
1613
- // ---------- Folder plugins ----------
1614
- if (plugin.isFolder) {
1615
- if (!fs.existsSync(searchRoot)) continue;
1616
-
1617
- const subDirs = fs.readdirSync(searchRoot)
1618
- .map(name => path.join(searchRoot, name))
1619
- .filter(p => fs.statSync(p).isDirectory());
1620
-
1621
- for (const dir of subDirs) {
1622
- const relativePath = path.relative(searchRoot, dir).replace(/\\/g, '/');
1623
- const match = plugin.pattern.exec(relativePath);
1624
-
1625
- if (match) {
1626
- const currentVersion = match[1];
1627
-
1628
- if (compareVersions(currentVersion, plugin.minVersion) < 0) {
1629
- outdatedPlugins.push({
1630
- name: relativePath,
1631
- currentVersion,
1632
- requiredVersion: plugin.minVersion,
1633
- mandatoryUpdate: plugin.mandatoryUpdate === true
1634
- });
1635
-
1636
- if (plugin.mandatoryUpdate) {
1637
- hasMandatoryUpdate = true;
1638
- }
1639
- }
1640
- }
1641
- }
1642
- continue;
1643
- }
1644
-
1645
- // ---------- File plugins ----------
1646
- const matchedFile = files.find(file =>
1647
- file.startsWith(searchRoot) && plugin.pattern.test(file)
1648
- );
1649
-
1650
- if (matchedFile) {
1651
- const match = plugin.pattern.exec(matchedFile);
1652
- if (match) {
1653
- const currentVersion = match[1];
1654
- const isBeta = !!match[2];
1655
-
1656
- const cmp = plugin.pattern.source.includes('beta')
1657
- ? compareWithBeta(currentVersion, plugin.minVersion, isBeta)
1658
- : compareVersions(currentVersion, plugin.minVersion);
1659
-
1660
- if (cmp < 0) {
1661
- outdatedPlugins.push({
1662
- name: path.relative(srcDir, matchedFile),
1663
- currentVersion: isBeta ? `${currentVersion}-beta` : currentVersion,
1664
- requiredVersion: plugin.minVersion,
1665
- mandatoryUpdate: plugin.mandatoryUpdate === true
1666
- });
1667
-
1668
- if (plugin.mandatoryUpdate) {
1669
- hasMandatoryUpdate = true;
1670
- }
1671
- }
1672
- }
1673
- }
1674
- }
1675
-
1676
- // ---------- Result handling ----------
1677
- if (outdatedPlugins.length > 0) {
1678
- console.log('\n❗ The following plugins are outdated:\n');
1679
-
1680
- outdatedPlugins.forEach( p => {
1681
- const tag = p.mandatoryUpdate ? '🔥 MANDATORY' : '';
1682
- console.log(
1683
- ` ⚠️ - ${p.name} (Current: ${p.currentVersion}, Required: ${p.requiredVersion}) ${tag}`
1684
- );
1685
- });
1686
-
1687
- // 🚨 Mandatory update → stop build
1688
- /* if (hasMandatoryUpdate) {
1689
- console.log('\n🚫 One or more plugins require a mandatory update.');
1690
- console.log('❌ Build cancelled. Please update mandatory plugins and try again.');
1691
- process.exit(1);
1692
- } */
1693
-
1694
-
1695
-
1696
-
1697
-
1698
- if (hasMandatoryUpdate) {
1699
-
1700
- //--------------------------------------------------
1701
- // 🚫 AUTO UPDATE DISABLED
1702
- //--------------------------------------------------
1703
- if (!ENABLE_AUTO_UPDATE) {
1704
- console.log("\n🚫 Auto-update disabled.");
1705
- console.log("❌ Manual update required.");
1706
- process.exit(1);
1707
- }
1708
-
1709
- //--------------------------------------------------
1710
- // 🔥 AUTO UPDATE ENABLED
1711
- //--------------------------------------------------
1712
- console.log("\n🔥 Mandatory plugins outdated. Trying auto-update...\n");
1713
-
1714
-
1715
-
1716
- let autoFailed = false;
1717
-
1718
- for (const p of outdatedPlugins.filter(x => x.mandatoryUpdate)) {
1719
-
1720
- const pluginDef = requiredPlugins.find(def =>
1721
- def.pattern.test(p.name)
1722
- );
1723
-
1724
- if (!pluginDef) continue;
1725
-
1726
- const success = await autoUpdatePlugin(
1727
- pluginDef,
1728
- p
1729
- );
1730
-
1731
- if (!success) {
1732
- autoFailed = true;
1733
-
1734
- const pluginDef = requiredPlugins.find(def =>
1735
- def.pattern.test(p.name)
1736
- );
1737
-
1738
- console.log(`❌ Manual update required for ${p.name}`);
1739
-
1740
- if (pluginDef) {
1741
- console.log(`👉 Required minimum version: ${pluginDef.minVersion}`);
1742
- }
1743
- }
1744
- }
1745
-
1746
- // 🚨 Fallback to manual if any failed
1747
- if (autoFailed) {
1748
- console.log('\n🚫 One or more plugins require manual update.');
1749
- console.log('❌ Build cancelled. Please update mandatory plugins.');
1750
- process.exit(1);
1751
- }
1752
-
1753
- console.log('\n🎉 All mandatory plugins auto-updated! Rechecking plugins...\n');
1754
-
1755
- // Re-run plugin check so outdated list becomes empty
1756
- await checkPlugins();
1757
- return;
1758
- }
1759
-
1760
-
1761
-
1762
-
1763
-
1764
-
1765
- // Optional updates ask user
1766
- const rl = readline.createInterface({
1767
- input: process.stdin,
1768
- output: process.stdout
1769
- });
1770
-
1771
- rl.question(
1772
- '\nAre you sure you want to continue without updating these plugins? (y/n): ',
1773
- answer => {
1774
- rl.close();
1775
-
1776
- if (answer.toLowerCase() !== 'y') {
1777
- console.log('\n❌ Build cancelled due to outdated plugins.');
1778
- process.exit(1);
1779
- } else {
1780
- console.log('\n✅ Continuing build...');
1781
- resolve();
1782
- }
1783
- }
1784
- );
1785
- } else {
1786
- console.log('✅ All plugin versions are up to date.');
1787
- saveUpdateLogs();
1788
- resolve();
1789
- }
1790
- });
1791
- }
1792
-
1793
-
1794
-
1795
-
1796
-
1797
-
1798
-
1799
-
1800
- // Check all the codeplays plugins version START
1801
-
1802
-
1803
-
1804
-
1805
- // ====================================================================
1806
- // AUTO-ADD esbuild.drop: ['console','debugger'] to vite.config.js / mjs
1807
- // ====================================================================
1808
-
1809
-
1810
-
1811
- const checkAndupdateDropInViteConfig = () => {
1812
-
1813
- const possibleFiles = [
1814
- "vite.config.js",
1815
- "vite.config.mjs"
1816
- ];
1817
-
1818
- // Detect existing config file
1819
- const viteConfigPath = possibleFiles
1820
- .map(file => path.join(process.cwd(), file))
1821
- .find(filePath => fs.existsSync(filePath));
1822
-
1823
- if (!viteConfigPath) {
1824
- console.warn("⚠️ No vite config found. Skipping.");
1825
- return;
1826
- }
1827
-
1828
- //console.log("📄 Using:", viteConfigPath.split("/").pop());
1829
-
1830
- let viteContent = fs.readFileSync(viteConfigPath, "utf8");
1831
-
1832
- // Skip if already exists
1833
- if (/drop\s*:\s*\[.*['"]console['"].*\]/.test(viteContent)) {
1834
- console.log("ℹ️ vite.config.(m)js already Updated. Skipping...");
1835
- return;
1836
- }
1837
-
1838
- console.log("🔧 Adding esbuild.drop ...");
1839
-
1840
- // If esbuild block exists
1841
- if (/esbuild\s*:\s*{/.test(viteContent)) {
1842
- viteContent = viteContent.replace(
1843
- /esbuild\s*:\s*{([\s\S]*?)(^ {0,8})}/m,
1844
- (full, inner, indent) => {
1845
-
1846
- let lines = inner
1847
- .split("\n")
1848
- .map(l => l.trim())
1849
- .filter(Boolean);
1850
-
1851
- // Fix last comma
1852
- if (lines.length > 0) {
1853
- lines[lines.length - 1] =
1854
- lines[lines.length - 1].replace(/,+$/, "") + ",";
1855
- }
1856
-
1857
- // Re-indent
1858
- lines = lines.map(l => indent + " " + l);
1859
-
1860
- // Add drop
1861
- lines.push(`${indent} drop: ['console','debugger'],`);
1862
-
1863
- return `esbuild: {\n${lines.join("\n")}\n${indent}}`;
1864
- }
1865
- );
1866
- }
1867
-
1868
- // If esbuild missing
1869
- else {
1870
- viteContent = viteContent.replace(
1871
- /export default defineConfig\s*\(\s*{/,
1872
- m => `${m}\n esbuild: {\n drop: ['console','debugger'],\n },`
1873
- );
1874
- }
1875
-
1876
- fs.writeFileSync(viteConfigPath, viteContent, "utf8");
1877
- console.log("✅ vite.config.(m)js Updated successfully.");
1878
- };
1879
-
1880
-
1881
-
1882
-
1883
-
1884
-
1885
-
1886
-
1887
-
1888
-
1889
- const compareVersion = (v1, v2) => {
1890
- const a = v1.split(".").map(Number);
1891
- const b = v2.split(".").map(Number);
1892
-
1893
- for (let i = 0; i < Math.max(a.length, b.length); i++) {
1894
- const num1 = a[i] || 0;
1895
- const num2 = b[i] || 0;
1896
- if (num1 > num2) return 1;
1897
- if (num1 < num2) return -1;
1898
- }
1899
- return 0;
1900
- };
1901
-
1902
-
1903
-
1904
-
1905
- const admobConfigPath = path.join('src', 'js','Ads', 'admob-ad-configuration.json');
1906
-
1907
- const checkAdmobConfigurationProperty=()=>{
1908
-
1909
-
1910
- if (!_admobConfig.ADMOB_ENABLED)
1911
- {
1912
- console.log("ℹ️ Admob is not enabled so 'admob-ad-configuration.json' checking is skipping...");
1913
- return;
1914
- }
1915
-
1916
-
1917
- const REQUIRED_CONFIG_KEYS = [
1918
- "isKidsApp",
1919
- "isTesting",
1920
- "isConsoleLogEnabled",
1921
- "bannerEnabled",
1922
- "interstitialEnabled",
1923
- "appOpenEnabled",
1924
- "rewardVideoEnabled",
1925
- "rewardInterstitialEnabled",
1926
- "collapsibleEnabled",
1927
- "isLandScape",
1928
- "isOverlappingEnable",
1929
- "bannerTypeAndroid",
1930
- "bannerTypeiOS",
1931
- "bannerTopSpaceColor",
1932
- "interstitialLoadScreenTextColor",
1933
- "interstitialLoadScreenBackgroundColor",
1934
- "beforeBannerSpace",
1935
- "whenShow",
1936
- "minimumClick",
1937
- "interstitialTimeOut",
1938
- "interstitialFirstTimeOut",
1939
- "appOpenAdsTimeOut",
1940
- "maxRetryCount",
1941
- "retrySecondsAr",
1942
- "appOpenPerSession",
1943
- "interstitialPerSession",
1944
- "appOpenFirstTimeOut"
1945
- ];
1946
-
1947
-
1948
-
1949
-
1950
-
1951
- let admobConfigInJson;
1952
-
1953
- try {
1954
- admobConfigInJson = JSON.parse(readFileSync(admobConfigPath, "utf8"));
1955
- } catch (err) {
1956
- console.error("❌ Failed to read admob-ad-configuration.json", err);
1957
- process.exit(1);
1958
- }
1959
-
1960
- // ✅ Validate config object exists
1961
- if (!admobConfigInJson.config) {
1962
- console.error('❌ "config" object is missing in admob-ad-configuration.json');
1963
- process.exit(1);
1964
- }
1965
-
1966
-
1967
- const admobConfigMinVersion="1.5"
1968
-
1969
- if (compareVersion(admobConfigInJson.VERSION, admobConfigMinVersion) < 0) {
1970
- console.error(`❌ Please use at-least version ${admobConfigMinVersion} in "src/js/Ads/admob-ad-configuration.json"`);
1971
- process.exit(1);
1972
- }
1973
-
1974
-
1975
- const config = admobConfigInJson.config;
1976
-
1977
- // Find missing properties
1978
- const missingKeys = REQUIRED_CONFIG_KEYS.filter(
1979
- key => !(key in config)
1980
- );
1981
-
1982
-
1983
-
1984
- if (missingKeys.length > 0) {
1985
- console.error("❌ Missing required configuration keys. Please check it in 'src/js/Ads/admob-ad-configuration.json'");
1986
-
1987
- missingKeys.forEach(k => console.error(" - " + k));
1988
- process.exit(1);
1989
- }
1990
-
1991
-
1992
- console.log('✅ All keys exist. in "admob-ad-configuration.json file" Configuration looks good.');
1993
- }
1994
-
1995
-
1996
-
1997
- function ensureGitignoreEntry(entry) {
1998
- const gitignorePath = path.join(process.cwd(), '.gitignore');
1999
-
2000
- // If .gitignore doesn't exist, create it
2001
- if (!fs.existsSync(gitignorePath)) {
2002
- fs.writeFileSync(gitignorePath, `${entry}\n`, 'utf8');
2003
- console.log(`✅ .gitignore created and added: ${entry}`);
2004
- return;
2005
- }
2006
-
2007
- const content = fs.readFileSync(gitignorePath, 'utf8');
2008
-
2009
- // Normalize lines (trim + remove trailing slashes for comparison)
2010
- const lines = content
2011
- .split(/\r?\n/)
2012
- .map(l => l.trim());
2013
-
2014
- const normalizedEntry = entry.replace(/\/$/, '');
2015
-
2016
- const exists = lines.some(
2017
- line => line.replace(/\/$/, '') === normalizedEntry
2018
- );
2019
-
2020
- if (exists) {
2021
- console.log(`ℹ️ .gitignore already contains: ${entry}`);
2022
- return;
2023
- }
2024
-
2025
- // Ensure file ends with newline
2026
- const separator = content.endsWith('\n') ? '' : '\n';
2027
-
2028
- fs.appendFileSync(gitignorePath, `${separator}${entry}\n`, 'utf8');
2029
- console.log(`✅ Added to .gitignore: ${entry}`);
2030
- }
2031
-
2032
-
2033
- ensureGitignoreEntry('buildCodeplay/');
2034
-
2035
-
2036
- // Run the validation
2037
- (async () => {
2038
-
2039
- await loadPluginVersions(); // 🔥 NEW
2040
-
2041
- await checkPlugins();
2042
- checkAndupdateDropInViteConfig();
2043
- checkAdmobConfigurationProperty()
2044
- })();
2045
-
2046
-
2047
- // ======================================================
2048
- // Validate theme folder location (src/js/theme is NOT allowed)
2049
- // ======================================================
2050
-
2051
- function validateThemeFolderLocation() {
2052
- const oldThemePath = path.join(process.cwd(), 'src', 'js', 'theme');
2053
- const newThemePath = path.join(process.cwd(), 'src', 'theme');
2054
-
2055
- // ❌ Block old structure
2056
- if (fs.existsSync(oldThemePath)) {
2057
- console.error(
2058
- '\n❌ INVALID PROJECT STRUCTURE DETECTED\n' +
2059
- '--------------------------------------------------\n' +
2060
- 'The "theme" folder must NOT be inside:\n' +
2061
- ' src/js/theme\n\n' +
2062
- '✅ Correct location is:\n' +
2063
- ' src/theme\n\n' +
2064
- '🛑 Please move the folder and re-run the build.\n'
2065
- );
2066
- process.exit(1);
2067
- }
2068
-
2069
- // ⚠️ Optional warning if new theme folder is missing
2070
- if (!fs.existsSync(newThemePath)) {
2071
- console.warn(
2072
- '\n⚠️ WARNING: "src/theme" folder not found.\n' +
2073
- 'If your app uses themes, please ensure it exists.\n'
2074
- );
2075
- } else {
2076
- console.log('✅ Theme folder structure validated (src/theme).');
2077
- }
2078
- }
2079
- validateThemeFolderLocation()
2080
-
2081
-
2082
-
2083
- const validateAndRestoreSignDetails=()=>{
2084
-
2085
- // Read config file
2086
- const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
2087
-
2088
- // Ensure android and buildOptions exist
2089
- if (!config.android) config.android = {};
2090
- if (!config.android.buildOptions) config.android.buildOptions = {};
2091
-
2092
- // Update only if changed
2093
- let updated = false;
2094
-
2095
- if (config.android.buildOptions.releaseType !== 'AAB') {
2096
- config.android.buildOptions.releaseType = 'AAB';
2097
- updated = true;
2098
- }
2099
-
2100
- if (config.android.buildOptions.signingType !== 'jarsigner') {
2101
- config.android.buildOptions.signingType = 'jarsigner';
2102
- updated = true;
2103
- }
2104
-
2105
- // Write back only if modified
2106
- if (updated) {
2107
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
2108
- console.log('capacitor.config.json updated successfully.');
2109
- } else {
2110
- console.log('No changes needed.');
2111
- }
2112
-
2113
- }
2114
-
2115
- validateAndRestoreSignDetails()
2116
-
2117
-
2118
- execSync('node buildCodeplay/fix-onesignal-plugin.js', { stdio: 'inherit' });
2119
-
2120
-
2121
-
2122
-
2123
-
2124
-
2125
-
2126
- //################################## SystemBars.java update for "@capacitor/android": "^8.3.0" plugin START ###############################
2127
-
2128
-
2129
- const filePath = path.join(
2130
- __dirname,
2131
- "../node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/plugin/SystemBars.java"
2132
- );
2133
-
2134
- // 🔍 OLD BLOCK (anchor)
2135
- const OLD_BLOCK = `if (shouldPassthroughInsets) {
2136
- // We need to correct for a possible shown IME
2137
- v.setPadding(0, 0, 0, keyboardVisible ? imeInsets.bottom : 0);
2138
-
2139
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM && hasViewportCover && insetHandlingEnabled) {
2140
- Insets safeAreaInsets = calcSafeAreaInsets(insets);
2141
- injectSafeAreaCSS(safeAreaInsets.top, safeAreaInsets.right, safeAreaInsets.bottom, safeAreaInsets.left);
2142
- }
2143
-
2144
- return new WindowInsetsCompat.Builder(insets)
2145
- .setInsets(
2146
- WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout(),
2147
- Insets.of(
2148
- systemBarsInsets.left,
2149
- systemBarsInsets.top,
2150
- systemBarsInsets.right,
2151
- getBottomInset(systemBarsInsets, keyboardVisible)
2152
- )
2153
- )
2154
- .build();
2155
- }`;
2156
-
2157
- // NEW BLOCK
2158
- const NEW_BLOCK = `if (shouldPassthroughInsets) {
2159
- /* 🔴 ORIGINAL CODE (COMMENTED FOR SAFETY)
2160
- ${OLD_BLOCK.split("\n").map(line => " " + line).join("\n")}
2161
- */
2162
-
2163
- // NEW LOGIC (CUSTOM FIX)
2164
- v.setPadding(0, 0, 0, 0);
2165
-
2166
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM && hasViewportCover && insetHandlingEnabled) {
2167
- Insets safeAreaInsets = calcSafeAreaInsets(insets);
2168
- injectSafeAreaCSS(safeAreaInsets.top, safeAreaInsets.right, safeAreaInsets.bottom, safeAreaInsets.left);
2169
- }
2170
-
2171
- return insets; // WebView handles everything
2172
- }`;
2173
-
2174
- // 🚨 ERROR MESSAGE
2175
- const ERROR_MSG = `
2176
- Capacitor SystemBars.java structure changed!
2177
-
2178
- Plugin: @capacitor/android
2179
- Path : node_modules\@capacitor\android\capacitor\src\main\java\com\getcapacitor\plugin\SystemBars.java
2180
-
2181
- Check version of "@capacitor/android": in package.json
2182
-
2183
- 👉 Expected code block not found.
2184
-
2185
- This usually means Capacitor updated internally.
2186
-
2187
- Please:
2188
- 1. Open SystemBars.java
2189
- 2. Update patch script
2190
- 3. Re-run build
2191
-
2192
- ⛔ Build stopped.
2193
- `;
2194
-
2195
- function patchFile() {
2196
- if (!fs.existsSync(filePath)) {
2197
- console.error("❌ SystemBars.java not found!");
2198
- process.exit(1);
2199
- }
2200
-
2201
- let content = fs.readFileSync(filePath, "utf8");
2202
-
2203
- // ✅ Already patched?
2204
- if (content.includes("🔴 ORIGINAL CODE (COMMENTED FOR SAFETY)")) {
2205
- console.log("✅ Already SystemBars.java patched. Skipping...");
2206
- return;
2207
- }
2208
-
2209
- // 🔍 Check old block exists
2210
- if (!content.includes(OLD_BLOCK)) {
2211
- console.error(ERROR_MSG);
2212
- process.exit(1);
2213
- }
2214
-
2215
- // 🔁 Replace
2216
- const updated = content.replace(OLD_BLOCK, NEW_BLOCK);
2217
-
2218
- fs.writeFileSync(filePath, updated, "utf8");
2219
-
2220
- console.log("✅ SystemBars.java patched (comment + new logic)!");
2221
- }
2222
-
2223
- patchFile();
2224
-
2225
- //################################## SystemBars.java update for "@capacitor/android": "^8.3.0" plugin END ###############################
2226
-
2227
-
2228
-
2229
-
2230
- /*
2231
- Release Notes
2232
-
2233
- 5.1
2234
- Kotlin version update is commented. Previously admob is not worked if not update the kotlin version to higher version
2235
-
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const plist = require('plist');
4
+
5
+
6
+
7
+ const { execSync } = require("child_process");
8
+
9
+
10
+
11
+
12
+ const { readFileSync } = require("fs");
13
+
14
+ const ENABLE_AUTO_UPDATE = true;
15
+ const USE_LIVE_SERVER_VERSION = true;
16
+
17
+ const configPath = path.join(process.cwd(), 'capacitor.config.json');
18
+ const updateLogFile = path.join(process.cwd(), "", "plugin-update-log.txt");
19
+
20
+ // Expected plugin list with minimum versions
21
+ /* const requiredPlugins = [
22
+
23
+ { pattern: /backbutton-(\d+\.\d+)\.js$/, minVersion: '2.0', required: true, baseDir: 'js',mandatoryUpdate: true},
24
+
25
+
26
+ { pattern: /common-(\d+\.\d+)(?:-beta-(\d+))?\.js$/, minVersion: '6.0', required: true, baseDir: 'js',mandatoryUpdate: true },
27
+
28
+ { pattern: /localization_settings-(\d+\.\d+)\.js$/, minVersion: '1.1', required: true, baseDir: 'js',mandatoryUpdate: false },
29
+ { pattern: /localization-(\d+\.\d+)\.js$/, minVersion: '1.5', required: true, baseDir: 'js',mandatoryUpdate: true },
30
+ { pattern: /localNotification-(\d+\.\d+)\.js$/, minVersion: '2.2', required: true, baseDir: 'js',mandatoryUpdate: false },
31
+ { pattern: /localNotification_AppSettings-(\d+\.\d+)\.js$/, minVersion: '1.0', required: true, baseDir: 'js',mandatoryUpdate: false },
32
+ { pattern: /onesignal-(\d+\.\d+)\.js$/, minVersion: '2.3', required: true, baseDir: 'js',mandatoryUpdate: false },
33
+ { pattern: /saveToGalleryAndSaveAnyFile-(\d+\.\d+)(-ios)?\.js$/, minVersion: '3.1', required: true, baseDir: 'js',mandatoryUpdate: true },
34
+ { pattern: /Ads[\/\\]admob-emi-(\d+\.\d+)\.js$/, minVersion: '3.7', required: true, baseDir: 'js',mandatoryUpdate: true },
35
+
36
+ // New added plugins
37
+ { pattern: /video-player-(\d+\.\d+)\.js$/, minVersion: '1.5', required: true, baseDir: 'js',mandatoryUpdate: false },
38
+ { pattern: /image-cropper-(\d+\.\d+)\.js$/, minVersion: '1.1', required: true, baseDir: 'js',mandatoryUpdate: false },
39
+ { pattern: /common-(\d+\.\d+)\.less$/, minVersion: '1.6', required: true, baseDir: 'assets/css',mandatoryUpdate: false },
40
+
41
+
42
+ // New folders
43
+ { pattern: /IAP-(\d+\.\d+)$/, minVersion: '2.8', isFolder: true , required: true, baseDir: 'js/Ads',mandatoryUpdate: true },
44
+ { pattern: /editor-(\d+\.\d+)$/, minVersion: '1.9', isFolder: true, required: true, baseDir: 'js',mandatoryUpdate: true },
45
+ { pattern: /ffmpeg-(\d+\.\d+)$/, minVersion: '1.6', isFolder: true, required: true, baseDir: 'js',mandatoryUpdate: true },
46
+ { pattern: /theme-(\d+\.\d+)$/, minVersion: '3.3', isFolder: true , required: true, baseDir: 'theme',mandatoryUpdate: true },
47
+
48
+
49
+ { pattern: /certificatejs-(\d+\.\d+)$/, minVersion: '1.6', isFolder: true , required: true, baseDir: 'certificate',mandatoryUpdate: true }
50
+
51
+ ]; */
52
+
53
+
54
+ const ROOT_DIR = path.join(__dirname, "..", "src");
55
+
56
+ function requireOrInstall(packageName) {
57
+ try {
58
+ return require(packageName);
59
+ } catch (err) {
60
+
61
+ console.log(`📦 "${packageName}" not found. Installing automatically...`);
62
+
63
+ try {
64
+ execSync(`npm install ${packageName}`, { stdio: "inherit" });
65
+ console.log(`✅ "${packageName}" installed successfully.`);
66
+ } catch (installErr) {
67
+ console.error(`❌ Failed to install "${packageName}".`);
68
+ process.exit(1);
69
+ }
70
+
71
+ // Try loading again
72
+ return require(packageName);
73
+ }
74
+ }
75
+
76
+ const AdmZip = requireOrInstall("adm-zip");
77
+
78
+
79
+
80
+ const pkg = require(path.join(process.cwd(), 'node_modules', 'codeplay-common', 'package.json'));
81
+
82
+ const pluginName = pkg.name;
83
+ const pluginVersion = pkg.version;
84
+
85
+ let updateLogs = [];
86
+
87
+ function writeUpdateLine(message) {
88
+ updateLogs.push(message);
89
+ }
90
+
91
+ const MAX_LOG_BLOCKS = 50;
92
+
93
+ function saveUpdateLogs() {
94
+
95
+ if (updateLogs.length === 0) return;
96
+
97
+ const logDir = path.dirname(updateLogFile);
98
+
99
+ if (!fs.existsSync(logDir)) {
100
+ fs.mkdirSync(logDir, { recursive: true });
101
+ }
102
+
103
+ const now = new Date();
104
+
105
+ const formattedTime = now.toLocaleString('en-GB', {
106
+ day: '2-digit',
107
+ month: '2-digit',
108
+ year: 'numeric',
109
+ hour: '2-digit',
110
+ minute: '2-digit',
111
+ hour12: true
112
+ }).replace(',', '').replace(/\//g, '-');
113
+
114
+ let newBlock = `${pluginName}: ${pluginVersion}\n[${formattedTime}]\n`;
115
+
116
+ updateLogs.forEach(line => {
117
+ newBlock += `${line}\n`;
118
+ });
119
+
120
+ newBlock += "\n";
121
+
122
+ let existingLog = "";
123
+
124
+ if (fs.existsSync(updateLogFile)) {
125
+ existingLog = fs.readFileSync(updateLogFile, "utf8");
126
+ }
127
+
128
+ let combinedLog = newBlock + existingLog;
129
+
130
+ // Split blocks by plugin header
131
+ const blocks = combinedLog.split(/\n(?=codeplay-common:)/);
132
+
133
+ // Keep only latest 50
134
+ const trimmed = blocks.slice(0, MAX_LOG_BLOCKS).join("\n");
135
+
136
+ fs.writeFileSync(updateLogFile, trimmed);
137
+
138
+ }
139
+
140
+
141
+
142
+
143
+
144
+ const versionsFile = path.join(__dirname, "versions.json");
145
+
146
+ function loadRequiredPlugins() {
147
+
148
+ if (!fs.existsSync(versionsFile)) {
149
+ console.error("❌ versions.json not found");
150
+ process.exit(1);
151
+ }
152
+
153
+ const json = JSON.parse(fs.readFileSync(versionsFile, "utf8"));
154
+
155
+ return json.plugins.map(p => ({
156
+ ...p,
157
+ pattern: new RegExp(p.pattern)
158
+ }));
159
+
160
+ }
161
+
162
+ let requiredPlugins = loadRequiredPlugins();
163
+
164
+
165
+
166
+
167
+
168
+
169
+ async function downloadAndExtractZip(url, destFolder) {
170
+
171
+ const zipPath = destFolder + ".zip";
172
+
173
+ await downloadFile(url, zipPath);
174
+
175
+ const zip = new AdmZip(zipPath);
176
+ zip.extractAllTo(destFolder, true);
177
+
178
+ fs.unlinkSync(zipPath);
179
+
180
+ }
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+ //Check codeplay-common latest version installed or not Start
189
+ //const { execSync } = require('child_process');
190
+
191
+
192
+ function getInstalledVersion(packageName) {
193
+ try {
194
+ const packageJsonPath = path.join(process.cwd(), 'node_modules', packageName, 'package.json');
195
+ if (fs.existsSync(packageJsonPath)) {
196
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
197
+ return packageJson.version;
198
+ }
199
+ } catch (error) {
200
+ return null;
201
+ }
202
+ return null;
203
+ }
204
+
205
+ function getLatestVersion(packageName) {
206
+ try {
207
+ return execSync(`npm view ${packageName} version`).toString().trim();
208
+ } catch (error) {
209
+ console.error(`Failed to fetch latest version for ${packageName}`);
210
+ return null;
211
+ }
212
+ }
213
+
214
+ function checkPackageVersion() {
215
+ const packageName = 'codeplay-common';
216
+ const installedVersion = getInstalledVersion(packageName);
217
+ const latestVersion = getLatestVersion(packageName);
218
+
219
+ if (!installedVersion) {
220
+ console.error(`${packageName} is not installed. Please install it using "npm install ${packageName}".`);
221
+ process.exit(1);
222
+ }
223
+
224
+ if (installedVersion !== latestVersion) {
225
+ console.error(`\x1b[31m${packageName} is outdated (installed: ${installedVersion}, latest: ${latestVersion}). Please update it.\x1b[0m\n\x1b[33mUse 'npm uninstall codeplay-common ; npm i codeplay-common'\x1b[0m`);
226
+ process.exit(1);
227
+ }
228
+
229
+ console.log(`${packageName} is up to date (version ${installedVersion}).`);
230
+ }
231
+
232
+ // Run package version check before executing the main script
233
+ try {
234
+ checkPackageVersion();
235
+ } catch (error) {
236
+ console.error(error.message);
237
+ process.exit(1);
238
+ }
239
+
240
+ //Check codeplay-common latest version installed or not END
241
+
242
+
243
+
244
+ function compareWithBeta(installedVersion, minVersion, isBeta) {
245
+ const baseCompare = compareVersions(installedVersion, minVersion);
246
+
247
+ if (!isBeta) {
248
+ // Stable version → normal compare
249
+ return baseCompare;
250
+ }
251
+
252
+ // Beta version logic
253
+ if (baseCompare > 0) return 1; // 5.3-beta > 5.2
254
+ if (baseCompare < 0) return -1; // 5.1-beta < 5.2
255
+
256
+ // Same version but beta → LOWER than stable
257
+ return -1; // 5.2-beta < 5.2
258
+ }
259
+
260
+
261
+
262
+
263
+ const checkAppUniqueId=()=>{
264
+
265
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
266
+
267
+ const appUniqueId = config.android?.APP_UNIQUE_ID;
268
+ const RESIZEABLE_ACTIVITY = config.android?.RESIZEABLE_ACTIVITY;
269
+ const orientation = config.android?.ORIENTATION;
270
+
271
+
272
+ let logErrorMessage="";
273
+
274
+ // 1️⃣ Check if it’s missing
275
+ if (RESIZEABLE_ACTIVITY === undefined) {
276
+ logErrorMessage+='❌ Missing android.RESIZEABLE_ACTIVITY option in capacitor.config.json.\n';
277
+ }
278
+
279
+ // 2️⃣ Check if it’s not boolean (true/false only)
280
+ else if (typeof RESIZEABLE_ACTIVITY !== 'boolean') {
281
+ logErrorMessage+='❌ Invalid android.RESIZEABLE_ACTIVITY value. Please use only true or false (without quotes).\n';
282
+ }
283
+
284
+
285
+
286
+ if (!orientation) {
287
+ logErrorMessage+='❌ Missing android.ORIENTATION option in capacitor.config.json.\n';
288
+ }
289
+
290
+ else if(orientation!="portrait" && orientation!="landscape" && orientation!="auto")
291
+ {
292
+ logErrorMessage+='❌ Spelling mistake in android.ORIENTATION option in capacitor.config.json. Please use only ["portrait" "landscape" "auto"]\n';
293
+ }
294
+
295
+
296
+ if (!appUniqueId) {
297
+ logErrorMessage+='❌ APP_UNIQUE_ID is missing in capacitor.config.json.';
298
+ }
299
+
300
+ else if (!Number.isInteger(appUniqueId)) {
301
+ logErrorMessage+='❌ APP_UNIQUE_ID must be an integer. Example: 1, 2, 3, etc.';
302
+ }
303
+
304
+
305
+
306
+ if(logErrorMessage!="")
307
+ {
308
+ console.error(logErrorMessage);
309
+ process.exit(1)
310
+ }
311
+
312
+
313
+ console.log(`✅ APP_UNIQUE_ID is valid: ${appUniqueId}`);
314
+
315
+ }
316
+
317
+ checkAppUniqueId();
318
+
319
+
320
+
321
+
322
+
323
+
324
+ // ======================================================
325
+ // 🚫 BLOCK STATIC IMPORT OF showSubscribePopup (ANY VERSION)
326
+ // ======================================================
327
+
328
+ const STATIC_SUBSCRIBE_REGEX = /import\s*{\s*showSubscribePopup\s*}\s*from\s*['"].*\/js\/Ads\/IAP-\d+(\.\d+)*\/IAP-check-And-LoadAd\.js['"]/;
329
+
330
+ // Detect dynamic import (valid)
331
+ const DYNAMIC_SUBSCRIBE_REGEX = /await\s+import\s*\(\s*['"].*\/js\/Ads\/IAP-\d+(\.\d+)*\/IAP-check-And-LoadAd\.js['"]\s*\)/;
332
+
333
+ let subscribeImportError = false;
334
+
335
+ function scanSubscribeImport(dir) {
336
+ const files = fs.readdirSync(dir);
337
+
338
+ for (const file of files) {
339
+ const fullPath = path.join(dir, file);
340
+ const stat = fs.statSync(fullPath);
341
+
342
+ if (stat.isDirectory()) {
343
+ scanSubscribeImport(fullPath);
344
+ }
345
+ else if (file.endsWith(".js") || file.endsWith(".ts") || file.endsWith(".f7")) {
346
+
347
+ const content = fs.readFileSync(fullPath, "utf-8");
348
+ const lines = content.split("\n");
349
+
350
+ lines.forEach((line, index) => {
351
+
352
+ // ❌ STATIC import → ERROR
353
+ if (STATIC_SUBSCRIBE_REGEX.test(line)) {
354
+ console.error(`
355
+ ❌ Forbidden static import detected!
356
+
357
+ File: ${fullPath}
358
+ Line: ${index + 1}
359
+ Code: ${line.trim()}
360
+
361
+ 🚫 DO NOT use static import for showSubscribePopup
362
+
363
+ 👉 Remove:
364
+ import { showSubscribePopup } from './../js/Ads/IAP-x.x/IAP-check-And-LoadAd.js'
365
+
366
+ ✅ Use dynamic import (ANY version allowed):
367
+
368
+ const { showSubscribePopup } = await import('./../js/Ads/IAP-x.x/IAP-check-And-LoadAd.js');
369
+ showSubscribePopup();
370
+ `);
371
+ subscribeImportError = true;
372
+ }
373
+
374
+ // Optional: detect wrong dynamic usage (no await)
375
+ if (
376
+ line.includes("import(") &&
377
+ line.includes("IAP-") &&
378
+ !line.includes("await")
379
+ ) {
380
+ console.warn(`
381
+ ⚠️ Warning: Dynamic import without await
382
+
383
+ File: ${fullPath}
384
+ Line: ${index + 1}
385
+ Code: ${line.trim()}
386
+
387
+ 👉 Always use:
388
+ const { showSubscribePopup } = await import(...)
389
+ `);
390
+ }
391
+
392
+ });
393
+ }
394
+ }
395
+ }
396
+
397
+
398
+ // Run scan
399
+ scanSubscribeImport(ROOT_DIR);
400
+
401
+ // Stop build
402
+ if (subscribeImportError) {
403
+ console.error("🚫 Build failed due to forbidden showSubscribePopup static import.");
404
+ process.exit(1);
405
+ } else {
406
+ console.log("✅ showSubscribePopup import usage is valid.");
407
+ }
408
+
409
+
410
+
411
+
412
+ // ======================================================
413
+ // 🚫 BLOCK STATIC IMPORT OF showSubscribePopup (ANY VERSION) END
414
+ // ======================================================
415
+
416
+
417
+
418
+
419
+
420
+
421
+
422
+
423
+
424
+
425
+
426
+ //@Codemirror check and install/uninstall the packages START
427
+ //const fs = require("fs");
428
+ //const path = require("path");
429
+ //const { execSync } = require("child_process");
430
+
431
+ const jsDir = path.join(__dirname, "..", "src", "js");
432
+
433
+ // 🔍 Detect OLD structure
434
+ const oldEditorDirs = fs.readdirSync(jsDir)
435
+ .filter(name => /^editor-\d+\.\d+$/.test(name));
436
+
437
+ // 📁 New structure path (optional, not mandatory)
438
+ const newEditorBaseDir = path.join(jsDir, "editor");
439
+
440
+ // ======================================================
441
+ // CASE 1: OLD STRUCTURE FOUND → STOP
442
+ // ======================================================
443
+ if (oldEditorDirs.length > 0) {
444
+
445
+ console.error(`
446
+ ❌ OLD EDITOR STRUCTURE DETECTED
447
+
448
+ You are using outdated folder structure:
449
+ src/js/editor-x.x/
450
+
451
+ 🚨 This is no longer supported.
452
+
453
+ 📦 Found folders:
454
+ ${oldEditorDirs.map(d => " - " + d).join("\n")}
455
+
456
+ 👉 Please move them manually:
457
+
458
+ src/js/editor-1.6
459
+
460
+ src/js/editor/editor-1.6
461
+
462
+ ⚠️ Also ensure:
463
+ src/js/editor/configuration.json exists
464
+
465
+ ❌ Build stopped.
466
+ `);
467
+
468
+ process.exit(1);
469
+ }
470
+
471
+ // ======================================================
472
+ // CASE 2: NEW STRUCTURE EXISTS VALIDATE
473
+ // ======================================================
474
+ if (fs.existsSync(newEditorBaseDir)) {
475
+
476
+ // 🔍 Find editor-x.x inside new folder
477
+ const editorDirs = fs.readdirSync(newEditorBaseDir)
478
+ .filter(name => /^editor-\d+\.\d+$/.test(name));
479
+
480
+ // 👉 If editor folder exists but no versions → skip safely
481
+ if (editorDirs.length === 0) {
482
+ console.log("ℹ️ No editor-x.x folders found inside src/js/editor/");
483
+ return;
484
+ }
485
+
486
+ // ======================================================
487
+ // Validate configuration.json (NEW RULE)
488
+ // ======================================================
489
+
490
+ const editorConfigPath = path.join(newEditorBaseDir, "configuration.json");
491
+
492
+ // Missing config
493
+ if (!fs.existsSync(editorConfigPath)) {
494
+ console.error(`
495
+ MISSING EDITOR CONFIGURATION FILE
496
+
497
+ Required:
498
+ src/js/editor/configuration.json
499
+
500
+ ❌ Build stopped.
501
+ `);
502
+ process.exit(1);
503
+ }
504
+
505
+ // Check wrong placement
506
+ const invalidConfigs = [];
507
+
508
+ editorDirs.forEach(dir => {
509
+ const wrongPath = path.join(newEditorBaseDir, dir, "configuration.json");
510
+ if (fs.existsSync(wrongPath)) {
511
+ invalidConfigs.push(`src/js/editor/${dir}/configuration.json`);
512
+ }
513
+ });
514
+
515
+ if (invalidConfigs.length > 0) {
516
+ console.error(`
517
+ ❌ INVALID CONFIGURATION LOCATION
518
+
519
+ 🚫 configuration.json must NOT be inside version folders.
520
+
521
+ Found:
522
+ ${invalidConfigs.map(p => " - " + p).join("\n")}
523
+
524
+ ✅ Correct:
525
+ src/js/editor/configuration.json
526
+
527
+ ❌ Build stopped.
528
+ `);
529
+ process.exit(1);
530
+ }
531
+
532
+ console.log("✅ Editor structure validated.");
533
+
534
+ // ======================================================
535
+ // 🚀 Continue execution (run.js)
536
+ // ======================================================
537
+
538
+ const latestEditorDir = editorDirs.sort((a, b) => {
539
+ const vA = parseFloat(a.split('-')[1]);
540
+ const vB = parseFloat(b.split('-')[1]);
541
+ return vB - vA;
542
+ })[0];
543
+
544
+ const runJsPath = path.join(newEditorBaseDir, latestEditorDir, "run.js");
545
+
546
+ if (!fs.existsSync(runJsPath)) {
547
+ console.error(`❌ run.js not found in ${latestEditorDir}`);
548
+ process.exit(1);
549
+ }
550
+
551
+ console.log(`🚀 Executing ${runJsPath}...`);
552
+ execSync(`node "${runJsPath}"`, { stdio: "inherit" });
553
+ }
554
+
555
+ // ======================================================
556
+ // CASE 3: NOTHING EXISTS → DO NOTHING
557
+ // ======================================================
558
+ else {
559
+ console.log("ℹ️ Editor not used in this project. Skipping...");
560
+ }
561
+
562
+ //@Codemirror check and install/uninstall the packages END
563
+
564
+
565
+
566
+
567
+
568
+
569
+
570
+
571
+ const localizationBaseDir = path.join(__dirname, "..", "src", "js", "localization");
572
+
573
+ // ======================================================
574
+ // 🌐 LOCALIZATION CHECK (FULLY DYNAMIC)
575
+ // ======================================================
576
+
577
+
578
+ const jsRootDir = path.join(__dirname, "..", "src", "js");
579
+
580
+ // 🔍 Detect OLD localization files in root js/
581
+ const oldLocalizationFiles = fs.readdirSync(jsRootDir)
582
+ .filter(name =>
583
+ /^localization-\d+(\.\d+)*\.js$/.test(name) ||
584
+ /^localization_settings-\d+(\.\d+)*\.js$/.test(name)
585
+ );
586
+
587
+ // ❌ If old structure found → STOP
588
+ if (oldLocalizationFiles.length > 0) {
589
+
590
+ console.error(`
591
+ OLD LOCALIZATION STRUCTURE DETECTED
592
+
593
+ You are using outdated file structure:
594
+ src/js/localization-x.x.js
595
+ src/js/localization_settings-x.x.js
596
+
597
+ 🚨 This is no longer supported.
598
+
599
+ 📦 Found files:
600
+ ${oldLocalizationFiles.map(f => " - " + f).join("\n")}
601
+
602
+ 👉 Please move them to new structure:
603
+
604
+ src/js/localization/localization_settings-x.x.js
605
+ src/js/localization/localization-x.x/
606
+
607
+ ⚠️ Example:
608
+
609
+ OLD:
610
+ src/js/localization-x.x.js
611
+ src/js/localization_settings-x.x.js
612
+
613
+ NEW:
614
+ src/js/localization/localization_settings-1.1.js
615
+ src/js/localization/localization-x.x/localization-x.x.js
616
+
617
+ Build stopped.
618
+ `);
619
+
620
+ process.exit(1);
621
+ }
622
+
623
+
624
+ if (fs.existsSync(localizationBaseDir)) {
625
+
626
+ // 🔍 Find localization-x.x folders
627
+ const localizationVersions = fs.readdirSync(localizationBaseDir)
628
+ .filter(name => /^localization-\d+(\.\d+)+$/.test(name));
629
+
630
+ if (localizationVersions.length === 0) {
631
+ console.log("ℹ️ No localization-x.x folder found. Skipping...");
632
+ } else {
633
+
634
+ // 🔥 Get latest version (supports 1.6, 1.6.1, etc.)
635
+ const latestLocalizationDir = localizationVersions.sort((a, b) => {
636
+ const vA = a.split('-')[1].split('.').map(Number);
637
+ const vB = b.split('-')[1].split('.').map(Number);
638
+
639
+ for (let i = 0; i < Math.max(vA.length, vB.length); i++) {
640
+ const diff = (vB[i] || 0) - (vA[i] || 0);
641
+ if (diff !== 0) return diff;
642
+ }
643
+ return 0;
644
+ })[0];
645
+
646
+ const localizationPath = path.join(localizationBaseDir, latestLocalizationDir);
647
+
648
+ // ======================================================
649
+ // 🔍 Find settings file dynamically
650
+ // ======================================================
651
+
652
+ const settingsFile = fs.readdirSync(localizationBaseDir)
653
+ .find(name => /^localization_settings-.*\.js$/.test(name));
654
+
655
+ if (!settingsFile) {
656
+ console.error(`
657
+ ❌ MISSING LOCALIZATION SETTINGS FILE
658
+
659
+ Expected:
660
+ src/js/localization/localization_settings-x.x.js
661
+
662
+ ❌ Build stopped.
663
+ `);
664
+ process.exit(1);
665
+ }
666
+
667
+ // ======================================================
668
+ // 🔍 Find run.js INSIDE version folder
669
+ // ======================================================
670
+
671
+ const runJsPath = path.join(localizationPath, "run.js");
672
+
673
+ if (!fs.existsSync(runJsPath)) {
674
+ console.error(`
675
+ ❌ LOCALIZATION run.js NOT FOUND
676
+
677
+ Expected:
678
+ ${runJsPath}
679
+
680
+ Build stopped.
681
+ `);
682
+ process.exit(1);
683
+ }
684
+
685
+ console.log(`🌐 Localization detected: ${latestLocalizationDir}`);
686
+ console.log(`⚙️ Using settings: ${settingsFile}`);
687
+ console.log(`🚀 Executing: ${runJsPath}`);
688
+
689
+ // ======================================================
690
+ // 🚀 Execute run.js
691
+ // ======================================================
692
+
693
+ execSync(`node "${runJsPath}"`, { stdio: "inherit" });
694
+ }
695
+
696
+ } else {
697
+ console.log("ℹ️ Localization not used in this project. Skipping...");
698
+ }
699
+
700
+
701
+
702
+
703
+
704
+
705
+
706
+
707
+
708
+
709
+
710
+
711
+
712
+
713
+
714
+
715
+
716
+
717
+
718
+ //editor-x.x import old style check and stop execution START
719
+
720
+
721
+
722
+ // Match: editor/editor-2.3, editor/editor-2.3.1, etc.
723
+ const FORBIDDEN_REGEX = /editor\/editor-\d+(\.\d+)+/;
724
+
725
+ let hasError = false;
726
+
727
+ const ERROR_MESSAGE = `const ERROR_MESSAGE = ❌ Invalid import detected!
728
+
729
+ You are using a direct version-based path like: editor/editor-x.x/editor.js
730
+
731
+ 🚫 This is NOT allowed.
732
+
733
+ 👉 Please use the proper alias or updated import method.
734
+ Example: import { ... } from '@editor'
735
+
736
+ ⚠️ Do not use version-based paths in imports.
737
+ 👉 Please add this manually in vite.config.js:
738
+
739
+ alias: {
740
+ '@editor': path.resolve(__dirname, './src/js/editor/editor-x.x')
741
+ }`
742
+
743
+ function scanDir(dir) {
744
+ const files = fs.readdirSync(dir);
745
+
746
+ for (const file of files) {
747
+ const fullPath = path.join(dir, file);
748
+ const stat = fs.statSync(fullPath);
749
+
750
+ if (stat.isDirectory()) {
751
+ scanDir(fullPath);
752
+ } else if (file.endsWith(".js") || file.endsWith(".ts") || file.endsWith(".f7")) {
753
+ const content = fs.readFileSync(fullPath, "utf-8");
754
+
755
+ const lines = content.split("\n");
756
+
757
+ lines.forEach((line, index) => {
758
+ if (FORBIDDEN_REGEX.test(line)) {
759
+ console.error(
760
+ `❌ Forbidden import found:\nFile: ${fullPath}\nLine: ${index + 1}\nCode: ${line.trim()}\n`,
761
+ ERROR_MESSAGE
762
+ );
763
+ hasError = true;
764
+ }
765
+ });
766
+ }
767
+ }
768
+ }
769
+
770
+ // Run scan
771
+ scanDir(ROOT_DIR);
772
+
773
+ // Throw error (exit process)
774
+ if (hasError) {
775
+ console.error("🚫 Build failed due to forbidden editor imports.");
776
+ process.exit(1);
777
+ } else {
778
+ console.log("✅ No forbidden imports found.");
779
+ }
780
+
781
+
782
+
783
+
784
+
785
+
786
+ //editor-x.x import old style check and stop execution START
787
+
788
+
789
+
790
+
791
+
792
+
793
+
794
+
795
+
796
+
797
+ // saveToGalleryAndSaveAnyFile-x.x-ios.js file check for android and return error if exists START
798
+
799
+ const os = require('os');
800
+
801
+ const saveToGalleryAndSaveFileCheck_iOS = () => {
802
+
803
+ // List of paths to scan
804
+ const SCAN_PATHS = [
805
+ path.resolve(__dirname, '../src/certificate'),
806
+ path.resolve(__dirname, '../src/pages'),
807
+ path.resolve(__dirname, '../src/js'),
808
+ path.resolve(__dirname, '../src/app.f7')
809
+ ];
810
+
811
+ // Directory to exclude
812
+ const EXCLUDED_DIR = path.resolve(__dirname, '../src/js/Ads');
813
+
814
+ const ANDROID_MANIFEST_PATH = path.resolve(__dirname, '../android/app/src/main/AndroidManifest.xml');
815
+
816
+
817
+ // Match iOS-specific imports (e.g., saveToGalleryAndSaveAnyFile-2.5-ios.js) not in comments
818
+ const IOS_FILE_REGEX = /^(?!\s*\/\/).*['"](?:.*\/)?saveToGalleryAndSaveAnyFile-\d+(\.\d+)*-ios\.js['"]/m;
819
+
820
+ // Match Android-specific imports (e.g., saveToGalleryAndSaveAnyFile-2.5.js) not in comments
821
+ const ANDROID_FILE_REGEX = /^(?!\s*\/\/).*['"](?:.*\/)?saveToGalleryAndSaveAnyFile-\d+(\.\d+)*\.js['"]/m;
822
+
823
+
824
+
825
+
826
+
827
+ const ALLOWED_EXTENSIONS = ['.js', '.f7'];
828
+ const isMac = os.platform() === 'darwin';
829
+
830
+ let iosImportFound = false;
831
+ let androidImportFound = false;
832
+
833
+ // Files to skip completely (full or partial match)
834
+ const SKIP_FILES = [
835
+ 'pdf-3.11.174.min.js',
836
+ 'pdf.worker-3.11.174.min.js'
837
+ ,'index.browser.js'
838
+ ];
839
+
840
+
841
+ function scanDirectory(dir) {
842
+
843
+ /*
844
+ //######################### DO NOT DELETE THIS - START [Appid base validation] #####################################
845
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
846
+ const appUniqueId = config.android?.APP_UNIQUE_ID;
847
+ if (appUniqueId == "206") return;
848
+ //######################### DO NOT DELETE THIS - END [Appid base validation] #####################################
849
+ */
850
+
851
+ const stat = fs.statSync(dir);
852
+
853
+ if (stat.isFile()) {
854
+
855
+ // 🔥 Skip files in SKIP_FILES array
856
+ const baseName = path.basename(dir);
857
+ if (SKIP_FILES.includes(baseName)) {
858
+ // Just skip silently
859
+ return;
860
+ }
861
+
862
+ // Only scan allowed file extensions
863
+ if (ALLOWED_EXTENSIONS.some(ext => dir.endsWith(ext))) {
864
+ process.stdout.write(`\r🔍 Scanning: ${dir} `);
865
+
866
+ const content = fs.readFileSync(dir, 'utf8');
867
+
868
+ if (IOS_FILE_REGEX.test(content)) {
869
+ iosImportFound = true;
870
+ if (!isMac) {
871
+ console.error(`\n❌ ERROR: iOS-specific import detected in: ${dir}`);
872
+ console.error(`🚫 STOPPED: This file should not be imported in Android/Windows/Linux builds.\n`);
873
+ process.exit(1);
874
+ }
875
+ }
876
+ else if (ANDROID_FILE_REGEX.test(content) && !content.includes('-ios.js')) {
877
+ androidImportFound = true;
878
+ }
879
+ }
880
+ }
881
+ else if (stat.isDirectory()) {
882
+ if (dir === EXCLUDED_DIR || path.basename(dir) === 'node_modules') return;
883
+
884
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
885
+ for (let entry of entries) {
886
+ scanDirectory(path.join(dir, entry.name));
887
+ }
888
+ }
889
+ }
890
+
891
+
892
+ // Run scan on all specified paths
893
+ for (let scanPath of SCAN_PATHS) {
894
+ if (fs.existsSync(scanPath)) {
895
+ scanDirectory(scanPath);
896
+ }
897
+ }
898
+
899
+
900
+
901
+ /* // Check src folder
902
+ if (!fs.existsSync(ROOT_DIR)) {
903
+ console.warn(`⚠️ Warning: 'src' directory not found at: ${ROOT_DIR}`);
904
+ return;
905
+ } */
906
+
907
+ //scanDirectory(ROOT_DIR);
908
+
909
+ // iOS Checks
910
+ if (isMac && !iosImportFound) {
911
+ console.warn(`⚠️ WARNING: You're on macOS but no iOS version (saveToGalleryAndSaveAnyFile-x.x-ios.js) found.`);
912
+ process.exit(1);
913
+ } else if (isMac && iosImportFound) {
914
+ console.log(' iOS version detected for macOS build.');
915
+ } else if (!iosImportFound) {
916
+ console.log('✅ No iOS-specific imports detected for non-macOS.');
917
+ }
918
+
919
+ // Android Checks
920
+ if (androidImportFound) {
921
+ console.log("📱 Android version of saveToGalleryAndSaveAnyFile detected. Checking AndroidManifest.xml...");
922
+
923
+ if (!fs.existsSync(ANDROID_MANIFEST_PATH)) {
924
+ console.error("❌ AndroidManifest.xml not found. Cannot add requestLegacyExternalStorage attribute.");
925
+ return;
926
+ }
927
+
928
+ let manifestContent = fs.readFileSync(ANDROID_MANIFEST_PATH, 'utf8');
929
+
930
+ if (!manifestContent.includes('android:requestLegacyExternalStorage="true"')) {
931
+ console.log("Adding android:requestLegacyExternalStorage=\"true\" to <application> tag...");
932
+
933
+ manifestContent = manifestContent.replace(
934
+ /<application([^>]*)>/,
935
+ (match, attrs) => {
936
+ if (attrs.includes('android:requestLegacyExternalStorage')) return match;
937
+ return `<application${attrs} android:requestLegacyExternalStorage="true">`;
938
+ }
939
+ );
940
+
941
+ fs.writeFileSync(ANDROID_MANIFEST_PATH, manifestContent, 'utf8');
942
+ console.log("✅ android:requestLegacyExternalStorage=\"true\" added successfully.");
943
+ } else {
944
+ console.log("ℹ️ android:requestLegacyExternalStorage already exists in AndroidManifest.xml.");
945
+ }
946
+ } else {
947
+ console.log("✅ No Android saveToGalleryAndSaveAnyFile imports detected.");
948
+ }
949
+ };
950
+
951
+ saveToGalleryAndSaveFileCheck_iOS();
952
+ // saveToGalleryAndSaveAnyFile-x.x-ios.js file check for android and return error if exists END
953
+
954
+
955
+
956
+
957
+
958
+
959
+
960
+
961
+
962
+
963
+
964
+
965
+
966
+ /*
967
+ // Clean up AppleDouble files (._*) created by macOS START
968
+ if (process.platform === 'darwin') {
969
+ try {
970
+ console.log('🧹 Cleaning up AppleDouble files (._*)...');
971
+ execSync(`find . -name '._*' -delete`);
972
+ console.log('✅ AppleDouble files removed.');
973
+ } catch (err) {
974
+ console.warn('⚠️ Failed to remove AppleDouble files:', err.message);
975
+ }
976
+ } else {
977
+ console.log('ℹ️ Skipping AppleDouble cleanup — not a macOS machine.');
978
+ }
979
+
980
+ // Clean up AppleDouble files (._*) created by macOS END
981
+ */
982
+
983
+
984
+
985
+
986
+
987
+
988
+ //In routes.js file check static import START
989
+
990
+ const routesPath = path.join(process.cwd(), 'src', 'js', 'routes.js');
991
+ const routesContent = fs.readFileSync(routesPath, 'utf-8');
992
+
993
+ let inBlockComment = false;
994
+ const lines = routesContent.split('\n');
995
+
996
+ const allowedImport = `import HomePage from '../pages/home.f7';`;
997
+ const badImportRegex = /^[ \t]*import\s+[\w{}*,\s]*\s+from\s+['"].+\.f7['"]\s*;/;
998
+ const badImports = [];
999
+
1000
+ lines.forEach((line, index) => {
1001
+ const trimmed = line.trim();
1002
+
1003
+ // Handle block comment start and end
1004
+ if (trimmed.startsWith('/*')) inBlockComment = true;
1005
+ if (inBlockComment && trimmed.endsWith('*/')) {
1006
+ inBlockComment = false;
1007
+ return;
1008
+ }
1009
+
1010
+ // Skip if inside block comment or line comment
1011
+ if (inBlockComment || trimmed.startsWith('//')) return;
1012
+
1013
+ // Match static .f7 import
1014
+ if (badImportRegex.test(trimmed) && trimmed !== allowedImport) {
1015
+ badImports.push({ line: trimmed, number: index + 1 });
1016
+ }
1017
+ });
1018
+
1019
+ if (badImports.length > 0) {
1020
+ console.error('\nERROR: Detected disallowed static imports of .f7 files in routes.js\n');
1021
+ console.error(`⚠️ Only this static import is allowed:\n ${allowedImport}\n`);
1022
+ console.error(`🔧 Please convert other imports to async dynamic imports like this:\n`);
1023
+ console.error(`
1024
+
1025
+ import HomePage from '../pages/home.f7';
1026
+
1027
+ const routes = [
1028
+ {
1029
+ path: '/',
1030
+ component:HomePage,
1031
+ },
1032
+ {
1033
+ path: '/ProfilePage/',
1034
+ async async({ resolve }) {
1035
+ const page = await import('../pages/profile.f7');
1036
+ resolve({ component: page.default });
1037
+ },
1038
+ }]
1039
+ `);
1040
+
1041
+ badImports.forEach(({ line, number }) => {
1042
+ console.error(`${number}: ${line}`);
1043
+ });
1044
+
1045
+ process.exit(1);
1046
+ } else {
1047
+ console.log('✅ routes.js passed the .f7 import check.');
1048
+ }
1049
+
1050
+ //In routes.js file check static import END
1051
+
1052
+
1053
+
1054
+
1055
+
1056
+
1057
+
1058
+
1059
+
1060
+
1061
+
1062
+
1063
+
1064
+ // Check and change the "BridgeWebViewClient.java" file START
1065
+ /*
1066
+ For crash issue due to low memory problem, we need to modify the onRenderProcessGone method in BridgeWebViewClient.java.
1067
+ */
1068
+
1069
+
1070
+ const bridgeWebViewClientFilePath = path.join(process.cwd(), 'node_modules', '@capacitor/android/capacitor/src/main/java/com/getcapacitor', 'BridgeWebViewClient.java');
1071
+
1072
+ // Read the file
1073
+ if (!fs.existsSync(bridgeWebViewClientFilePath)) {
1074
+ console.error('❌ Error: BridgeWebViewClient.java not found.');
1075
+ process.exit(1);
1076
+ }
1077
+
1078
+ let fileContent = fs.readFileSync(bridgeWebViewClientFilePath, 'utf8');
1079
+
1080
+ // Define old and new code
1081
+ const oldCodeStart = `@Override
1082
+ public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) {
1083
+ super.onRenderProcessGone(view, detail);
1084
+ boolean result = false;
1085
+
1086
+ List<WebViewListener> webViewListeners = bridge.getWebViewListeners();
1087
+ if (webViewListeners != null) {
1088
+ for (WebViewListener listener : bridge.getWebViewListeners()) {
1089
+ result = listener.onRenderProcessGone(view, detail) || result;
1090
+ }
1091
+ }
1092
+
1093
+ return result;
1094
+ }`;
1095
+
1096
+ const newCode = `@Override
1097
+ public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) {
1098
+ super.onRenderProcessGone(view, detail);
1099
+
1100
+ boolean result = false;
1101
+
1102
+ List<WebViewListener> webViewListeners = bridge.getWebViewListeners();
1103
+ if (webViewListeners != null) {
1104
+ for (WebViewListener listener : bridge.getWebViewListeners()) {
1105
+ result = listener.onRenderProcessGone(view, detail) || result;
1106
+ }
1107
+ }
1108
+
1109
+ if (!result) {
1110
+ // If no one handled it, handle it ourselves!
1111
+
1112
+ /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
1113
+ if (detail.didCrash()) {
1114
+ //Log.e("CapacitorWebView", "WebView crashed internally!");
1115
+ } else {
1116
+ //Log.w("CapacitorWebView", "WebView was killed by system (low memory) internally!");
1117
+ }
1118
+ }*/
1119
+
1120
+ view.post(() -> {
1121
+ Toast.makeText(view.getContext(), "Reloading due to low memory issue", Toast.LENGTH_SHORT).show();
1122
+ });
1123
+
1124
+ view.reload(); // Safely reload WebView
1125
+
1126
+ return true; // We handled it
1127
+ }
1128
+
1129
+ return result;
1130
+ }`;
1131
+
1132
+ // Step 1: Update method if needed
1133
+ let updated = false;
1134
+
1135
+ if (fileContent.includes(oldCodeStart)) {
1136
+ console.log('✅ Found old onRenderProcessGone method. Replacing it...');
1137
+ fileContent = fileContent.replace(oldCodeStart, newCode);
1138
+ updated = true;
1139
+ } else if (fileContent.includes(newCode)) {
1140
+ console.log('ℹ️ Method already updated. No changes needed in "BridgeWebViewClient.java".');
1141
+ } else {
1142
+ console.error('❌ Error: Neither old nor new code found. Unexpected content.');
1143
+ process.exit(1);
1144
+ }
1145
+
1146
+ // Step 2: Check and add import if missing
1147
+ const importToast = 'import android.widget.Toast;';
1148
+ if (!fileContent.includes(importToast)) {
1149
+ console.log('✅ Adding missing import for Toast...');
1150
+ const importRegex = /import\s+[^;]+;/g;
1151
+ const matches = [...fileContent.matchAll(importRegex)];
1152
+
1153
+ if (matches.length > 0) {
1154
+ const lastImport = matches[matches.length - 1];
1155
+ const insertPosition = lastImport.index + lastImport[0].length;
1156
+ fileContent = fileContent.slice(0, insertPosition) + `\n${importToast}` + fileContent.slice(insertPosition);
1157
+ updated = true;
1158
+ } else {
1159
+ console.error('❌ Error: No import section found in file.');
1160
+ process.exit(1);
1161
+ }
1162
+ } else {
1163
+ console.log('ℹ️ Import for Toast already exists. No changes needed.');
1164
+ }
1165
+
1166
+ // Step 3: Save if updated
1167
+ if (updated) {
1168
+ fs.writeFileSync(bridgeWebViewClientFilePath, fileContent, 'utf8');
1169
+ console.log('✅ File updated successfully.');
1170
+ } else {
1171
+ console.log('ℹ️ No changes needed.');
1172
+ }
1173
+
1174
+
1175
+
1176
+
1177
+ // Check and change the "BridgeWebViewClient.java" file END
1178
+
1179
+
1180
+
1181
+
1182
+
1183
+
1184
+
1185
+
1186
+ /*
1187
+ // To resolve the kotlin version issue, we need to update the kotlin version in the build.gradle file START
1188
+
1189
+ // Build the path dynamically like you requested
1190
+ const gradlePath = path.join(
1191
+ process.cwd(),
1192
+ 'android',
1193
+ 'build.gradle'
1194
+ );
1195
+
1196
+ // Read the existing build.gradle
1197
+ let gradleContent = fs.readFileSync(gradlePath, 'utf8');
1198
+
1199
+ // Add `ext.kotlin_version` if it's not already there
1200
+ if (!gradleContent.includes('ext.kotlin_version')) {
1201
+ gradleContent = gradleContent.replace(
1202
+ /buildscript\s*{/,
1203
+ `buildscript {\n ext.kotlin_version = '2.1.0'`
1204
+ );
1205
+ }
1206
+
1207
+ // Add Kotlin classpath if it's not already there
1208
+ if (!gradleContent.includes('org.jetbrains.kotlin:kotlin-gradle-plugin')) {
1209
+ gradleContent = gradleContent.replace(
1210
+ /dependencies\s*{([\s\S]*?)classpath 'com.android.tools.build:gradle:8.7.2'/,
1211
+ `dependencies {\n classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")\n$1classpath 'com.android.tools.build:gradle:8.7.2'`
1212
+ );
1213
+ }
1214
+
1215
+ // Write back the modified content
1216
+ fs.writeFileSync(gradlePath, gradleContent, 'utf8');
1217
+
1218
+ console.log('✅ Kotlin version updated in build.gradle.');
1219
+
1220
+ // To resolve the kotlin version issue, we need to update the kotlin version in the build.gradle file END
1221
+ */
1222
+
1223
+
1224
+
1225
+
1226
+
1227
+
1228
+
1229
+
1230
+ let _admobConfig;
1231
+
1232
+
1233
+
1234
+ const androidPlatformPath = path.join(process.cwd(), 'android');
1235
+ const iosPlatformPath = path.join(process.cwd(), 'ios');
1236
+ const pluginPath = path.join(process.cwd(), 'node_modules', 'emi-indo-cordova-plugin-admob', 'plugin.xml');
1237
+ const infoPlistPath = path.join(process.cwd(), 'ios', 'App', 'App', 'Info.plist');
1238
+ const resourcesPath = path.join(process.cwd(), 'resources', 'res');
1239
+ const androidResPath = path.join(process.cwd(), 'android', 'app', 'src', 'main', 'res');
1240
+ const localNotificationsPluginPath = path.join(process.cwd(), 'node_modules', '@capacitor', 'local-notifications');
1241
+
1242
+ function fileExists(filePath) {
1243
+ return fs.existsSync(filePath);
1244
+ }
1245
+
1246
+ function copyFolderSync(source, target) {
1247
+ if (!fs.existsSync(target)) {
1248
+ fs.mkdirSync(target, { recursive: true });
1249
+ }
1250
+
1251
+ fs.readdirSync(source).forEach(file => {
1252
+ const sourceFile = path.join(source, file);
1253
+ const targetFile = path.join(target, file);
1254
+
1255
+ if (fs.lstatSync(sourceFile).isDirectory()) {
1256
+ copyFolderSync(sourceFile, targetFile);
1257
+ } else {
1258
+ fs.copyFileSync(sourceFile, targetFile);
1259
+ }
1260
+ });
1261
+ }
1262
+
1263
+ function checkAndCopyResources() {
1264
+ if (fileExists(resourcesPath)) {
1265
+ copyFolderSync(resourcesPath, androidResPath);
1266
+ console.log('✅ Successfully copied resources/res to android/app/src/main/res.');
1267
+ } else {
1268
+ console.log('resources/res folder not found.');
1269
+
1270
+ if (fileExists(localNotificationsPluginPath)) {
1271
+ throw new Error('❌ resources/res is required for @capacitor/local-notifications. Stopping execution.');
1272
+ }
1273
+ }
1274
+ }
1275
+
1276
+
1277
+
1278
+
1279
+
1280
+
1281
+
1282
+
1283
+ function getAdMobConfig() {
1284
+ if (!fileExists(configPath)) {
1285
+ throw new Error('❌ capacitor.config.json not found. Ensure this is a Capacitor project.');
1286
+ }
1287
+
1288
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
1289
+ const admobConfig = config.plugins?.AdMob;
1290
+
1291
+ if (!admobConfig) {
1292
+ throw new Error('❌ AdMob configuration is missing in capacitor.config.json.');
1293
+ }
1294
+
1295
+ // Default to true if ADMOB_ENABLED is not specified
1296
+ const isEnabled = admobConfig.ADMOB_ENABLED !== false;
1297
+
1298
+ if (!isEnabled) {
1299
+ return { ADMOB_ENABLED: false }; // Skip further validation
1300
+ }
1301
+
1302
+ if (!admobConfig.APP_ID_ANDROID || !admobConfig.APP_ID_IOS) {
1303
+ throw new Error(' ❌ AdMob configuration is incomplete. Ensure APP_ID_ANDROID and APP_ID_IOS are defined.');
1304
+ }
1305
+
1306
+ return {
1307
+ ADMOB_ENABLED: true,
1308
+ APP_ID_ANDROID: admobConfig.APP_ID_ANDROID,
1309
+ APP_ID_IOS: admobConfig.APP_ID_IOS,
1310
+ USE_LITE_ADS: admobConfig.USE_LITE_ADS === "lite",
1311
+ };
1312
+ }
1313
+
1314
+ function validateAndroidBuildOptions() {
1315
+
1316
+
1317
+ if (!fileExists(configPath)) {
1318
+ console.log('❌ capacitor.config.json not found. Ensure this is a Capacitor project.');
1319
+ process.exit(1);
1320
+ }
1321
+
1322
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
1323
+
1324
+ const targetAppId=config.appId
1325
+
1326
+ const buildOptions = config.android?.buildOptions;
1327
+
1328
+ if (!buildOptions) {
1329
+ console.log('❌ Missing android.buildOptions in capacitor.config.json.');
1330
+ process.exit(1);
1331
+ }
1332
+
1333
+ const requiredProps = [
1334
+ 'keystorePath',
1335
+ 'keystorePassword',
1336
+ 'keystoreAlias',
1337
+ 'keystoreAliasPassword',
1338
+ 'releaseType',
1339
+ 'signingType'
1340
+ ];
1341
+
1342
+ const missing = requiredProps.filter(prop => !buildOptions[prop]);
1343
+
1344
+ if (missing.length > 0) {
1345
+ console.log('❌ Missing properties android.buildOptions in capacitor.config.json.');
1346
+ process.exit(1);
1347
+ }
1348
+
1349
+
1350
+ const keystorePath=buildOptions.keystorePath
1351
+ const keyFileName = path.basename(keystorePath);
1352
+
1353
+
1354
+
1355
+ const keystoreMap = {
1356
+ "gameskey.jks": [
1357
+ "com.cube.blaster",
1358
+ ],
1359
+ "htmleditorkeystoke.jks": [
1360
+ "com.HTML.AngularJS.Codeplay",
1361
+ "com.html.codeplay.pro",
1362
+ "com.bootstrap.code.play",
1363
+ "com.kids.learning.master",
1364
+ "com.Simple.Barcode.Scanner",
1365
+ "com.FAShtmlcssjs.editor"
1366
+ ]
1367
+ };
1368
+
1369
+ // find which keystore is required for the given targetAppId
1370
+ let requiredKey = "newappskey.jks"; // default
1371
+ for (const [keyFile, appIds] of Object.entries(keystoreMap)) {
1372
+ if (appIds.includes(targetAppId)) {
1373
+ requiredKey = keyFile;
1374
+ break;
1375
+ }
1376
+ }
1377
+
1378
+ // validate
1379
+ if (keyFileName !== requiredKey) {
1380
+ console.log(`❌ The keystore path is mismatched. Expected ${requiredKey} for ${targetAppId}, but got ${keyFileName}`);
1381
+ process.exit(1);
1382
+ }
1383
+
1384
+
1385
+
1386
+
1387
+
1388
+ // optionally return them
1389
+ //return buildOptions;
1390
+ }
1391
+
1392
+ function updatePluginXml(admobConfig) {
1393
+ if (!fileExists(pluginPath)) {
1394
+ console.error(' ❌ plugin.xml not found. Ensure the plugin is installed.');
1395
+ return;
1396
+ }
1397
+
1398
+ let pluginContent = fs.readFileSync(pluginPath, 'utf8');
1399
+
1400
+ pluginContent = pluginContent
1401
+ .replace(/<preference name="APP_ID_ANDROID" default=".*?" \/>/, `<preference name="APP_ID_ANDROID" default="${admobConfig.APP_ID_ANDROID}" />`)
1402
+ .replace(/<preference name="APP_ID_IOS" default=".*?" \/>/, `<preference name="APP_ID_IOS" default="${admobConfig.APP_ID_IOS}" />`);
1403
+
1404
+ fs.writeFileSync(pluginPath, pluginContent, 'utf8');
1405
+ console.log('✅ AdMob IDs successfully updated in plugin.xml');
1406
+ }
1407
+
1408
+ function updateInfoPlist(admobConfig) {
1409
+ if (!fileExists(infoPlistPath)) {
1410
+ console.error(' ❌ Info.plist not found. Ensure you have built the iOS project.');
1411
+ return;
1412
+ }
1413
+
1414
+ const plistContent = fs.readFileSync(infoPlistPath, 'utf8');
1415
+ const plistData = plist.parse(plistContent);
1416
+
1417
+ plistData.GADApplicationIdentifier = admobConfig.APP_ID_IOS;
1418
+ plistData.NSUserTrackingUsageDescription = 'This identifier will be used to deliver personalized ads to you.';
1419
+ plistData.GADDelayAppMeasurementInit = true;
1420
+
1421
+ const updatedPlistContent = plist.build(plistData);
1422
+ fs.writeFileSync(infoPlistPath, updatedPlistContent, 'utf8');
1423
+ console.log('AdMob IDs and additional configurations successfully updated in Info.plist');
1424
+ }
1425
+
1426
+
1427
+ try {
1428
+ if (!fileExists(configPath)) {
1429
+ throw new Error(' ❌ capacitor.config.json not found. Skipping setup.');
1430
+ }
1431
+
1432
+ if (!fileExists(androidPlatformPath) && !fileExists(iosPlatformPath)) {
1433
+ throw new Error('Neither Android nor iOS platforms are found. Ensure platforms are added to your Capacitor project.');
1434
+ }
1435
+
1436
+ checkAndCopyResources();
1437
+
1438
+
1439
+
1440
+ _admobConfig = getAdMobConfig();
1441
+
1442
+
1443
+
1444
+
1445
+
1446
+ // Proceed only if ADMOB_ENABLED is true
1447
+ if (_admobConfig.ADMOB_ENABLED) {
1448
+ if (fileExists(androidPlatformPath)) {
1449
+ updatePluginXml(_admobConfig);
1450
+ }
1451
+
1452
+ if (fileExists(iosPlatformPath)) {
1453
+ updateInfoPlist(_admobConfig);
1454
+ }
1455
+ }
1456
+
1457
+
1458
+ } catch (error) {
1459
+ console.error(error.message);
1460
+ process.exit(1); // Stop execution if there's a critical error
1461
+ }
1462
+
1463
+
1464
+
1465
+ validateAndroidBuildOptions();
1466
+
1467
+
1468
+
1469
+
1470
+
1471
+
1472
+ // Check all the codeplays plugins version START
1473
+
1474
+
1475
+ const readline = require('readline');
1476
+
1477
+
1478
+ //const srcDir = path.join(__dirname, 'src');
1479
+ const srcDir = path.join(process.cwd(), 'src');
1480
+ let outdatedPlugins = [];
1481
+
1482
+ function parseVersion(ver) {
1483
+ return ver.split('.').map(n => parseInt(n, 10));
1484
+ }
1485
+
1486
+ function compareVersions(v1, v2) {
1487
+ const [a1, b1] = parseVersion(v1);
1488
+ const [a2, b2] = parseVersion(v2);
1489
+ if (a1 !== a2) return a1 - a2;
1490
+ return b1 - b2;
1491
+ }
1492
+
1493
+ function walkSync(dir, filelist = []) {
1494
+ fs.readdirSync(dir).forEach(file => {
1495
+ const fullPath = path.join(dir, file);
1496
+ const stat = fs.statSync(fullPath);
1497
+ if (stat.isDirectory()) {
1498
+ walkSync(fullPath, filelist);
1499
+ } else {
1500
+ filelist.push(fullPath);
1501
+ }
1502
+ });
1503
+ return filelist;
1504
+ }
1505
+
1506
+
1507
+
1508
+ function getSearchRoot(plugin) {
1509
+ return path.join(srcDir, plugin.baseDir || 'js');
1510
+ }
1511
+
1512
+
1513
+
1514
+
1515
+
1516
+
1517
+
1518
+
1519
+
1520
+
1521
+
1522
+
1523
+
1524
+
1525
+
1526
+
1527
+
1528
+
1529
+
1530
+
1531
+ /*############################################## AUTO DOWNLOAD FROM SERVER START #####################################*/
1532
+
1533
+ // ============================================================
1534
+ // 🔥 AUTO PLUGIN UPDATE SYSTEM (MANDATORY UPDATES)
1535
+ // ============================================================
1536
+
1537
+ const https = require("https");
1538
+
1539
+ /**
1540
+ * Check if file exists on server using HEAD request
1541
+ */
1542
+ function urlExists(url) {
1543
+ return new Promise(resolve => {
1544
+ const req = https.request(url, { method: "HEAD" }, res => {
1545
+ resolve(res.statusCode === 200);
1546
+ });
1547
+
1548
+ req.on("error", () => resolve(false));
1549
+ req.end();
1550
+ });
1551
+ }
1552
+
1553
+ /**
1554
+ * Download file from server
1555
+ */
1556
+ function downloadFile(url, dest) {
1557
+ return new Promise((resolve, reject) => {
1558
+ const file = fs.createWriteStream(dest);
1559
+
1560
+ https.get(url, response => {
1561
+ if (response.statusCode !== 200) {
1562
+ reject("Download failed");
1563
+ return;
1564
+ }
1565
+
1566
+ response.pipe(file);
1567
+
1568
+ file.on("finish", () => {
1569
+ file.close(resolve);
1570
+ });
1571
+ }).on("error", err => {
1572
+ fs.unlink(dest, () => {});
1573
+ reject(err);
1574
+ });
1575
+ });
1576
+ }
1577
+
1578
+ /**
1579
+ * Update imports across src folder
1580
+ * Replaces old filename → new filename
1581
+ */
1582
+ /**
1583
+ * Update imports across project
1584
+ * Replaces old filename → new filename
1585
+ */
1586
+
1587
+ const VITE_ALIAS_ONLY = [
1588
+ "common",
1589
+ "admob-emi",
1590
+ "localization",
1591
+ "theme",
1592
+ "certificatejs",
1593
+ "ffmpeg"
1594
+ ];
1595
+
1596
+ function updateImports(oldName, newName) {
1597
+
1598
+ const projectRoot = process.cwd();
1599
+
1600
+ const filesToScan = [
1601
+ path.join(projectRoot, "vite.config.js"),
1602
+ path.join(projectRoot, "vite.config.mjs")
1603
+ ];
1604
+
1605
+ const srcDir = path.join(projectRoot, "src");
1606
+
1607
+ // scan vite config
1608
+ filesToScan.forEach(file => {
1609
+
1610
+ if (!fs.existsSync(file)) return;
1611
+
1612
+ let content = fs.readFileSync(file, "utf8");
1613
+
1614
+ if (content.includes(oldName)) {
1615
+
1616
+ content = content.split(oldName).join(newName);
1617
+
1618
+ fs.writeFileSync(file, content);
1619
+
1620
+ console.log(`✏️ Updated alias in ${path.basename(file)}`);
1621
+ }
1622
+
1623
+ });
1624
+
1625
+ // scan src files
1626
+ function walk(dir) {
1627
+
1628
+ fs.readdirSync(dir).forEach(file => {
1629
+
1630
+ if (["node_modules","android","ios","dist",".git"].includes(file))
1631
+ return;
1632
+
1633
+ const full = path.join(dir, file);
1634
+ const stat = fs.statSync(full);
1635
+
1636
+ if (stat.isDirectory()) {
1637
+ walk(full);
1638
+ }
1639
+
1640
+ else if (
1641
+ (full.endsWith(".js") ||
1642
+ full.endsWith(".f7") ||
1643
+ full.endsWith(".mjs")) &&
1644
+ !full.endsWith(".min.js")
1645
+ ) {
1646
+
1647
+ let content = fs.readFileSync(full, "utf8");
1648
+
1649
+ if (content.includes(oldName)) {
1650
+
1651
+ content = content.split(oldName).join(newName);
1652
+
1653
+ fs.writeFileSync(full, content);
1654
+
1655
+ console.log(`✏️ Updated import in ${path.relative(projectRoot, full)}`);
1656
+ }
1657
+
1658
+ }
1659
+
1660
+ });
1661
+
1662
+ }
1663
+
1664
+ if (fs.existsSync(srcDir)) {
1665
+ walk(srcDir);
1666
+ }
1667
+
1668
+ }
1669
+
1670
+
1671
+ /**
1672
+ * Auto-update a plugin file
1673
+ * Returns TRUE if success
1674
+ * Returns FALSE if fallback to manual needed
1675
+ */
1676
+
1677
+
1678
+ let _serverVersions = null;
1679
+ async function fetchVersions() {
1680
+
1681
+ if (_serverVersions) return _serverVersions;
1682
+
1683
+ return new Promise((resolve) => {
1684
+
1685
+ https.get(
1686
+ "https://htmlcodeplay.com/code-play-plugin/versions.json",
1687
+ { timeout: 5000 },
1688
+ res => {
1689
+
1690
+ let data = "";
1691
+
1692
+ res.on("data", chunk => data += chunk);
1693
+
1694
+ res.on("end", () => {
1695
+
1696
+ try {
1697
+
1698
+ _serverVersions = JSON.parse(data);
1699
+
1700
+ resolve(_serverVersions);
1701
+
1702
+ } catch {
1703
+
1704
+ resolve(null);
1705
+
1706
+ }
1707
+
1708
+ });
1709
+
1710
+ }
1711
+
1712
+ ).on("error", () => resolve(null));
1713
+
1714
+ });
1715
+
1716
+ }
1717
+
1718
+
1719
+
1720
+ async function autoUpdatePlugin(pluginDef, pluginInfo) {
1721
+
1722
+ const versions = await fetchVersions();
1723
+
1724
+ if (!versions) {
1725
+ console.log("⚠️ versions.json not reachable");
1726
+ return false;
1727
+ }
1728
+
1729
+ const oldFullPath = path.join(srcDir, pluginInfo.name);
1730
+ const oldFileName = path.basename(oldFullPath);
1731
+
1732
+ //const oldFileName = path.basename(oldFullPath);
1733
+ const oldVersionFile = oldFileName;
1734
+
1735
+
1736
+ const ext = path.extname(oldFileName); // .js or .less
1737
+ //const baseName = oldFileName.replace(/-\d+\.\d+.*$/, "");
1738
+ const baseName = oldFileName.replace(/-\d+\.\d+.*$/, '').replace(/\.(js|less)$/, '');
1739
+
1740
+ // version lookup key
1741
+ let pluginKey = baseName;
1742
+
1743
+
1744
+ // Only common plugin has js and less variants
1745
+ if (baseName === "common") {
1746
+ if (ext === ".js") pluginKey = "common-js";
1747
+ if (ext === ".less") pluginKey = "common-less";
1748
+ }
1749
+
1750
+ const latestVersion = versions[pluginKey];
1751
+
1752
+ if (!latestVersion) {
1753
+ console.log(`❌ No version entry for ${baseName}`);
1754
+ return false;
1755
+ }
1756
+
1757
+ // ===============================
1758
+ // FOLDER PLUGIN UPDATE
1759
+ // ===============================
1760
+ if (pluginDef.isFolder) {
1761
+
1762
+ const zipName = `${baseName}-${latestVersion}.zip`;
1763
+ const url = `https://htmlcodeplay.com/code-play-plugin/${zipName}`;
1764
+
1765
+ const destRoot = path.join(srcDir, pluginDef.destDir || pluginDef.baseDir || '');
1766
+ const oldPath = path.join(destRoot, pluginInfo.name);
1767
+ const newPath = path.join(destRoot, `${baseName}-${latestVersion}`);
1768
+
1769
+ if (!(await urlExists(url))) return false;
1770
+
1771
+ fs.rmSync(oldPath, { recursive: true, force: true });
1772
+
1773
+ await downloadAndExtractZip(url, newPath);
1774
+
1775
+ updateImports(pluginInfo.name, `${baseName}-${latestVersion}`);
1776
+
1777
+ // ADD THIS
1778
+ writeUpdateLine(`${pluginInfo.name} -> ${baseName}-${latestVersion}`);
1779
+
1780
+ console.log(`✅ Folder updated → ${baseName}-${latestVersion}`);
1781
+
1782
+ return true;
1783
+ }
1784
+ // ===============================
1785
+ // FILE PLUGIN UPDATE
1786
+ // ===============================
1787
+
1788
+ const pluginDir = path.dirname(oldFullPath);
1789
+
1790
+ // Only this plugin has ios variant
1791
+ const IOS_VARIANT_PLUGINS = [
1792
+ "saveToGalleryAndSaveAnyFile"
1793
+ ];
1794
+
1795
+ /* let variants = [
1796
+ `${baseName}-${latestVersion}.js`
1797
+ ]; */
1798
+
1799
+ //const ext = path.extname(oldFileName);
1800
+ const variants = [`${baseName.replace(ext,'')}-${latestVersion}${ext}`];
1801
+
1802
+
1803
+ if (IOS_VARIANT_PLUGINS.includes(baseName)) {
1804
+ variants.push(`${baseName}-${latestVersion}-ios.js`);
1805
+ }
1806
+
1807
+ let downloaded = [];
1808
+
1809
+ // Download files
1810
+ for (const fileName of variants) {
1811
+
1812
+ const url = `https://htmlcodeplay.com/code-play-plugin/${fileName}`;
1813
+
1814
+ console.log(`🔍 Checking latest: ${fileName}`);
1815
+
1816
+ if (await urlExists(url)) {
1817
+
1818
+ const destPath = path.join(pluginDir, fileName);
1819
+
1820
+ await downloadFile(url, destPath);
1821
+
1822
+ downloaded.push(fileName);
1823
+
1824
+ console.log(`⬇ Downloaded ${fileName}`);
1825
+
1826
+ //writeUpdateLine(`Downloaded: ${fileName}`);
1827
+
1828
+ }
1829
+ }
1830
+
1831
+ if (downloaded.length === 0) {
1832
+ console.log(`❌ No files downloaded for ${baseName}`);
1833
+ return false;
1834
+ }
1835
+
1836
+ // Remove ONLY versioned files (safe)
1837
+ //const versionPattern = new RegExp(`^${baseName}-\\d+\\.\\d+(-ios)?\\.js$`);
1838
+ const versionPattern = new RegExp(`^${baseName}-\\d+\\.\\d+(-ios)?\\${ext}$`);
1839
+
1840
+ const existingFiles = fs.readdirSync(pluginDir);
1841
+
1842
+ existingFiles.forEach(file => {
1843
+
1844
+ if (
1845
+ versionPattern.test(file) &&
1846
+ !downloaded.includes(file)
1847
+ ) {
1848
+
1849
+ const oldPath = path.join(pluginDir, file);
1850
+
1851
+ fs.unlinkSync(oldPath);
1852
+
1853
+ console.log(`🗑 Removed old file → ${file}`);
1854
+ //writeUpdateLine(`Removed old file: ${file}`);
1855
+ }
1856
+
1857
+ });
1858
+
1859
+ //const newFileName = `${baseName}-${latestVersion}.js`;
1860
+ const newFileName = `${baseName}-${latestVersion}${ext}`;
1861
+
1862
+ writeUpdateLine(`${oldVersionFile} -> ${newFileName}`);
1863
+
1864
+ updateImports(oldFileName, newFileName);
1865
+ //updateImports(baseName, `${baseName}-${latestVersion}.js`);
1866
+ //updateImports(pluginInfo.name, `${baseName}-${latestVersion}`);
1867
+
1868
+ //console.log(`✅ Updated ${newFileName}`);
1869
+ //console.log(`✅ Updated → ${baseName}-${latestVersion}`);
1870
+
1871
+ return true;
1872
+ }
1873
+
1874
+
1875
+
1876
+
1877
+ /*############################################## AUTO DOWNLOAD FROM SERVER END #####################################*/
1878
+
1879
+
1880
+
1881
+
1882
+
1883
+
1884
+
1885
+
1886
+
1887
+
1888
+
1889
+
1890
+
1891
+
1892
+
1893
+
1894
+
1895
+
1896
+ async function loadPluginVersions() {
1897
+
1898
+ if (!USE_LIVE_SERVER_VERSION) {
1899
+ console.log("ℹ️ Using local plugin versions (offline mode).");
1900
+ return;
1901
+ }
1902
+
1903
+ console.log("🌐 Fetching plugin versions from server...");
1904
+
1905
+ const versions = await fetchVersions();
1906
+
1907
+ if (!versions || typeof versions !== "object") {
1908
+ console.log("⚠️ Server unavailable or invalid versions.json. Falling back to local versions.");
1909
+ return;
1910
+ }
1911
+
1912
+ requiredPlugins.forEach(plugin => {
1913
+
1914
+ if (!plugin.name) return;
1915
+
1916
+ if (versions[plugin.name]) {
1917
+ plugin.minVersion = versions[plugin.name];
1918
+ }
1919
+
1920
+ });
1921
+
1922
+ console.log("✅ Plugin versions loaded from server.");
1923
+
1924
+ }
1925
+
1926
+
1927
+
1928
+ let hasMandatoryUpdate = false;
1929
+ function checkPlugins() {
1930
+ return new Promise(async (resolve, reject) => {
1931
+ const files = walkSync(srcDir);
1932
+ const outdatedPlugins = [];
1933
+ let hasMandatoryUpdate = false;
1934
+
1935
+ for (const plugin of requiredPlugins) {
1936
+ const searchRoot = getSearchRoot(plugin);
1937
+
1938
+ // ---------- Folder plugins ----------
1939
+ if (plugin.isFolder) {
1940
+ if (!fs.existsSync(searchRoot)) continue;
1941
+
1942
+ const subDirs = fs.readdirSync(searchRoot)
1943
+ .map(name => path.join(searchRoot, name))
1944
+ .filter(p => fs.statSync(p).isDirectory());
1945
+
1946
+ for (const dir of subDirs) {
1947
+ const relativePath = path.relative(searchRoot, dir).replace(/\\/g, '/');
1948
+ const match = plugin.pattern.exec(relativePath);
1949
+
1950
+ if (match) {
1951
+ const currentVersion = match[1];
1952
+
1953
+ if (compareVersions(currentVersion, plugin.minVersion) < 0) {
1954
+ outdatedPlugins.push({
1955
+ name: relativePath,
1956
+ currentVersion,
1957
+ requiredVersion: plugin.minVersion,
1958
+ mandatoryUpdate: plugin.mandatoryUpdate === true
1959
+ });
1960
+
1961
+ if (plugin.mandatoryUpdate) {
1962
+ hasMandatoryUpdate = true;
1963
+ }
1964
+ }
1965
+ }
1966
+ }
1967
+ continue;
1968
+ }
1969
+
1970
+ // ---------- File plugins ----------
1971
+ const matchedFile = files.find(file =>
1972
+ file.startsWith(searchRoot) && plugin.pattern.test(file)
1973
+ );
1974
+
1975
+ if (matchedFile) {
1976
+ const match = plugin.pattern.exec(matchedFile);
1977
+ if (match) {
1978
+ const currentVersion = match[1];
1979
+ const isBeta = !!match[2];
1980
+
1981
+ const cmp = plugin.pattern.source.includes('beta')
1982
+ ? compareWithBeta(currentVersion, plugin.minVersion, isBeta)
1983
+ : compareVersions(currentVersion, plugin.minVersion);
1984
+
1985
+ if (cmp < 0) {
1986
+ outdatedPlugins.push({
1987
+ name: path.relative(srcDir, matchedFile),
1988
+ currentVersion: isBeta ? `${currentVersion}-beta` : currentVersion,
1989
+ requiredVersion: plugin.minVersion,
1990
+ mandatoryUpdate: plugin.mandatoryUpdate === true
1991
+ });
1992
+
1993
+ if (plugin.mandatoryUpdate) {
1994
+ hasMandatoryUpdate = true;
1995
+ }
1996
+ }
1997
+ }
1998
+ }
1999
+ }
2000
+
2001
+ // ---------- Result handling ----------
2002
+ if (outdatedPlugins.length > 0) {
2003
+ console.log('\n❗ The following plugins are outdated:\n');
2004
+
2005
+ outdatedPlugins.forEach( p => {
2006
+ const tag = p.mandatoryUpdate ? '🔥 MANDATORY' : '';
2007
+ console.log(
2008
+ ` ⚠️ - ${p.name} (Current: ${p.currentVersion}, Required: ${p.requiredVersion}) ${tag}`
2009
+ );
2010
+ });
2011
+
2012
+ // 🚨 Mandatory update → stop build
2013
+ /* if (hasMandatoryUpdate) {
2014
+ console.log('\n🚫 One or more plugins require a mandatory update.');
2015
+ console.log('❌ Build cancelled. Please update mandatory plugins and try again.');
2016
+ process.exit(1);
2017
+ } */
2018
+
2019
+
2020
+
2021
+
2022
+
2023
+ if (hasMandatoryUpdate) {
2024
+
2025
+ //--------------------------------------------------
2026
+ // 🚫 AUTO UPDATE DISABLED
2027
+ //--------------------------------------------------
2028
+ if (!ENABLE_AUTO_UPDATE) {
2029
+ console.log("\n🚫 Auto-update disabled.");
2030
+ console.log("❌ Manual update required.");
2031
+ process.exit(1);
2032
+ }
2033
+
2034
+ //--------------------------------------------------
2035
+ // 🔥 AUTO UPDATE ENABLED
2036
+ //--------------------------------------------------
2037
+ console.log("\n🔥 Mandatory plugins outdated. Trying auto-update...\n");
2038
+
2039
+
2040
+
2041
+ let autoFailed = false;
2042
+
2043
+ for (const p of outdatedPlugins.filter(x => x.mandatoryUpdate)) {
2044
+
2045
+ const pluginDef = requiredPlugins.find(def =>
2046
+ def.pattern.test(p.name)
2047
+ );
2048
+
2049
+ if (!pluginDef) continue;
2050
+
2051
+ const success = await autoUpdatePlugin(
2052
+ pluginDef,
2053
+ p
2054
+ );
2055
+
2056
+ if (!success) {
2057
+ autoFailed = true;
2058
+
2059
+ const pluginDef = requiredPlugins.find(def =>
2060
+ def.pattern.test(p.name)
2061
+ );
2062
+
2063
+ console.log(`❌ Manual update required for ${p.name}`);
2064
+
2065
+ if (pluginDef) {
2066
+ console.log(`👉 Required minimum version: ${pluginDef.minVersion}`);
2067
+ }
2068
+ }
2069
+ }
2070
+
2071
+ // 🚨 Fallback to manual if any failed
2072
+ if (autoFailed) {
2073
+ console.log('\n🚫 One or more plugins require manual update.');
2074
+ console.log('❌ Build cancelled. Please update mandatory plugins.');
2075
+ process.exit(1);
2076
+ }
2077
+
2078
+ console.log('\n🎉 All mandatory plugins auto-updated! Rechecking plugins...\n');
2079
+
2080
+ // Re-run plugin check so outdated list becomes empty
2081
+ await checkPlugins();
2082
+ return;
2083
+ }
2084
+
2085
+
2086
+
2087
+
2088
+
2089
+
2090
+ // Optional updates ask user
2091
+ const rl = readline.createInterface({
2092
+ input: process.stdin,
2093
+ output: process.stdout
2094
+ });
2095
+
2096
+ rl.question(
2097
+ '\nAre you sure you want to continue without updating these plugins? (y/n): ',
2098
+ answer => {
2099
+ rl.close();
2100
+
2101
+ if (answer.toLowerCase() !== 'y') {
2102
+ console.log('\n❌ Build cancelled due to outdated plugins.');
2103
+ process.exit(1);
2104
+ } else {
2105
+ console.log('\n✅ Continuing build...');
2106
+ resolve();
2107
+ }
2108
+ }
2109
+ );
2110
+ } else {
2111
+ console.log('✅ All plugin versions are up to date.');
2112
+ saveUpdateLogs();
2113
+ resolve();
2114
+ }
2115
+ });
2116
+ }
2117
+
2118
+
2119
+
2120
+
2121
+
2122
+
2123
+
2124
+
2125
+ // Check all the codeplays plugins version START
2126
+
2127
+
2128
+
2129
+
2130
+ // ====================================================================
2131
+ // AUTO-ADD esbuild.drop: ['console','debugger'] to vite.config.js / mjs
2132
+ // ====================================================================
2133
+
2134
+
2135
+
2136
+ const checkAndupdateDropInViteConfig = () => {
2137
+
2138
+ const possibleFiles = [
2139
+ "vite.config.js",
2140
+ "vite.config.mjs"
2141
+ ];
2142
+
2143
+ // Detect existing config file
2144
+ const viteConfigPath = possibleFiles
2145
+ .map(file => path.join(process.cwd(), file))
2146
+ .find(filePath => fs.existsSync(filePath));
2147
+
2148
+ if (!viteConfigPath) {
2149
+ console.warn("⚠️ No vite config found. Skipping.");
2150
+ return;
2151
+ }
2152
+
2153
+ //console.log("📄 Using:", viteConfigPath.split("/").pop());
2154
+
2155
+ let viteContent = fs.readFileSync(viteConfigPath, "utf8");
2156
+
2157
+ // Skip if already exists
2158
+ if (/drop\s*:\s*\[.*['"]console['"].*\]/.test(viteContent)) {
2159
+ console.log("ℹ️ vite.config.(m)js already Updated. Skipping...");
2160
+ return;
2161
+ }
2162
+
2163
+ console.log("🔧 Adding esbuild.drop ...");
2164
+
2165
+ // If esbuild block exists
2166
+ if (/esbuild\s*:\s*{/.test(viteContent)) {
2167
+ viteContent = viteContent.replace(
2168
+ /esbuild\s*:\s*{([\s\S]*?)(^ {0,8})}/m,
2169
+ (full, inner, indent) => {
2170
+
2171
+ let lines = inner
2172
+ .split("\n")
2173
+ .map(l => l.trim())
2174
+ .filter(Boolean);
2175
+
2176
+ // Fix last comma
2177
+ if (lines.length > 0) {
2178
+ lines[lines.length - 1] =
2179
+ lines[lines.length - 1].replace(/,+$/, "") + ",";
2180
+ }
2181
+
2182
+ // Re-indent
2183
+ lines = lines.map(l => indent + " " + l);
2184
+
2185
+ // Add drop
2186
+ lines.push(`${indent} drop: ['console','debugger'],`);
2187
+
2188
+ return `esbuild: {\n${lines.join("\n")}\n${indent}}`;
2189
+ }
2190
+ );
2191
+ }
2192
+
2193
+ // If esbuild missing
2194
+ else {
2195
+ viteContent = viteContent.replace(
2196
+ /export default defineConfig\s*\(\s*{/,
2197
+ m => `${m}\n esbuild: {\n drop: ['console','debugger'],\n },`
2198
+ );
2199
+ }
2200
+
2201
+ fs.writeFileSync(viteConfigPath, viteContent, "utf8");
2202
+ console.log("✅ vite.config.(m)js Updated successfully.");
2203
+ };
2204
+
2205
+
2206
+
2207
+
2208
+
2209
+
2210
+
2211
+
2212
+
2213
+
2214
+ const compareVersion = (v1, v2) => {
2215
+ const a = v1.split(".").map(Number);
2216
+ const b = v2.split(".").map(Number);
2217
+
2218
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
2219
+ const num1 = a[i] || 0;
2220
+ const num2 = b[i] || 0;
2221
+ if (num1 > num2) return 1;
2222
+ if (num1 < num2) return -1;
2223
+ }
2224
+ return 0;
2225
+ };
2226
+
2227
+
2228
+
2229
+
2230
+ const admobConfigPath = path.join('src', 'js','Ads', 'admob-ad-configuration.json');
2231
+
2232
+ const checkAdmobConfigurationProperty=()=>{
2233
+
2234
+
2235
+ if (!_admobConfig.ADMOB_ENABLED)
2236
+ {
2237
+ console.log("ℹ️ Admob is not enabled so 'admob-ad-configuration.json' checking is skipping...");
2238
+ return;
2239
+ }
2240
+
2241
+
2242
+ const REQUIRED_CONFIG_KEYS = [
2243
+ "isKidsApp",
2244
+ "isTesting",
2245
+ "isConsoleLogEnabled",
2246
+ "bannerEnabled",
2247
+ "interstitialEnabled",
2248
+ "appOpenEnabled",
2249
+ "rewardVideoEnabled",
2250
+ "rewardInterstitialEnabled",
2251
+ "collapsibleEnabled",
2252
+ "isLandScape",
2253
+ "isOverlappingEnable",
2254
+ "bannerTypeAndroid",
2255
+ "bannerTypeiOS",
2256
+ "bannerTopSpaceColor",
2257
+ "interstitialLoadScreenTextColor",
2258
+ "interstitialLoadScreenBackgroundColor",
2259
+ "beforeBannerSpace",
2260
+ "whenShow",
2261
+ "minimumClick",
2262
+ "interstitialTimeOut",
2263
+ "interstitialFirstTimeOut",
2264
+ "appOpenAdsTimeOut",
2265
+ "maxRetryCount",
2266
+ "retrySecondsAr",
2267
+ "appOpenPerSession",
2268
+ "interstitialPerSession",
2269
+ "appOpenFirstTimeOut"
2270
+ ];
2271
+
2272
+
2273
+
2274
+
2275
+
2276
+ let admobConfigInJson;
2277
+
2278
+ try {
2279
+ admobConfigInJson = JSON.parse(readFileSync(admobConfigPath, "utf8"));
2280
+ } catch (err) {
2281
+ console.error("❌ Failed to read admob-ad-configuration.json", err);
2282
+ process.exit(1);
2283
+ }
2284
+
2285
+ // ✅ Validate config object exists
2286
+ if (!admobConfigInJson.config) {
2287
+ console.error('❌ "config" object is missing in admob-ad-configuration.json');
2288
+ process.exit(1);
2289
+ }
2290
+
2291
+
2292
+ const admobConfigMinVersion="1.5"
2293
+
2294
+ if (compareVersion(admobConfigInJson.VERSION, admobConfigMinVersion) < 0) {
2295
+ console.error(`❌ Please use at-least version ${admobConfigMinVersion} in "src/js/Ads/admob-ad-configuration.json"`);
2296
+ process.exit(1);
2297
+ }
2298
+
2299
+
2300
+ const config = admobConfigInJson.config;
2301
+
2302
+ // ✅ Find missing properties
2303
+ const missingKeys = REQUIRED_CONFIG_KEYS.filter(
2304
+ key => !(key in config)
2305
+ );
2306
+
2307
+
2308
+
2309
+ if (missingKeys.length > 0) {
2310
+ console.error("❌ Missing required configuration keys. Please check it in 'src/js/Ads/admob-ad-configuration.json'");
2311
+
2312
+ missingKeys.forEach(k => console.error(" - " + k));
2313
+ process.exit(1);
2314
+ }
2315
+
2316
+
2317
+ console.log('✅ All keys exist. in "admob-ad-configuration.json file" Configuration looks good.');
2318
+ }
2319
+
2320
+
2321
+
2322
+ function ensureGitignoreEntry(entry) {
2323
+ const gitignorePath = path.join(process.cwd(), '.gitignore');
2324
+
2325
+ // If .gitignore doesn't exist, create it
2326
+ if (!fs.existsSync(gitignorePath)) {
2327
+ fs.writeFileSync(gitignorePath, `${entry}\n`, 'utf8');
2328
+ console.log(`✅ .gitignore created and added: ${entry}`);
2329
+ return;
2330
+ }
2331
+
2332
+ const content = fs.readFileSync(gitignorePath, 'utf8');
2333
+
2334
+ // Normalize lines (trim + remove trailing slashes for comparison)
2335
+ const lines = content
2336
+ .split(/\r?\n/)
2337
+ .map(l => l.trim());
2338
+
2339
+ const normalizedEntry = entry.replace(/\/$/, '');
2340
+
2341
+ const exists = lines.some(
2342
+ line => line.replace(/\/$/, '') === normalizedEntry
2343
+ );
2344
+
2345
+ if (exists) {
2346
+ console.log(`ℹ️ .gitignore already contains: ${entry}`);
2347
+ return;
2348
+ }
2349
+
2350
+ // Ensure file ends with newline
2351
+ const separator = content.endsWith('\n') ? '' : '\n';
2352
+
2353
+ fs.appendFileSync(gitignorePath, `${separator}${entry}\n`, 'utf8');
2354
+ console.log(`✅ Added to .gitignore: ${entry}`);
2355
+ }
2356
+
2357
+
2358
+ ensureGitignoreEntry('buildCodeplay/');
2359
+
2360
+
2361
+ // Run the validation
2362
+ (async () => {
2363
+
2364
+ await loadPluginVersions(); // 🔥 NEW
2365
+
2366
+ await checkPlugins();
2367
+ checkAndupdateDropInViteConfig();
2368
+ checkAdmobConfigurationProperty()
2369
+ })();
2370
+
2371
+
2372
+ // ======================================================
2373
+ // Validate theme folder location (src/js/theme is NOT allowed)
2374
+ // ======================================================
2375
+
2376
+ function validateThemeFolderLocation() {
2377
+ const oldThemePath = path.join(process.cwd(), 'src', 'js', 'theme');
2378
+ const newThemePath = path.join(process.cwd(), 'src', 'theme');
2379
+
2380
+ // ❌ Block old structure
2381
+ if (fs.existsSync(oldThemePath)) {
2382
+ console.error(
2383
+ '\n❌ INVALID PROJECT STRUCTURE DETECTED\n' +
2384
+ '--------------------------------------------------\n' +
2385
+ 'The "theme" folder must NOT be inside:\n' +
2386
+ ' src/js/theme\n\n' +
2387
+ '✅ Correct location is:\n' +
2388
+ ' src/theme\n\n' +
2389
+ '🛑 Please move the folder and re-run the build.\n'
2390
+ );
2391
+ process.exit(1);
2392
+ }
2393
+
2394
+ // ⚠️ Optional warning if new theme folder is missing
2395
+ if (!fs.existsSync(newThemePath)) {
2396
+ console.warn(
2397
+ '\n⚠️ WARNING: "src/theme" folder not found.\n' +
2398
+ 'If your app uses themes, please ensure it exists.\n'
2399
+ );
2400
+ } else {
2401
+ console.log('✅ Theme folder structure validated (src/theme).');
2402
+ }
2403
+ }
2404
+ validateThemeFolderLocation()
2405
+
2406
+
2407
+
2408
+ const validateAndRestoreSignDetails=()=>{
2409
+
2410
+ // Read config file
2411
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
2412
+
2413
+ // Ensure android and buildOptions exist
2414
+ if (!config.android) config.android = {};
2415
+ if (!config.android.buildOptions) config.android.buildOptions = {};
2416
+
2417
+ // Update only if changed
2418
+ let updated = false;
2419
+
2420
+ if (config.android.buildOptions.releaseType !== 'AAB') {
2421
+ config.android.buildOptions.releaseType = 'AAB';
2422
+ updated = true;
2423
+ }
2424
+
2425
+ if (config.android.buildOptions.signingType !== 'jarsigner') {
2426
+ config.android.buildOptions.signingType = 'jarsigner';
2427
+ updated = true;
2428
+ }
2429
+
2430
+ // Write back only if modified
2431
+ if (updated) {
2432
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
2433
+ console.log('capacitor.config.json updated successfully.');
2434
+ } else {
2435
+ console.log('No changes needed.');
2436
+ }
2437
+
2438
+ }
2439
+
2440
+ validateAndRestoreSignDetails()
2441
+
2442
+
2443
+ execSync('node buildCodeplay/fix-onesignal-plugin.js', { stdio: 'inherit' });
2444
+
2445
+
2446
+
2447
+
2448
+
2449
+
2450
+
2451
+ //################################## SystemBars.java update for "@capacitor/android": "^8.3.0" plugin START ###############################
2452
+
2453
+
2454
+ const filePath = path.join(
2455
+ __dirname,
2456
+ "../node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/plugin/SystemBars.java"
2457
+ );
2458
+
2459
+ // 🔍 OLD BLOCK (anchor)
2460
+ const OLD_BLOCK = `if (shouldPassthroughInsets) {
2461
+ // We need to correct for a possible shown IME
2462
+ v.setPadding(0, 0, 0, keyboardVisible ? imeInsets.bottom : 0);
2463
+
2464
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM && hasViewportCover && insetHandlingEnabled) {
2465
+ Insets safeAreaInsets = calcSafeAreaInsets(insets);
2466
+ injectSafeAreaCSS(safeAreaInsets.top, safeAreaInsets.right, safeAreaInsets.bottom, safeAreaInsets.left);
2467
+ }
2468
+
2469
+ return new WindowInsetsCompat.Builder(insets)
2470
+ .setInsets(
2471
+ WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout(),
2472
+ Insets.of(
2473
+ systemBarsInsets.left,
2474
+ systemBarsInsets.top,
2475
+ systemBarsInsets.right,
2476
+ getBottomInset(systemBarsInsets, keyboardVisible)
2477
+ )
2478
+ )
2479
+ .build();
2480
+ }`;
2481
+
2482
+ // ✅ NEW BLOCK
2483
+ const NEW_BLOCK = `if (shouldPassthroughInsets) {
2484
+ /* 🔴 ORIGINAL CODE (COMMENTED FOR SAFETY)
2485
+ ${OLD_BLOCK.split("\n").map(line => " " + line).join("\n")}
2486
+ */
2487
+
2488
+ // ✅ NEW LOGIC (CUSTOM FIX)
2489
+ v.setPadding(0, 0, 0, 0);
2490
+
2491
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM && hasViewportCover && insetHandlingEnabled) {
2492
+ Insets safeAreaInsets = calcSafeAreaInsets(insets);
2493
+ injectSafeAreaCSS(safeAreaInsets.top, safeAreaInsets.right, safeAreaInsets.bottom, safeAreaInsets.left);
2494
+ }
2495
+
2496
+ return insets; // WebView handles everything
2497
+ }`;
2498
+
2499
+ // 🚨 ERROR MESSAGE
2500
+ const ERROR_MSG = `
2501
+ ❌ Capacitor SystemBars.java structure changed!
2502
+
2503
+ Plugin: @capacitor/android
2504
+ Path : node_modules\@capacitor\android\capacitor\src\main\java\com\getcapacitor\plugin\SystemBars.java
2505
+
2506
+ Check version of "@capacitor/android": in package.json
2507
+
2508
+ 👉 Expected code block not found.
2509
+
2510
+ This usually means Capacitor updated internally.
2511
+
2512
+ Please:
2513
+ 1. Open SystemBars.java
2514
+ 2. Update patch script
2515
+ 3. Re-run build
2516
+
2517
+ ⛔ Build stopped.
2518
+ `;
2519
+
2520
+ function patchFile() {
2521
+ if (!fs.existsSync(filePath)) {
2522
+ console.error("❌ SystemBars.java not found!");
2523
+ process.exit(1);
2524
+ }
2525
+
2526
+ let content = fs.readFileSync(filePath, "utf8");
2527
+
2528
+ // ✅ Already patched?
2529
+ if (content.includes("🔴 ORIGINAL CODE (COMMENTED FOR SAFETY)")) {
2530
+ console.log("✅ Already SystemBars.java patched. Skipping...");
2531
+ return;
2532
+ }
2533
+
2534
+ // 🔍 Check old block exists
2535
+ if (!content.includes(OLD_BLOCK)) {
2536
+ console.error(ERROR_MSG);
2537
+ process.exit(1);
2538
+ }
2539
+
2540
+ // 🔁 Replace
2541
+ const updated = content.replace(OLD_BLOCK, NEW_BLOCK);
2542
+
2543
+ fs.writeFileSync(filePath, updated, "utf8");
2544
+
2545
+ console.log("✅ SystemBars.java patched (comment + new logic)!");
2546
+ }
2547
+
2548
+ patchFile();
2549
+
2550
+ //################################## SystemBars.java update for "@capacitor/android": "^8.3.0" plugin END ###############################
2551
+
2552
+
2553
+
2554
+
2555
+ /*
2556
+ Release Notes
2557
+
2558
+ 5.1
2559
+ Kotlin version update is commented. Previously admob is not worked if not update the kotlin version to higher version
2560
+
2236
2561
  */