codeplay-common 2.1.12 → 2.1.14

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,1231 +1,1231 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const plist = require('plist');
4
-
5
- const { readFileSync } = require("fs");
6
-
7
-
8
-
9
- const configPath = path.join(process.cwd(), 'capacitor.config.json');
10
-
11
- // Expected plugin list with minimum versions
12
- const requiredPlugins = [
13
- { pattern: /backbutton-(\d+\.\d+)\.js$/, minVersion: '1.6', required: true, baseDir: 'js' },
14
- { pattern: /common-(\d+\.\d+)\.js$/, minVersion: '5.1', required: true, baseDir: 'js' },
15
- { pattern: /localization_settings-(\d+\.\d+)\.js$/, minVersion: '1.1', required: true, baseDir: 'js' },
16
- { pattern: /localization-(\d+\.\d+)\.js$/, minVersion: '1.3', required: true, baseDir: 'js' },
17
- { pattern: /localNotification-(\d+\.\d+)\.js$/, minVersion: '2.2', required: true, baseDir: 'js' },
18
- { pattern: /localNotification_AppSettings-(\d+\.\d+)\.js$/, minVersion: '1.0', required: true, baseDir: 'js' },
19
- { pattern: /onesignal-(\d+\.\d+)\.js$/, minVersion: '2.2', required: true, baseDir: 'js' },
20
- { pattern: /saveToGalleryAndSaveAnyFile-(\d+\.\d+)(-ios)?\.js$/, minVersion: '3.0', required: true, baseDir: 'js' },
21
- { pattern: /Ads[\/\\]IAP-(\d+\.\d+)$/, minVersion: '2.5', isFolder: true , required: true, baseDir: 'js' },
22
- { pattern: /Ads[\/\\]admob-emi-(\d+\.\d+)\.js$/, minVersion: '3.3', required: true, baseDir: 'js' },
23
-
24
- // New added plugins
25
- { pattern: /video-player-(\d+\.\d+)\.js$/, minVersion: '1.5', required: true, baseDir: 'js' },
26
- { pattern: /image-cropper-(\d+\.\d+)\.js$/, minVersion: '1.1', required: true, baseDir: 'js' },
27
-
28
- { pattern: /common-(\d+\.\d+)\.less$/, minVersion: '1.4', required: true, baseDir: 'assets/css' },
29
-
30
-
31
- // New folders
32
- { pattern: /editor-(\d+\.\d+)$/, minVersion: '1.8', isFolder: true, required: true, baseDir: 'js' },
33
- { pattern: /ffmpeg-(\d+\.\d+)$/, minVersion: '1.3', isFolder: true, required: true, baseDir: 'js' },
34
- { pattern: /theme-(\d+\.\d+)$/, minVersion: '1.3', isFolder: true , required: true, baseDir: 'js' }
35
- ];
36
-
37
-
38
-
39
-
40
-
41
-
42
- //Check codeplay-common latest version installed or not Start
43
- const { execSync } = require('child_process');
44
-
45
- function getInstalledVersion(packageName) {
46
- try {
47
- const packageJsonPath = path.join(process.cwd(), 'node_modules', packageName, 'package.json');
48
- if (fs.existsSync(packageJsonPath)) {
49
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
50
- return packageJson.version;
51
- }
52
- } catch (error) {
53
- return null;
54
- }
55
- return null;
56
- }
57
-
58
- function getLatestVersion(packageName) {
59
- try {
60
- return execSync(`npm view ${packageName} version`).toString().trim();
61
- } catch (error) {
62
- console.error(`Failed to fetch latest version for ${packageName}`);
63
- return null;
64
- }
65
- }
66
-
67
- function checkPackageVersion() {
68
- const packageName = 'codeplay-common';
69
- const installedVersion = getInstalledVersion(packageName);
70
- const latestVersion = getLatestVersion(packageName);
71
-
72
- if (!installedVersion) {
73
- console.error(`${packageName} is not installed. Please install it using "npm install ${packageName}".`);
74
- process.exit(1);
75
- }
76
-
77
- if (installedVersion !== latestVersion) {
78
- 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`);
79
- process.exit(1);
80
- }
81
-
82
- console.log(`${packageName} is up to date (version ${installedVersion}).`);
83
- }
84
-
85
- // Run package version check before executing the main script
86
- try {
87
- checkPackageVersion();
88
- } catch (error) {
89
- console.error(error.message);
90
- process.exit(1);
91
- }
92
-
93
- //Check codeplay-common latest version installed or not END
94
-
95
-
96
-
97
-
98
-
99
-
100
- const checkAppUniqueId=()=>{
101
-
102
- const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
103
-
104
- const appUniqueId = config.android?.APP_UNIQUE_ID;
105
- const RESIZEABLE_ACTIVITY = config.android?.RESIZEABLE_ACTIVITY;
106
- const orientation = config.android?.ORIENTATION;
107
-
108
-
109
- let logErrorMessage="";
110
-
111
- // 1️⃣ Check if it’s missing
112
- if (RESIZEABLE_ACTIVITY === undefined) {
113
- logErrorMessage+='❌ Missing android.RESIZEABLE_ACTIVITY option in capacitor.config.json.\n';
114
- }
115
-
116
- // 2️⃣ Check if it’s not boolean (true/false only)
117
- else if (typeof RESIZEABLE_ACTIVITY !== 'boolean') {
118
- logErrorMessage+='❌ Invalid android.RESIZEABLE_ACTIVITY value. Please use only true or false (without quotes).\n';
119
- }
120
-
121
-
122
-
123
- if (!orientation) {
124
- logErrorMessage+='❌ Missing android.ORIENTATION option in capacitor.config.json.\n';
125
- }
126
-
127
- else if(orientation!="portrait" && orientation!="landscape" && orientation!="auto")
128
- {
129
- logErrorMessage+='❌ Spelling mistake in android.ORIENTATION option in capacitor.config.json. Please use only ["portrait" "landscape" "auto"]\n';
130
- }
131
-
132
-
133
- if (!appUniqueId) {
134
- logErrorMessage+='❌ APP_UNIQUE_ID is missing in capacitor.config.json.';
135
- }
136
-
137
- else if (!Number.isInteger(appUniqueId)) {
138
- logErrorMessage+='❌ APP_UNIQUE_ID must be an integer. Example: 1, 2, 3, etc.';
139
- }
140
-
141
-
142
-
143
- if(logErrorMessage!="")
144
- {
145
- console.error(logErrorMessage);
146
- process.exit(1)
147
- }
148
-
149
-
150
- console.log(`✅ APP_UNIQUE_ID is valid: ${appUniqueId}`);
151
-
152
- }
153
-
154
- checkAppUniqueId();
155
-
156
-
157
-
158
-
159
-
160
-
161
-
162
- //@Codemirror check and install/uninstall the packages START
163
- //const fs = require("fs");
164
- //const path = require("path");
165
- //const { execSync } = require("child_process");
166
-
167
- const baseDir = path.join(__dirname, "..", "src", "js");
168
-
169
- // Step 1: Find highest versioned folder like `editor-1.6`
170
- const editorDirs = fs.readdirSync(baseDir)
171
- .filter(name => /^editor-\d+\.\d+$/.test(name))
172
- .sort((a, b) => {
173
- const getVersion = str => str.match(/(\d+)\.(\d+)/).slice(1).map(Number);
174
- const [aMajor, aMinor] = getVersion(a);
175
- const [bMajor, bMinor] = getVersion(b);
176
- return bMajor - aMajor || bMinor - aMinor;
177
- });
178
-
179
- if (editorDirs.length === 0) {
180
-
181
- console.log("@Codemirror used editor(s) are not found")
182
- //console.error("❌ No editor-x.x folders found in src/js.");
183
- //process.exit(1);
184
- }
185
- else
186
- {
187
-
188
- const latestEditorDir = editorDirs.sort((a, b) => {
189
- const versionA = parseFloat(a.split('-')[1]);
190
- const versionB = parseFloat(b.split('-')[1]);
191
- return versionB - versionA;
192
- })[0];
193
-
194
- //const latestEditorDir = editorDirs[editorDirs.length - 1];
195
- const runJsPath = path.join(baseDir, latestEditorDir, "run.js");
196
-
197
- if (!fs.existsSync(runJsPath)) {
198
- console.error(`❌ run.js not found in ${latestEditorDir}`);
199
- process.exit(1);
200
- }
201
-
202
- // Step 2: Execute the run.js file
203
- console.log(`🚀 Executing ${runJsPath}...`);
204
- execSync(`node "${runJsPath}"`, { stdio: "inherit" });
205
- }
206
-
207
- //@Codemirror check and install/uninstall the packages END
208
-
209
-
210
-
211
-
212
-
213
-
214
-
215
-
216
-
217
-
218
-
219
-
220
- // saveToGalleryAndSaveAnyFile-x.x-ios.js file check for android and return error if exists START
221
-
222
- const os = require('os');
223
-
224
- const saveToGalleryAndSaveFileCheck_iOS = () => {
225
-
226
- // List of paths to scan
227
- const SCAN_PATHS = [
228
- path.resolve(__dirname, '../src/certificate'),
229
- path.resolve(__dirname, '../src/pages'),
230
- path.resolve(__dirname, '../src/js'),
231
- path.resolve(__dirname, '../src/app.f7')
232
- ];
233
-
234
- // Directory to exclude
235
- const EXCLUDED_DIR = path.resolve(__dirname, '../src/js/Ads');
236
-
237
- const ANDROID_MANIFEST_PATH = path.resolve(__dirname, '../android/app/src/main/AndroidManifest.xml');
238
-
239
-
240
- // Match iOS-specific imports (e.g., saveToGalleryAndSaveAnyFile-2.5-ios.js) not in comments
241
- const IOS_FILE_REGEX = /^(?!\s*\/\/).*['"](?:.*\/)?saveToGalleryAndSaveAnyFile-\d+(\.\d+)*-ios\.js['"]/m;
242
-
243
- // Match Android-specific imports (e.g., saveToGalleryAndSaveAnyFile-2.5.js) not in comments
244
- const ANDROID_FILE_REGEX = /^(?!\s*\/\/).*['"](?:.*\/)?saveToGalleryAndSaveAnyFile-\d+(\.\d+)*\.js['"]/m;
245
-
246
-
247
-
248
-
249
-
250
- const ALLOWED_EXTENSIONS = ['.js', '.f7'];
251
- const isMac = os.platform() === 'darwin';
252
-
253
- let iosImportFound = false;
254
- let androidImportFound = false;
255
-
256
- // Files to skip completely (full or partial match)
257
- const SKIP_FILES = [
258
- 'pdf-3.11.174.min.js',
259
- 'pdf.worker-3.11.174.min.js'
260
- ,'index.browser.js'
261
- ];
262
-
263
-
264
- function scanDirectory(dir) {
265
-
266
- /*
267
- //######################### DO NOT DELETE THIS - START [Appid base validation] #####################################
268
- const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
269
- const appUniqueId = config.android?.APP_UNIQUE_ID;
270
- if (appUniqueId == "206") return;
271
- //######################### DO NOT DELETE THIS - END [Appid base validation] #####################################
272
- */
273
-
274
- const stat = fs.statSync(dir);
275
-
276
- if (stat.isFile()) {
277
-
278
- // 🔥 Skip files in SKIP_FILES array
279
- const baseName = path.basename(dir);
280
- if (SKIP_FILES.includes(baseName)) {
281
- // Just skip silently
282
- return;
283
- }
284
-
285
- // Only scan allowed file extensions
286
- if (ALLOWED_EXTENSIONS.some(ext => dir.endsWith(ext))) {
287
- process.stdout.write(`\r🔍 Scanning: ${dir} `);
288
-
289
- const content = fs.readFileSync(dir, 'utf8');
290
-
291
- if (IOS_FILE_REGEX.test(content)) {
292
- iosImportFound = true;
293
- if (!isMac) {
294
- console.error(`\n❌ ERROR: iOS-specific import detected in: ${dir}`);
295
- console.error(`🚫 STOPPED: This file should not be imported in Android/Windows/Linux builds.\n`);
296
- process.exit(1);
297
- }
298
- }
299
- else if (ANDROID_FILE_REGEX.test(content) && !content.includes('-ios.js')) {
300
- androidImportFound = true;
301
- }
302
- }
303
- }
304
- else if (stat.isDirectory()) {
305
- if (dir === EXCLUDED_DIR || path.basename(dir) === 'node_modules') return;
306
-
307
- const entries = fs.readdirSync(dir, { withFileTypes: true });
308
- for (let entry of entries) {
309
- scanDirectory(path.join(dir, entry.name));
310
- }
311
- }
312
- }
313
-
314
-
315
- // Run scan on all specified paths
316
- for (let scanPath of SCAN_PATHS) {
317
- if (fs.existsSync(scanPath)) {
318
- scanDirectory(scanPath);
319
- }
320
- }
321
-
322
-
323
-
324
- /* // Check src folder
325
- if (!fs.existsSync(ROOT_DIR)) {
326
- console.warn(`⚠️ Warning: 'src' directory not found at: ${ROOT_DIR}`);
327
- return;
328
- } */
329
-
330
- //scanDirectory(ROOT_DIR);
331
-
332
- // iOS Checks
333
- if (isMac && !iosImportFound) {
334
- console.warn(`⚠️ WARNING: You're on macOS but no iOS version (saveToGalleryAndSaveAnyFile-x.x-ios.js) found.`);
335
- process.exit(1);
336
- } else if (isMac && iosImportFound) {
337
- console.log('✅ iOS version detected for macOS build.');
338
- } else if (!iosImportFound) {
339
- console.log('✅ No iOS-specific imports detected for non-macOS.');
340
- }
341
-
342
- // Android Checks
343
- if (androidImportFound) {
344
- console.log("📱 Android version of saveToGalleryAndSaveAnyFile detected. Checking AndroidManifest.xml...");
345
-
346
- if (!fs.existsSync(ANDROID_MANIFEST_PATH)) {
347
- console.error("❌ AndroidManifest.xml not found. Cannot add requestLegacyExternalStorage attribute.");
348
- return;
349
- }
350
-
351
- let manifestContent = fs.readFileSync(ANDROID_MANIFEST_PATH, 'utf8');
352
-
353
- if (!manifestContent.includes('android:requestLegacyExternalStorage="true"')) {
354
- console.log("Adding android:requestLegacyExternalStorage=\"true\" to <application> tag...");
355
-
356
- manifestContent = manifestContent.replace(
357
- /<application([^>]*)>/,
358
- (match, attrs) => {
359
- if (attrs.includes('android:requestLegacyExternalStorage')) return match;
360
- return `<application${attrs} android:requestLegacyExternalStorage="true">`;
361
- }
362
- );
363
-
364
- fs.writeFileSync(ANDROID_MANIFEST_PATH, manifestContent, 'utf8');
365
- console.log("✅ android:requestLegacyExternalStorage=\"true\" added successfully.");
366
- } else {
367
- console.log("ℹ️ android:requestLegacyExternalStorage already exists in AndroidManifest.xml.");
368
- }
369
- } else {
370
- console.log("✅ No Android saveToGalleryAndSaveAnyFile imports detected.");
371
- }
372
- };
373
-
374
- saveToGalleryAndSaveFileCheck_iOS();
375
- // saveToGalleryAndSaveAnyFile-x.x-ios.js file check for android and return error if exists END
376
-
377
-
378
-
379
-
380
-
381
-
382
-
383
-
384
-
385
-
386
-
387
-
388
-
389
- /*
390
- // Clean up AppleDouble files (._*) created by macOS START
391
- if (process.platform === 'darwin') {
392
- try {
393
- console.log('🧹 Cleaning up AppleDouble files (._*)...');
394
- execSync(`find . -name '._*' -delete`);
395
- console.log('✅ AppleDouble files removed.');
396
- } catch (err) {
397
- console.warn('⚠️ Failed to remove AppleDouble files:', err.message);
398
- }
399
- } else {
400
- console.log('ℹ️ Skipping AppleDouble cleanup — not a macOS machine.');
401
- }
402
-
403
- // Clean up AppleDouble files (._*) created by macOS END
404
- */
405
-
406
-
407
-
408
-
409
-
410
-
411
- //In routes.js file check static import START
412
-
413
- const routesPath = path.join(process.cwd(), 'src', 'js', 'routes.js');
414
- const routesContent = fs.readFileSync(routesPath, 'utf-8');
415
-
416
- let inBlockComment = false;
417
- const lines = routesContent.split('\n');
418
-
419
- const allowedImport = `import HomePage from '../pages/home.f7';`;
420
- const badImportRegex = /^[ \t]*import\s+[\w{}*,\s]*\s+from\s+['"].+\.f7['"]\s*;/;
421
- const badImports = [];
422
-
423
- lines.forEach((line, index) => {
424
- const trimmed = line.trim();
425
-
426
- // Handle block comment start and end
427
- if (trimmed.startsWith('/*')) inBlockComment = true;
428
- if (inBlockComment && trimmed.endsWith('*/')) {
429
- inBlockComment = false;
430
- return;
431
- }
432
-
433
- // Skip if inside block comment or line comment
434
- if (inBlockComment || trimmed.startsWith('//')) return;
435
-
436
- // Match static .f7 import
437
- if (badImportRegex.test(trimmed) && trimmed !== allowedImport) {
438
- badImports.push({ line: trimmed, number: index + 1 });
439
- }
440
- });
441
-
442
- if (badImports.length > 0) {
443
- console.error('\n❌ ERROR: Detected disallowed static imports of .f7 files in routes.js\n');
444
- console.error(`⚠️ Only this static import is allowed:\n ${allowedImport}\n`);
445
- console.error(`🔧 Please convert other imports to async dynamic imports like this:\n`);
446
- console.error(`
447
-
448
- import HomePage from '../pages/home.f7';
449
-
450
- const routes = [
451
- {
452
- path: '/',
453
- component:HomePage,
454
- },
455
- {
456
- path: '/ProfilePage/',
457
- async async({ resolve }) {
458
- const page = await import('../pages/profile.f7');
459
- resolve({ component: page.default });
460
- },
461
- }]
462
- `);
463
-
464
- badImports.forEach(({ line, number }) => {
465
- console.error(`${number}: ${line}`);
466
- });
467
-
468
- process.exit(1);
469
- } else {
470
- console.log('✅ routes.js passed the .f7 import check.');
471
- }
472
-
473
- //In routes.js file check static import END
474
-
475
-
476
-
477
-
478
-
479
-
480
-
481
-
482
-
483
-
484
-
485
-
486
-
487
- // Check and change the "BridgeWebViewClient.java" file START
488
- /*
489
- For crash issue due to low memory problem, we need to modify the onRenderProcessGone method in BridgeWebViewClient.java.
490
- */
491
-
492
-
493
- const bridgeWebViewClientFilePath = path.join(process.cwd(), 'node_modules', '@capacitor/android/capacitor/src/main/java/com/getcapacitor', 'BridgeWebViewClient.java');
494
-
495
- // Read the file
496
- if (!fs.existsSync(bridgeWebViewClientFilePath)) {
497
- console.error('❌ Error: BridgeWebViewClient.java not found.');
498
- process.exit(1);
499
- }
500
-
501
- let fileContent = fs.readFileSync(bridgeWebViewClientFilePath, 'utf8');
502
-
503
- // Define old and new code
504
- const oldCodeStart = `@Override
505
- public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) {
506
- super.onRenderProcessGone(view, detail);
507
- boolean result = false;
508
-
509
- List<WebViewListener> webViewListeners = bridge.getWebViewListeners();
510
- if (webViewListeners != null) {
511
- for (WebViewListener listener : bridge.getWebViewListeners()) {
512
- result = listener.onRenderProcessGone(view, detail) || result;
513
- }
514
- }
515
-
516
- return result;
517
- }`;
518
-
519
- const newCode = `@Override
520
- public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) {
521
- super.onRenderProcessGone(view, detail);
522
-
523
- boolean result = false;
524
-
525
- List<WebViewListener> webViewListeners = bridge.getWebViewListeners();
526
- if (webViewListeners != null) {
527
- for (WebViewListener listener : bridge.getWebViewListeners()) {
528
- result = listener.onRenderProcessGone(view, detail) || result;
529
- }
530
- }
531
-
532
- if (!result) {
533
- // If no one handled it, handle it ourselves!
534
-
535
- /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
536
- if (detail.didCrash()) {
537
- //Log.e("CapacitorWebView", "WebView crashed internally!");
538
- } else {
539
- //Log.w("CapacitorWebView", "WebView was killed by system (low memory) internally!");
540
- }
541
- }*/
542
-
543
- view.post(() -> {
544
- Toast.makeText(view.getContext(), "Reloading due to low memory issue", Toast.LENGTH_SHORT).show();
545
- });
546
-
547
- view.reload(); // Safely reload WebView
548
-
549
- return true; // We handled it
550
- }
551
-
552
- return result;
553
- }`;
554
-
555
- // Step 1: Update method if needed
556
- let updated = false;
557
-
558
- if (fileContent.includes(oldCodeStart)) {
559
- console.log('✅ Found old onRenderProcessGone method. Replacing it...');
560
- fileContent = fileContent.replace(oldCodeStart, newCode);
561
- updated = true;
562
- } else if (fileContent.includes(newCode)) {
563
- console.log('ℹ️ Method already updated. No changes needed in "BridgeWebViewClient.java".');
564
- } else {
565
- console.error('❌ Error: Neither old nor new code found. Unexpected content.');
566
- process.exit(1);
567
- }
568
-
569
- // Step 2: Check and add import if missing
570
- const importToast = 'import android.widget.Toast;';
571
- if (!fileContent.includes(importToast)) {
572
- console.log('✅ Adding missing import for Toast...');
573
- const importRegex = /import\s+[^;]+;/g;
574
- const matches = [...fileContent.matchAll(importRegex)];
575
-
576
- if (matches.length > 0) {
577
- const lastImport = matches[matches.length - 1];
578
- const insertPosition = lastImport.index + lastImport[0].length;
579
- fileContent = fileContent.slice(0, insertPosition) + `\n${importToast}` + fileContent.slice(insertPosition);
580
- updated = true;
581
- } else {
582
- console.error('❌ Error: No import section found in file.');
583
- process.exit(1);
584
- }
585
- } else {
586
- console.log('ℹ️ Import for Toast already exists. No changes needed.');
587
- }
588
-
589
- // Step 3: Save if updated
590
- if (updated) {
591
- fs.writeFileSync(bridgeWebViewClientFilePath, fileContent, 'utf8');
592
- console.log('✅ File updated successfully.');
593
- } else {
594
- console.log('ℹ️ No changes needed.');
595
- }
596
-
597
-
598
-
599
-
600
- // Check and change the "BridgeWebViewClient.java" file END
601
-
602
-
603
-
604
-
605
-
606
-
607
-
608
-
609
- /*
610
- // To resolve the kotlin version issue, we need to update the kotlin version in the build.gradle file START
611
-
612
- // Build the path dynamically like you requested
613
- const gradlePath = path.join(
614
- process.cwd(),
615
- 'android',
616
- 'build.gradle'
617
- );
618
-
619
- // Read the existing build.gradle
620
- let gradleContent = fs.readFileSync(gradlePath, 'utf8');
621
-
622
- // Add `ext.kotlin_version` if it's not already there
623
- if (!gradleContent.includes('ext.kotlin_version')) {
624
- gradleContent = gradleContent.replace(
625
- /buildscript\s*{/,
626
- `buildscript {\n ext.kotlin_version = '2.1.0'`
627
- );
628
- }
629
-
630
- // Add Kotlin classpath if it's not already there
631
- if (!gradleContent.includes('org.jetbrains.kotlin:kotlin-gradle-plugin')) {
632
- gradleContent = gradleContent.replace(
633
- /dependencies\s*{([\s\S]*?)classpath 'com.android.tools.build:gradle:8.7.2'/,
634
- `dependencies {\n classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")\n$1classpath 'com.android.tools.build:gradle:8.7.2'`
635
- );
636
- }
637
-
638
- // Write back the modified content
639
- fs.writeFileSync(gradlePath, gradleContent, 'utf8');
640
-
641
- console.log('✅ Kotlin version updated in build.gradle.');
642
-
643
- // To resolve the kotlin version issue, we need to update the kotlin version in the build.gradle file END
644
- */
645
-
646
-
647
-
648
-
649
-
650
-
651
-
652
-
653
- let _admobConfig;
654
-
655
-
656
-
657
- const androidPlatformPath = path.join(process.cwd(), 'android');
658
- const iosPlatformPath = path.join(process.cwd(), 'ios');
659
- const pluginPath = path.join(process.cwd(), 'node_modules', 'emi-indo-cordova-plugin-admob', 'plugin.xml');
660
- const infoPlistPath = path.join(process.cwd(), 'ios', 'App', 'App', 'Info.plist');
661
- const resourcesPath = path.join(process.cwd(), 'resources', 'res');
662
- const androidResPath = path.join(process.cwd(), 'android', 'app', 'src', 'main', 'res');
663
- const localNotificationsPluginPath = path.join(process.cwd(), 'node_modules', '@capacitor', 'local-notifications');
664
-
665
- function fileExists(filePath) {
666
- return fs.existsSync(filePath);
667
- }
668
-
669
- function copyFolderSync(source, target) {
670
- if (!fs.existsSync(target)) {
671
- fs.mkdirSync(target, { recursive: true });
672
- }
673
-
674
- fs.readdirSync(source).forEach(file => {
675
- const sourceFile = path.join(source, file);
676
- const targetFile = path.join(target, file);
677
-
678
- if (fs.lstatSync(sourceFile).isDirectory()) {
679
- copyFolderSync(sourceFile, targetFile);
680
- } else {
681
- fs.copyFileSync(sourceFile, targetFile);
682
- }
683
- });
684
- }
685
-
686
- function checkAndCopyResources() {
687
- if (fileExists(resourcesPath)) {
688
- copyFolderSync(resourcesPath, androidResPath);
689
- console.log('✅ Successfully copied resources/res to android/app/src/main/res.');
690
- } else {
691
- console.log('resources/res folder not found.');
692
-
693
- if (fileExists(localNotificationsPluginPath)) {
694
- throw new Error('❌ resources/res is required for @capacitor/local-notifications. Stopping execution.');
695
- }
696
- }
697
- }
698
-
699
-
700
-
701
-
702
-
703
-
704
-
705
-
706
- function getAdMobConfig() {
707
- if (!fileExists(configPath)) {
708
- throw new Error('❌ capacitor.config.json not found. Ensure this is a Capacitor project.');
709
- }
710
-
711
- const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
712
- const admobConfig = config.plugins?.AdMob;
713
-
714
- if (!admobConfig) {
715
- throw new Error('❌ AdMob configuration is missing in capacitor.config.json.');
716
- }
717
-
718
- // Default to true if ADMOB_ENABLED is not specified
719
- const isEnabled = admobConfig.ADMOB_ENABLED !== false;
720
-
721
- if (!isEnabled) {
722
- return { ADMOB_ENABLED: false }; // Skip further validation
723
- }
724
-
725
- if (!admobConfig.APP_ID_ANDROID || !admobConfig.APP_ID_IOS) {
726
- throw new Error(' ❌ AdMob configuration is incomplete. Ensure APP_ID_ANDROID and APP_ID_IOS are defined.');
727
- }
728
-
729
- return {
730
- ADMOB_ENABLED: true,
731
- APP_ID_ANDROID: admobConfig.APP_ID_ANDROID,
732
- APP_ID_IOS: admobConfig.APP_ID_IOS,
733
- USE_LITE_ADS: admobConfig.USE_LITE_ADS === "lite",
734
- };
735
- }
736
-
737
- function validateAndroidBuildOptions() {
738
-
739
-
740
- if (!fileExists(configPath)) {
741
- console.log('❌ capacitor.config.json not found. Ensure this is a Capacitor project.');
742
- process.exit(1);
743
- }
744
-
745
- const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
746
-
747
- const targetAppId=config.appId
748
-
749
- const buildOptions = config.android?.buildOptions;
750
-
751
- if (!buildOptions) {
752
- console.log('❌ Missing android.buildOptions in capacitor.config.json.');
753
- process.exit(1);
754
- }
755
-
756
- const requiredProps = [
757
- 'keystorePath',
758
- 'keystorePassword',
759
- 'keystoreAlias',
760
- 'keystoreAliasPassword',
761
- 'releaseType',
762
- 'signingType'
763
- ];
764
-
765
- const missing = requiredProps.filter(prop => !buildOptions[prop]);
766
-
767
- if (missing.length > 0) {
768
- console.log('❌ Missing properties android.buildOptions in capacitor.config.json.');
769
- process.exit(1);
770
- }
771
-
772
-
773
- const keystorePath=buildOptions.keystorePath
774
- const keyFileName = path.basename(keystorePath);
775
-
776
-
777
-
778
- const keystoreMap = {
779
- "gameskey.jks": [
780
- "com.cube.blaster",
781
- ],
782
- "htmleditorkeystoke.jks": [
783
- "com.HTML.AngularJS.Codeplay",
784
- "com.html.codeplay.pro",
785
- "com.bootstrap.code.play",
786
- "com.kids.learning.master",
787
- "com.Simple.Barcode.Scanner"
788
- ]
789
- };
790
-
791
- // find which keystore is required for the given targetAppId
792
- let requiredKey = "newappskey.jks"; // default
793
- for (const [keyFile, appIds] of Object.entries(keystoreMap)) {
794
- if (appIds.includes(targetAppId)) {
795
- requiredKey = keyFile;
796
- break;
797
- }
798
- }
799
-
800
- // validate
801
- if (keyFileName !== requiredKey) {
802
- console.log(`❌ The keystore path is mismatched. Expected ${requiredKey} for ${targetAppId}, but got ${keyFileName}`);
803
- process.exit(1);
804
- }
805
-
806
-
807
-
808
-
809
-
810
- // optionally return them
811
- //return buildOptions;
812
- }
813
-
814
- function updatePluginXml(admobConfig) {
815
- if (!fileExists(pluginPath)) {
816
- console.error(' ❌ plugin.xml not found. Ensure the plugin is installed.');
817
- return;
818
- }
819
-
820
- let pluginContent = fs.readFileSync(pluginPath, 'utf8');
821
-
822
- pluginContent = pluginContent
823
- .replace(/<preference name="APP_ID_ANDROID" default=".*?" \/>/, `<preference name="APP_ID_ANDROID" default="${admobConfig.APP_ID_ANDROID}" />`)
824
- .replace(/<preference name="APP_ID_IOS" default=".*?" \/>/, `<preference name="APP_ID_IOS" default="${admobConfig.APP_ID_IOS}" />`);
825
-
826
- fs.writeFileSync(pluginPath, pluginContent, 'utf8');
827
- console.log('✅ AdMob IDs successfully updated in plugin.xml');
828
- }
829
-
830
- function updateInfoPlist(admobConfig) {
831
- if (!fileExists(infoPlistPath)) {
832
- console.error(' ❌ Info.plist not found. Ensure you have built the iOS project.');
833
- return;
834
- }
835
-
836
- const plistContent = fs.readFileSync(infoPlistPath, 'utf8');
837
- const plistData = plist.parse(plistContent);
838
-
839
- plistData.GADApplicationIdentifier = admobConfig.APP_ID_IOS;
840
- plistData.NSUserTrackingUsageDescription = 'This identifier will be used to deliver personalized ads to you.';
841
- plistData.GADDelayAppMeasurementInit = true;
842
-
843
- const updatedPlistContent = plist.build(plistData);
844
- fs.writeFileSync(infoPlistPath, updatedPlistContent, 'utf8');
845
- console.log('AdMob IDs and additional configurations successfully updated in Info.plist');
846
- }
847
-
848
-
849
- try {
850
- if (!fileExists(configPath)) {
851
- throw new Error(' ❌ capacitor.config.json not found. Skipping setup.');
852
- }
853
-
854
- if (!fileExists(androidPlatformPath) && !fileExists(iosPlatformPath)) {
855
- throw new Error('Neither Android nor iOS platforms are found. Ensure platforms are added to your Capacitor project.');
856
- }
857
-
858
- checkAndCopyResources();
859
-
860
-
861
-
862
- _admobConfig = getAdMobConfig();
863
-
864
-
865
-
866
-
867
-
868
- // Proceed only if ADMOB_ENABLED is true
869
- if (_admobConfig.ADMOB_ENABLED) {
870
- if (fileExists(androidPlatformPath)) {
871
- updatePluginXml(_admobConfig);
872
- }
873
-
874
- if (fileExists(iosPlatformPath)) {
875
- updateInfoPlist(_admobConfig);
876
- }
877
- }
878
-
879
-
880
- } catch (error) {
881
- console.error(error.message);
882
- process.exit(1); // Stop execution if there's a critical error
883
- }
884
-
885
-
886
-
887
- validateAndroidBuildOptions();
888
-
889
-
890
-
891
-
892
-
893
-
894
- // Check all the codeplays plugins version START
895
-
896
-
897
- const readline = require('readline');
898
-
899
-
900
- //const srcDir = path.join(__dirname, 'src');
901
- const srcDir = path.join(process.cwd(), 'src');
902
- let outdatedPlugins = [];
903
-
904
- function parseVersion(ver) {
905
- return ver.split('.').map(n => parseInt(n, 10));
906
- }
907
-
908
- function compareVersions(v1, v2) {
909
- const [a1, b1] = parseVersion(v1);
910
- const [a2, b2] = parseVersion(v2);
911
- if (a1 !== a2) return a1 - a2;
912
- return b1 - b2;
913
- }
914
-
915
- function walkSync(dir, filelist = []) {
916
- fs.readdirSync(dir).forEach(file => {
917
- const fullPath = path.join(dir, file);
918
- const stat = fs.statSync(fullPath);
919
- if (stat.isDirectory()) {
920
- walkSync(fullPath, filelist);
921
- } else {
922
- filelist.push(fullPath);
923
- }
924
- });
925
- return filelist;
926
- }
927
-
928
-
929
-
930
- function getSearchRoot(plugin) {
931
- return path.join(srcDir, plugin.baseDir || 'js');
932
- }
933
-
934
- function checkPlugins() {
935
- const files = walkSync(srcDir);
936
-
937
- for (const plugin of requiredPlugins) {
938
-
939
- const searchRoot = getSearchRoot(plugin);
940
-
941
- // ---------- FOLDER PLUGINS ----------
942
- if (plugin.isFolder) {
943
-
944
- if (!fs.existsSync(searchRoot)) continue;
945
-
946
- const subDirs = fs.readdirSync(searchRoot)
947
- .map(name => path.join(searchRoot, name))
948
- .filter(p => fs.statSync(p).isDirectory());
949
-
950
- for (const dir of subDirs) {
951
- const relativePath = path
952
- .relative(searchRoot, dir)
953
- .replace(/\\/g, '/');
954
-
955
- const match = plugin.pattern.exec(relativePath);
956
- if (match) {
957
- const currentVersion = match[1];
958
- if (compareVersions(currentVersion, plugin.minVersion) < 0) {
959
- outdatedPlugins.push({
960
- name: relativePath,
961
- currentVersion,
962
- requiredVersion: plugin.minVersion
963
- });
964
- }
965
- }
966
- }
967
- continue;
968
- }
969
-
970
- // ---------- FILE PLUGINS ----------
971
- const matchedFile = files.find(file =>
972
- file.startsWith(searchRoot) && plugin.pattern.test(file)
973
- );
974
-
975
- if (matchedFile) {
976
- const match = plugin.pattern.exec(matchedFile);
977
- if (match) {
978
- const currentVersion = match[1];
979
- if (compareVersions(currentVersion, plugin.minVersion) < 0) {
980
- outdatedPlugins.push({
981
- name: path.relative(srcDir, matchedFile),
982
- currentVersion,
983
- requiredVersion: plugin.minVersion
984
- });
985
- }
986
- }
987
- }
988
- }
989
-
990
-
991
- if (outdatedPlugins.length > 0) {
992
- console.log('\n❗ The following plugins are outdated:');
993
- outdatedPlugins.forEach(p => {
994
- console.log(` ❌ - ${p.name} (Current: ${p.currentVersion}, Required: ${p.requiredVersion})`);
995
- });
996
-
997
- const rl = readline.createInterface({
998
- input: process.stdin,
999
- output: process.stdout
1000
- });
1001
-
1002
- rl.question('\nAre you sure you want to continue without updating these plugins? (y/n): ', answer => {
1003
- if (answer.toLowerCase() !== 'y') {
1004
- console.log('\n❌ Build cancelled due to outdated plugins.');
1005
- process.exit(1);
1006
- } else {
1007
- console.log('\n✅ Continuing build...');
1008
- rl.close();
1009
- }
1010
- });
1011
- } else {
1012
- console.log('✅ All plugin versions are up to date.');
1013
- }
1014
- }
1015
-
1016
-
1017
- // Run the validation
1018
- checkPlugins();
1019
-
1020
-
1021
-
1022
-
1023
- // Check all the codeplays plugins version START
1024
-
1025
-
1026
-
1027
-
1028
- // ====================================================================
1029
- // AUTO-ADD esbuild.drop: ['console','debugger'] to vite.config.js / mjs
1030
- // ====================================================================
1031
-
1032
-
1033
-
1034
- const checkAndupdateDropInViteConfig = () => {
1035
-
1036
- const possibleFiles = [
1037
- "vite.config.js",
1038
- "vite.config.mjs"
1039
- ];
1040
-
1041
- // Detect existing config file
1042
- const viteConfigPath = possibleFiles
1043
- .map(file => path.join(process.cwd(), file))
1044
- .find(filePath => fs.existsSync(filePath));
1045
-
1046
- if (!viteConfigPath) {
1047
- console.warn("⚠️ No vite config found. Skipping.");
1048
- return;
1049
- }
1050
-
1051
- //console.log("📄 Using:", viteConfigPath.split("/").pop());
1052
-
1053
- let viteContent = fs.readFileSync(viteConfigPath, "utf8");
1054
-
1055
- // Skip if already exists
1056
- if (/drop\s*:\s*\[.*['"]console['"].*\]/.test(viteContent)) {
1057
- console.log("ℹ️ vite.config.(m)js already Updated. Skipping...");
1058
- return;
1059
- }
1060
-
1061
- console.log("🔧 Adding esbuild.drop ...");
1062
-
1063
- // If esbuild block exists
1064
- if (/esbuild\s*:\s*{/.test(viteContent)) {
1065
- viteContent = viteContent.replace(
1066
- /esbuild\s*:\s*{([\s\S]*?)(^ {0,8})}/m,
1067
- (full, inner, indent) => {
1068
-
1069
- let lines = inner
1070
- .split("\n")
1071
- .map(l => l.trim())
1072
- .filter(Boolean);
1073
-
1074
- // Fix last comma
1075
- if (lines.length > 0) {
1076
- lines[lines.length - 1] =
1077
- lines[lines.length - 1].replace(/,+$/, "") + ",";
1078
- }
1079
-
1080
- // Re-indent
1081
- lines = lines.map(l => indent + " " + l);
1082
-
1083
- // Add drop
1084
- lines.push(`${indent} drop: ['console','debugger'],`);
1085
-
1086
- return `esbuild: {\n${lines.join("\n")}\n${indent}}`;
1087
- }
1088
- );
1089
- }
1090
-
1091
- // If esbuild missing
1092
- else {
1093
- viteContent = viteContent.replace(
1094
- /export default defineConfig\s*\(\s*{/,
1095
- m => `${m}\n esbuild: {\n drop: ['console','debugger'],\n },`
1096
- );
1097
- }
1098
-
1099
- fs.writeFileSync(viteConfigPath, viteContent, "utf8");
1100
- console.log("✅ vite.config.(m)js Updated successfully.");
1101
- };
1102
-
1103
- checkAndupdateDropInViteConfig();
1104
-
1105
-
1106
-
1107
-
1108
-
1109
-
1110
-
1111
-
1112
- const compareVersion = (v1, v2) => {
1113
- const a = v1.split(".").map(Number);
1114
- const b = v2.split(".").map(Number);
1115
-
1116
- for (let i = 0; i < Math.max(a.length, b.length); i++) {
1117
- const num1 = a[i] || 0;
1118
- const num2 = b[i] || 0;
1119
- if (num1 > num2) return 1;
1120
- if (num1 < num2) return -1;
1121
- }
1122
- return 0;
1123
- };
1124
-
1125
-
1126
-
1127
-
1128
- const admobConfigPath = path.join('src', 'js','Ads', 'admob-ad-configuration.json');
1129
-
1130
- const checkAdmobConfigurationProperty=()=>{
1131
-
1132
-
1133
- if (!_admobConfig.ADMOB_ENABLED)
1134
- {
1135
- console.log("ℹ️ Admob is not enabled so 'admob-ad-configuration.json' checking is skipping...");
1136
- return;
1137
- }
1138
-
1139
-
1140
- const REQUIRED_CONFIG_KEYS = [
1141
- "isKidsApp",
1142
- "isTesting",
1143
- "isConsoleLogEnabled",
1144
- "bannerEnabled",
1145
- "interstitialEnabled",
1146
- "appOpenEnabled",
1147
- "rewardVideoEnabled",
1148
- "rewardInterstitialEnabled",
1149
- "collapsibleEnabled",
1150
- "isLandScape",
1151
- "overlappingHeight",
1152
- "isOverlappingEnable",
1153
- "bannerTypeAndroid",
1154
- "bannerTypeiOS",
1155
- "bannerTopSpaceColor",
1156
- "interstitialLoadScreenTextColor",
1157
- "interstitialLoadScreenBackgroundColor",
1158
- "beforeBannerSpace",
1159
- "whenShow",
1160
- "minimumClick",
1161
- "interstitialTimeOut",
1162
- "interstitialFirstTimeOut",
1163
- "appOpenAdsTimeOut",
1164
- "maxRetryCount",
1165
- "retrySecondsAr",
1166
- "appOpenPerSession",
1167
- "interstitialPerSession",
1168
- "appOpenFirstTimeOut"
1169
- ];
1170
-
1171
-
1172
-
1173
-
1174
-
1175
- let admobConfigInJson;
1176
-
1177
- try {
1178
- admobConfigInJson = JSON.parse(readFileSync(admobConfigPath, "utf8"));
1179
- } catch (err) {
1180
- console.error("❌ Failed to read admob-ad-configuration.json", err);
1181
- process.exit(1);
1182
- }
1183
-
1184
- // ✅ Validate config object exists
1185
- if (!admobConfigInJson.config) {
1186
- console.error('❌ "config" object is missing in admob-ad-configuration.json');
1187
- process.exit(1);
1188
- }
1189
-
1190
-
1191
- const admobConfigMinVersion="1.4"
1192
-
1193
- if (compareVersion(admobConfigInJson.VERSION, admobConfigMinVersion) < 0) {
1194
- console.error(`❌ Please use at-least version ${admobConfigMinVersion} in "src/js/Ads/admob-ad-configuration.json"`);
1195
- process.exit(1);
1196
- }
1197
-
1198
-
1199
- const config = admobConfigInJson.config;
1200
-
1201
- // ✅ Find missing properties
1202
- const missingKeys = REQUIRED_CONFIG_KEYS.filter(
1203
- key => !(key in config)
1204
- );
1205
-
1206
-
1207
-
1208
- if (missingKeys.length > 0) {
1209
- console.error("❌ Missing required configuration keys. Please check it in 'src/js/Ads/admob-ad-configuration.json'");
1210
-
1211
- missingKeys.forEach(k => console.error(" - " + k));
1212
- process.exit(1);
1213
- }
1214
-
1215
-
1216
- console.log('✅ All keys exist. in "admob-ad-configuration.json file" Configuration looks good.');
1217
- }
1218
-
1219
-
1220
- checkAdmobConfigurationProperty()
1221
-
1222
-
1223
-
1224
-
1225
- /*
1226
- Release Notes
1227
-
1228
- 5.1
1229
- Kotlin version update is commented. Previously admob is not worked if not update the kotlin version to higher version
1230
-
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const plist = require('plist');
4
+
5
+ const { readFileSync } = require("fs");
6
+
7
+
8
+
9
+ const configPath = path.join(process.cwd(), 'capacitor.config.json');
10
+
11
+ // Expected plugin list with minimum versions
12
+ const requiredPlugins = [
13
+ { pattern: /backbutton-(\d+\.\d+)\.js$/, minVersion: '1.6', required: true, baseDir: 'js' },
14
+ { pattern: /common-(\d+\.\d+)\.js$/, minVersion: '5.2', required: true, baseDir: 'js' },
15
+ { pattern: /localization_settings-(\d+\.\d+)\.js$/, minVersion: '1.1', required: true, baseDir: 'js' },
16
+ { pattern: /localization-(\d+\.\d+)\.js$/, minVersion: '1.3', required: true, baseDir: 'js' },
17
+ { pattern: /localNotification-(\d+\.\d+)\.js$/, minVersion: '2.2', required: true, baseDir: 'js' },
18
+ { pattern: /localNotification_AppSettings-(\d+\.\d+)\.js$/, minVersion: '1.0', required: true, baseDir: 'js' },
19
+ { pattern: /onesignal-(\d+\.\d+)\.js$/, minVersion: '2.2', required: true, baseDir: 'js' },
20
+ { pattern: /saveToGalleryAndSaveAnyFile-(\d+\.\d+)(-ios)?\.js$/, minVersion: '3.0', required: true, baseDir: 'js' },
21
+ { pattern: /Ads[\/\\]IAP-(\d+\.\d+)$/, minVersion: '2.5', isFolder: true , required: true, baseDir: 'js' },
22
+ { pattern: /Ads[\/\\]admob-emi-(\d+\.\d+)\.js$/, minVersion: '3.3', required: true, baseDir: 'js' },
23
+
24
+ // New added plugins
25
+ { pattern: /video-player-(\d+\.\d+)\.js$/, minVersion: '1.5', required: true, baseDir: 'js' },
26
+ { pattern: /image-cropper-(\d+\.\d+)\.js$/, minVersion: '1.1', required: true, baseDir: 'js' },
27
+
28
+ { pattern: /common-(\d+\.\d+)\.less$/, minVersion: '1.4', required: true, baseDir: 'assets/css' },
29
+
30
+
31
+ // New folders
32
+ { pattern: /editor-(\d+\.\d+)$/, minVersion: '1.8', isFolder: true, required: true, baseDir: 'js' },
33
+ { pattern: /ffmpeg-(\d+\.\d+)$/, minVersion: '1.3', isFolder: true, required: true, baseDir: 'js' },
34
+ { pattern: /theme-(\d+\.\d+)$/, minVersion: '1.6', isFolder: true , required: true, baseDir: 'js' }
35
+ ];
36
+
37
+
38
+
39
+
40
+
41
+
42
+ //Check codeplay-common latest version installed or not Start
43
+ const { execSync } = require('child_process');
44
+
45
+ function getInstalledVersion(packageName) {
46
+ try {
47
+ const packageJsonPath = path.join(process.cwd(), 'node_modules', packageName, 'package.json');
48
+ if (fs.existsSync(packageJsonPath)) {
49
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
50
+ return packageJson.version;
51
+ }
52
+ } catch (error) {
53
+ return null;
54
+ }
55
+ return null;
56
+ }
57
+
58
+ function getLatestVersion(packageName) {
59
+ try {
60
+ return execSync(`npm view ${packageName} version`).toString().trim();
61
+ } catch (error) {
62
+ console.error(`Failed to fetch latest version for ${packageName}`);
63
+ return null;
64
+ }
65
+ }
66
+
67
+ function checkPackageVersion() {
68
+ const packageName = 'codeplay-common';
69
+ const installedVersion = getInstalledVersion(packageName);
70
+ const latestVersion = getLatestVersion(packageName);
71
+
72
+ if (!installedVersion) {
73
+ console.error(`${packageName} is not installed. Please install it using "npm install ${packageName}".`);
74
+ process.exit(1);
75
+ }
76
+
77
+ if (installedVersion !== latestVersion) {
78
+ 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`);
79
+ process.exit(1);
80
+ }
81
+
82
+ console.log(`${packageName} is up to date (version ${installedVersion}).`);
83
+ }
84
+
85
+ // Run package version check before executing the main script
86
+ try {
87
+ checkPackageVersion();
88
+ } catch (error) {
89
+ console.error(error.message);
90
+ process.exit(1);
91
+ }
92
+
93
+ //Check codeplay-common latest version installed or not END
94
+
95
+
96
+
97
+
98
+
99
+
100
+ const checkAppUniqueId=()=>{
101
+
102
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
103
+
104
+ const appUniqueId = config.android?.APP_UNIQUE_ID;
105
+ const RESIZEABLE_ACTIVITY = config.android?.RESIZEABLE_ACTIVITY;
106
+ const orientation = config.android?.ORIENTATION;
107
+
108
+
109
+ let logErrorMessage="";
110
+
111
+ // 1️⃣ Check if it’s missing
112
+ if (RESIZEABLE_ACTIVITY === undefined) {
113
+ logErrorMessage+='❌ Missing android.RESIZEABLE_ACTIVITY option in capacitor.config.json.\n';
114
+ }
115
+
116
+ // 2️⃣ Check if it’s not boolean (true/false only)
117
+ else if (typeof RESIZEABLE_ACTIVITY !== 'boolean') {
118
+ logErrorMessage+='❌ Invalid android.RESIZEABLE_ACTIVITY value. Please use only true or false (without quotes).\n';
119
+ }
120
+
121
+
122
+
123
+ if (!orientation) {
124
+ logErrorMessage+='❌ Missing android.ORIENTATION option in capacitor.config.json.\n';
125
+ }
126
+
127
+ else if(orientation!="portrait" && orientation!="landscape" && orientation!="auto")
128
+ {
129
+ logErrorMessage+='❌ Spelling mistake in android.ORIENTATION option in capacitor.config.json. Please use only ["portrait" "landscape" "auto"]\n';
130
+ }
131
+
132
+
133
+ if (!appUniqueId) {
134
+ logErrorMessage+='❌ APP_UNIQUE_ID is missing in capacitor.config.json.';
135
+ }
136
+
137
+ else if (!Number.isInteger(appUniqueId)) {
138
+ logErrorMessage+='❌ APP_UNIQUE_ID must be an integer. Example: 1, 2, 3, etc.';
139
+ }
140
+
141
+
142
+
143
+ if(logErrorMessage!="")
144
+ {
145
+ console.error(logErrorMessage);
146
+ process.exit(1)
147
+ }
148
+
149
+
150
+ console.log(`✅ APP_UNIQUE_ID is valid: ${appUniqueId}`);
151
+
152
+ }
153
+
154
+ checkAppUniqueId();
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+ //@Codemirror check and install/uninstall the packages START
163
+ //const fs = require("fs");
164
+ //const path = require("path");
165
+ //const { execSync } = require("child_process");
166
+
167
+ const baseDir = path.join(__dirname, "..", "src", "js");
168
+
169
+ // Step 1: Find highest versioned folder like `editor-1.6`
170
+ const editorDirs = fs.readdirSync(baseDir)
171
+ .filter(name => /^editor-\d+\.\d+$/.test(name))
172
+ .sort((a, b) => {
173
+ const getVersion = str => str.match(/(\d+)\.(\d+)/).slice(1).map(Number);
174
+ const [aMajor, aMinor] = getVersion(a);
175
+ const [bMajor, bMinor] = getVersion(b);
176
+ return bMajor - aMajor || bMinor - aMinor;
177
+ });
178
+
179
+ if (editorDirs.length === 0) {
180
+
181
+ console.log("@Codemirror used editor(s) are not found")
182
+ //console.error("❌ No editor-x.x folders found in src/js.");
183
+ //process.exit(1);
184
+ }
185
+ else
186
+ {
187
+
188
+ const latestEditorDir = editorDirs.sort((a, b) => {
189
+ const versionA = parseFloat(a.split('-')[1]);
190
+ const versionB = parseFloat(b.split('-')[1]);
191
+ return versionB - versionA;
192
+ })[0];
193
+
194
+ //const latestEditorDir = editorDirs[editorDirs.length - 1];
195
+ const runJsPath = path.join(baseDir, latestEditorDir, "run.js");
196
+
197
+ if (!fs.existsSync(runJsPath)) {
198
+ console.error(`❌ run.js not found in ${latestEditorDir}`);
199
+ process.exit(1);
200
+ }
201
+
202
+ // Step 2: Execute the run.js file
203
+ console.log(`🚀 Executing ${runJsPath}...`);
204
+ execSync(`node "${runJsPath}"`, { stdio: "inherit" });
205
+ }
206
+
207
+ //@Codemirror check and install/uninstall the packages END
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+ // saveToGalleryAndSaveAnyFile-x.x-ios.js file check for android and return error if exists START
221
+
222
+ const os = require('os');
223
+
224
+ const saveToGalleryAndSaveFileCheck_iOS = () => {
225
+
226
+ // List of paths to scan
227
+ const SCAN_PATHS = [
228
+ path.resolve(__dirname, '../src/certificate'),
229
+ path.resolve(__dirname, '../src/pages'),
230
+ path.resolve(__dirname, '../src/js'),
231
+ path.resolve(__dirname, '../src/app.f7')
232
+ ];
233
+
234
+ // Directory to exclude
235
+ const EXCLUDED_DIR = path.resolve(__dirname, '../src/js/Ads');
236
+
237
+ const ANDROID_MANIFEST_PATH = path.resolve(__dirname, '../android/app/src/main/AndroidManifest.xml');
238
+
239
+
240
+ // Match iOS-specific imports (e.g., saveToGalleryAndSaveAnyFile-2.5-ios.js) not in comments
241
+ const IOS_FILE_REGEX = /^(?!\s*\/\/).*['"](?:.*\/)?saveToGalleryAndSaveAnyFile-\d+(\.\d+)*-ios\.js['"]/m;
242
+
243
+ // Match Android-specific imports (e.g., saveToGalleryAndSaveAnyFile-2.5.js) not in comments
244
+ const ANDROID_FILE_REGEX = /^(?!\s*\/\/).*['"](?:.*\/)?saveToGalleryAndSaveAnyFile-\d+(\.\d+)*\.js['"]/m;
245
+
246
+
247
+
248
+
249
+
250
+ const ALLOWED_EXTENSIONS = ['.js', '.f7'];
251
+ const isMac = os.platform() === 'darwin';
252
+
253
+ let iosImportFound = false;
254
+ let androidImportFound = false;
255
+
256
+ // Files to skip completely (full or partial match)
257
+ const SKIP_FILES = [
258
+ 'pdf-3.11.174.min.js',
259
+ 'pdf.worker-3.11.174.min.js'
260
+ ,'index.browser.js'
261
+ ];
262
+
263
+
264
+ function scanDirectory(dir) {
265
+
266
+ /*
267
+ //######################### DO NOT DELETE THIS - START [Appid base validation] #####################################
268
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
269
+ const appUniqueId = config.android?.APP_UNIQUE_ID;
270
+ if (appUniqueId == "206") return;
271
+ //######################### DO NOT DELETE THIS - END [Appid base validation] #####################################
272
+ */
273
+
274
+ const stat = fs.statSync(dir);
275
+
276
+ if (stat.isFile()) {
277
+
278
+ // 🔥 Skip files in SKIP_FILES array
279
+ const baseName = path.basename(dir);
280
+ if (SKIP_FILES.includes(baseName)) {
281
+ // Just skip silently
282
+ return;
283
+ }
284
+
285
+ // Only scan allowed file extensions
286
+ if (ALLOWED_EXTENSIONS.some(ext => dir.endsWith(ext))) {
287
+ process.stdout.write(`\r🔍 Scanning: ${dir} `);
288
+
289
+ const content = fs.readFileSync(dir, 'utf8');
290
+
291
+ if (IOS_FILE_REGEX.test(content)) {
292
+ iosImportFound = true;
293
+ if (!isMac) {
294
+ console.error(`\n❌ ERROR: iOS-specific import detected in: ${dir}`);
295
+ console.error(`🚫 STOPPED: This file should not be imported in Android/Windows/Linux builds.\n`);
296
+ process.exit(1);
297
+ }
298
+ }
299
+ else if (ANDROID_FILE_REGEX.test(content) && !content.includes('-ios.js')) {
300
+ androidImportFound = true;
301
+ }
302
+ }
303
+ }
304
+ else if (stat.isDirectory()) {
305
+ if (dir === EXCLUDED_DIR || path.basename(dir) === 'node_modules') return;
306
+
307
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
308
+ for (let entry of entries) {
309
+ scanDirectory(path.join(dir, entry.name));
310
+ }
311
+ }
312
+ }
313
+
314
+
315
+ // Run scan on all specified paths
316
+ for (let scanPath of SCAN_PATHS) {
317
+ if (fs.existsSync(scanPath)) {
318
+ scanDirectory(scanPath);
319
+ }
320
+ }
321
+
322
+
323
+
324
+ /* // Check src folder
325
+ if (!fs.existsSync(ROOT_DIR)) {
326
+ console.warn(`⚠️ Warning: 'src' directory not found at: ${ROOT_DIR}`);
327
+ return;
328
+ } */
329
+
330
+ //scanDirectory(ROOT_DIR);
331
+
332
+ // iOS Checks
333
+ if (isMac && !iosImportFound) {
334
+ console.warn(`⚠️ WARNING: You're on macOS but no iOS version (saveToGalleryAndSaveAnyFile-x.x-ios.js) found.`);
335
+ process.exit(1);
336
+ } else if (isMac && iosImportFound) {
337
+ console.log('✅ iOS version detected for macOS build.');
338
+ } else if (!iosImportFound) {
339
+ console.log('✅ No iOS-specific imports detected for non-macOS.');
340
+ }
341
+
342
+ // Android Checks
343
+ if (androidImportFound) {
344
+ console.log("📱 Android version of saveToGalleryAndSaveAnyFile detected. Checking AndroidManifest.xml...");
345
+
346
+ if (!fs.existsSync(ANDROID_MANIFEST_PATH)) {
347
+ console.error("❌ AndroidManifest.xml not found. Cannot add requestLegacyExternalStorage attribute.");
348
+ return;
349
+ }
350
+
351
+ let manifestContent = fs.readFileSync(ANDROID_MANIFEST_PATH, 'utf8');
352
+
353
+ if (!manifestContent.includes('android:requestLegacyExternalStorage="true"')) {
354
+ console.log("Adding android:requestLegacyExternalStorage=\"true\" to <application> tag...");
355
+
356
+ manifestContent = manifestContent.replace(
357
+ /<application([^>]*)>/,
358
+ (match, attrs) => {
359
+ if (attrs.includes('android:requestLegacyExternalStorage')) return match;
360
+ return `<application${attrs} android:requestLegacyExternalStorage="true">`;
361
+ }
362
+ );
363
+
364
+ fs.writeFileSync(ANDROID_MANIFEST_PATH, manifestContent, 'utf8');
365
+ console.log("✅ android:requestLegacyExternalStorage=\"true\" added successfully.");
366
+ } else {
367
+ console.log("ℹ️ android:requestLegacyExternalStorage already exists in AndroidManifest.xml.");
368
+ }
369
+ } else {
370
+ console.log("✅ No Android saveToGalleryAndSaveAnyFile imports detected.");
371
+ }
372
+ };
373
+
374
+ saveToGalleryAndSaveFileCheck_iOS();
375
+ // saveToGalleryAndSaveAnyFile-x.x-ios.js file check for android and return error if exists END
376
+
377
+
378
+
379
+
380
+
381
+
382
+
383
+
384
+
385
+
386
+
387
+
388
+
389
+ /*
390
+ // Clean up AppleDouble files (._*) created by macOS START
391
+ if (process.platform === 'darwin') {
392
+ try {
393
+ console.log('🧹 Cleaning up AppleDouble files (._*)...');
394
+ execSync(`find . -name '._*' -delete`);
395
+ console.log('✅ AppleDouble files removed.');
396
+ } catch (err) {
397
+ console.warn('⚠️ Failed to remove AppleDouble files:', err.message);
398
+ }
399
+ } else {
400
+ console.log('ℹ️ Skipping AppleDouble cleanup — not a macOS machine.');
401
+ }
402
+
403
+ // Clean up AppleDouble files (._*) created by macOS END
404
+ */
405
+
406
+
407
+
408
+
409
+
410
+
411
+ //In routes.js file check static import START
412
+
413
+ const routesPath = path.join(process.cwd(), 'src', 'js', 'routes.js');
414
+ const routesContent = fs.readFileSync(routesPath, 'utf-8');
415
+
416
+ let inBlockComment = false;
417
+ const lines = routesContent.split('\n');
418
+
419
+ const allowedImport = `import HomePage from '../pages/home.f7';`;
420
+ const badImportRegex = /^[ \t]*import\s+[\w{}*,\s]*\s+from\s+['"].+\.f7['"]\s*;/;
421
+ const badImports = [];
422
+
423
+ lines.forEach((line, index) => {
424
+ const trimmed = line.trim();
425
+
426
+ // Handle block comment start and end
427
+ if (trimmed.startsWith('/*')) inBlockComment = true;
428
+ if (inBlockComment && trimmed.endsWith('*/')) {
429
+ inBlockComment = false;
430
+ return;
431
+ }
432
+
433
+ // Skip if inside block comment or line comment
434
+ if (inBlockComment || trimmed.startsWith('//')) return;
435
+
436
+ // Match static .f7 import
437
+ if (badImportRegex.test(trimmed) && trimmed !== allowedImport) {
438
+ badImports.push({ line: trimmed, number: index + 1 });
439
+ }
440
+ });
441
+
442
+ if (badImports.length > 0) {
443
+ console.error('\n❌ ERROR: Detected disallowed static imports of .f7 files in routes.js\n');
444
+ console.error(`⚠️ Only this static import is allowed:\n ${allowedImport}\n`);
445
+ console.error(`🔧 Please convert other imports to async dynamic imports like this:\n`);
446
+ console.error(`
447
+
448
+ import HomePage from '../pages/home.f7';
449
+
450
+ const routes = [
451
+ {
452
+ path: '/',
453
+ component:HomePage,
454
+ },
455
+ {
456
+ path: '/ProfilePage/',
457
+ async async({ resolve }) {
458
+ const page = await import('../pages/profile.f7');
459
+ resolve({ component: page.default });
460
+ },
461
+ }]
462
+ `);
463
+
464
+ badImports.forEach(({ line, number }) => {
465
+ console.error(`${number}: ${line}`);
466
+ });
467
+
468
+ process.exit(1);
469
+ } else {
470
+ console.log('✅ routes.js passed the .f7 import check.');
471
+ }
472
+
473
+ //In routes.js file check static import END
474
+
475
+
476
+
477
+
478
+
479
+
480
+
481
+
482
+
483
+
484
+
485
+
486
+
487
+ // Check and change the "BridgeWebViewClient.java" file START
488
+ /*
489
+ For crash issue due to low memory problem, we need to modify the onRenderProcessGone method in BridgeWebViewClient.java.
490
+ */
491
+
492
+
493
+ const bridgeWebViewClientFilePath = path.join(process.cwd(), 'node_modules', '@capacitor/android/capacitor/src/main/java/com/getcapacitor', 'BridgeWebViewClient.java');
494
+
495
+ // Read the file
496
+ if (!fs.existsSync(bridgeWebViewClientFilePath)) {
497
+ console.error('❌ Error: BridgeWebViewClient.java not found.');
498
+ process.exit(1);
499
+ }
500
+
501
+ let fileContent = fs.readFileSync(bridgeWebViewClientFilePath, 'utf8');
502
+
503
+ // Define old and new code
504
+ const oldCodeStart = `@Override
505
+ public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) {
506
+ super.onRenderProcessGone(view, detail);
507
+ boolean result = false;
508
+
509
+ List<WebViewListener> webViewListeners = bridge.getWebViewListeners();
510
+ if (webViewListeners != null) {
511
+ for (WebViewListener listener : bridge.getWebViewListeners()) {
512
+ result = listener.onRenderProcessGone(view, detail) || result;
513
+ }
514
+ }
515
+
516
+ return result;
517
+ }`;
518
+
519
+ const newCode = `@Override
520
+ public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) {
521
+ super.onRenderProcessGone(view, detail);
522
+
523
+ boolean result = false;
524
+
525
+ List<WebViewListener> webViewListeners = bridge.getWebViewListeners();
526
+ if (webViewListeners != null) {
527
+ for (WebViewListener listener : bridge.getWebViewListeners()) {
528
+ result = listener.onRenderProcessGone(view, detail) || result;
529
+ }
530
+ }
531
+
532
+ if (!result) {
533
+ // If no one handled it, handle it ourselves!
534
+
535
+ /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
536
+ if (detail.didCrash()) {
537
+ //Log.e("CapacitorWebView", "WebView crashed internally!");
538
+ } else {
539
+ //Log.w("CapacitorWebView", "WebView was killed by system (low memory) internally!");
540
+ }
541
+ }*/
542
+
543
+ view.post(() -> {
544
+ Toast.makeText(view.getContext(), "Reloading due to low memory issue", Toast.LENGTH_SHORT).show();
545
+ });
546
+
547
+ view.reload(); // Safely reload WebView
548
+
549
+ return true; // We handled it
550
+ }
551
+
552
+ return result;
553
+ }`;
554
+
555
+ // Step 1: Update method if needed
556
+ let updated = false;
557
+
558
+ if (fileContent.includes(oldCodeStart)) {
559
+ console.log('✅ Found old onRenderProcessGone method. Replacing it...');
560
+ fileContent = fileContent.replace(oldCodeStart, newCode);
561
+ updated = true;
562
+ } else if (fileContent.includes(newCode)) {
563
+ console.log('ℹ️ Method already updated. No changes needed in "BridgeWebViewClient.java".');
564
+ } else {
565
+ console.error('❌ Error: Neither old nor new code found. Unexpected content.');
566
+ process.exit(1);
567
+ }
568
+
569
+ // Step 2: Check and add import if missing
570
+ const importToast = 'import android.widget.Toast;';
571
+ if (!fileContent.includes(importToast)) {
572
+ console.log('✅ Adding missing import for Toast...');
573
+ const importRegex = /import\s+[^;]+;/g;
574
+ const matches = [...fileContent.matchAll(importRegex)];
575
+
576
+ if (matches.length > 0) {
577
+ const lastImport = matches[matches.length - 1];
578
+ const insertPosition = lastImport.index + lastImport[0].length;
579
+ fileContent = fileContent.slice(0, insertPosition) + `\n${importToast}` + fileContent.slice(insertPosition);
580
+ updated = true;
581
+ } else {
582
+ console.error('❌ Error: No import section found in file.');
583
+ process.exit(1);
584
+ }
585
+ } else {
586
+ console.log('ℹ️ Import for Toast already exists. No changes needed.');
587
+ }
588
+
589
+ // Step 3: Save if updated
590
+ if (updated) {
591
+ fs.writeFileSync(bridgeWebViewClientFilePath, fileContent, 'utf8');
592
+ console.log('✅ File updated successfully.');
593
+ } else {
594
+ console.log('ℹ️ No changes needed.');
595
+ }
596
+
597
+
598
+
599
+
600
+ // Check and change the "BridgeWebViewClient.java" file END
601
+
602
+
603
+
604
+
605
+
606
+
607
+
608
+
609
+ /*
610
+ // To resolve the kotlin version issue, we need to update the kotlin version in the build.gradle file START
611
+
612
+ // Build the path dynamically like you requested
613
+ const gradlePath = path.join(
614
+ process.cwd(),
615
+ 'android',
616
+ 'build.gradle'
617
+ );
618
+
619
+ // Read the existing build.gradle
620
+ let gradleContent = fs.readFileSync(gradlePath, 'utf8');
621
+
622
+ // Add `ext.kotlin_version` if it's not already there
623
+ if (!gradleContent.includes('ext.kotlin_version')) {
624
+ gradleContent = gradleContent.replace(
625
+ /buildscript\s*{/,
626
+ `buildscript {\n ext.kotlin_version = '2.1.0'`
627
+ );
628
+ }
629
+
630
+ // Add Kotlin classpath if it's not already there
631
+ if (!gradleContent.includes('org.jetbrains.kotlin:kotlin-gradle-plugin')) {
632
+ gradleContent = gradleContent.replace(
633
+ /dependencies\s*{([\s\S]*?)classpath 'com.android.tools.build:gradle:8.7.2'/,
634
+ `dependencies {\n classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")\n$1classpath 'com.android.tools.build:gradle:8.7.2'`
635
+ );
636
+ }
637
+
638
+ // Write back the modified content
639
+ fs.writeFileSync(gradlePath, gradleContent, 'utf8');
640
+
641
+ console.log('✅ Kotlin version updated in build.gradle.');
642
+
643
+ // To resolve the kotlin version issue, we need to update the kotlin version in the build.gradle file END
644
+ */
645
+
646
+
647
+
648
+
649
+
650
+
651
+
652
+
653
+ let _admobConfig;
654
+
655
+
656
+
657
+ const androidPlatformPath = path.join(process.cwd(), 'android');
658
+ const iosPlatformPath = path.join(process.cwd(), 'ios');
659
+ const pluginPath = path.join(process.cwd(), 'node_modules', 'emi-indo-cordova-plugin-admob', 'plugin.xml');
660
+ const infoPlistPath = path.join(process.cwd(), 'ios', 'App', 'App', 'Info.plist');
661
+ const resourcesPath = path.join(process.cwd(), 'resources', 'res');
662
+ const androidResPath = path.join(process.cwd(), 'android', 'app', 'src', 'main', 'res');
663
+ const localNotificationsPluginPath = path.join(process.cwd(), 'node_modules', '@capacitor', 'local-notifications');
664
+
665
+ function fileExists(filePath) {
666
+ return fs.existsSync(filePath);
667
+ }
668
+
669
+ function copyFolderSync(source, target) {
670
+ if (!fs.existsSync(target)) {
671
+ fs.mkdirSync(target, { recursive: true });
672
+ }
673
+
674
+ fs.readdirSync(source).forEach(file => {
675
+ const sourceFile = path.join(source, file);
676
+ const targetFile = path.join(target, file);
677
+
678
+ if (fs.lstatSync(sourceFile).isDirectory()) {
679
+ copyFolderSync(sourceFile, targetFile);
680
+ } else {
681
+ fs.copyFileSync(sourceFile, targetFile);
682
+ }
683
+ });
684
+ }
685
+
686
+ function checkAndCopyResources() {
687
+ if (fileExists(resourcesPath)) {
688
+ copyFolderSync(resourcesPath, androidResPath);
689
+ console.log('✅ Successfully copied resources/res to android/app/src/main/res.');
690
+ } else {
691
+ console.log('resources/res folder not found.');
692
+
693
+ if (fileExists(localNotificationsPluginPath)) {
694
+ throw new Error('❌ resources/res is required for @capacitor/local-notifications. Stopping execution.');
695
+ }
696
+ }
697
+ }
698
+
699
+
700
+
701
+
702
+
703
+
704
+
705
+
706
+ function getAdMobConfig() {
707
+ if (!fileExists(configPath)) {
708
+ throw new Error('❌ capacitor.config.json not found. Ensure this is a Capacitor project.');
709
+ }
710
+
711
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
712
+ const admobConfig = config.plugins?.AdMob;
713
+
714
+ if (!admobConfig) {
715
+ throw new Error('❌ AdMob configuration is missing in capacitor.config.json.');
716
+ }
717
+
718
+ // Default to true if ADMOB_ENABLED is not specified
719
+ const isEnabled = admobConfig.ADMOB_ENABLED !== false;
720
+
721
+ if (!isEnabled) {
722
+ return { ADMOB_ENABLED: false }; // Skip further validation
723
+ }
724
+
725
+ if (!admobConfig.APP_ID_ANDROID || !admobConfig.APP_ID_IOS) {
726
+ throw new Error(' ❌ AdMob configuration is incomplete. Ensure APP_ID_ANDROID and APP_ID_IOS are defined.');
727
+ }
728
+
729
+ return {
730
+ ADMOB_ENABLED: true,
731
+ APP_ID_ANDROID: admobConfig.APP_ID_ANDROID,
732
+ APP_ID_IOS: admobConfig.APP_ID_IOS,
733
+ USE_LITE_ADS: admobConfig.USE_LITE_ADS === "lite",
734
+ };
735
+ }
736
+
737
+ function validateAndroidBuildOptions() {
738
+
739
+
740
+ if (!fileExists(configPath)) {
741
+ console.log('❌ capacitor.config.json not found. Ensure this is a Capacitor project.');
742
+ process.exit(1);
743
+ }
744
+
745
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
746
+
747
+ const targetAppId=config.appId
748
+
749
+ const buildOptions = config.android?.buildOptions;
750
+
751
+ if (!buildOptions) {
752
+ console.log('❌ Missing android.buildOptions in capacitor.config.json.');
753
+ process.exit(1);
754
+ }
755
+
756
+ const requiredProps = [
757
+ 'keystorePath',
758
+ 'keystorePassword',
759
+ 'keystoreAlias',
760
+ 'keystoreAliasPassword',
761
+ 'releaseType',
762
+ 'signingType'
763
+ ];
764
+
765
+ const missing = requiredProps.filter(prop => !buildOptions[prop]);
766
+
767
+ if (missing.length > 0) {
768
+ console.log('❌ Missing properties android.buildOptions in capacitor.config.json.');
769
+ process.exit(1);
770
+ }
771
+
772
+
773
+ const keystorePath=buildOptions.keystorePath
774
+ const keyFileName = path.basename(keystorePath);
775
+
776
+
777
+
778
+ const keystoreMap = {
779
+ "gameskey.jks": [
780
+ "com.cube.blaster",
781
+ ],
782
+ "htmleditorkeystoke.jks": [
783
+ "com.HTML.AngularJS.Codeplay",
784
+ "com.html.codeplay.pro",
785
+ "com.bootstrap.code.play",
786
+ "com.kids.learning.master",
787
+ "com.Simple.Barcode.Scanner"
788
+ ]
789
+ };
790
+
791
+ // find which keystore is required for the given targetAppId
792
+ let requiredKey = "newappskey.jks"; // default
793
+ for (const [keyFile, appIds] of Object.entries(keystoreMap)) {
794
+ if (appIds.includes(targetAppId)) {
795
+ requiredKey = keyFile;
796
+ break;
797
+ }
798
+ }
799
+
800
+ // validate
801
+ if (keyFileName !== requiredKey) {
802
+ console.log(`❌ The keystore path is mismatched. Expected ${requiredKey} for ${targetAppId}, but got ${keyFileName}`);
803
+ process.exit(1);
804
+ }
805
+
806
+
807
+
808
+
809
+
810
+ // optionally return them
811
+ //return buildOptions;
812
+ }
813
+
814
+ function updatePluginXml(admobConfig) {
815
+ if (!fileExists(pluginPath)) {
816
+ console.error(' ❌ plugin.xml not found. Ensure the plugin is installed.');
817
+ return;
818
+ }
819
+
820
+ let pluginContent = fs.readFileSync(pluginPath, 'utf8');
821
+
822
+ pluginContent = pluginContent
823
+ .replace(/<preference name="APP_ID_ANDROID" default=".*?" \/>/, `<preference name="APP_ID_ANDROID" default="${admobConfig.APP_ID_ANDROID}" />`)
824
+ .replace(/<preference name="APP_ID_IOS" default=".*?" \/>/, `<preference name="APP_ID_IOS" default="${admobConfig.APP_ID_IOS}" />`);
825
+
826
+ fs.writeFileSync(pluginPath, pluginContent, 'utf8');
827
+ console.log('✅ AdMob IDs successfully updated in plugin.xml');
828
+ }
829
+
830
+ function updateInfoPlist(admobConfig) {
831
+ if (!fileExists(infoPlistPath)) {
832
+ console.error(' ❌ Info.plist not found. Ensure you have built the iOS project.');
833
+ return;
834
+ }
835
+
836
+ const plistContent = fs.readFileSync(infoPlistPath, 'utf8');
837
+ const plistData = plist.parse(plistContent);
838
+
839
+ plistData.GADApplicationIdentifier = admobConfig.APP_ID_IOS;
840
+ plistData.NSUserTrackingUsageDescription = 'This identifier will be used to deliver personalized ads to you.';
841
+ plistData.GADDelayAppMeasurementInit = true;
842
+
843
+ const updatedPlistContent = plist.build(plistData);
844
+ fs.writeFileSync(infoPlistPath, updatedPlistContent, 'utf8');
845
+ console.log('AdMob IDs and additional configurations successfully updated in Info.plist');
846
+ }
847
+
848
+
849
+ try {
850
+ if (!fileExists(configPath)) {
851
+ throw new Error(' ❌ capacitor.config.json not found. Skipping setup.');
852
+ }
853
+
854
+ if (!fileExists(androidPlatformPath) && !fileExists(iosPlatformPath)) {
855
+ throw new Error('Neither Android nor iOS platforms are found. Ensure platforms are added to your Capacitor project.');
856
+ }
857
+
858
+ checkAndCopyResources();
859
+
860
+
861
+
862
+ _admobConfig = getAdMobConfig();
863
+
864
+
865
+
866
+
867
+
868
+ // Proceed only if ADMOB_ENABLED is true
869
+ if (_admobConfig.ADMOB_ENABLED) {
870
+ if (fileExists(androidPlatformPath)) {
871
+ updatePluginXml(_admobConfig);
872
+ }
873
+
874
+ if (fileExists(iosPlatformPath)) {
875
+ updateInfoPlist(_admobConfig);
876
+ }
877
+ }
878
+
879
+
880
+ } catch (error) {
881
+ console.error(error.message);
882
+ process.exit(1); // Stop execution if there's a critical error
883
+ }
884
+
885
+
886
+
887
+ validateAndroidBuildOptions();
888
+
889
+
890
+
891
+
892
+
893
+
894
+ // Check all the codeplays plugins version START
895
+
896
+
897
+ const readline = require('readline');
898
+
899
+
900
+ //const srcDir = path.join(__dirname, 'src');
901
+ const srcDir = path.join(process.cwd(), 'src');
902
+ let outdatedPlugins = [];
903
+
904
+ function parseVersion(ver) {
905
+ return ver.split('.').map(n => parseInt(n, 10));
906
+ }
907
+
908
+ function compareVersions(v1, v2) {
909
+ const [a1, b1] = parseVersion(v1);
910
+ const [a2, b2] = parseVersion(v2);
911
+ if (a1 !== a2) return a1 - a2;
912
+ return b1 - b2;
913
+ }
914
+
915
+ function walkSync(dir, filelist = []) {
916
+ fs.readdirSync(dir).forEach(file => {
917
+ const fullPath = path.join(dir, file);
918
+ const stat = fs.statSync(fullPath);
919
+ if (stat.isDirectory()) {
920
+ walkSync(fullPath, filelist);
921
+ } else {
922
+ filelist.push(fullPath);
923
+ }
924
+ });
925
+ return filelist;
926
+ }
927
+
928
+
929
+
930
+ function getSearchRoot(plugin) {
931
+ return path.join(srcDir, plugin.baseDir || 'js');
932
+ }
933
+
934
+ function checkPlugins() {
935
+ const files = walkSync(srcDir);
936
+
937
+ for (const plugin of requiredPlugins) {
938
+
939
+ const searchRoot = getSearchRoot(plugin);
940
+
941
+ // ---------- FOLDER PLUGINS ----------
942
+ if (plugin.isFolder) {
943
+
944
+ if (!fs.existsSync(searchRoot)) continue;
945
+
946
+ const subDirs = fs.readdirSync(searchRoot)
947
+ .map(name => path.join(searchRoot, name))
948
+ .filter(p => fs.statSync(p).isDirectory());
949
+
950
+ for (const dir of subDirs) {
951
+ const relativePath = path
952
+ .relative(searchRoot, dir)
953
+ .replace(/\\/g, '/');
954
+
955
+ const match = plugin.pattern.exec(relativePath);
956
+ if (match) {
957
+ const currentVersion = match[1];
958
+ if (compareVersions(currentVersion, plugin.minVersion) < 0) {
959
+ outdatedPlugins.push({
960
+ name: relativePath,
961
+ currentVersion,
962
+ requiredVersion: plugin.minVersion
963
+ });
964
+ }
965
+ }
966
+ }
967
+ continue;
968
+ }
969
+
970
+ // ---------- FILE PLUGINS ----------
971
+ const matchedFile = files.find(file =>
972
+ file.startsWith(searchRoot) && plugin.pattern.test(file)
973
+ );
974
+
975
+ if (matchedFile) {
976
+ const match = plugin.pattern.exec(matchedFile);
977
+ if (match) {
978
+ const currentVersion = match[1];
979
+ if (compareVersions(currentVersion, plugin.minVersion) < 0) {
980
+ outdatedPlugins.push({
981
+ name: path.relative(srcDir, matchedFile),
982
+ currentVersion,
983
+ requiredVersion: plugin.minVersion
984
+ });
985
+ }
986
+ }
987
+ }
988
+ }
989
+
990
+
991
+ if (outdatedPlugins.length > 0) {
992
+ console.log('\n❗ The following plugins are outdated:');
993
+ outdatedPlugins.forEach(p => {
994
+ console.log(` ❌ - ${p.name} (Current: ${p.currentVersion}, Required: ${p.requiredVersion})`);
995
+ });
996
+
997
+ const rl = readline.createInterface({
998
+ input: process.stdin,
999
+ output: process.stdout
1000
+ });
1001
+
1002
+ rl.question('\nAre you sure you want to continue without updating these plugins? (y/n): ', answer => {
1003
+ if (answer.toLowerCase() !== 'y') {
1004
+ console.log('\n❌ Build cancelled due to outdated plugins.');
1005
+ process.exit(1);
1006
+ } else {
1007
+ console.log('\n✅ Continuing build...');
1008
+ rl.close();
1009
+ }
1010
+ });
1011
+ } else {
1012
+ console.log('✅ All plugin versions are up to date.');
1013
+ }
1014
+ }
1015
+
1016
+
1017
+ // Run the validation
1018
+ checkPlugins();
1019
+
1020
+
1021
+
1022
+
1023
+ // Check all the codeplays plugins version START
1024
+
1025
+
1026
+
1027
+
1028
+ // ====================================================================
1029
+ // AUTO-ADD esbuild.drop: ['console','debugger'] to vite.config.js / mjs
1030
+ // ====================================================================
1031
+
1032
+
1033
+
1034
+ const checkAndupdateDropInViteConfig = () => {
1035
+
1036
+ const possibleFiles = [
1037
+ "vite.config.js",
1038
+ "vite.config.mjs"
1039
+ ];
1040
+
1041
+ // Detect existing config file
1042
+ const viteConfigPath = possibleFiles
1043
+ .map(file => path.join(process.cwd(), file))
1044
+ .find(filePath => fs.existsSync(filePath));
1045
+
1046
+ if (!viteConfigPath) {
1047
+ console.warn("⚠️ No vite config found. Skipping.");
1048
+ return;
1049
+ }
1050
+
1051
+ //console.log("📄 Using:", viteConfigPath.split("/").pop());
1052
+
1053
+ let viteContent = fs.readFileSync(viteConfigPath, "utf8");
1054
+
1055
+ // Skip if already exists
1056
+ if (/drop\s*:\s*\[.*['"]console['"].*\]/.test(viteContent)) {
1057
+ console.log("ℹ️ vite.config.(m)js already Updated. Skipping...");
1058
+ return;
1059
+ }
1060
+
1061
+ console.log("🔧 Adding esbuild.drop ...");
1062
+
1063
+ // If esbuild block exists
1064
+ if (/esbuild\s*:\s*{/.test(viteContent)) {
1065
+ viteContent = viteContent.replace(
1066
+ /esbuild\s*:\s*{([\s\S]*?)(^ {0,8})}/m,
1067
+ (full, inner, indent) => {
1068
+
1069
+ let lines = inner
1070
+ .split("\n")
1071
+ .map(l => l.trim())
1072
+ .filter(Boolean);
1073
+
1074
+ // Fix last comma
1075
+ if (lines.length > 0) {
1076
+ lines[lines.length - 1] =
1077
+ lines[lines.length - 1].replace(/,+$/, "") + ",";
1078
+ }
1079
+
1080
+ // Re-indent
1081
+ lines = lines.map(l => indent + " " + l);
1082
+
1083
+ // Add drop
1084
+ lines.push(`${indent} drop: ['console','debugger'],`);
1085
+
1086
+ return `esbuild: {\n${lines.join("\n")}\n${indent}}`;
1087
+ }
1088
+ );
1089
+ }
1090
+
1091
+ // If esbuild missing
1092
+ else {
1093
+ viteContent = viteContent.replace(
1094
+ /export default defineConfig\s*\(\s*{/,
1095
+ m => `${m}\n esbuild: {\n drop: ['console','debugger'],\n },`
1096
+ );
1097
+ }
1098
+
1099
+ fs.writeFileSync(viteConfigPath, viteContent, "utf8");
1100
+ console.log("✅ vite.config.(m)js Updated successfully.");
1101
+ };
1102
+
1103
+ checkAndupdateDropInViteConfig();
1104
+
1105
+
1106
+
1107
+
1108
+
1109
+
1110
+
1111
+
1112
+ const compareVersion = (v1, v2) => {
1113
+ const a = v1.split(".").map(Number);
1114
+ const b = v2.split(".").map(Number);
1115
+
1116
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
1117
+ const num1 = a[i] || 0;
1118
+ const num2 = b[i] || 0;
1119
+ if (num1 > num2) return 1;
1120
+ if (num1 < num2) return -1;
1121
+ }
1122
+ return 0;
1123
+ };
1124
+
1125
+
1126
+
1127
+
1128
+ const admobConfigPath = path.join('src', 'js','Ads', 'admob-ad-configuration.json');
1129
+
1130
+ const checkAdmobConfigurationProperty=()=>{
1131
+
1132
+
1133
+ if (!_admobConfig.ADMOB_ENABLED)
1134
+ {
1135
+ console.log("ℹ️ Admob is not enabled so 'admob-ad-configuration.json' checking is skipping...");
1136
+ return;
1137
+ }
1138
+
1139
+
1140
+ const REQUIRED_CONFIG_KEYS = [
1141
+ "isKidsApp",
1142
+ "isTesting",
1143
+ "isConsoleLogEnabled",
1144
+ "bannerEnabled",
1145
+ "interstitialEnabled",
1146
+ "appOpenEnabled",
1147
+ "rewardVideoEnabled",
1148
+ "rewardInterstitialEnabled",
1149
+ "collapsibleEnabled",
1150
+ "isLandScape",
1151
+ "overlappingHeight",
1152
+ "isOverlappingEnable",
1153
+ "bannerTypeAndroid",
1154
+ "bannerTypeiOS",
1155
+ "bannerTopSpaceColor",
1156
+ "interstitialLoadScreenTextColor",
1157
+ "interstitialLoadScreenBackgroundColor",
1158
+ "beforeBannerSpace",
1159
+ "whenShow",
1160
+ "minimumClick",
1161
+ "interstitialTimeOut",
1162
+ "interstitialFirstTimeOut",
1163
+ "appOpenAdsTimeOut",
1164
+ "maxRetryCount",
1165
+ "retrySecondsAr",
1166
+ "appOpenPerSession",
1167
+ "interstitialPerSession",
1168
+ "appOpenFirstTimeOut"
1169
+ ];
1170
+
1171
+
1172
+
1173
+
1174
+
1175
+ let admobConfigInJson;
1176
+
1177
+ try {
1178
+ admobConfigInJson = JSON.parse(readFileSync(admobConfigPath, "utf8"));
1179
+ } catch (err) {
1180
+ console.error("❌ Failed to read admob-ad-configuration.json", err);
1181
+ process.exit(1);
1182
+ }
1183
+
1184
+ // ✅ Validate config object exists
1185
+ if (!admobConfigInJson.config) {
1186
+ console.error('❌ "config" object is missing in admob-ad-configuration.json');
1187
+ process.exit(1);
1188
+ }
1189
+
1190
+
1191
+ const admobConfigMinVersion="1.4"
1192
+
1193
+ if (compareVersion(admobConfigInJson.VERSION, admobConfigMinVersion) < 0) {
1194
+ console.error(`❌ Please use at-least version ${admobConfigMinVersion} in "src/js/Ads/admob-ad-configuration.json"`);
1195
+ process.exit(1);
1196
+ }
1197
+
1198
+
1199
+ const config = admobConfigInJson.config;
1200
+
1201
+ // ✅ Find missing properties
1202
+ const missingKeys = REQUIRED_CONFIG_KEYS.filter(
1203
+ key => !(key in config)
1204
+ );
1205
+
1206
+
1207
+
1208
+ if (missingKeys.length > 0) {
1209
+ console.error("❌ Missing required configuration keys. Please check it in 'src/js/Ads/admob-ad-configuration.json'");
1210
+
1211
+ missingKeys.forEach(k => console.error(" - " + k));
1212
+ process.exit(1);
1213
+ }
1214
+
1215
+
1216
+ console.log('✅ All keys exist. in "admob-ad-configuration.json file" Configuration looks good.');
1217
+ }
1218
+
1219
+
1220
+ checkAdmobConfigurationProperty()
1221
+
1222
+
1223
+
1224
+
1225
+ /*
1226
+ Release Notes
1227
+
1228
+ 5.1
1229
+ Kotlin version update is commented. Previously admob is not worked if not update the kotlin version to higher version
1230
+
1231
1231
  */