snowymoon 0.0.0-stage → 1.0.0

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.
Files changed (3) hide show
  1. package/README.md +22 -2
  2. package/package.json +23 -4
  3. package/src/index.ts +278 -0
package/README.md CHANGED
@@ -1,3 +1,23 @@
1
- # Temporary Holding Version
1
+ # snowymoon
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ CLI updater for the [Snowymoon](https://snowymoon.io/) ETS2/ATS lighting + DLSS mods.
4
+ Finds your game's `bin/win_x64` folder, checks snowymoon.io for the latest version of
5
+ each mod, and downloads/extracts them for you.
6
+
7
+ Requires [Bun](https://bun.sh) installed.
8
+
9
+ ## Usage
10
+
11
+ ```
12
+ bunx snowymoon
13
+ ```
14
+
15
+ First run asks for your ETS2/ATS `bin/win_x64` path (auto-detects the default Steam
16
+ install) and remembers it. Every run after that just checks for updates.
17
+
18
+ ## What it does
19
+
20
+ - Reads https://snowymoon.io/ to find the current version of each mod.
21
+ - If a newer version is out, deletes the old DLLs and extracts the new ones into
22
+ `bin/win_x64`.
23
+ - Does nothing else. No telemetry, no other files touched.
package/package.json CHANGED
@@ -1,6 +1,25 @@
1
1
  {
2
2
  "name": "snowymoon",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "CLI updater that downloads the latest Snowymoon lighting/DLSS mods into your ETS2/ATS bin/win_x64 folder",
5
+ "type": "module",
6
+ "bin": {
7
+ "snowymoon": "./src/index.ts"
8
+ },
9
+ "files": [
10
+ "src"
11
+ ],
12
+ "scripts": {
13
+ "start": "bun run src/index.ts"
14
+ },
15
+ "keywords": [
16
+ "ets2",
17
+ "ats",
18
+ "snowymoon",
19
+ "euro-truck-simulator-2"
20
+ ],
21
+ "license": "MIT",
22
+ "engines": {
23
+ "bun": ">=1.0.0"
24
+ }
25
+ }
package/src/index.ts ADDED
@@ -0,0 +1,278 @@
1
+ #!/usr/bin/env bun
2
+
3
+ import {
4
+ existsSync,
5
+ mkdirSync,
6
+ readdirSync,
7
+ readFileSync,
8
+ renameSync,
9
+ rmSync,
10
+ writeFileSync,
11
+ } from "node:fs";
12
+ import { homedir } from "node:os";
13
+ import { join } from "node:path";
14
+ import { styleText } from "node:util";
15
+
16
+ const log = {
17
+ info: (msg: string) => console.log(styleText("cyan", msg)),
18
+ ok: (msg: string) => console.log(styleText("green", msg)),
19
+ warn: (msg: string) => console.log(styleText("yellow", msg)),
20
+ error: (msg: string) => console.error(styleText("red", msg)),
21
+ };
22
+
23
+ async function typewriter(text: string, delayMs = 15) {
24
+ for (const char of text) {
25
+ process.stdout.write(char);
26
+ await new Promise((r) => setTimeout(r, delayMs));
27
+ }
28
+ process.stdout.write("\n");
29
+ }
30
+
31
+ async function printBanner() {
32
+ await typewriter(styleText(["bold", "magenta"], "snowymoon-updater — made by iiDOR"));
33
+ await typewriter(
34
+ styleText(
35
+ "gray",
36
+ "Disclaimer: this is an automated script that only deletes old Snowymoon DLLs in your win_x64 folder and downloads/extracts the latest versions from the official snowymoon.io site. It does nothing else.",
37
+ ),
38
+ 4,
39
+ );
40
+ console.log();
41
+ }
42
+
43
+ const CONFIG_DIR = join(homedir(), ".snowymoon");
44
+ const CONFIG_FILE = join(CONFIG_DIR, "config.json");
45
+
46
+ const DEFAULT_CANDIDATES = [
47
+ "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Euro Truck Simulator 2\\bin\\win_x64",
48
+ "C:\\Program Files\\Steam\\steamapps\\common\\Euro Truck Simulator 2\\bin\\win_x64",
49
+ ];
50
+
51
+ type Config = { binPath: string; installed?: Record<string, string> };
52
+
53
+ function loadConfig(): Config | undefined {
54
+ if (!existsSync(CONFIG_FILE)) return undefined;
55
+ return JSON.parse(readFileSync(CONFIG_FILE, "utf-8"));
56
+ }
57
+
58
+ function saveConfig(config: Config) {
59
+ mkdirSync(CONFIG_DIR, { recursive: true });
60
+ writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
61
+ }
62
+
63
+ function getBinPath(): string {
64
+ const saved = loadConfig();
65
+ if (saved?.binPath) return saved.binPath;
66
+
67
+ const detected = DEFAULT_CANDIDATES.find((p) => existsSync(p));
68
+ const binPath = prompt("Where is your ETS2 bin path?", detected ?? "");
69
+
70
+ if (!binPath) {
71
+ log.error("No path provided.");
72
+ process.exit(1);
73
+ }
74
+
75
+ saveConfig({ binPath });
76
+ return binPath;
77
+ }
78
+
79
+ const SITE_URL = "https://snowymoon.io/";
80
+
81
+ // Each pattern matches the download links snowymoon.io embeds in its page
82
+ // (including old changelog entries). Group 1 is the version string used to
83
+ // pick the newest one.
84
+ const PACKAGES = [
85
+ {
86
+ name: "lighting",
87
+ pattern:
88
+ /https:\/\/cdn\.snowymoondl\.net\/lighting_v2\/ets2ats_lighting_v2_([\d_]+)_snowymoon\.io\.zip/g,
89
+ // The zip extracts into its own subfolder; the game only looks for the
90
+ // DLLs directly inside win_x64, so flatten it out.
91
+ extractedSubfolder: "ETS2ATS_Lighting_v2",
92
+ files: ["dinput8.dll", "dxgi.dll"],
93
+ },
94
+ {
95
+ name: "dlss",
96
+ pattern: /https:\/\/cdn\.snowymoondl\.net\/dlss_([\d.]+)\.zip/g,
97
+ files: ["nvngx_dlss.dll"],
98
+ },
99
+ ];
100
+
101
+ function versionParts(version: string): number[] {
102
+ return version.split(/[_.]/).map(Number);
103
+ }
104
+
105
+ function compareVersions(a: number[], b: number[]): number {
106
+ const len = Math.max(a.length, b.length);
107
+ for (let i = 0; i < len; i++) {
108
+ const diff = (a[i] ?? 0) - (b[i] ?? 0);
109
+ if (diff !== 0) return diff;
110
+ }
111
+ return 0;
112
+ }
113
+
114
+ function findLatest(
115
+ html: string,
116
+ pkg: (typeof PACKAGES)[number],
117
+ ): { url: string; version: string } {
118
+ const matches = [...html.matchAll(pkg.pattern)];
119
+ if (matches.length === 0) {
120
+ throw new Error(`No download link found on site for package "${pkg.name}"`);
121
+ }
122
+
123
+ let best = matches[0]!;
124
+ for (const m of matches) {
125
+ if (compareVersions(versionParts(m[1]!), versionParts(best[1]!)) > 0) {
126
+ best = m;
127
+ }
128
+ }
129
+ return { url: best[0], version: best[1]! };
130
+ }
131
+
132
+ // Installed versions are tracked in the home config, not inside win_x64 --
133
+ // the game folder should only ever contain the game's own files.
134
+ function readInstalledVersion(pkgName: string): string | undefined {
135
+ return loadConfig()?.installed?.[pkgName];
136
+ }
137
+
138
+ function writeInstalledVersion(pkgName: string, version: string) {
139
+ const config = loadConfig()!;
140
+ saveConfig({
141
+ ...config,
142
+ installed: { ...config.installed, [pkgName]: version },
143
+ });
144
+ }
145
+
146
+ function removeOldFiles(binPath: string, files: string[]) {
147
+ for (const file of files) {
148
+ const filePath = join(binPath, file);
149
+ if (existsSync(filePath)) rmSync(filePath, { force: true });
150
+ }
151
+ }
152
+
153
+ function filenameFromUrl(url: string): string {
154
+ return new URL(url).pathname.split("/").pop()!;
155
+ }
156
+
157
+ function renderProgressBar(label: string, fraction: number) {
158
+ const width = 24;
159
+ const filled = Math.round(width * fraction);
160
+ const bar = "#".repeat(filled) + "-".repeat(width - filled);
161
+ process.stdout.write(
162
+ `\r${label} [${styleText("green", bar)}] ${Math.round(fraction * 100)}% `,
163
+ );
164
+ }
165
+
166
+ async function downloadFile(url: string, destPath: string, label: string) {
167
+ const res = await fetch(url);
168
+ if (!res.ok) throw new Error(`Failed to download ${url}: ${res.status}`);
169
+
170
+ const total = Number(res.headers.get("content-length") ?? 0);
171
+ const file = Bun.file(destPath).writer();
172
+ let received = 0;
173
+
174
+ for await (const chunk of res.body!) {
175
+ file.write(chunk);
176
+ received += chunk.length;
177
+ renderProgressBar(label, total ? received / total : 0);
178
+ }
179
+ await file.end();
180
+ process.stdout.write("\n");
181
+ }
182
+
183
+ function flattenSubfolder(binPath: string, subfolder: string) {
184
+ const subfolderPath = join(binPath, subfolder);
185
+ if (!existsSync(subfolderPath)) return;
186
+
187
+ for (const entry of readdirSync(subfolderPath)) {
188
+ renameSync(join(subfolderPath, entry), join(binPath, entry));
189
+ }
190
+ rmSync(subfolderPath, { recursive: true, force: true });
191
+ }
192
+
193
+ async function extractZip(zipPath: string, destDir: string) {
194
+ const proc = Bun.spawn(
195
+ [
196
+ "powershell",
197
+ "-NoProfile",
198
+ "-Command",
199
+ `Expand-Archive -Path '${zipPath}' -DestinationPath '${destDir}' -Force`,
200
+ ],
201
+ { stdout: "pipe", stderr: "pipe" },
202
+ );
203
+ const exitCode = await proc.exited;
204
+ if (exitCode !== 0) throw new Error(`Extraction failed for ${zipPath}`);
205
+ }
206
+
207
+ const SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
208
+
209
+ async function withSpinner<T>(label: string, task: Promise<T>): Promise<T> {
210
+ let i = 0;
211
+ const interval = setInterval(() => {
212
+ process.stdout.write(`\r${SPINNER_FRAMES[i++ % SPINNER_FRAMES.length]} ${label}`);
213
+ }, 80);
214
+
215
+ try {
216
+ return await task;
217
+ } finally {
218
+ clearInterval(interval);
219
+ process.stdout.write(`\r${" ".repeat(label.length + 2)}\r`);
220
+ }
221
+ }
222
+
223
+ async function syncPackages(binPath: string) {
224
+ const html = await withSpinner(
225
+ `Checking ${SITE_URL} for the latest versions...`,
226
+ fetch(SITE_URL).then(async (res) => {
227
+ if (!res.ok) throw new Error(`Failed to load ${SITE_URL}: ${res.status}`);
228
+ return res.text();
229
+ }),
230
+ );
231
+
232
+ const tmpDir = join(CONFIG_DIR, "downloads");
233
+ mkdirSync(tmpDir, { recursive: true });
234
+
235
+ for (const pkg of PACKAGES) {
236
+ const { url, version } = findLatest(html, pkg);
237
+ const filename = filenameFromUrl(url);
238
+
239
+ // The cached version only counts if the files it refers to are still
240
+ // actually there -- otherwise someone deleted them and we need to redo it.
241
+ const filesPresent = pkg.files.every((f) => existsSync(join(binPath, f)));
242
+ const installedVersion = filesPresent ? readInstalledVersion(pkg.name) : undefined;
243
+
244
+ if (
245
+ installedVersion &&
246
+ compareVersions(versionParts(version), versionParts(installedVersion)) <= 0
247
+ ) {
248
+ log.ok(`${pkg.name}: up to date (${installedVersion})`);
249
+ continue;
250
+ }
251
+
252
+ log.warn(
253
+ `${pkg.name}: ${installedVersion ? `old version ${installedVersion} found, ` : ""}latest is ${version}`,
254
+ );
255
+
256
+ const zipPath = join(tmpDir, filename);
257
+ await downloadFile(url, zipPath, pkg.name);
258
+
259
+ if (installedVersion) removeOldFiles(binPath, pkg.files);
260
+
261
+ await withSpinner(
262
+ `${pkg.name}: extracting into ${binPath}`,
263
+ extractZip(zipPath, binPath),
264
+ );
265
+
266
+ if (pkg.extractedSubfolder) {
267
+ flattenSubfolder(binPath, pkg.extractedSubfolder);
268
+ }
269
+
270
+ writeInstalledVersion(pkg.name, version);
271
+ log.ok(`${pkg.name}: updated to ${version}`);
272
+ }
273
+ }
274
+
275
+ await printBanner();
276
+ const binPath = getBinPath();
277
+ log.info(`ETS2 bin path: ${binPath}`);
278
+ await syncPackages(binPath);