superprint 1.0.70 → 1.0.72

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 +14 -2
  2. package/cli.mjs +36 -19
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -16,12 +16,24 @@ Use the npm launcher below when you prefer to run SuperPrint locally on your com
16
16
 
17
17
  Prerequisite: [Node.js 18+](https://nodejs.org) (npm included).
18
18
 
19
+ ### Windows PowerShell
20
+
21
+ The `npm i superprint` command displayed automatically by npm installs the package but does not launch SuperPrint. On Windows PowerShell, script execution policies may also block `npm.ps1` and `npx.ps1`.
22
+
23
+ Launch SuperPrint with the Windows command wrapper instead:
24
+
25
+ ```powershell
26
+ npx.cmd superprint@latest
27
+ ```
28
+
29
+ This does not require changing your PowerShell execution policy. If you specifically want to install the package first, use `npm.cmd i superprint`, then launch it with `npx.cmd superprint`.
30
+
31
+ ### macOS and Linux
32
+
19
33
  ```bash
20
34
  npx superprint
21
35
  ```
22
36
 
23
- **Windows PowerShell:** if script execution is disabled, use `npx.cmd superprint`.
24
-
25
37
  On first launch, the launcher downloads the application (about 50 MB), installs its local dependencies and opens **http://127.0.0.1:5173**. Later launches reuse the installed copy and automatically detect application updates. The server binds to the loopback interface by default, so it is not exposed to your local network or the Internet.
26
38
 
27
39
  ## What is included
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.72",
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",