codeplay-common 1.0.43 → 1.0.44

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.44",
4
4
  "description": "Common build scripts and files",
5
5
  "scripts": {
6
6
 
@@ -9,67 +9,59 @@ console.log("🚀 Uninstalling: Removing copied files...");
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
- // Helper function to extract version from file name
14
+ // Helper function to extract version from filename
16
15
  const extractVersion = (filename) => {
17
16
  const match = filename.match(/-(\d+\.\d+)\.js$/);
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 of versioned files
21
+ const getBaseName = (filename) => {
22
+ return filename.replace(/-\d+\.\d+\.js$/, "");
23
+ };
24
+
25
+ // Find versioned files in the project directory
26
+ const versionedFiles = fs.readdirSync(projectRoot)
27
+ .filter(file => file.match(/(add-splash-screen|setSplashAnimation|codeplayBeforeBuild)-\d+\.\d+\.js/));
28
+
29
+ const latestVersions = {};
23
30
 
24
- // Scan project directory for versioned files
25
- fs.readdirSync(projectRoot).forEach(file => {
26
- if (file.match(/(add-splash-screen|setSplashAnimation|codeplayBeforeBuild)-\d+\.\d+\.js/)) {
27
- const baseName = file.split('-')[0];
28
- const version = extractVersion(file);
31
+ // Group files by their base name and track latest versions
32
+ versionedFiles.forEach(file => {
33
+ const baseName = getBaseName(file);
34
+ const version = extractVersion(file);
29
35
 
30
- if (version !== null) {
31
- if (!versionedFilesMap[baseName] || version > versionedFilesMap[baseName].version) {
32
- versionedFilesMap[baseName] = { file, version };
33
- }
36
+ if (version !== null) {
37
+ if (!latestVersions[baseName] || version > latestVersions[baseName].version) {
38
+ latestVersions[baseName] = { file, version };
34
39
  }
35
40
  }
36
41
  });
37
42
 
38
- // Read the common build folder and remove copied files
43
+ // Remove older versions
44
+ versionedFiles.forEach(file => {
45
+ const baseName = getBaseName(file);
46
+ if (latestVersions[baseName] && file !== latestVersions[baseName].file) {
47
+ const filePath = path.join(projectRoot, file);
48
+ fs.unlinkSync(filePath);
49
+ console.log(`🗑️ Removed old version: ${filePath}`);
50
+ }
51
+ });
52
+
53
+ // Remove files listed in commonBuildPath
39
54
  fs.readdirSync(commonBuildPath).forEach(file => {
40
55
  const destPath = path.join(projectRoot, file);
41
56
 
42
57
  if (fs.existsSync(destPath)) {
43
58
  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
- }
59
+ fs.unlinkSync(destPath);
60
+ console.log(`🗑️ Removed file: ${destPath}`);
53
61
  } catch (error) {
54
62
  console.warn(`⚠️ Failed to remove ${destPath}: ${error.message}`);
55
63
  }
56
- } else {
57
- console.log(`✅ Already removed: ${destPath}`);
58
64
  }
59
65
  });
60
66
 
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
67
  console.log("✅ Uninstall cleanup complete!");