codeplay-common 3.0.9 → 3.1.1

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
@@ -15,6 +15,7 @@ const ENABLE_AUTO_UPDATE = true;
15
15
  const USE_LIVE_SERVER_VERSION = true;
16
16
 
17
17
  const configPath = path.join(process.cwd(), 'capacitor.config.json');
18
+ const updateLogFile = path.join(process.cwd(), "", "plugin-update-log.txt");
18
19
 
19
20
  // Expected plugin list with minimum versions
20
21
  /* const requiredPlugins = [
@@ -74,6 +75,69 @@ const AdmZip = requireOrInstall("adm-zip");
74
75
 
75
76
 
76
77
 
78
+ const pkg = require(path.join(process.cwd(), 'node_modules', 'codeplay-common', 'package.json'));
79
+
80
+ const pluginName = pkg.name;
81
+ const pluginVersion = pkg.version;
82
+
83
+ let updateLogs = [];
84
+
85
+ function writeUpdateLine(message) {
86
+ updateLogs.push(message);
87
+ }
88
+
89
+ const MAX_LOG_BLOCKS = 50;
90
+
91
+ function saveUpdateLogs() {
92
+
93
+ if (updateLogs.length === 0) return;
94
+
95
+ const logDir = path.dirname(updateLogFile);
96
+
97
+ if (!fs.existsSync(logDir)) {
98
+ fs.mkdirSync(logDir, { recursive: true });
99
+ }
100
+
101
+ const now = new Date();
102
+
103
+ const formattedTime = now.toLocaleString('en-GB', {
104
+ day: '2-digit',
105
+ month: '2-digit',
106
+ year: 'numeric',
107
+ hour: '2-digit',
108
+ minute: '2-digit',
109
+ hour12: true
110
+ }).replace(',', '').replace(/\//g, '-');
111
+
112
+ let newBlock = `${pluginName}: ${pluginVersion}\n[${formattedTime}]\n`;
113
+
114
+ updateLogs.forEach(line => {
115
+ newBlock += `${line}\n`;
116
+ });
117
+
118
+ newBlock += "\n";
119
+
120
+ let existingLog = "";
121
+
122
+ if (fs.existsSync(updateLogFile)) {
123
+ existingLog = fs.readFileSync(updateLogFile, "utf8");
124
+ }
125
+
126
+ let combinedLog = newBlock + existingLog;
127
+
128
+ // Split blocks by plugin header
129
+ const blocks = combinedLog.split(/\n(?=codeplay-common:)/);
130
+
131
+ // Keep only latest 50
132
+ const trimmed = blocks.slice(0, MAX_LOG_BLOCKS).join("\n");
133
+
134
+ fs.writeFileSync(updateLogFile, trimmed);
135
+
136
+ }
137
+
138
+
139
+
140
+
77
141
 
78
142
  const versionsFile = path.join(__dirname, "versions.json");
79
143
 
@@ -1111,50 +1175,39 @@ const VITE_ALIAS_ONLY = [
1111
1175
  "certificatejs",
1112
1176
  "ffmpeg"
1113
1177
  ];
1178
+
1114
1179
  function updateImports(oldName, newName) {
1115
1180
 
1116
1181
  const projectRoot = process.cwd();
1117
1182
 
1118
- const viteFiles = [
1183
+ const filesToScan = [
1119
1184
  path.join(projectRoot, "vite.config.js"),
1120
1185
  path.join(projectRoot, "vite.config.mjs")
1121
1186
  ];
1122
1187
 
1123
- // Detect if alias-only plugin
1124
- const isAliasOnly = VITE_ALIAS_ONLY.some(p =>
1125
- oldName.includes(p)
1126
- );
1188
+ const srcDir = path.join(projectRoot, "src");
1189
+
1190
+ // scan vite config
1191
+ filesToScan.forEach(file => {
1127
1192
 
1128
- //--------------------------------------------------
1129
- // 1️⃣ ALWAYS update vite config
1130
- //--------------------------------------------------
1131
- viteFiles.forEach(file => {
1132
1193
  if (!fs.existsSync(file)) return;
1133
1194
 
1134
1195
  let content = fs.readFileSync(file, "utf8");
1135
1196
 
1136
1197
  if (content.includes(oldName)) {
1137
- content = content.replaceAll(oldName, newName);
1198
+
1199
+ content = content.split(oldName).join(newName);
1200
+
1138
1201
  fs.writeFileSync(file, content);
1139
1202
 
1140
1203
  console.log(`✏️ Updated alias in ${path.basename(file)}`);
1141
1204
  }
1142
- });
1143
1205
 
1144
- //--------------------------------------------------
1145
- // 2️⃣ If alias-only → STOP here
1146
- //--------------------------------------------------
1147
- if (isAliasOnly) {
1148
- console.log(`⚡ Alias-only plugin → skipped full scan`);
1149
- return;
1150
- }
1151
-
1152
- //--------------------------------------------------
1153
- // 3️⃣ Otherwise scan src
1154
- //--------------------------------------------------
1155
- const srcDir = path.join(projectRoot, "src");
1206
+ });
1156
1207
 
1208
+ // scan src files
1157
1209
  function walk(dir) {
1210
+
1158
1211
  fs.readdirSync(dir).forEach(file => {
1159
1212
 
1160
1213
  if (["node_modules","android","ios","dist",".git"].includes(file))
@@ -1166,29 +1219,36 @@ function updateImports(oldName, newName) {
1166
1219
  if (stat.isDirectory()) {
1167
1220
  walk(full);
1168
1221
  }
1222
+
1169
1223
  else if (
1170
1224
  (full.endsWith(".js") ||
1171
1225
  full.endsWith(".f7") ||
1172
1226
  full.endsWith(".mjs")) &&
1173
1227
  !full.endsWith(".min.js")
1174
1228
  ) {
1229
+
1175
1230
  let content = fs.readFileSync(full, "utf8");
1176
1231
 
1177
1232
  if (content.includes(oldName)) {
1178
- content = content.replaceAll(oldName, newName);
1233
+
1234
+ content = content.split(oldName).join(newName);
1235
+
1179
1236
  fs.writeFileSync(full, content);
1180
1237
 
1181
1238
  console.log(`✏️ Updated import in ${path.relative(projectRoot, full)}`);
1182
1239
  }
1240
+
1183
1241
  }
1242
+
1184
1243
  });
1244
+
1185
1245
  }
1186
1246
 
1187
1247
  if (fs.existsSync(srcDir)) {
1188
1248
  walk(srcDir);
1189
1249
  }
1190
- }
1191
1250
 
1251
+ }
1192
1252
 
1193
1253
 
1194
1254
  /**
@@ -1252,10 +1312,21 @@ async function autoUpdatePlugin(pluginDef, pluginInfo) {
1252
1312
  const oldFullPath = path.join(srcDir, pluginInfo.name);
1253
1313
  const oldFileName = path.basename(oldFullPath);
1254
1314
 
1255
- // Extract base name
1256
- const baseName = oldFileName.replace(/-\d+\.\d+.*$/, "");
1315
+ //const oldFileName = path.basename(oldFullPath);
1316
+ const oldVersionFile = oldFileName;
1317
+
1318
+
1319
+ const ext = path.extname(oldFileName); // .js or .less
1320
+ //const baseName = oldFileName.replace(/-\d+\.\d+.*$/, "");
1321
+ const baseName = oldFileName.replace(/-\d+\.\d+.*$/, '').replace(/\.(js|less)$/, '');
1257
1322
 
1258
- const latestVersion = versions[baseName];
1323
+ // version lookup key
1324
+ let pluginKey = baseName;
1325
+
1326
+ if (ext === ".js") pluginKey = `${baseName}-js`;
1327
+ if (ext === ".less") pluginKey = `${baseName}-less`;
1328
+
1329
+ const latestVersion = versions[pluginKey];
1259
1330
 
1260
1331
  if (!latestVersion) {
1261
1332
  console.log(`❌ No version entry for ${baseName}`);
@@ -1265,25 +1336,28 @@ async function autoUpdatePlugin(pluginDef, pluginInfo) {
1265
1336
  // ===============================
1266
1337
  // FOLDER PLUGIN UPDATE
1267
1338
  // ===============================
1268
- if (pluginDef.isFolder) {
1339
+ if (pluginDef.isFolder) {
1269
1340
 
1270
- const zipName = `${baseName}-${latestVersion}.zip`;
1271
- const url = `https://htmlcodeplay.com/code-play-plugin/${zipName}`;
1341
+ const zipName = `${baseName}-${latestVersion}.zip`;
1342
+ const url = `https://htmlcodeplay.com/code-play-plugin/${zipName}`;
1272
1343
 
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}`);
1344
+ const destRoot = path.join(srcDir, pluginDef.destDir || pluginDef.baseDir || '');
1345
+ const oldPath = path.join(destRoot, pluginInfo.name);
1346
+ const newPath = path.join(destRoot, `${baseName}-${latestVersion}`);
1276
1347
 
1277
- if (!(await urlExists(url))) return false;
1348
+ if (!(await urlExists(url))) return false;
1278
1349
 
1279
- fs.rmSync(oldPath, { recursive: true, force: true });
1350
+ fs.rmSync(oldPath, { recursive: true, force: true });
1280
1351
 
1281
- await downloadAndExtractZip(url, newPath);
1352
+ await downloadAndExtractZip(url, newPath);
1282
1353
 
1283
- console.log(`✅ Folder updated ${baseName}-${latestVersion}`);
1354
+ // 🔥 FIX: update imports
1355
+ updateImports(pluginInfo.name, `${baseName}-${latestVersion}`);
1284
1356
 
1285
- return true;
1286
- }
1357
+ console.log(`✅ Folder updated → ${baseName}-${latestVersion}`);
1358
+
1359
+ return true;
1360
+ }
1287
1361
  // ===============================
1288
1362
  // FILE PLUGIN UPDATE
1289
1363
  // ===============================
@@ -1295,9 +1369,13 @@ const IOS_VARIANT_PLUGINS = [
1295
1369
  "saveToGalleryAndSaveAnyFile"
1296
1370
  ];
1297
1371
 
1298
- let variants = [
1372
+ /* let variants = [
1299
1373
  `${baseName}-${latestVersion}.js`
1300
- ];
1374
+ ]; */
1375
+
1376
+ //const ext = path.extname(oldFileName);
1377
+ const variants = [`${baseName.replace(ext,'')}-${latestVersion}${ext}`];
1378
+
1301
1379
 
1302
1380
  if (IOS_VARIANT_PLUGINS.includes(baseName)) {
1303
1381
  variants.push(`${baseName}-${latestVersion}-ios.js`);
@@ -1321,6 +1399,9 @@ for (const fileName of variants) {
1321
1399
  downloaded.push(fileName);
1322
1400
 
1323
1401
  console.log(`⬇ Downloaded → ${fileName}`);
1402
+
1403
+ //writeUpdateLine(`Downloaded: ${fileName}`);
1404
+
1324
1405
  }
1325
1406
  }
1326
1407
 
@@ -1330,7 +1411,8 @@ if (downloaded.length === 0) {
1330
1411
  }
1331
1412
 
1332
1413
  // Remove ONLY versioned files (safe)
1333
- const versionPattern = new RegExp(`^${baseName}-\\d+\\.\\d+(-ios)?\\.js$`);
1414
+ //const versionPattern = new RegExp(`^${baseName}-\\d+\\.\\d+(-ios)?\\.js$`);
1415
+ const versionPattern = new RegExp(`^${baseName}-\\d+\\.\\d+(-ios)?\\${ext}$`);
1334
1416
 
1335
1417
  const existingFiles = fs.readdirSync(pluginDir);
1336
1418
 
@@ -1346,15 +1428,22 @@ existingFiles.forEach(file => {
1346
1428
  fs.unlinkSync(oldPath);
1347
1429
 
1348
1430
  console.log(`🗑 Removed old file → ${file}`);
1431
+ //writeUpdateLine(`Removed old file: ${file}`);
1349
1432
  }
1350
1433
 
1351
1434
  });
1352
1435
 
1353
- const newFileName = `${baseName}-${latestVersion}.js`;
1436
+ //const newFileName = `${baseName}-${latestVersion}.js`;
1437
+ const newFileName = `${baseName}-${latestVersion}${ext}`;
1438
+
1439
+ writeUpdateLine(`${oldVersionFile} -> ${newFileName}`);
1354
1440
 
1355
1441
  updateImports(oldFileName, newFileName);
1442
+ //updateImports(baseName, `${baseName}-${latestVersion}.js`);
1443
+ //updateImports(pluginInfo.name, `${baseName}-${latestVersion}`);
1356
1444
 
1357
- console.log(`✅ Updated → ${newFileName}`);
1445
+ //console.log(`✅ Updated → ${newFileName}`);
1446
+ //console.log(`✅ Updated → ${baseName}-${latestVersion}`);
1358
1447
 
1359
1448
  return true;
1360
1449
  }
@@ -1597,6 +1686,7 @@ if (hasMandatoryUpdate) {
1597
1686
  );
1598
1687
  } else {
1599
1688
  console.log('✅ All plugin versions are up to date.');
1689
+ saveUpdateLogs();
1600
1690
  resolve();
1601
1691
  }
1602
1692
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "plugins":[
3
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},
4
+ {"name":"common-js","pattern":"common-(\\d+\\.\\d+)(?:-beta-(\\d+))?\\.js$","minVersion":"6.0","baseDir":"js","mandatoryUpdate":true},
5
5
  {"name":"localization_settings","pattern":"localization_settings-(\\d+\\.\\d+)\\.js$","minVersion":"1.1","baseDir":"js","mandatoryUpdate":true},
6
6
  {"name":"localization","pattern":"localization-(\\d+\\.\\d+)\\.js$","minVersion":"1.5","baseDir":"js","mandatoryUpdate":true},
7
7
  {"name":"admob-emi","pattern":"Ads[\\\\/]admob-emi-(\\d+\\.\\d+)\\.js$","minVersion":"3.7","baseDir":"js","mandatoryUpdate":true},
@@ -12,7 +12,7 @@
12
12
  {"name":"theme","pattern":"theme-(\\d+\\.\\d+)$","minVersion":"3.3","baseDir":"theme","destDir":"theme","mandatoryUpdate":true,"isFolder":true},
13
13
  {"name":"certificatejs","pattern":"certificatejs-(\\d+\\.\\d+)$","minVersion":"1.6","baseDir":"certificate","destDir":"certificate","mandatoryUpdate":true,"isFolder":true},
14
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},
15
+ {"name":"common-less","pattern":"common-(\\d+\\.\\d+)\\.less$","minVersion":"1.7","baseDir":"assets/css","mandatoryUpdate":true},
16
16
  {"name":"localNotification_AppSettings","pattern":"localNotification_AppSettings-(\\d+\\.\\d+)\\.js$","minVersion":"1.0","baseDir":"js","mandatoryUpdate":true},
17
17
  {"name":"localNotification","pattern":"localNotification-(\\d+\\.\\d+)\\.js$","minVersion":"2.2","baseDir":"js","mandatoryUpdate":true},
18
18
  {"name":"onesignal","pattern":"onesignal-(\\d+\\.\\d+)\\.js$","minVersion":"2.3","baseDir":"js","mandatoryUpdate":true},