superprint 1.0.70 → 1.0.71

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 (2) hide show
  1. package/cli.mjs +36 -19
  2. package/package.json +1 -1
package/cli.mjs CHANGED
@@ -141,17 +141,28 @@ function isInstalled() {
141
141
  return existsSync(path.join(APP_DIR, 'package.json'));
142
142
  }
143
143
  function installedVersion() {
144
+ try { return JSON.parse(readFileSync(path.join(APP_DIR, 'package.json'), 'utf8')).version || null; } catch {}
144
145
  try { return readFileSync(VERSION_FILE, 'utf8').trim(); } catch { return null; }
145
146
  }
146
- function newestVersion(first, second) {
147
+ function compareVersions(first, second) {
147
148
  const parts = version => String(version || '').split('.').map(value => parseInt(value, 10) || 0);
148
149
  const a = parts(first);
149
150
  const b = parts(second);
150
151
  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;
152
+ if ((a[index] || 0) > (b[index] || 0)) return 1;
153
+ if ((a[index] || 0) < (b[index] || 0)) return -1;
154
+ }
155
+ return 0;
156
+ }
157
+ function newestVersion(first, second) {
158
+ return compareVersions(first, second) >= 0 ? (first || second) : second;
159
+ }
160
+ function extractedVersion() {
161
+ try {
162
+ return JSON.parse(readFileSync(path.join(APP_DIR, 'package.json'), 'utf8')).version || null;
163
+ } catch {
164
+ return null;
153
165
  }
154
- return first || second;
155
166
  }
156
167
  function dependenciesReady() {
157
168
  return [
@@ -161,8 +172,8 @@ function dependenciesReady() {
161
172
  ].every(existsSync);
162
173
  }
163
174
  function runNpmInstall() {
164
- return spawnSync('npm', ['install', '--no-audit', '--no-fund'], {
165
- stdio: 'inherit', cwd: APP_DIR, shell: true
175
+ return spawnSync(isWin ? 'npm.cmd' : 'npm', ['install', '--no-audit', '--no-fund'], {
176
+ stdio: 'inherit', cwd: APP_DIR, shell: isWin
166
177
  });
167
178
  }
168
179
 
@@ -180,8 +191,8 @@ async function main() {
180
191
  const localVer = installedVersion();
181
192
 
182
193
  if (isInstalled()) {
183
- if (onlineVersion && localVer && onlineVersion !== localVer) {
184
- info('Online version (' + onlineVersion + ') local (' + localVer + ') — updating.');
194
+ if (!localVer || compareVersions(localVer, onlineVersion) < 0) {
195
+ info('Online version (' + onlineVersion + ') is newer than local (' + (localVer || '?') + ') — updating.');
185
196
  // Remove the old app to re-download the new one
186
197
  const { rmSync } = await import('node:fs');
187
198
  rmSync(APP_DIR, { recursive: true, force: true });
@@ -213,11 +224,14 @@ async function main() {
213
224
  fail('Failed to extract the zip.');
214
225
  process.exit(1);
215
226
  }
216
- ok('Application extracted.');
217
- if (onlineVersion) {
218
- try { mkdirSync(APP_DIR, { recursive: true }); } catch {}
219
- try { writeFileSync(VERSION_FILE, onlineVersion); } catch {}
227
+ const downloadedVersion = extractedVersion();
228
+ if (!downloadedVersion || compareVersions(downloadedVersion, onlineVersion) < 0) {
229
+ rmSync(APP_DIR, { recursive: true, force: true });
230
+ fail('Downloaded application version is invalid or older than the online version.');
231
+ process.exit(1);
220
232
  }
233
+ ok('Application extracted.');
234
+ try { writeFileSync(VERSION_FILE, downloadedVersion); } catch {}
221
235
  // Clean up the zip (save space)
222
236
  try { unlinkSync(ZIP_PATH); } catch {}
223
237
  }
@@ -238,8 +252,8 @@ async function main() {
238
252
  // npm 12+ blocks install scripts (e.g. esbuild needs its postinstall
239
253
  // to place its native binary). We approve all: this is our own
240
254
  // trusted application.
241
- const appr = spawnSync('npm', ['install-scripts', 'approve', '--all'], {
242
- stdio: 'inherit', cwd: APP_DIR, shell: true
255
+ const appr = spawnSync(isWin ? 'npm.cmd' : 'npm', ['install-scripts', 'approve', '--all'], {
256
+ stdio: 'inherit', cwd: APP_DIR, shell: isWin
243
257
  });
244
258
  if (appr.status !== 0) {
245
259
  // Command missing (npm < 12): not an issue, scripts run by default.
@@ -252,15 +266,18 @@ async function main() {
252
266
  }
253
267
 
254
268
  // ---- Launch Vite ----
255
- console.log(SEP);
256
- console.log(C.green + C.bold + ' Starting SuperPrint…' + C.reset);
257
- console.log(C.dim + ' Open your browser at: http://127.0.0.1:5173' + C.reset);
258
- console.log(SEP);
259
-
260
269
  const viteBin = path.join(APP_DIR, 'node_modules', 'vite', 'bin', 'vite.js');
261
270
  const userArgs = process.argv.slice(2);
262
271
  const hasExplicitHost = userArgs.some(arg => arg === '--host' || arg.startsWith('--host='));
272
+ const portArgIndex = userArgs.findIndex(arg => arg === '--port');
273
+ const inlinePort = userArgs.find(arg => arg.startsWith('--port='));
274
+ const displayPort = inlinePort ? inlinePort.slice('--port='.length) : (portArgIndex >= 0 ? userArgs[portArgIndex + 1] : '5173');
263
275
  const args = hasExplicitHost ? userArgs : ['--host', '127.0.0.1', ...userArgs];
276
+
277
+ console.log(SEP);
278
+ console.log(C.green + C.bold + ' Starting SuperPrint…' + C.reset);
279
+ console.log(C.dim + ' Open your browser at: http://127.0.0.1:' + displayPort + C.reset);
280
+ console.log(SEP);
264
281
  const child = spawn(process.execPath, [viteBin, ...args], {
265
282
  stdio: 'inherit', cwd: APP_DIR
266
283
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "superprint",
3
- "version": "1.0.70",
3
+ "version": "1.0.71",
4
4
  "description": "SuperPrint by 2.13 — free browser DTP and prepress editor. Use online at https://superprint.cc or run locally with npx.",
5
5
  "keywords": [
6
6
  "superprint",