codeplay-common 1.8.5 → 1.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -242,33 +242,62 @@ const addPermission_AD_ID=async()=>{
242
242
  isAdmobFound = false;
243
243
  }
244
244
 
245
+
245
246
 
246
- if (isAdmobFound) {
247
- // Check if AndroidManifest.xml exists
248
- if (existsSync(androidManifestPath)) {
249
- // Read the content of AndroidManifest.xml
250
- let manifestContent = readFileSync(androidManifestPath, 'utf8');
251
-
252
- // Check if the ad_id permission already exists
253
- const adIdPermission = '<uses-permission android:name="com.google.android.gms.permission.AD_ID" />';
254
- if (!manifestContent.includes(adIdPermission)) {
255
- console.log("ad_id permission not found. Adding to AndroidManifest.xml.");
256
-
257
- // Add the ad_id permission before the closing </manifest> tag
258
- manifestContent = manifestContent.replace('</manifest>', ` ${adIdPermission}\n</manifest>`);
259
-
260
- // Write the updated manifest content back to AndroidManifest.xml
261
- writeFileSync(androidManifestPath, manifestContent, 'utf8');
262
- console.log("✅ ad_id permission added successfully.");
247
+ if (isAdmobFound) {
248
+ if (existsSync(androidManifestPath)) {
249
+ let manifestContent = readFileSync(androidManifestPath, 'utf8');
250
+ let modified = false;
251
+
252
+ // --- Step 1: Ensure AD_ID permission exists ---
253
+ const adIdPermission = '<uses-permission android:name="com.google.android.gms.permission.AD_ID" />';
254
+ if (!manifestContent.includes(adIdPermission)) {
255
+ console.log("📄 AD_ID permission not found. Adding to AndroidManifest.xml.");
256
+ manifestContent = manifestContent.replace('</manifest>', ` ${adIdPermission}\n</manifest>`);
257
+ console.log("✅ AD_ID permission added successfully.");
258
+ modified = true;
259
+ } else {
260
+ console.log("â„šī¸ AD_ID permission already exists in AndroidManifest.xml.");
261
+ }
262
+
263
+ // --- Step 2: Ensure OPTIMIZE_AD_LOADING meta-data exists ---
264
+ const optimizeAdMeta = `<meta-data android:name="com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING" android:value="true" />`;
265
+
266
+ if (!manifestContent.includes(optimizeAdMeta)) {
267
+ console.log("📄 OPTIMIZE_AD_LOADING meta-data not found. Adding to AndroidManifest.xml.");
268
+
269
+ const appTagPattern = /<application[^>]*>/;
270
+ if (appTagPattern.test(manifestContent)) {
271
+ manifestContent = manifestContent.replace(appTagPattern, match => `${match}\n ${optimizeAdMeta}`);
272
+ console.log("✅ OPTIMIZE_AD_LOADING meta-data added successfully.");
273
+ modified = true;
263
274
  } else {
264
- console.log("â„šī¸ ad_id permission already exists in AndroidManifest.xml.");
275
+ console.error("❌ <application> tag not found in AndroidManifest.xml.");
265
276
  }
266
277
  } else {
267
- console.error("❌ AndroidManifest.xml not found at the specified path.");
278
+ console.log("â„šī¸ OPTIMIZE_AD_LOADING meta-data already exists in AndroidManifest.xml.");
279
+ }
280
+
281
+ // --- Step 3: Write only if modified ---
282
+ if (modified) {
283
+ writeFileSync(androidManifestPath, manifestContent, 'utf8');
284
+ console.log("💾 AndroidManifest.xml updated successfully.");
285
+ } else {
286
+ console.log("✅ No changes needed. AndroidManifest.xml is up to date.");
268
287
  }
288
+
269
289
  } else {
270
- console.log("\x1b[33m%s\x1b[0m", "âš ī¸ No admob found, so permission.AD_ID is not added");
290
+ console.error("❌ AndroidManifest.xml not found at the specified path.");
271
291
  }
292
+ } else {
293
+ console.log("\x1b[33m%s\x1b[0m", "âš ī¸ No AdMob found, so AD_ID permission and meta-data were not added");
294
+ }
295
+
296
+
297
+
298
+
299
+
300
+
272
301
  }
273
302
 
274
303
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeplay-common",
3
- "version": "1.8.5",
3
+ "version": "1.8.6",
4
4
  "description": "Common build scripts and files",
5
5
  "scripts": {
6
6
  "postinstall": "node scripts/sync-files.js",