codeplay-common 1.0.45 → 1.0.46
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 +1 -1
- package/scripts/uninstall.js +32 -38
package/package.json
CHANGED
package/scripts/uninstall.js
CHANGED
|
@@ -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
|
-
//
|
|
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
|
|
21
|
-
const getBaseName = (filename) =>
|
|
22
|
-
|
|
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
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
|
44
|
-
|
|
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] &&
|
|
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
|
|
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.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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!");
|