codeplay-common 1.0.45 → 1.0.47

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.45",
3
+ "version": "1.0.47",
4
4
  "description": "Common build scripts and files",
5
5
  "scripts": {
6
6
 
@@ -6,68 +6,62 @@ const commonBuildPath = path.join(__dirname, "../files"); // Path where files we
6
6
 
7
7
  console.log("🚀 Uninstalling: Removing old and copied files...");
8
8
 
9
- // Check if commonBuildPath exists
10
- if (!fs.existsSync(commonBuildPath)) {
11
- console.warn("⚠️ Common build path does not exist, skipping removal.");
12
- }
13
-
14
- // Helper function to extract version from file name
9
+ // Helper function to extract version from filename
15
10
  const extractVersion = (filename) => {
16
11
  const match = filename.match(/-(\d+\.\d+)\.js$/);
17
12
  return match ? parseFloat(match[1]) : null;
18
13
  };
19
14
 
20
- // Helper function to get base name (without version and extension)
21
- const getBaseName = (filename) => {
22
- return filename.replace(/-\d+\.\d+\.js$/, "");
23
- };
15
+ // Helper function to get base name without version
16
+ const getBaseName = (filename) => filename.replace(/-\d+\.\d+\.js$/, "");
17
+
18
+ // Step 1: Find all versioned files in the project directory
19
+ const filesInProject = fs.readdirSync(projectRoot)
20
+ .filter(file => file.match(/(add-splash-screen-|setSplashAnimation-|codeplayBeforeBuild-)-\d+\.\d+\.js/));
24
21
 
25
- // Store latest versions for each file category
26
22
  const latestVersions = {};
27
23
 
28
- // Scan project directory for versioned files
29
- fs.readdirSync(projectRoot).forEach(file => {
30
- if (file.match(/(add-splash-screen|setSplashAnimation|codeplayBeforeBuild)-\d+\.\d+\.js/)) {
31
- const baseName = getBaseName(file);
32
- const version = extractVersion(file);
24
+ // Step 2: Determine the latest version for each file type
25
+ filesInProject.forEach(file => {
26
+ const baseName = getBaseName(file);
27
+ const version = extractVersion(file);
33
28
 
34
- if (version !== null) {
35
- // Store the latest version found
36
- if (!latestVersions[baseName] || version > latestVersions[baseName].version) {
37
- latestVersions[baseName] = { file, version };
38
- }
29
+ if (version !== null) {
30
+ if (!latestVersions[baseName] || version > latestVersions[baseName].version) {
31
+ latestVersions[baseName] = { file, version };
39
32
  }
40
33
  }
41
34
  });
42
35
 
43
- // Remove all outdated versions
44
- fs.readdirSync(projectRoot).forEach(file => {
36
+ // Step 3: Remove ALL outdated versions, even if latest is missing
37
+ filesInProject.forEach(file => {
45
38
  const baseName = getBaseName(file);
46
39
  const version = extractVersion(file);
40
+ const filePath = path.join(projectRoot, file);
47
41
 
48
- if (version !== null && latestVersions[baseName] && file !== latestVersions[baseName].file) {
49
- const filePath = path.join(projectRoot, file);
42
+ if (version !== null && latestVersions[baseName] && version < latestVersions[baseName].version) {
50
43
  try {
51
44
  fs.unlinkSync(filePath);
52
- console.log(`🗑️ Removed old version: ${filePath}`);
45
+ console.log(`🗑️ Removed outdated file: ${filePath}`);
53
46
  } catch (error) {
54
47
  console.warn(`⚠️ Failed to remove ${filePath}: ${error.message}`);
55
48
  }
56
49
  }
57
50
  });
58
51
 
59
- // Remove files listed in commonBuildPath
60
- fs.readdirSync(commonBuildPath).forEach(file => {
61
- const destPath = path.join(projectRoot, file);
62
-
63
- if (fs.existsSync(destPath)) {
64
- try {
65
- fs.unlinkSync(destPath);
66
- console.log(`🗑️ Removed file: ${destPath}`);
67
- } catch (error) {
68
- console.warn(`⚠️ Failed to remove ${destPath}: ${error.message}`);
52
+ // Step 4: Remove files listed in commonBuildPath
53
+ if (fs.existsSync(commonBuildPath)) {
54
+ fs.readdirSync(commonBuildPath).forEach(file => {
55
+ const destPath = path.join(projectRoot, file);
56
+ if (fs.existsSync(destPath)) {
57
+ try {
58
+ fs.unlinkSync(destPath);
59
+ console.log(`🗑️ Removed file: ${destPath}`);
60
+ } catch (error) {
61
+ console.warn(`⚠️ Failed to remove ${destPath}: ${error.message}`);
62
+ }
69
63
  }
70
- }
71
- });
64
+ });
65
+ }
72
66
 
73
67
  console.log("✅ Uninstall cleanup complete!");