@zaisma/cli 0.24.0 → 0.25.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.
- package/README.md +2 -0
- package/chrome.mjs +105 -0
- package/package.json +3 -1
- package/shader-check.mjs +953 -0
- package/zaisma.mjs +371 -5
package/README.md
CHANGED
|
@@ -13,6 +13,8 @@ Before anything else, `zaisma check ./build` lists anything in the game Zaisma w
|
|
|
13
13
|
|
|
14
14
|
`zaisma versions <slug>` lists versions and their preview links; `zaisma publish` with an older version rolls back, and `--scheduled-publish-at "2026-11-01T17:00+01:00"` publishes later (an ISO time with `Z` or an offset; `zaisma unschedule` cancels). Files over 95 MB are sent in parts automatically, up to 500 MB each.
|
|
15
15
|
|
|
16
|
+
A background shader lives in a folder of its own: `image.glsl` (Shadertoy's `mainImage`), `buffer-a.glsl` to `buffer-d.glsl` if it has buffers, `channels.json` wiring each pass's channels to a buffer or a texture file, and the textures (`zaisma help` shows the folder). `zaisma check ./sky` draws it as Zaisma's check does, in your Chrome, and saves a sheet picture of it under Zaisma's glass beside the folder; `zaisma shader ./sky --game sky-hopper --screen wide` sends its textures and the shader.
|
|
17
|
+
|
|
16
18
|
For scripts, CI and AI tools: every command takes `--json` and prints the API's answer as-is, or its `{ "error": { code, message, field, fix, retry_after_sec } }`. Commands refuse flags and choices they don't take instead of ignoring them, and the exit code says how it went: `0` done (for upload: passed), `1` failed, `2` a wrong command line (nothing was sent), `3` held for a person to look at, `4` rejected, `5` still scanning, `6` the check found something to fix. `zaisma help --json` lists every command, flag and code.
|
|
17
19
|
|
|
18
20
|
Found a bug in Zaisma, or missing something? Search the developer forum first with `zaisma forum --search "too_big"`. `zaisma forum post --kind bug --title "…" --category mcp --text "…"` starts a public topic, and `zaisma forum message …` sends Zaisma a private one (logs, an unreleased game). `zaisma forum` lists your topics and messages, `zaisma forum <topic_id>` shows one with its replies, and `zaisma forum reply <topic_id> --text "…"` replies (`--reopen` if a fixed one is back). Posts say an AI wrote them unless you add `--by-me`. Everything here uses the [developer API](https://github.com/zaisma/zaisma/blob/main/docs/DEVELOPER-API.md#the-upload-command).
|
package/chrome.mjs
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Headless Chrome, for `zaisma check` on a shader's folder and Zaisma's own scripts that look at pages in a real browser
|
|
2
|
+
// (scripts/chrome.mjs), driven over its DevTools protocol with Node's own WebSocket (Node 22 or newer), so it needs no dependency and
|
|
3
|
+
// never downloads a browser. Chrome is the one in CHROME_PATH, the system's, or one Playwright or @puppeteer/browsers downloaded.
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { existsSync, mkdtempSync, readdirSync, rmSync } from "node:fs";
|
|
6
|
+
import { homedir, tmpdir } from "node:os";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
|
|
9
|
+
/** Where Chrome is on each system, when it's installed. */
|
|
10
|
+
const SYSTEM_CHROMES = [
|
|
11
|
+
"/usr/bin/google-chrome",
|
|
12
|
+
"/usr/bin/google-chrome-stable",
|
|
13
|
+
"/usr/bin/chromium",
|
|
14
|
+
"/usr/bin/chromium-browser",
|
|
15
|
+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
16
|
+
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
|
17
|
+
...[process.env.PROGRAMFILES, process.env["PROGRAMFILES(X86)"], process.env.LOCALAPPDATA].filter(Boolean).map((folder) => join(folder, "Google/Chrome/Application/chrome.exe")),
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
/** A Chrome on this machine, or null: CHROME_PATH, the system's, then one downloaded into downloadFolders (as @puppeteer/browsers lays them out), puppeteer's own cache, or Playwright's. */
|
|
21
|
+
export function findChrome(downloadFolders = []) {
|
|
22
|
+
const downloaded = [...downloadFolders, join(homedir(), ".cache/puppeteer")].flatMap((folder) => downloadedChromes(folder));
|
|
23
|
+
return [process.env.CHROME_PATH, ...SYSTEM_CHROMES, ...downloaded, ...playwrightChromes()].find((candidate) => candidate && existsSync(candidate)) ?? null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const newestFirst = (names) => names.sort((first, second) => second.localeCompare(first, "en", { numeric: true }));
|
|
27
|
+
const listed = (folder) => (existsSync(folder) ? readdirSync(folder) : []);
|
|
28
|
+
|
|
29
|
+
/** Chrome for Testing that @puppeteer/browsers installed in a folder (<folder>/chrome/<platform>-<build>/chrome-<platform>/…), newest first. */
|
|
30
|
+
function downloadedChromes(folder) {
|
|
31
|
+
return newestFirst(listed(join(folder, "chrome"))).flatMap((build) =>
|
|
32
|
+
listed(join(folder, "chrome", build))
|
|
33
|
+
.filter((name) => name.startsWith("chrome-"))
|
|
34
|
+
.flatMap((name) => {
|
|
35
|
+
const inside = join(folder, "chrome", build, name);
|
|
36
|
+
return [join(inside, "Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing"), join(inside, "chrome"), join(inside, "chrome.exe")];
|
|
37
|
+
}),
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Chromium that Playwright downloaded, newest first. */
|
|
42
|
+
function playwrightChromes() {
|
|
43
|
+
const cache = process.env.PLAYWRIGHT_BROWSERS_PATH || join(homedir(), process.platform === "darwin" ? "Library/Caches/ms-playwright" : process.platform === "win32" ? "AppData/Local/ms-playwright" : ".cache/ms-playwright");
|
|
44
|
+
return newestFirst(listed(cache).filter((name) => name.startsWith("chromium-"))).flatMap((name) =>
|
|
45
|
+
["chrome-mac-arm64", "chrome-mac", "chrome-mac-x64"]
|
|
46
|
+
.map((folder) => join(cache, name, folder, "Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing"))
|
|
47
|
+
.concat(join(cache, name, "chrome-mac/Chromium.app/Contents/MacOS/Chromium"), join(cache, name, "chrome-linux64/chrome"), join(cache, name, "chrome-linux/chrome"), join(cache, name, "chrome-win/chrome.exe"), join(cache, name, "chrome-win64/chrome.exe")),
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
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), and a DevTools connection to it: send(method, parameters,
|
|
54
|
+
* sessionId), listen(sessionId, onEvent) and close().
|
|
55
|
+
*/
|
|
56
|
+
export async function openChrome(path, profilePrefix, { isGpu = false } = {}) {
|
|
57
|
+
const profile = mkdtempSync(join(tmpdir(), profilePrefix));
|
|
58
|
+
const webgl = isGpu ? ["--enable-gpu", "--ignore-gpu-blocklist", ...(process.platform === "darwin" ? ["--use-angle=metal"] : [])] : ["--use-angle=swiftshader", "--enable-unsafe-swiftshader"];
|
|
59
|
+
const 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"] });
|
|
60
|
+
const address = await new Promise((resolve, reject) => {
|
|
61
|
+
let output = "";
|
|
62
|
+
child.stderr.on("data", (chunk) => {
|
|
63
|
+
output += chunk;
|
|
64
|
+
const match = output.match(/DevTools listening on (ws:\/\/\S+)/);
|
|
65
|
+
if (match) resolve(match[1]);
|
|
66
|
+
});
|
|
67
|
+
child.on("error", (error) => reject(error));
|
|
68
|
+
child.on("exit", (code) => reject(new Error(`Chrome stopped (${code}): ${output.slice(-500)}`)));
|
|
69
|
+
});
|
|
70
|
+
const socket = new WebSocket(address);
|
|
71
|
+
await new Promise((resolve, reject) => ((socket.onopen = resolve), (socket.onerror = reject)));
|
|
72
|
+
let nextMessageNumber = 1;
|
|
73
|
+
const waiting = new Map();
|
|
74
|
+
const listeners = new Set();
|
|
75
|
+
socket.onmessage = (event) => {
|
|
76
|
+
const message = JSON.parse(event.data);
|
|
77
|
+
if (message.id && waiting.has(message.id)) {
|
|
78
|
+
const { resolve, reject } = waiting.get(message.id);
|
|
79
|
+
waiting.delete(message.id);
|
|
80
|
+
if (message.error) reject(new Error(message.error.message));
|
|
81
|
+
else resolve(message.result);
|
|
82
|
+
} else if (message.method) for (const listener of listeners) listener(message);
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
send: (method, parameters = {}, sessionId) =>
|
|
86
|
+
new Promise((resolve, reject) => {
|
|
87
|
+
const id = nextMessageNumber++;
|
|
88
|
+
waiting.set(id, { resolve, reject });
|
|
89
|
+
socket.send(JSON.stringify({ id, method, params: parameters, ...(sessionId ? { sessionId } : {}) }));
|
|
90
|
+
}),
|
|
91
|
+
listen: (sessionId, onEvent) => {
|
|
92
|
+
const listener = (message) => message.sessionId === sessionId && onEvent(message.method, message.params);
|
|
93
|
+
listeners.add(listener);
|
|
94
|
+
return () => listeners.delete(listener);
|
|
95
|
+
},
|
|
96
|
+
// Chrome writes to its profile until it has exited, so it goes after.
|
|
97
|
+
close: async () => {
|
|
98
|
+
socket.close();
|
|
99
|
+
const exited = new Promise((resolve) => child.once("exit", resolve));
|
|
100
|
+
child.kill();
|
|
101
|
+
await exited;
|
|
102
|
+
rmSync(profile, { recursive: true, force: true, maxRetries: 5 });
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zaisma/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.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",
|
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
"check.d.mts",
|
|
30
30
|
"performance.mjs",
|
|
31
31
|
"performance.d.mts",
|
|
32
|
+
"shader-check.mjs",
|
|
33
|
+
"chrome.mjs",
|
|
32
34
|
"README.md",
|
|
33
35
|
"LICENSE"
|
|
34
36
|
],
|