superprint 1.0.57 → 1.0.59
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/cli.mjs +34 -8
- package/package.json +1 -1
package/cli.mjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// Works identically on Windows, macOS and Linux.
|
|
7
7
|
// ═══════════════════════════════════════════════════════════════
|
|
8
8
|
import { spawn, spawnSync } from 'node:child_process';
|
|
9
|
-
import { createWriteStream, existsSync, mkdirSync, readFileSync, statSync, writeFileSync, unlinkSync } from 'node:fs';
|
|
9
|
+
import { createWriteStream, existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync, unlinkSync } from 'node:fs';
|
|
10
10
|
import { get as httpsGet } from 'node:https';
|
|
11
11
|
import { pipeline } from 'node:stream/promises';
|
|
12
12
|
import path from 'node:path';
|
|
@@ -19,6 +19,7 @@ const isWin = process.platform === 'win32';
|
|
|
19
19
|
// ── URLs & chemins ────────────────────────────────────────────
|
|
20
20
|
const APP_VERSION_URL = 'https://superprint.cc/version.txt';
|
|
21
21
|
const APP_ZIP_URL = 'https://app.zigmoon.com/sp213-local.zip';
|
|
22
|
+
const MIN_APP_VERSION = '1.7.318';
|
|
22
23
|
const APP_DIR = path.join(os.homedir(), '.superprint', 'app');
|
|
23
24
|
const ZIP_PATH = path.join(os.homedir(), '.superprint', 'sp213-local.zip');
|
|
24
25
|
const VERSION_FILE = path.join(APP_DIR, 'version.txt');
|
|
@@ -142,6 +143,28 @@ function isInstalled() {
|
|
|
142
143
|
function installedVersion() {
|
|
143
144
|
try { return readFileSync(VERSION_FILE, 'utf8').trim(); } catch { return null; }
|
|
144
145
|
}
|
|
146
|
+
function newestVersion(first, second) {
|
|
147
|
+
const parts = version => String(version || '').split('.').map(value => parseInt(value, 10) || 0);
|
|
148
|
+
const a = parts(first);
|
|
149
|
+
const b = parts(second);
|
|
150
|
+
for (let index = 0; index < Math.max(a.length, b.length); index++) {
|
|
151
|
+
if ((a[index] || 0) > (b[index] || 0)) return first;
|
|
152
|
+
if ((a[index] || 0) < (b[index] || 0)) return second;
|
|
153
|
+
}
|
|
154
|
+
return first || second;
|
|
155
|
+
}
|
|
156
|
+
function dependenciesReady() {
|
|
157
|
+
return [
|
|
158
|
+
path.join(APP_DIR, 'node_modules', 'vite', 'bin', 'vite.js'),
|
|
159
|
+
path.join(APP_DIR, 'node_modules', '@mlc-ai', 'web-llm', 'package.json'),
|
|
160
|
+
path.join(APP_DIR, 'node_modules', '@e965', 'xlsx', 'package.json')
|
|
161
|
+
].every(existsSync);
|
|
162
|
+
}
|
|
163
|
+
function runNpmInstall() {
|
|
164
|
+
return spawnSync('npm', ['install', '--no-audit', '--no-fund'], {
|
|
165
|
+
stdio: 'inherit', cwd: APP_DIR, shell: true
|
|
166
|
+
});
|
|
167
|
+
}
|
|
145
168
|
|
|
146
169
|
// ── Main ──────────────────────────────────────────────────────
|
|
147
170
|
async function main() {
|
|
@@ -152,8 +175,8 @@ async function main() {
|
|
|
152
175
|
|
|
153
176
|
// ---- Step 1/4: check online version ----
|
|
154
177
|
step(1, 'Checking online version');
|
|
155
|
-
let onlineVersion =
|
|
156
|
-
try { onlineVersion = await httpsGetText(APP_VERSION_URL); } catch (e) {}
|
|
178
|
+
let onlineVersion = MIN_APP_VERSION;
|
|
179
|
+
try { onlineVersion = newestVersion(await httpsGetText(APP_VERSION_URL), MIN_APP_VERSION); } catch (e) {}
|
|
157
180
|
const localVer = installedVersion();
|
|
158
181
|
|
|
159
182
|
if (isInstalled()) {
|
|
@@ -200,15 +223,18 @@ async function main() {
|
|
|
200
223
|
}
|
|
201
224
|
|
|
202
225
|
// ---- Step 4/4: npm install if needed ----
|
|
203
|
-
if (!
|
|
226
|
+
if (!dependenciesReady()) {
|
|
204
227
|
step(4, 'Installing dependencies (npm install)');
|
|
205
228
|
info('First install: a few minutes. Subsequent launches will be instant.');
|
|
206
229
|
// shell:true needed on Windows to launch npm (the .cmd wrappers
|
|
207
230
|
// fail with EINVAL via spawnSync without shell).
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
231
|
+
let install = runNpmInstall();
|
|
232
|
+
if (install.status !== 0) {
|
|
233
|
+
warn('The dependency folder is incomplete. Cleaning it and retrying once.');
|
|
234
|
+
try { rmSync(path.join(APP_DIR, 'node_modules'), { recursive: true, force: true }); } catch (_) {}
|
|
235
|
+
install = runNpmInstall();
|
|
236
|
+
}
|
|
237
|
+
if (install.status !== 0 || !dependenciesReady()) { fail('npm install failed.'); process.exit(1); }
|
|
212
238
|
// npm 12+ blocks install scripts (e.g. esbuild needs its postinstall
|
|
213
239
|
// to place its native binary). We approve all: this is our own
|
|
214
240
|
// trusted application.
|