@hackthedev/frontend-libs 1.0.3 → 1.0.4
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/index.mjs +22 -6
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -23,10 +23,22 @@ export default class FrontendLibs {
|
|
|
23
23
|
: packageName;
|
|
24
24
|
|
|
25
25
|
const targetPath = path.resolve(pathToSave, folderName);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const versionFile = path.join(targetPath, '.version');
|
|
27
|
+
|
|
28
|
+
// check if already installed with same version
|
|
29
|
+
if (fs.existsSync(targetPath) && fs.existsSync(versionFile)) {
|
|
30
|
+
const installedVersion = fs.readFileSync(versionFile, 'utf8').trim();
|
|
31
|
+
if (installedVersion === version) {
|
|
32
|
+
return {
|
|
33
|
+
success: true,
|
|
34
|
+
message: `Package ${packageName}@${version} already installed. Skipped.`,
|
|
35
|
+
path: targetPath,
|
|
36
|
+
skipped: true
|
|
37
|
+
};
|
|
38
|
+
} else {
|
|
39
|
+
console.log(`Removing old version ${installedVersion} of ${folderName}...`);
|
|
40
|
+
fs.rmSync(targetPath, { recursive: true, force: true });
|
|
41
|
+
}
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
const tempDir = path.join(process.cwd(), '.temp', `${Date.now()}`);
|
|
@@ -51,13 +63,17 @@ export default class FrontendLibs {
|
|
|
51
63
|
|
|
52
64
|
this._copyRecursive(extractedPath, targetPath);
|
|
53
65
|
|
|
66
|
+
// write version file
|
|
67
|
+
fs.writeFileSync(versionFile, version, 'utf8');
|
|
68
|
+
|
|
54
69
|
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
55
70
|
|
|
56
71
|
return {
|
|
57
72
|
success: true,
|
|
58
73
|
message: `Successfully installed ${packageName}@${version}`,
|
|
59
|
-
path: targetPath
|
|
60
|
-
|
|
74
|
+
path: targetPath,
|
|
75
|
+
skipped: false
|
|
76
|
+
};
|
|
61
77
|
|
|
62
78
|
} catch (error) {
|
|
63
79
|
return {
|