codeplay-common 3.0.7 → 3.0.9

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/.gitattributes CHANGED
@@ -1,2 +1,2 @@
1
- # Auto detect text files and perform LF normalization
2
- * text=auto
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Merbin Joe
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Merbin Joe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
- # codeplay-common
2
- Everything automatted in Capacitor apps, easy to maintain many apps in capacitor. It will reduce your 40% of work, with common file code.
3
-
4
-
5
- Easy add splashscreen and set animation
6
- Admob id automatically from capacitor.config.json file
7
- Make three build file for different store as per our requirement
8
- Based on store install various IAP plugins
9
- Make it to ionic project
10
-
11
- Donate to get full code including many common functions
1
+ # codeplay-common
2
+ Everything automatted in Capacitor apps, easy to maintain many apps in capacitor. It will reduce your 40% of work, with common file code.
3
+
4
+
5
+ Easy add splashscreen and set animation
6
+ Admob id automatically from capacitor.config.json file
7
+ Make three build file for different store as per our requirement
8
+ Based on store install various IAP plugins
9
+ Make it to ionic project
10
+
11
+ Donate to get full code including many common functions
12
12
  https://ko-fi.com/codeplay
@@ -2,18 +2,26 @@ const fs = require('fs');
2
2
  const path = require('path');
3
3
  const plist = require('plist');
4
4
 
5
+
6
+
7
+ const { execSync } = require("child_process");
8
+
9
+
10
+
11
+
5
12
  const { readFileSync } = require("fs");
6
13
 
7
14
  const ENABLE_AUTO_UPDATE = true;
15
+ const USE_LIVE_SERVER_VERSION = true;
8
16
 
9
17
  const configPath = path.join(process.cwd(), 'capacitor.config.json');
10
18
 
11
19
  // Expected plugin list with minimum versions
12
- const requiredPlugins = [
20
+ /* const requiredPlugins = [
13
21
 
14
22
  { pattern: /backbutton-(\d+\.\d+)\.js$/, minVersion: '2.0', required: true, baseDir: 'js',mandatoryUpdate: true},
15
23
 
16
- /*/common-(\d+\.\d+)\.js$/*/
24
+
17
25
  { pattern: /common-(\d+\.\d+)(?:-beta-(\d+))?\.js$/, minVersion: '6.0', required: true, baseDir: 'js',mandatoryUpdate: true },
18
26
 
19
27
  { pattern: /localization_settings-(\d+\.\d+)\.js$/, minVersion: '1.1', required: true, baseDir: 'js',mandatoryUpdate: false },
@@ -39,7 +47,72 @@ const requiredPlugins = [
39
47
 
40
48
  { pattern: /certificatejs-(\d+\.\d+)$/, minVersion: '1.6', isFolder: true , required: true, baseDir: 'certificate',mandatoryUpdate: true }
41
49
 
42
- ];
50
+ ]; */
51
+
52
+
53
+ function requireOrInstall(packageName) {
54
+ try {
55
+ return require(packageName);
56
+ } catch (err) {
57
+
58
+ console.log(`📦 "${packageName}" not found. Installing automatically...`);
59
+
60
+ try {
61
+ execSync(`npm install ${packageName}`, { stdio: "inherit" });
62
+ console.log(`✅ "${packageName}" installed successfully.`);
63
+ } catch (installErr) {
64
+ console.error(`❌ Failed to install "${packageName}".`);
65
+ process.exit(1);
66
+ }
67
+
68
+ // Try loading again
69
+ return require(packageName);
70
+ }
71
+ }
72
+
73
+ const AdmZip = requireOrInstall("adm-zip");
74
+
75
+
76
+
77
+
78
+ const versionsFile = path.join(__dirname, "versions.json");
79
+
80
+ function loadRequiredPlugins() {
81
+
82
+ if (!fs.existsSync(versionsFile)) {
83
+ console.error("❌ versions.json not found");
84
+ process.exit(1);
85
+ }
86
+
87
+ const json = JSON.parse(fs.readFileSync(versionsFile, "utf8"));
88
+
89
+ return json.plugins.map(p => ({
90
+ ...p,
91
+ pattern: new RegExp(p.pattern)
92
+ }));
93
+
94
+ }
95
+
96
+ let requiredPlugins = loadRequiredPlugins();
97
+
98
+
99
+
100
+
101
+
102
+
103
+ async function downloadAndExtractZip(url, destFolder) {
104
+
105
+ const zipPath = destFolder + ".zip";
106
+
107
+ await downloadFile(url, zipPath);
108
+
109
+ const zip = new AdmZip(zipPath);
110
+ zip.extractAllTo(destFolder, true);
111
+
112
+ fs.unlinkSync(zipPath);
113
+
114
+ }
115
+
43
116
 
44
117
 
45
118
 
@@ -47,7 +120,8 @@ const requiredPlugins = [
47
120
 
48
121
 
49
122
  //Check codeplay-common latest version installed or not Start
50
- const { execSync } = require('child_process');
123
+ //const { execSync } = require('child_process');
124
+
51
125
 
52
126
  function getInstalledVersion(packageName) {
53
127
  try {
@@ -1124,33 +1198,50 @@ function updateImports(oldName, newName) {
1124
1198
  */
1125
1199
 
1126
1200
 
1201
+ let _serverVersions = null;
1202
+ async function fetchVersions() {
1203
+
1204
+ if (_serverVersions) return _serverVersions;
1205
+
1206
+ return new Promise((resolve) => {
1127
1207
 
1128
- function fetchVersions() {
1129
- return new Promise((resolve, reject) => {
1130
1208
  https.get(
1131
1209
  "https://htmlcodeplay.com/code-play-plugin/versions.json",
1210
+ { timeout: 5000 },
1132
1211
  res => {
1212
+
1133
1213
  let data = "";
1134
1214
 
1135
1215
  res.on("data", chunk => data += chunk);
1216
+
1136
1217
  res.on("end", () => {
1218
+
1137
1219
  try {
1138
- resolve(JSON.parse(data));
1220
+
1221
+ _serverVersions = JSON.parse(data);
1222
+
1223
+ resolve(_serverVersions);
1224
+
1139
1225
  } catch {
1226
+
1140
1227
  resolve(null);
1228
+
1141
1229
  }
1230
+
1142
1231
  });
1232
+
1143
1233
  }
1234
+
1144
1235
  ).on("error", () => resolve(null));
1236
+
1145
1237
  });
1238
+
1146
1239
  }
1147
1240
 
1148
1241
 
1149
1242
 
1150
1243
  async function autoUpdatePlugin(pluginDef, pluginInfo) {
1151
1244
 
1152
- if (pluginDef.isFolder) return false;
1153
-
1154
1245
  const versions = await fetchVersions();
1155
1246
 
1156
1247
  if (!versions) {
@@ -1171,30 +1262,101 @@ async function autoUpdatePlugin(pluginDef, pluginInfo) {
1171
1262
  return false;
1172
1263
  }
1173
1264
 
1174
- const newFileName = `${baseName}-${latestVersion}.js`;
1265
+ // ===============================
1266
+ // FOLDER PLUGIN UPDATE
1267
+ // ===============================
1268
+ if (pluginDef.isFolder) {
1175
1269
 
1176
- const url =
1177
- `https://htmlcodeplay.com/code-play-plugin/${newFileName}`;
1270
+ const zipName = `${baseName}-${latestVersion}.zip`;
1271
+ const url = `https://htmlcodeplay.com/code-play-plugin/${zipName}`;
1178
1272
 
1179
- console.log(`🔍 Checking latest: ${newFileName}`);
1273
+ const destRoot = path.join(srcDir, pluginDef.destDir || pluginDef.baseDir || '');
1274
+ const oldPath = path.join(destRoot, pluginInfo.name);
1275
+ const newPath = path.join(destRoot, `${baseName}-${latestVersion}`);
1180
1276
 
1181
- if (!(await urlExists(url))) {
1182
- console.log(`❌ File missing on server`);
1183
- return false;
1277
+ if (!(await urlExists(url))) return false;
1278
+
1279
+ fs.rmSync(oldPath, { recursive: true, force: true });
1280
+
1281
+ await downloadAndExtractZip(url, newPath);
1282
+
1283
+ console.log(`✅ Folder updated → ${baseName}-${latestVersion}`);
1284
+
1285
+ return true;
1184
1286
  }
1287
+ // ===============================
1288
+ // FILE PLUGIN UPDATE
1289
+ // ===============================
1290
+
1291
+ const pluginDir = path.dirname(oldFullPath);
1292
+
1293
+ // Only this plugin has ios variant
1294
+ const IOS_VARIANT_PLUGINS = [
1295
+ "saveToGalleryAndSaveAnyFile"
1296
+ ];
1297
+
1298
+ let variants = [
1299
+ `${baseName}-${latestVersion}.js`
1300
+ ];
1185
1301
 
1186
- const destPath =
1187
- path.join(path.dirname(oldFullPath), newFileName);
1302
+ if (IOS_VARIANT_PLUGINS.includes(baseName)) {
1303
+ variants.push(`${baseName}-${latestVersion}-ios.js`);
1304
+ }
1305
+
1306
+ let downloaded = [];
1307
+
1308
+ // Download files
1309
+ for (const fileName of variants) {
1310
+
1311
+ const url = `https://htmlcodeplay.com/code-play-plugin/${fileName}`;
1188
1312
 
1189
- await downloadFile(url, destPath);
1313
+ console.log(`🔍 Checking latest: ${fileName}`);
1190
1314
 
1191
- fs.unlinkSync(oldFullPath);
1315
+ if (await urlExists(url)) {
1192
1316
 
1193
- updateImports(oldFileName, newFileName);
1317
+ const destPath = path.join(pluginDir, fileName);
1194
1318
 
1195
- console.log(`✅ Updated → ${newFileName}`);
1319
+ await downloadFile(url, destPath);
1320
+
1321
+ downloaded.push(fileName);
1322
+
1323
+ console.log(`⬇ Downloaded → ${fileName}`);
1324
+ }
1325
+ }
1196
1326
 
1197
- return true;
1327
+ if (downloaded.length === 0) {
1328
+ console.log(`❌ No files downloaded for ${baseName}`);
1329
+ return false;
1330
+ }
1331
+
1332
+ // Remove ONLY versioned files (safe)
1333
+ const versionPattern = new RegExp(`^${baseName}-\\d+\\.\\d+(-ios)?\\.js$`);
1334
+
1335
+ const existingFiles = fs.readdirSync(pluginDir);
1336
+
1337
+ existingFiles.forEach(file => {
1338
+
1339
+ if (
1340
+ versionPattern.test(file) &&
1341
+ !downloaded.includes(file)
1342
+ ) {
1343
+
1344
+ const oldPath = path.join(pluginDir, file);
1345
+
1346
+ fs.unlinkSync(oldPath);
1347
+
1348
+ console.log(`🗑 Removed old file → ${file}`);
1349
+ }
1350
+
1351
+ });
1352
+
1353
+ const newFileName = `${baseName}-${latestVersion}.js`;
1354
+
1355
+ updateImports(oldFileName, newFileName);
1356
+
1357
+ console.log(`✅ Updated → ${newFileName}`);
1358
+
1359
+ return true;
1198
1360
  }
1199
1361
 
1200
1362
 
@@ -1219,7 +1381,35 @@ async function autoUpdatePlugin(pluginDef, pluginInfo) {
1219
1381
 
1220
1382
 
1221
1383
 
1384
+ async function loadPluginVersions() {
1222
1385
 
1386
+ if (!USE_LIVE_SERVER_VERSION) {
1387
+ console.log("ℹ️ Using local plugin versions (offline mode).");
1388
+ return;
1389
+ }
1390
+
1391
+ console.log("🌐 Fetching plugin versions from server...");
1392
+
1393
+ const versions = await fetchVersions();
1394
+
1395
+ if (!versions || typeof versions !== "object") {
1396
+ console.log("⚠️ Server unavailable or invalid versions.json. Falling back to local versions.");
1397
+ return;
1398
+ }
1399
+
1400
+ requiredPlugins.forEach(plugin => {
1401
+
1402
+ if (!plugin.name) return;
1403
+
1404
+ if (versions[plugin.name]) {
1405
+ plugin.minVersion = versions[plugin.name];
1406
+ }
1407
+
1408
+ });
1409
+
1410
+ console.log("✅ Plugin versions loaded from server.");
1411
+
1412
+ }
1223
1413
 
1224
1414
 
1225
1415
 
@@ -1303,7 +1493,7 @@ function checkPlugins() {
1303
1493
  outdatedPlugins.forEach( p => {
1304
1494
  const tag = p.mandatoryUpdate ? '🔥 MANDATORY' : '';
1305
1495
  console.log(
1306
- ` - ${p.name} (Current: ${p.currentVersion}, Required: ${p.requiredVersion}) ${tag}`
1496
+ ` ⚠️ - ${p.name} (Current: ${p.currentVersion}, Required: ${p.requiredVersion}) ${tag}`
1307
1497
  );
1308
1498
  });
1309
1499
 
@@ -1373,7 +1563,11 @@ if (hasMandatoryUpdate) {
1373
1563
  process.exit(1);
1374
1564
  }
1375
1565
 
1376
- console.log('\n🎉 All mandatory plugins auto-updated!');
1566
+ console.log('\n🎉 All mandatory plugins auto-updated! Rechecking plugins...\n');
1567
+
1568
+ // Re-run plugin check so outdated list becomes empty
1569
+ await checkPlugins();
1570
+ return;
1377
1571
  }
1378
1572
 
1379
1573
 
@@ -1653,6 +1847,9 @@ ensureGitignoreEntry('buildCodeplay/');
1653
1847
 
1654
1848
  // Run the validation
1655
1849
  (async () => {
1850
+
1851
+ await loadPluginVersions(); // 🔥 NEW
1852
+
1656
1853
  await checkPlugins();
1657
1854
  checkAndupdateDropInViteConfig();
1658
1855
  checkAdmobConfigurationProperty()
@@ -0,0 +1,21 @@
1
+ {
2
+ "plugins":[
3
+ {"name":"backbutton","pattern":"backbutton-(\\d+\\.\\d+)\\.js$","minVersion":"2.0","baseDir":"js","mandatoryUpdate":true},
4
+ {"name":"common","pattern":"common-(\\d+\\.\\d+)(?:-beta-(\\d+))?\\.js$","minVersion":"6.0","baseDir":"js","mandatoryUpdate":true},
5
+ {"name":"localization_settings","pattern":"localization_settings-(\\d+\\.\\d+)\\.js$","minVersion":"1.1","baseDir":"js","mandatoryUpdate":true},
6
+ {"name":"localization","pattern":"localization-(\\d+\\.\\d+)\\.js$","minVersion":"1.5","baseDir":"js","mandatoryUpdate":true},
7
+ {"name":"admob-emi","pattern":"Ads[\\\\/]admob-emi-(\\d+\\.\\d+)\\.js$","minVersion":"3.7","baseDir":"js","mandatoryUpdate":true},
8
+ {"name":"video-player","pattern":"video-player-(\\d+\\.\\d+)\\.js$","minVersion":"1.6","baseDir":"js","mandatoryUpdate":true},
9
+ {"name":"image-cropper","pattern":"image-cropper-(\\d+\\.\\d+)\\.js$","minVersion":"1.1","baseDir":"js","mandatoryUpdate":true},
10
+ {"name":"editor","pattern":"editor-(\\d+\\.\\d+)$","minVersion":"1.9","baseDir":"js","mandatoryUpdate":true,"isFolder":true},
11
+ {"name":"ffmpeg","pattern":"ffmpeg-(\\d+\\.\\d+)$","minVersion":"1.6","baseDir":"js","mandatoryUpdate":true,"isFolder":true},
12
+ {"name":"theme","pattern":"theme-(\\d+\\.\\d+)$","minVersion":"3.3","baseDir":"theme","destDir":"theme","mandatoryUpdate":true,"isFolder":true},
13
+ {"name":"certificatejs","pattern":"certificatejs-(\\d+\\.\\d+)$","minVersion":"1.6","baseDir":"certificate","destDir":"certificate","mandatoryUpdate":true,"isFolder":true},
14
+ {"name":"IAP","pattern":"IAP-(\\d+\\.\\d+)$","minVersion":"2.8","baseDir":"js/Ads","mandatoryUpdate":true,"isFolder":true},
15
+ {"name":"common-css","pattern":"common-(\\d+\\.\\d+)\\.less$","minVersion":"1.6","baseDir":"assets/css","mandatoryUpdate":true},
16
+ {"name":"localNotification_AppSettings","pattern":"localNotification_AppSettings-(\\d+\\.\\d+)\\.js$","minVersion":"1.0","baseDir":"js","mandatoryUpdate":true},
17
+ {"name":"localNotification","pattern":"localNotification-(\\d+\\.\\d+)\\.js$","minVersion":"2.2","baseDir":"js","mandatoryUpdate":true},
18
+ {"name":"onesignal","pattern":"onesignal-(\\d+\\.\\d+)\\.js$","minVersion":"2.3","baseDir":"js","mandatoryUpdate":true},
19
+ {"name":"saveToGalleryAndSaveAnyFile","pattern":"saveToGalleryAndSaveAnyFile-(\\d+\\.\\d+)(-ios)?\\.js$","minVersion":"3.1","baseDir":"js","mandatoryUpdate":true}
20
+ ]
21
+ }