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