codeplay-common 1.6.4 → 1.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/files/finalrelease20 +74 -67
- package/package.json +1 -1
package/files/finalrelease20
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { existsSync, readFileSync, readdirSync, promises, constants, writeFileSync, unlinkSync, mkdirSync, renameSync } from 'fs';
|
|
2
|
+
import { join, resolve } from 'path';
|
|
3
|
+
import { execSync } from 'child_process';
|
|
4
|
+
import { createInterface } from 'readline';
|
|
5
|
+
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
import { dirname } from 'path';
|
|
5
8
|
|
|
6
9
|
// Define a mapping between store IDs and store names
|
|
7
10
|
const storeNames = {
|
|
@@ -15,22 +18,26 @@ let isAdmobFound = false;
|
|
|
15
18
|
|
|
16
19
|
const amazonMinSdkVersion=23;
|
|
17
20
|
|
|
18
|
-
const androidManifestPath =
|
|
21
|
+
const androidManifestPath = join("android", "app", "src", "main", "AndroidManifest.xml");
|
|
22
|
+
|
|
23
|
+
|
|
19
24
|
|
|
25
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
26
|
+
const __dirname = dirname(__filename);
|
|
20
27
|
|
|
21
28
|
function fileExists(filePath) {
|
|
22
|
-
return
|
|
29
|
+
return existsSync(filePath);
|
|
23
30
|
}
|
|
24
31
|
|
|
25
32
|
|
|
26
|
-
const capacitorConfigPath =
|
|
33
|
+
const capacitorConfigPath = join(process.cwd(), 'capacitor.config.json');
|
|
27
34
|
|
|
28
35
|
function getAdMobConfig() {
|
|
29
36
|
if (!fileExists(capacitorConfigPath)) {
|
|
30
37
|
throw new Error('❌ capacitor.config.json not found. Ensure this is a Capacitor project.');
|
|
31
38
|
}
|
|
32
39
|
|
|
33
|
-
const config = JSON.parse(
|
|
40
|
+
const config = JSON.parse(readFileSync(capacitorConfigPath, 'utf8'));
|
|
34
41
|
const admobConfig = config.plugins?.AdMob;
|
|
35
42
|
|
|
36
43
|
if (!admobConfig) {
|
|
@@ -66,14 +73,14 @@ function getAdMobConfig() {
|
|
|
66
73
|
//if (_capacitorConfig.ADMOB_ENABLED)
|
|
67
74
|
|
|
68
75
|
|
|
69
|
-
const admobConfigPath =
|
|
76
|
+
const admobConfigPath = join('src', 'js','Ads', 'admob-ad-configuration.json');
|
|
70
77
|
let admobConfig;
|
|
71
78
|
|
|
72
79
|
if (_isADMOB_ENABLED)
|
|
73
80
|
{
|
|
74
81
|
try
|
|
75
82
|
{
|
|
76
|
-
admobConfig = JSON.parse(
|
|
83
|
+
admobConfig = JSON.parse(readFileSync(admobConfigPath, 'utf8'));
|
|
77
84
|
}
|
|
78
85
|
catch (err)
|
|
79
86
|
{
|
|
@@ -107,8 +114,8 @@ const checkCommonFileStoreId=()=>{
|
|
|
107
114
|
const possibleConfigFiles = ['vite.config.mjs', 'vite.config.js'];
|
|
108
115
|
let viteConfigPath;
|
|
109
116
|
for (const configFile of possibleConfigFiles) {
|
|
110
|
-
const fullPath =
|
|
111
|
-
if (
|
|
117
|
+
const fullPath = resolve( configFile);
|
|
118
|
+
if (existsSync(fullPath)) {
|
|
112
119
|
viteConfigPath = fullPath;
|
|
113
120
|
break;
|
|
114
121
|
}
|
|
@@ -121,7 +128,7 @@ const checkCommonFileStoreId=()=>{
|
|
|
121
128
|
|
|
122
129
|
try {
|
|
123
130
|
// Read vite config file
|
|
124
|
-
const viteConfigContent =
|
|
131
|
+
const viteConfigContent = readFileSync(viteConfigPath, 'utf-8');
|
|
125
132
|
|
|
126
133
|
// Extract @common alias path
|
|
127
134
|
const aliasPattern = /'@common':\s*path\.resolve\(__dirname,\s*'(.+?)'\)/;
|
|
@@ -133,15 +140,15 @@ const checkCommonFileStoreId=()=>{
|
|
|
133
140
|
}
|
|
134
141
|
|
|
135
142
|
const commonFilePath = match[1];
|
|
136
|
-
const resolvedCommonPath =
|
|
143
|
+
const resolvedCommonPath = resolve(__dirname, commonFilePath);
|
|
137
144
|
|
|
138
145
|
// Read the common file content
|
|
139
|
-
if (!
|
|
146
|
+
if (!existsSync(resolvedCommonPath)) {
|
|
140
147
|
console.error(`❌ Error: Resolved common file does not exist: ${resolvedCommonPath}`);
|
|
141
148
|
process.exit(1);
|
|
142
149
|
}
|
|
143
150
|
|
|
144
|
-
const commonFileContent =
|
|
151
|
+
const commonFileContent = readFileSync(resolvedCommonPath, 'utf-8');
|
|
145
152
|
|
|
146
153
|
// Check for the _storeid export line
|
|
147
154
|
const storeIdPattern = /export\s+let\s+_storeid\s*=\s*import\.meta\.env\.VITE_STORE_ID\s*\|\|\s*1\s*;/;
|
|
@@ -171,11 +178,11 @@ const checkIsTestingInAdmob=()=>{
|
|
|
171
178
|
const checkIsAdsDisableByReturnStatement=()=>{
|
|
172
179
|
|
|
173
180
|
|
|
174
|
-
const adsFolder =
|
|
181
|
+
const adsFolder = join('src', 'js', 'Ads');
|
|
175
182
|
const filePattern = /^admob-emi-(\d+\.)+\d+\.js$/;
|
|
176
183
|
|
|
177
184
|
// Step 1: Find the admob file
|
|
178
|
-
const files =
|
|
185
|
+
const files = readdirSync(adsFolder);
|
|
179
186
|
const admobFile = files.find(f => filePattern.test(f));
|
|
180
187
|
|
|
181
188
|
if (!admobFile) {
|
|
@@ -183,8 +190,8 @@ const checkIsAdsDisableByReturnStatement=()=>{
|
|
|
183
190
|
process.exit(1);
|
|
184
191
|
}
|
|
185
192
|
|
|
186
|
-
const filePath =
|
|
187
|
-
const content =
|
|
193
|
+
const filePath = join(adsFolder, admobFile);
|
|
194
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
188
195
|
|
|
189
196
|
// Step 2: Extract the adsOnDeviceReady function body
|
|
190
197
|
const functionRegex = /async\s+function\s+adsOnDeviceReady\s*\([^)]*\)\s*{([\s\S]*?)^}/m;
|
|
@@ -221,12 +228,12 @@ const checkIsAdsDisableByReturnStatement=()=>{
|
|
|
221
228
|
|
|
222
229
|
const addPermission_AD_ID=async()=>{
|
|
223
230
|
|
|
224
|
-
const admobPluginXmlPath =
|
|
231
|
+
const admobPluginXmlPath = join('node_modules', 'emi-indo-cordova-plugin-admob', 'plugin.xml');
|
|
225
232
|
|
|
226
233
|
|
|
227
234
|
//let isAdmobFound = false;
|
|
228
235
|
try {
|
|
229
|
-
await
|
|
236
|
+
await promises.access(admobPluginXmlPath, constants.F_OK);
|
|
230
237
|
isAdmobFound = true;
|
|
231
238
|
} catch (err) {
|
|
232
239
|
isAdmobFound = false;
|
|
@@ -235,9 +242,9 @@ const addPermission_AD_ID=async()=>{
|
|
|
235
242
|
|
|
236
243
|
if (isAdmobFound) {
|
|
237
244
|
// Check if AndroidManifest.xml exists
|
|
238
|
-
if (
|
|
245
|
+
if (existsSync(androidManifestPath)) {
|
|
239
246
|
// Read the content of AndroidManifest.xml
|
|
240
|
-
let manifestContent =
|
|
247
|
+
let manifestContent = readFileSync(androidManifestPath, 'utf8');
|
|
241
248
|
|
|
242
249
|
// Check if the ad_id permission already exists
|
|
243
250
|
const adIdPermission = '<uses-permission android:name="com.google.android.gms.permission.AD_ID" />';
|
|
@@ -248,7 +255,7 @@ const addPermission_AD_ID=async()=>{
|
|
|
248
255
|
manifestContent = manifestContent.replace('</manifest>', ` ${adIdPermission}\n</manifest>`);
|
|
249
256
|
|
|
250
257
|
// Write the updated manifest content back to AndroidManifest.xml
|
|
251
|
-
|
|
258
|
+
writeFileSync(androidManifestPath, manifestContent, 'utf8');
|
|
252
259
|
console.log("✅ ad_id permission added successfully.");
|
|
253
260
|
} else {
|
|
254
261
|
console.log("ℹ️ ad_id permission already exists in AndroidManifest.xml.");
|
|
@@ -280,7 +287,7 @@ if (_isADMOB_ENABLED)
|
|
|
280
287
|
checkIsTestingInAdmob();
|
|
281
288
|
checkIsAdsDisableByReturnStatement()
|
|
282
289
|
|
|
283
|
-
addPermission_AD_ID()
|
|
290
|
+
await addPermission_AD_ID()
|
|
284
291
|
}
|
|
285
292
|
|
|
286
293
|
|
|
@@ -304,35 +311,35 @@ const storeIds = storeIdArg ? [storeIdArg] : ["1", "2", "7"]; // If a specific I
|
|
|
304
311
|
let originalMinSdkVersion;
|
|
305
312
|
|
|
306
313
|
// Remove any existing AAB files before starting the build process
|
|
307
|
-
const aabDirectory =
|
|
308
|
-
if (
|
|
309
|
-
const files =
|
|
314
|
+
const aabDirectory = join("android", "app", "build", "outputs", "bundle", "release");
|
|
315
|
+
if (existsSync(aabDirectory)) {
|
|
316
|
+
const files = readdirSync(aabDirectory).filter(file => file.endsWith('.aab'));
|
|
310
317
|
files.forEach(file => {
|
|
311
|
-
const filePath =
|
|
312
|
-
|
|
318
|
+
const filePath = join(aabDirectory, file);
|
|
319
|
+
unlinkSync(filePath);
|
|
313
320
|
console.log(`ℹ️ Deleted existing AAB file: ${file}`);
|
|
314
321
|
});
|
|
315
322
|
}
|
|
316
323
|
|
|
317
|
-
const aabOutputDir =
|
|
318
|
-
if (!
|
|
319
|
-
|
|
324
|
+
const aabOutputDir = join("AAB");
|
|
325
|
+
if (!existsSync(aabOutputDir)) {
|
|
326
|
+
mkdirSync(aabOutputDir);
|
|
320
327
|
console.log(`Created directory: ${aabOutputDir}`);
|
|
321
328
|
}
|
|
322
329
|
|
|
323
|
-
if (
|
|
324
|
-
const files =
|
|
330
|
+
if (existsSync(aabOutputDir)) {
|
|
331
|
+
const files = readdirSync(aabOutputDir).filter(file => file.endsWith('.aab'));
|
|
325
332
|
files.forEach(file => {
|
|
326
|
-
const filePath =
|
|
327
|
-
|
|
333
|
+
const filePath = join(aabOutputDir, file);
|
|
334
|
+
unlinkSync(filePath);
|
|
328
335
|
console.log(`Deleted existing AAB file: ${file}`);
|
|
329
336
|
});
|
|
330
337
|
}
|
|
331
338
|
|
|
332
339
|
|
|
333
340
|
// Extract version code and version name from build.gradle
|
|
334
|
-
const gradleFilePath =
|
|
335
|
-
const gradleContent =
|
|
341
|
+
const gradleFilePath = join("android", "app", "build.gradle");
|
|
342
|
+
const gradleContent = readFileSync(gradleFilePath, 'utf8');
|
|
336
343
|
|
|
337
344
|
const versionCodeMatch = gradleContent.match(/versionCode\s+(\d+)/);
|
|
338
345
|
const versionNameMatch = gradleContent.match(/versionName\s+"([^"]+)"/);
|
|
@@ -345,7 +352,7 @@ console.log(`Current versionCode: ${versionCode}`);
|
|
|
345
352
|
console.log(`Current versionName: ${versionName}`);
|
|
346
353
|
|
|
347
354
|
// Create an interface for user input
|
|
348
|
-
const rl =
|
|
355
|
+
const rl = createInterface({
|
|
349
356
|
input: process.stdin,
|
|
350
357
|
output: process.stdout
|
|
351
358
|
});
|
|
@@ -407,7 +414,7 @@ rl.question('Enter new versionCode (press enter to keep current): ', (newVersion
|
|
|
407
414
|
|
|
408
415
|
|
|
409
416
|
// Write the updated gradle content back to build.gradle
|
|
410
|
-
|
|
417
|
+
writeFileSync(gradleFilePath, updatedGradleContent, 'utf8');
|
|
411
418
|
console.log(`✅ Updated build.gradle with versionCode: ${finalVersionCode}, versionName: ${finalVersionName}, resConfigs "en" and "minifyEnabled true"`);
|
|
412
419
|
|
|
413
420
|
storeIds.forEach((id) => {
|
|
@@ -431,11 +438,11 @@ rl.question('Enter new versionCode (press enter to keep current): ', (newVersion
|
|
|
431
438
|
}
|
|
432
439
|
|
|
433
440
|
//storeName="amazon"
|
|
434
|
-
const checkFullPath =
|
|
441
|
+
const checkFullPath = join("AAB", newFileName); // Update to point to the new AAB directory
|
|
435
442
|
|
|
436
443
|
// Modify minSdkVersion in variables.gradle for SamsungStore
|
|
437
|
-
const variablesGradleFilePath =
|
|
438
|
-
let variablesGradleContent =
|
|
444
|
+
const variablesGradleFilePath = join("android", "variables.gradle");
|
|
445
|
+
let variablesGradleContent = readFileSync(variablesGradleFilePath, 'utf8');
|
|
439
446
|
|
|
440
447
|
// Extract the current minSdkVersion
|
|
441
448
|
const minSdkVersionMatch = variablesGradleContent.match(/minSdkVersion\s*=\s*(\d+)/);
|
|
@@ -451,14 +458,14 @@ rl.question('Enter new versionCode (press enter to keep current): ', (newVersion
|
|
|
451
458
|
if (currentMinSdkVersion !== 24) {
|
|
452
459
|
variablesGradleContent = variablesGradleContent.replace(/minSdkVersion\s*=\s*\d+/, 'minSdkVersion = 24');
|
|
453
460
|
console.log('minSdkVersion updated to 24 for SamsungStore & PlayStore');
|
|
454
|
-
|
|
461
|
+
writeFileSync(variablesGradleFilePath, variablesGradleContent);
|
|
455
462
|
}
|
|
456
463
|
} else {
|
|
457
464
|
// For PlayStore and AmazonStore, ensure minSdkVersion is originalMinSdkVersion
|
|
458
465
|
//if (currentMinSdkVersion !== originalMinSdkVersion) {
|
|
459
466
|
variablesGradleContent = variablesGradleContent.replace(/minSdkVersion\s*=\s*\d+/, `minSdkVersion = ${amazonMinSdkVersion}`);
|
|
460
467
|
console.log(`minSdkVersion reverted to ${amazonMinSdkVersion} for ${storeName}`);
|
|
461
|
-
|
|
468
|
+
writeFileSync(variablesGradleFilePath, variablesGradleContent);
|
|
462
469
|
//}
|
|
463
470
|
}
|
|
464
471
|
|
|
@@ -466,42 +473,42 @@ rl.question('Enter new versionCode (press enter to keep current): ', (newVersion
|
|
|
466
473
|
|
|
467
474
|
// Run the Node.js script to modify plugin.xml
|
|
468
475
|
if (isAdmobFound) {
|
|
469
|
-
|
|
476
|
+
execSync('node buildCodeplay/modify-plugin-xml.js', { stdio: 'inherit' });
|
|
470
477
|
} else {
|
|
471
478
|
console.log("\x1b[33m%s\x1b[0m", "Seems to Pro Version [No ads found]");
|
|
472
479
|
}
|
|
473
480
|
|
|
474
481
|
// Run the Vite build
|
|
475
|
-
|
|
482
|
+
execSync(`npm run build:storeid${id}`, { stdio: 'inherit' });
|
|
476
483
|
|
|
477
484
|
|
|
478
485
|
|
|
479
486
|
// Copy the built files to the appropriate folder
|
|
480
|
-
const src =
|
|
481
|
-
const dest =
|
|
487
|
+
const src = join("www", "*");
|
|
488
|
+
const dest = join("android", "app", "src", "main", "assets", "public");
|
|
482
489
|
|
|
483
490
|
// Use 'xcopy' command for Windows
|
|
484
|
-
|
|
491
|
+
execSync(`xcopy ${src} ${dest} /E /I /Y`, { stdio: 'inherit' });
|
|
485
492
|
|
|
486
493
|
// Build Android AAB file
|
|
487
494
|
//child_process.execSync('cd android && ./gradlew bundleRelease', { stdio: 'inherit' });
|
|
488
495
|
|
|
489
496
|
|
|
490
497
|
// Build Android AAB file with Capacitor
|
|
491
|
-
|
|
492
|
-
|
|
498
|
+
execSync('npx cap sync android', { stdio: 'inherit' });
|
|
499
|
+
execSync('npx cap build android --androidreleasetype=AAB', { stdio: 'inherit' });
|
|
493
500
|
|
|
494
501
|
|
|
495
502
|
|
|
496
503
|
variablesGradleContent = variablesGradleContent.replace(/minSdkVersion\s*=\s*\d+/, 'minSdkVersion = 24');
|
|
497
504
|
console.log('minSdkVersion revert to 24 (default)');
|
|
498
|
-
|
|
505
|
+
writeFileSync(variablesGradleFilePath, variablesGradleContent);
|
|
499
506
|
|
|
500
507
|
|
|
501
508
|
// Rename the output AAB file
|
|
502
|
-
const oldFilePath =
|
|
503
|
-
if (
|
|
504
|
-
|
|
509
|
+
const oldFilePath = join(aabDirectory, "app-release-signed.aab");
|
|
510
|
+
if (existsSync(oldFilePath)) {
|
|
511
|
+
renameSync(oldFilePath, checkFullPath);
|
|
505
512
|
console.log(`✅ Renamed output AAB file to: ${newFileName}`);
|
|
506
513
|
} else {
|
|
507
514
|
console.error("❌ AAB file not found after build.");
|
|
@@ -529,7 +536,7 @@ function managePackages(store) {
|
|
|
529
536
|
|
|
530
537
|
|
|
531
538
|
|
|
532
|
-
let manifestContent =
|
|
539
|
+
let manifestContent = readFileSync(androidManifestPath, 'utf-8');
|
|
533
540
|
|
|
534
541
|
const permissionsToRemove = [
|
|
535
542
|
'com.android.vending.BILLING',
|
|
@@ -546,7 +553,7 @@ function managePackages(store) {
|
|
|
546
553
|
});
|
|
547
554
|
|
|
548
555
|
// Write the updated content back to the file
|
|
549
|
-
|
|
556
|
+
writeFileSync(androidManifestPath, manifestContent, 'utf-8');
|
|
550
557
|
|
|
551
558
|
|
|
552
559
|
|
|
@@ -570,8 +577,8 @@ function managePackages(store) {
|
|
|
570
577
|
} else {
|
|
571
578
|
console.log("No valid store specified or no configurations found. Both plugins will be uninstalled.");
|
|
572
579
|
try {
|
|
573
|
-
|
|
574
|
-
|
|
580
|
+
execSync(`npm uninstall cordova-plugin-samsungiap`, { stdio: 'inherit' });
|
|
581
|
+
execSync(`npm uninstall @revenuecat/purchases-capacitor`, { stdio: 'inherit' });
|
|
575
582
|
console.log(`✅ Both plugins uninstalled successfully.`);
|
|
576
583
|
} catch (err) {
|
|
577
584
|
console.error("❌ Error uninstalling plugins:", err);
|
|
@@ -582,10 +589,10 @@ function managePackages(store) {
|
|
|
582
589
|
console.log(`⚠️ Installing ${install} and uninstalling ${uninstall} for ${store}...`);
|
|
583
590
|
try {
|
|
584
591
|
if (install) {
|
|
585
|
-
|
|
592
|
+
execSync(`npm install ${install}`, { stdio: 'inherit' });
|
|
586
593
|
}
|
|
587
594
|
if (uninstall) {
|
|
588
|
-
|
|
595
|
+
execSync(`npm uninstall ${uninstall}`, { stdio: 'inherit' });
|
|
589
596
|
}
|
|
590
597
|
console.log(`✅ ${install} installed and ${uninstall} uninstalled successfully.`);
|
|
591
598
|
} catch (err) {
|
|
@@ -597,13 +604,13 @@ function managePackages(store) {
|
|
|
597
604
|
|
|
598
605
|
function updateAndroidManifest(store, addPermission) {
|
|
599
606
|
try {
|
|
600
|
-
if (!
|
|
607
|
+
if (!existsSync(androidManifestPath)) {
|
|
601
608
|
console.error("❌ AndroidManifest.xml file not found!");
|
|
602
609
|
return;
|
|
603
610
|
}
|
|
604
611
|
|
|
605
612
|
// Read the content of the AndroidManifest.xml
|
|
606
|
-
let manifestContent =
|
|
613
|
+
let manifestContent = readFileSync(androidManifestPath, 'utf-8');
|
|
607
614
|
|
|
608
615
|
// Normalize line endings to `\n` for consistent processing
|
|
609
616
|
manifestContent = manifestContent.replace(/\r\n/g, '\n');
|
|
@@ -630,7 +637,7 @@ function updateAndroidManifest(store, addPermission) {
|
|
|
630
637
|
|
|
631
638
|
// Normalize line endings back to `\r\n` and write the updated content
|
|
632
639
|
manifestContent = manifestContent.replace(/\n/g, '\r\n');
|
|
633
|
-
|
|
640
|
+
writeFileSync(androidManifestPath, manifestContent, 'utf-8');
|
|
634
641
|
console.log(`✅ AndroidManifest.xml updated successfully for ${store}`);
|
|
635
642
|
} catch (err) {
|
|
636
643
|
console.error(`❌ Error updating AndroidManifest.xml for ${store}:`, err);
|