codeplay-common 1.0.43 → 1.0.45

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeplay-common",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
4
4
  "description": "Common build scripts and files",
5
5
  "scripts": {
6
6
 
@@ -4,12 +4,11 @@ const path = require("path");
4
4
  const projectRoot = path.resolve(__dirname, "../../../"); // Project root
5
5
  const commonBuildPath = path.join(__dirname, "../files"); // Path where files were copied from
6
6
 
7
- console.log("🚀 Uninstalling: Removing copied files...");
7
+ console.log("🚀 Uninstalling: Removing old and copied files...");
8
8
 
9
9
  // Check if commonBuildPath exists
10
10
  if (!fs.existsSync(commonBuildPath)) {
11
11
  console.warn("⚠️ Common build path does not exist, skipping removal.");
12
- process.exit(0);
13
12
  }
14
13
 
15
14
  // Helper function to extract version from file name
@@ -18,58 +17,57 @@ const extractVersion = (filename) => {
18
17
  return match ? parseFloat(match[1]) : null;
19
18
  };
20
19
 
21
- // Collect files that match versioned patterns
22
- const versionedFilesMap = {};
20
+ // Helper function to get base name (without version and extension)
21
+ const getBaseName = (filename) => {
22
+ return filename.replace(/-\d+\.\d+\.js$/, "");
23
+ };
24
+
25
+ // Store latest versions for each file category
26
+ const latestVersions = {};
23
27
 
24
28
  // Scan project directory for versioned files
25
29
  fs.readdirSync(projectRoot).forEach(file => {
26
30
  if (file.match(/(add-splash-screen|setSplashAnimation|codeplayBeforeBuild)-\d+\.\d+\.js/)) {
27
- const baseName = file.split('-')[0];
31
+ const baseName = getBaseName(file);
28
32
  const version = extractVersion(file);
29
33
 
30
34
  if (version !== null) {
31
- if (!versionedFilesMap[baseName] || version > versionedFilesMap[baseName].version) {
32
- versionedFilesMap[baseName] = { file, version };
35
+ // Store the latest version found
36
+ if (!latestVersions[baseName] || version > latestVersions[baseName].version) {
37
+ latestVersions[baseName] = { file, version };
33
38
  }
34
39
  }
35
40
  }
36
41
  });
37
42
 
38
- // Read the common build folder and remove copied files
43
+ // Remove all outdated versions
44
+ fs.readdirSync(projectRoot).forEach(file => {
45
+ const baseName = getBaseName(file);
46
+ const version = extractVersion(file);
47
+
48
+ if (version !== null && latestVersions[baseName] && file !== latestVersions[baseName].file) {
49
+ const filePath = path.join(projectRoot, file);
50
+ try {
51
+ fs.unlinkSync(filePath);
52
+ console.log(`🗑️ Removed old version: ${filePath}`);
53
+ } catch (error) {
54
+ console.warn(`⚠️ Failed to remove ${filePath}: ${error.message}`);
55
+ }
56
+ }
57
+ });
58
+
59
+ // Remove files listed in commonBuildPath
39
60
  fs.readdirSync(commonBuildPath).forEach(file => {
40
61
  const destPath = path.join(projectRoot, file);
41
62
 
42
63
  if (fs.existsSync(destPath)) {
43
64
  try {
44
- const stats = fs.statSync(destPath);
45
-
46
- if (stats.isDirectory()) {
47
- fs.rmSync(destPath, { recursive: true, force: true });
48
- console.log(`🗑️ Removed folder: ${destPath}`);
49
- } else {
50
- fs.unlinkSync(destPath);
51
- console.log(`🗑️ Removed file: ${destPath}`);
52
- }
65
+ fs.unlinkSync(destPath);
66
+ console.log(`🗑️ Removed file: ${destPath}`);
53
67
  } catch (error) {
54
68
  console.warn(`⚠️ Failed to remove ${destPath}: ${error.message}`);
55
69
  }
56
- } else {
57
- console.log(`✅ Already removed: ${destPath}`);
58
70
  }
59
71
  });
60
72
 
61
- // Remove older versions of versioned files
62
- Object.keys(versionedFilesMap).forEach(baseName => {
63
- fs.readdirSync(projectRoot).forEach(file => {
64
- if (file.startsWith(baseName) && file.match(/-\d+\.\d+\.js$/)) {
65
- const version = extractVersion(file);
66
- if (version !== null && version < versionedFilesMap[baseName].version) {
67
- const filePath = path.join(projectRoot, file);
68
- fs.unlinkSync(filePath);
69
- console.log(`🗑️ Removed old version: ${filePath}`);
70
- }
71
- }
72
- });
73
- });
74
-
75
73
  console.log("✅ Uninstall cleanup complete!");