betool-cli 0.5.1 → 0.6.1
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/install.js +48 -0
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -79,6 +79,53 @@ function download(url, dest) {
|
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
// cleanupResiduals removes leftover betool binaries so a fresh install never
|
|
83
|
+
// leaves a stale/duplicate executable that could shadow the freshly downloaded
|
|
84
|
+
// one. Best-effort : every step is guarded, a failure here never fails the
|
|
85
|
+
// install. Only ever touches files named ``betool``/``betool.exe`` in known
|
|
86
|
+
// locations.
|
|
87
|
+
function cleanupResiduals(activeDest) {
|
|
88
|
+
const removed = [];
|
|
89
|
+
|
|
90
|
+
// 1. Our own bin/ dir : drop any betool binary that isn't the active one
|
|
91
|
+
// (e.g. a wrong-platform leftover or a partial previous download). The
|
|
92
|
+
// ``betool.js`` launcher is kept.
|
|
93
|
+
try {
|
|
94
|
+
const binDir = path.dirname(activeDest);
|
|
95
|
+
for (const f of fs.readdirSync(binDir)) {
|
|
96
|
+
const full = path.join(binDir, f);
|
|
97
|
+
if (full === activeDest || f === "betool.js") continue;
|
|
98
|
+
if (/^betool(\.exe)?$/.test(f) || /^betool-/.test(f)) {
|
|
99
|
+
try { fs.rmSync(full, { force: true }); removed.push(full); } catch (_) {}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
} catch (_) {}
|
|
103
|
+
|
|
104
|
+
// 2. Legacy standalone install location (Makefile ``install-client`` and
|
|
105
|
+
// manual copies dropped a binary in %LOCALAPPDATA%\betool\bin). Remove it
|
|
106
|
+
// so the npm install is the single source of truth.
|
|
107
|
+
const legacyDirs = [];
|
|
108
|
+
if (process.platform === "win32" && process.env.LOCALAPPDATA) {
|
|
109
|
+
legacyDirs.push(path.join(process.env.LOCALAPPDATA, "betool", "bin"));
|
|
110
|
+
}
|
|
111
|
+
const ext = process.platform === "win32" ? ".exe" : "";
|
|
112
|
+
for (const dir of legacyDirs) {
|
|
113
|
+
const legacyBin = path.join(dir, `betool${ext}`);
|
|
114
|
+
try {
|
|
115
|
+
if (fs.existsSync(legacyBin) && path.resolve(legacyBin) !== path.resolve(activeDest)) {
|
|
116
|
+
fs.rmSync(legacyBin, { force: true });
|
|
117
|
+
removed.push(legacyBin);
|
|
118
|
+
try { if (fs.readdirSync(dir).length === 0) fs.rmdirSync(dir); } catch (_) {}
|
|
119
|
+
}
|
|
120
|
+
} catch (_) {}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (removed.length) {
|
|
124
|
+
console.log(` nettoyage : ${removed.length} résidu(s) supprimé(s)`);
|
|
125
|
+
for (const r of removed) console.log(` - ${r}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
82
129
|
async function main() {
|
|
83
130
|
const binaryName = getBinaryName();
|
|
84
131
|
const url = `${BASE_URL}/${binaryName}`;
|
|
@@ -102,6 +149,7 @@ async function main() {
|
|
|
102
149
|
}
|
|
103
150
|
|
|
104
151
|
console.log(` OK — installe dans ${dest}`);
|
|
152
|
+
cleanupResiduals(dest);
|
|
105
153
|
} catch (err) {
|
|
106
154
|
console.error(`Erreur de telechargement : ${err.message}`);
|
|
107
155
|
console.error(`\nInstallation manuelle :`);
|