snowymoon 1.0.1 → 1.0.2
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/src/index.ts +37 -9
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -65,15 +65,28 @@ function getBinPath(): string {
|
|
|
65
65
|
if (saved?.binPath) return saved.binPath;
|
|
66
66
|
|
|
67
67
|
const detected = DEFAULT_CANDIDATES.find((p) => existsSync(p));
|
|
68
|
-
const binPath = prompt("Where is your ETS2 bin path?", detected ?? "");
|
|
69
68
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
while (true) {
|
|
70
|
+
const binPath = prompt("Where is your ETS2 bin path?", detected ?? "");
|
|
71
|
+
|
|
72
|
+
if (!binPath) {
|
|
73
|
+
log.error("No path provided.");
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
74
76
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
if (
|
|
78
|
+
!existsSync(join(binPath, "eurotrucks2.exe")) &&
|
|
79
|
+
!existsSync(join(binPath, "amtrucks.exe"))
|
|
80
|
+
) {
|
|
81
|
+
log.error(
|
|
82
|
+
`That doesn't look like a bin\\win_x64 folder (no eurotrucks2.exe/amtrucks.exe found in ${binPath})`,
|
|
83
|
+
);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
saveConfig({ binPath });
|
|
88
|
+
return binPath;
|
|
89
|
+
}
|
|
77
90
|
}
|
|
78
91
|
|
|
79
92
|
const SITE_URL = "https://snowymoon.io/";
|
|
@@ -232,9 +245,13 @@ async function syncPackages(binPath: string) {
|
|
|
232
245
|
const tmpDir = join(CONFIG_DIR, "downloads");
|
|
233
246
|
mkdirSync(tmpDir, { recursive: true });
|
|
234
247
|
|
|
248
|
+
// All questions are asked up front (no downloads/extraction in between),
|
|
249
|
+
// because interleaving async I/O with sync prompt() calls on piped stdin
|
|
250
|
+
// corrupts the next read.
|
|
251
|
+
const toUpdate: { pkg: (typeof PACKAGES)[number]; url: string; version: string }[] = [];
|
|
252
|
+
|
|
235
253
|
for (const pkg of PACKAGES) {
|
|
236
254
|
const { url, version } = findLatest(html, pkg);
|
|
237
|
-
const filename = filenameFromUrl(url);
|
|
238
255
|
|
|
239
256
|
// The cached version only counts if the files it refers to are still
|
|
240
257
|
// actually there -- otherwise someone deleted them and we need to redo it.
|
|
@@ -253,10 +270,21 @@ async function syncPackages(binPath: string) {
|
|
|
253
270
|
`${pkg.name}: ${installedVersion ? `old version ${installedVersion} found, ` : ""}latest is ${version}`,
|
|
254
271
|
);
|
|
255
272
|
|
|
273
|
+
const answer = prompt(`Update ${pkg.name} to ${version} now? [y/N]`, "n");
|
|
274
|
+
if (answer?.trim().toLowerCase()[0] !== "y") {
|
|
275
|
+
log.warn(`${pkg.name}: skipped`);
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
toUpdate.push({ pkg, url, version });
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
for (const { pkg, url, version } of toUpdate) {
|
|
283
|
+
const filename = filenameFromUrl(url);
|
|
256
284
|
const zipPath = join(tmpDir, filename);
|
|
257
285
|
await downloadFile(url, zipPath, pkg.name);
|
|
258
286
|
|
|
259
|
-
|
|
287
|
+
removeOldFiles(binPath, pkg.files);
|
|
260
288
|
|
|
261
289
|
await withSpinner(
|
|
262
290
|
`${pkg.name}: extracting into ${binPath}`,
|