ryugi-artifacts 1.9.1 → 1.9.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.
Files changed (2) hide show
  1. package/dist/cli.cjs +16 -9
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -64,6 +64,7 @@ function projectPaths(dir) {
64
64
  lock: import_node_path.default.join(state, "start.lock")
65
65
  };
66
66
  }
67
+ var invocation = () => process.env.RYUGI_ARTIFACTS_COMMAND || "ryugi-artifacts";
67
68
  var ARTIFACT_PATTERN = /^(artboard|document|html)\/[a-z0-9][a-z0-9-]*$/;
68
69
  var ARTIFACT_ERROR = "--artifact must be <type>/<id>: type artboard, document or html, id of lowercase letters, digits and hyphens";
69
70
 
@@ -148,9 +149,14 @@ function commandLine(pid) {
148
149
  const line = full.stdout.split("\n").slice(1).join(" ").trim();
149
150
  return line ? line.split(/\s+/) : null;
150
151
  }
152
+ var isNodeImage = (tasklistLine) => /^"node\.exe"/i.test(tasklistLine.trim());
153
+ function windowsNodeAt(pid) {
154
+ const result = (0, import_node_child_process.spawnSync)("tasklist", ["/FI", `PID eq ${pid}`, "/FO", "CSV", "/NH"], { encoding: "utf8", windowsHide: true });
155
+ return result.status === 0 && isNodeImage(result.stdout);
156
+ }
151
157
  function hasServerId(pid, id) {
152
158
  if (!alive(pid)) return false;
153
- if (process.platform === "win32") return true;
159
+ if (process.platform === "win32") return windowsNodeAt(pid);
154
160
  return commandLine(pid)?.includes(`--artifacts-server-id=${id}`) ?? false;
155
161
  }
156
162
  function parentOf(pid) {
@@ -230,7 +236,7 @@ function recordAgent(paths) {
230
236
  if (Object.keys(markers).length) import_node_fs3.default.writeFileSync(paths.agent, `${JSON.stringify(markers)}
231
237
  `);
232
238
  }
233
- async function replace(pid) {
239
+ async function replace(pid, paths) {
234
240
  try {
235
241
  process.kill(pid, "SIGTERM");
236
242
  } catch {
@@ -241,7 +247,7 @@ async function replace(pid) {
241
247
  } catch {
242
248
  }
243
249
  if (await waitForExit(pid, 2e3)) return;
244
- throw new CliError(`The running server (pid ${pid}) is on another release and did not stop; stop it with \`ryugi-artifacts stop\` and retry`);
250
+ throw new CliError(`The running server (pid ${pid}) is on another release and did not stop; stop it with \`${invocation()} stop --project-dir ${paths.project}\` and retry`);
245
251
  }
246
252
  function serverEnv(paths, options) {
247
253
  const env = { ...process.env, ARTIFACTS_ROOT: paths.root, ARTIFACTS_HOST: options.host, ARTIFACTS_URL_HOST: options.urlHost, ARTIFACTS_OPEN: options.open ? "1" : "0" };
@@ -249,6 +255,7 @@ function serverEnv(paths, options) {
249
255
  if (options.idleTimeoutMinutes) env.ARTIFACTS_IDLE_TIMEOUT_MS = String(Number(options.idleTimeoutMinutes) * 6e4);
250
256
  delete env.RYUGI_ARTIFACTS_OWNER;
251
257
  delete env.RYUGI_ARTIFACTS_VERSION;
258
+ delete env.RYUGI_ARTIFACTS_COMMAND;
252
259
  return env;
253
260
  }
254
261
  async function start(options, emit) {
@@ -282,7 +289,7 @@ async function start(options, emit) {
282
289
  emit(withLink(JSON.parse(info), options.artifact, true));
283
290
  return 0;
284
291
  }
285
- await replace(running);
292
+ await replace(running, paths);
286
293
  }
287
294
  registerOwner(paths);
288
295
  recordAgent(paths);
@@ -326,7 +333,7 @@ async function start(options, emit) {
326
333
  const started = lines.find((line) => line.includes('"server-started"'));
327
334
  if (started) {
328
335
  for (let check = 0; check < 20; check++) {
329
- if (!alive(child.pid)) throw new CliError(`Server started but was killed. Retry in a persistent terminal with: ryugi-artifacts start --project-dir ${paths.project} --host ${options.host} --url-host ${options.urlHost} --foreground`);
336
+ if (!alive(child.pid)) throw new CliError(`Server started but was killed. Retry in a persistent terminal with: ${invocation()} start --project-dir ${paths.project}${options.artifact ? ` --artifact ${options.artifact}` : ""} --host ${options.host} --url-host ${options.urlHost} --foreground`);
330
337
  await sleep(100);
331
338
  }
332
339
  emit(withLink(JSON.parse(started), options.artifact, false));
@@ -346,7 +353,7 @@ async function start(options, emit) {
346
353
  }
347
354
 
348
355
  // src/cli/publish.ts
349
- var NOT_RUNNING = "No artifacts server is running for this project. Start it with `ryugi-artifacts start`, then run this again.";
356
+ var notRunning = (project) => `No artifacts server is running for this project. Start it with \`${invocation()} start --project-dir ${project}\`, then run this again.`;
350
357
  async function publish(options, emit) {
351
358
  if (options.action === "publish" || options.action === "unpublish") {
352
359
  if (!options.artifact) throw new CliError("--artifact <type>/<id> is required");
@@ -358,7 +365,7 @@ async function publish(options, emit) {
358
365
  try {
359
366
  info = JSON.parse(readText(paths.info) ?? "");
360
367
  } catch {
361
- throw new CliError(NOT_RUNNING);
368
+ throw new CliError(notRunning(paths.project));
362
369
  }
363
370
  const base = new URL(info.url);
364
371
  const key = base.searchParams.get("key") ?? "";
@@ -372,7 +379,7 @@ async function publish(options, emit) {
372
379
  body: body ? JSON.stringify(body) : void 0
373
380
  });
374
381
  } catch {
375
- throw new CliError(NOT_RUNNING);
382
+ throw new CliError(notRunning(paths.project));
376
383
  }
377
384
  const json = await res.json().catch(() => ({}));
378
385
  if (res.status === 401) throw new CliError("", { type: "login-required", url: json.loginUrl, message: "Open url to sign in to the Ryugi cloud, then run the same command again." }, 2);
@@ -569,7 +576,7 @@ async function main(argv) {
569
576
  }, emit);
570
577
  }
571
578
  if (command === "--version" || command === "-v") {
572
- console.log("1.9.1");
579
+ console.log("1.9.2");
573
580
  return 0;
574
581
  }
575
582
  if (command === "--help" || command === "-h") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ryugi-artifacts",
3
- "version": "1.9.1",
3
+ "version": "1.9.2",
4
4
  "type": "module",
5
5
  "description": "Server and viewer for the Ryugi artifacts app",
6
6
  "license": "MIT",