@zaisma/cli 0.38.0 → 0.40.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/chrome.mjs +16 -7
  2. package/package.json +1 -1
  3. package/zaisma.mjs +17 -6
package/chrome.mjs CHANGED
@@ -49,22 +49,31 @@ function playwrightChromes() {
49
49
  }
50
50
 
51
51
  /**
52
- * Headless Chrome at path with WebGL in software (SwiftShader, as on Zaisma's check and on machines without a GPU), or on the machine's
53
- * own GPU with isGpu (scripts/city.mjs times and renders the city on it), or with no GPU and no WebGL at all with isDrawingOnCpu (the
54
- * layout check measures boxes, not pixels), and a DevTools connection to it: send(method, parameters,
55
- * sessionId), listen(sessionId, onEvent) and close().
52
+ * What Chrome starts with besides its profile. It never touches the machine's GPU: WebGL in software (SwiftShader, as on Zaisma's check and
53
+ * on machines without a GPU), or with isDrawingOnCpu --disable-gpu, for the layout check, which measures boxes, not pixels (no WebGL on a Mac, SwiftShader on Linux).
54
+ * test/node/chrome-no-gpu.test.ts holds this, and that nothing else starts a Chrome.
56
55
  */
57
- export async function openChrome(path, profilePrefix, { isGpu = false, isDrawingOnCpu = false } = {}) {
56
+ export function chromeFlags({ isDrawingOnCpu = false } = {}) {
57
+ const drawing = isDrawingOnCpu ? ["--disable-gpu"] : ["--use-angle=swiftshader", "--enable-unsafe-swiftshader"];
58
+ return ["--headless=new", "--remote-debugging-port=0", "--no-first-run", "--no-default-browser-check", ...drawing, "--autoplay-policy=no-user-gesture-required", "--hide-scrollbars", "--disable-renderer-backgrounding", "--disable-background-timer-throttling", "--disable-backgrounding-occluded-windows"];
59
+ }
60
+
61
+ /**
62
+ * Headless Chrome at path, without the machine's GPU (chromeFlags), and a DevTools connection to it: send(method, parameters, sessionId),
63
+ * listen(sessionId, onEvent) and close().
64
+ */
65
+ export async function openChrome(path, profilePrefix, { isDrawingOnCpu = false, ...others } = {}) {
66
+ const unknownOptions = Object.keys(others);
67
+ if (unknownOptions.length) throw new Error(`openChrome has no option ${unknownOptions.join(", ")}: its only option is isDrawingOnCpu, and every Chrome runs without the machine's GPU.`);
58
68
  await sweepOrphans();
59
69
  // A folder for each Chrome: OWNER_FILE, which says whose it is, and Chrome's profile inside, removed before the folder so a profile
60
70
  // that can't be removed yet keeps its owner for the next sweep.
61
71
  const folder = mkdtempSync(join(tmpdir(), profilePrefix));
62
72
  const profile = join(folder, "profile");
63
73
  mkdirSync(profile);
64
- const webgl = isDrawingOnCpu ? ["--disable-gpu"] : isGpu ? ["--enable-gpu", "--ignore-gpu-blocklist", ...(process.platform === "darwin" ? ["--use-angle=metal"] : [])] : ["--use-angle=swiftshader", "--enable-unsafe-swiftshader"];
65
74
  let child;
66
75
  try {
67
- child = spawn(path, ["--headless=new", "--remote-debugging-port=0", `--user-data-dir=${profile}`, "--no-first-run", "--no-default-browser-check", ...webgl, "--autoplay-policy=no-user-gesture-required", "--hide-scrollbars", "--disable-renderer-backgrounding", "--disable-background-timer-throttling", "--disable-backgrounding-occluded-windows", "about:blank"], { stdio: ["ignore", "ignore", "pipe"] });
76
+ child = spawn(path, [...chromeFlags({ isDrawingOnCpu }), `--user-data-dir=${profile}`, "about:blank"], { stdio: ["ignore", "ignore", "pipe"] });
68
77
  } catch (error) {
69
78
  rmSync(folder, { recursive: true, force: true });
70
79
  throw error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zaisma/cli",
3
- "version": "0.38.0",
3
+ "version": "0.40.0",
4
4
  "description": "Upload and publish browser games on Zaisma from the command line.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://zaisma.com",
package/zaisma.mjs CHANGED
@@ -212,7 +212,9 @@ const COMMANDS = {
212
212
  },
213
213
  "items remove": { about: "Remove an item nobody bought or was granted", arguments: [{ name: "slug" }, { name: "item_name" }], flags: {} },
214
214
  "kept-rooms": { about: "A game's kept rooms (room.setKept), worlds that sleep with nobody in them: each one's code, name, size and when it was last played, and the game's storage", arguments: [{ name: "slug" }], flags: {} },
215
- "kept-rooms delete": { about: "Delete a kept room's world for good; players in it are sent out", arguments: [{ name: "slug" }, { name: "room_code" }], flags: {} },
215
+ "kept-rooms delete": { about: "Delete a kept room's world; players in it are sent out, and it waits a week before it's erased", arguments: [{ name: "slug" }, { name: "room_code" }], flags: {} },
216
+ "kept-rooms bring-back": { about: "Bring back a kept room's world waiting to be erased, as it was", arguments: [{ name: "slug" }, { name: "room_code" }], flags: {} },
217
+ "kept-rooms erase-now": { about: "Erase a waiting kept room's world at once; answers a link where the developer approves with a passkey tap", arguments: [{ name: "slug" }, { name: "room_code" }], flags: {} },
216
218
  rooms: { about: "A game's live rooms on Zaisma, newest first: each one's code, name, labels, players and spectators, and whether it's kept", arguments: [{ name: "slug" }], flags: {} },
217
219
  logs: {
218
220
  about: "What a game's server printed on Zaisma in the last 30 days, oldest first: the newest lines, older ones with --cursor, or new ones as they come with --follow",
@@ -315,7 +317,7 @@ const COMMANDS = {
315
317
  help: { about: "This help; with --json, every command, flag, exit code and error code", arguments: [], flags: {} },
316
318
  };
317
319
  /** Commands with a second word, like zaisma forum post. */
318
- const SUBCOMMANDS = { links: ["set", "remove"], forum: ["post", "message", "reply"], database: ["query", "batch", "export", "import", "restore", "undo-restore"], saves: ["get", "change", "replace", "reset", "copies", "copy", "restore"], secrets: ["set", "delete"], items: ["set", "remove"], "kept-rooms": ["delete"] };
320
+ const SUBCOMMANDS = { links: ["set", "remove"], forum: ["post", "message", "reply"], database: ["query", "batch", "export", "import", "restore", "undo-restore"], saves: ["get", "change", "replace", "reset", "copies", "copy", "restore"], secrets: ["set", "delete"], items: ["set", "remove"], "kept-rooms": ["delete", "bring-back", "erase-now"] };
319
321
  /** Flags every command takes. */
320
322
  const GLOBAL_FLAGS = {
321
323
  json: { hasValue: false, about: "Print the API's answer as JSON, as-is (on failure its { error }), and nothing else" },
@@ -1948,19 +1950,28 @@ async function liveRooms(values) {
1948
1950
  if (answer.next_cursor) console.log(`${answer.room_count} rooms in all; --json, or list_rooms with cursor, gives the rest.`);
1949
1951
  }
1950
1952
 
1951
- /** A game's kept rooms (…/games/<slug>/kept-rooms…), as the MCP's list_kept_rooms and delete_kept_room. */
1953
+ /** A game's kept rooms (…/games/<slug>/kept-rooms…), as the MCP's list_kept_rooms, delete_kept_room, bring_back_kept_room and erase_kept_room_now. */
1952
1954
  async function keptRooms(command, values) {
1953
1955
  if (command === "kept-rooms") {
1954
1956
  const answer = await api("GET", `/games/${values.slug}/kept-rooms`);
1955
1957
  if (isJson) return printJson(answer);
1956
1958
  if (!answer.kept_rooms.length) console.log(`No kept rooms. A game server keeps one with room.setKept(true).`);
1957
- for (const keptRoom of answer.kept_rooms) console.log(`${keptRoom.room_code} ${(keptRoom.name ?? "").padEnd(24)} ${sizeText(keptRoom.saved_size_bytes).padStart(9)} played ${keptRoom.last_played_at ? when(keptRoom.last_played_at) : "never"}`);
1959
+ for (const keptRoom of answer.kept_rooms) console.log(`${keptRoom.room_code} ${(keptRoom.name ?? "").padEnd(24)} ${sizeText(keptRoom.saved_size_bytes).padStart(9)} played ${keptRoom.erases_at ? `waiting, erased ${when(keptRoom.erases_at)} ` : ""}${keptRoom.last_played_at ? when(keptRoom.last_played_at) : "never"}`);
1958
1960
  console.log(`Storage: ${sizeText(answer.storage_size_bytes)} of the ${sizeText(answer.maximum_storage_size_bytes)} a game can keep (database and kept rooms).`);
1959
1961
  return;
1960
1962
  }
1961
- const answer = await api("DELETE", `/games/${values.slug}/kept-rooms/${encodeURIComponent(values.room_code)}`);
1963
+ const roomPath = `/games/${values.slug}/kept-rooms/${encodeURIComponent(values.room_code)}`;
1964
+ const code = values.room_code.toUpperCase();
1965
+ if (command === "kept-rooms bring-back" || command === "kept-rooms erase-now") {
1966
+ const isBringingBack = command === "kept-rooms bring-back";
1967
+ const answer = await api("POST", `${roomPath}/${isBringingBack ? "bring-back" : "erase-now"}`);
1968
+ if (isJson) return printJson(answer);
1969
+ console.log(isBringingBack ? `Kept room ${code} of ${values.slug} is back, as it was.` : `Erased kept room ${code} of ${values.slug} for good.`);
1970
+ return;
1971
+ }
1972
+ const answer = await api("DELETE", roomPath);
1962
1973
  if (isJson) return printJson(answer);
1963
- console.log(`Deleted kept room ${values.room_code.toUpperCase()} from ${values.slug}, and its world with it.`);
1974
+ console.log(answer.erases_at ? `Deleted kept room ${code} from ${values.slug}. Its world waits until ${when(answer.erases_at)}: zaisma kept-rooms bring-back ${values.slug} ${code} brings it back.` : `Deleted kept room ${code} from ${values.slug}, and its world with it.`);
1964
1975
  }
1965
1976
 
1966
1977
  /** A game server's logs (GET …/games/<slug>/logs), as the MCP's get_logs; --follow asks for new lines every 2 seconds. */