@bigmistqke/whiteboard 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +609 -2
- package/bin/whiteboard.ts +431 -0
- package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
- package/dist/bin/whiteboard.js +471 -0
- package/dist/client/runtime.js +391 -0
- package/dist/define.js +7 -0
- package/dist/plugins/callout/README.md +13 -0
- package/dist/plugins/callout/index.js +27 -0
- package/dist/plugins/callout/style.css +12 -0
- package/dist/plugins/chat/README.md +45 -0
- package/dist/plugins/chat/client.js +3 -0
- package/dist/plugins/chat/index.js +46 -0
- package/dist/plugins/chat/style.css +17 -0
- package/dist/plugins/claude-code/index.js +120 -0
- package/dist/plugins/code/README.md +42 -0
- package/dist/plugins/code/diff.js +64 -0
- package/dist/plugins/code/index.js +77 -0
- package/dist/plugins/code/style.css +29 -0
- package/dist/plugins/comments/client.js +10 -0
- package/dist/plugins/comments/index.js +51 -0
- package/dist/plugins/comments/style.css +32 -0
- package/dist/plugins/details/README.md +17 -0
- package/dist/plugins/details/index.js +17 -0
- package/dist/plugins/details/style.css +3 -0
- package/dist/plugins/form/README.md +111 -0
- package/dist/plugins/form/index.js +102 -0
- package/dist/plugins/form/style.css +41 -0
- package/dist/plugins/gallery/README.md +30 -0
- package/dist/plugins/gallery/client.js +1 -0
- package/dist/plugins/gallery/index.js +74 -0
- package/dist/plugins/gallery/style.css +27 -0
- package/dist/plugins/grid/README.md +33 -0
- package/dist/plugins/grid/index.js +33 -0
- package/dist/plugins/grid/style.css +25 -0
- package/dist/plugins/index.js +26 -0
- package/dist/plugins/mermaid/README.md +21 -0
- package/dist/plugins/mermaid/index.js +34 -0
- package/dist/plugins/mermaid/style.css +16 -0
- package/dist/plugins/quiet/README.md +26 -0
- package/dist/plugins/quiet/index.js +17 -0
- package/dist/plugins/terminal/client.js +41 -0
- package/dist/plugins/terminal/host.js +332 -0
- package/dist/plugins/terminal/index.js +171 -0
- package/dist/plugins/terminal/modes.js +32 -0
- package/dist/plugins/terminal/server.js +256 -0
- package/dist/plugins/terminal/sizes.js +57 -0
- package/dist/plugins/terminal/style.css +357 -0
- package/dist/solid/index.js +35 -0
- package/dist/src/auth.js +54 -0
- package/dist/src/client/page/base.css +274 -0
- package/dist/src/client/page/main.js +1004 -0
- package/dist/src/config.js +76 -0
- package/dist/src/events.js +162 -0
- package/dist/src/html.js +34 -0
- package/dist/src/load.js +77 -0
- package/dist/src/loader.js +120 -0
- package/dist/src/package.js +33 -0
- package/dist/src/pages/blocks.js +49 -0
- package/dist/src/pages/index.js +14 -0
- package/dist/src/pages/markdown.js +307 -0
- package/dist/src/pages/render.js +257 -0
- package/dist/src/plugins.js +238 -0
- package/dist/src/running.js +24 -0
- package/dist/src/serve.js +71 -0
- package/dist/src/server.js +700 -0
- package/dist/src/status.js +43 -0
- package/package.json +131 -4
- package/plugins/callout/README.md +13 -0
- package/plugins/callout/index.ts +25 -0
- package/plugins/callout/style.css +12 -0
- package/plugins/chat/README.md +45 -0
- package/plugins/chat/autosize.ts +101 -0
- package/plugins/chat/client.tsx +81 -0
- package/plugins/chat/index.ts +61 -0
- package/plugins/chat/style.css +17 -0
- package/plugins/claude-code/index.ts +136 -0
- package/plugins/code/README.md +42 -0
- package/plugins/code/diff.ts +58 -0
- package/plugins/code/index.ts +94 -0
- package/plugins/code/style.css +29 -0
- package/plugins/comments/client.ts +448 -0
- package/plugins/comments/index.ts +52 -0
- package/plugins/comments/style.css +32 -0
- package/plugins/details/README.md +17 -0
- package/plugins/details/index.ts +21 -0
- package/plugins/details/style.css +3 -0
- package/plugins/form/README.md +111 -0
- package/plugins/form/index.ts +104 -0
- package/plugins/form/style.css +41 -0
- package/plugins/gallery/README.md +30 -0
- package/plugins/gallery/client.tsx +64 -0
- package/plugins/gallery/index.ts +67 -0
- package/plugins/gallery/style.css +27 -0
- package/plugins/grid/README.md +33 -0
- package/plugins/grid/index.ts +36 -0
- package/plugins/grid/style.css +25 -0
- package/plugins/index.ts +19 -0
- package/plugins/mermaid/README.md +21 -0
- package/plugins/mermaid/index.ts +39 -0
- package/plugins/mermaid/style.css +16 -0
- package/plugins/quiet/README.md +26 -0
- package/plugins/quiet/index.ts +27 -0
- package/plugins/terminal/client.ts +317 -0
- package/plugins/terminal/host.ts +326 -0
- package/plugins/terminal/index.ts +138 -0
- package/plugins/terminal/modes.ts +30 -0
- package/plugins/terminal/server.ts +215 -0
- package/plugins/terminal/sizes.ts +60 -0
- package/plugins/terminal/style.css +71 -0
- package/skills/whiteboard/SKILL.md +292 -0
- package/solid/index.tsx +56 -0
- package/src/auth.ts +66 -0
- package/src/client/forms.ts +186 -0
- package/src/client/page/base.css +274 -0
- package/src/client/page/fresh.ts +205 -0
- package/src/client/page/main.ts +249 -0
- package/src/client/page/orphans.ts +46 -0
- package/src/client/page/theme.ts +32 -0
- package/src/client/page/view.ts +9 -0
- package/src/client/page/waiting.ts +109 -0
- package/src/client/runtime.ts +170 -0
- package/src/config.ts +96 -0
- package/src/define.ts +546 -0
- package/src/events.ts +194 -0
- package/src/html.ts +40 -0
- package/src/load.ts +89 -0
- package/src/loader.ts +109 -0
- package/src/package.ts +39 -0
- package/src/pages/blocks.ts +67 -0
- package/src/pages/index.ts +36 -0
- package/src/pages/markdown.ts +276 -0
- package/src/pages/render.ts +196 -0
- package/src/plugins.ts +197 -0
- package/src/running.ts +22 -0
- package/src/serve.ts +52 -0
- package/src/server.ts +644 -0
- package/src/status.ts +69 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
// src/plugins.ts
|
|
3
|
+
const TYPES = {
|
|
4
|
+
string: (v) => typeof v === "string",
|
|
5
|
+
number: (v) => typeof v === "number" && Number.isFinite(v),
|
|
6
|
+
boolean: (v) => typeof v === "boolean",
|
|
7
|
+
"string[]": (v) => Array.isArray(v) && v.every((x) => typeof x === "string")
|
|
8
|
+
};
|
|
9
|
+
function parseType(spec, where) {
|
|
10
|
+
const optional = spec.endsWith("?");
|
|
11
|
+
const type = optional ? spec.slice(0, -1) : spec;
|
|
12
|
+
if (!(type in TYPES)) throw new Error(`${where}: unknown type "${spec}" (one of ${Object.keys(TYPES).join(", ")}, with ? when optional)`);
|
|
13
|
+
return {
|
|
14
|
+
type,
|
|
15
|
+
optional
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** What is wrong with `value` against `spec` ({ name: 'string?' }), or null. Unknown fields are wrong too. */
|
|
19
|
+
function checkFields(spec = {}, input = {}, where) {
|
|
20
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) return `${where} must be an object`;
|
|
21
|
+
const value = input;
|
|
22
|
+
for (const [name, s] of Object.entries(spec)) {
|
|
23
|
+
const { type, optional } = parseType(s, where);
|
|
24
|
+
if (value[name] === void 0) {
|
|
25
|
+
if (!optional) return `${where}: ${name} is missing`;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (!TYPES[type](value[name])) return `${where}: ${name} must be ${type}`;
|
|
29
|
+
}
|
|
30
|
+
for (const name of Object.keys(value)) if (!(name in spec)) return `${where}: unknown field ${name}`;
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
/** Query strings are text: a number or boolean in the spec is read from it. */
|
|
34
|
+
function fromQuery(spec = {}, params) {
|
|
35
|
+
const out = {};
|
|
36
|
+
for (const [name, value] of params) {
|
|
37
|
+
const field = spec[name];
|
|
38
|
+
const type = field ? parseType(field, "query").type : "string";
|
|
39
|
+
out[name] = type === "number" ? Number(value) : type === "boolean" ? value === "true" || value === "" : value;
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
const ROUTE = /^(GET|POST|PUT|PATCH|DELETE) (\/[\w\-/]*)$/;
|
|
44
|
+
/** A plugin's routes, checked and mounted under /api/<name>/. Throws on a malformed one. */
|
|
45
|
+
function mountRoutes(name, routes = {}) {
|
|
46
|
+
const table = [];
|
|
47
|
+
for (const [key, route] of Object.entries(routes)) {
|
|
48
|
+
const m = ROUTE.exec(key);
|
|
49
|
+
if (!m) throw new Error(`plugin ${name}: route "${key}" must look like "GET /path"`);
|
|
50
|
+
if (typeof route?.run !== "function") throw new Error(`plugin ${name}: route "${key}" has no run function`);
|
|
51
|
+
for (const [field, spec] of Object.entries({
|
|
52
|
+
...route.body,
|
|
53
|
+
...route.query
|
|
54
|
+
})) parseType(spec, `plugin ${name}, route "${key}", ${field}`);
|
|
55
|
+
const [, method, at] = m;
|
|
56
|
+
const path = `/api/${name}${at === "/" ? "" : at.replace(/\/$/, "")}`;
|
|
57
|
+
if (table.some((r) => r.method === method && r.path === path)) throw new Error(`plugin ${name}: route "${key}" is declared twice`);
|
|
58
|
+
table.push({
|
|
59
|
+
method,
|
|
60
|
+
path,
|
|
61
|
+
route,
|
|
62
|
+
plugin: name
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return table;
|
|
66
|
+
}
|
|
67
|
+
function readJson(req) {
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
let body = "";
|
|
70
|
+
req.on("data", (c) => {
|
|
71
|
+
body += c;
|
|
72
|
+
if (body.length > 1e6) {
|
|
73
|
+
reject(/* @__PURE__ */ new Error("body too large"));
|
|
74
|
+
req.destroy();
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
req.on("end", () => {
|
|
78
|
+
try {
|
|
79
|
+
resolve(body ? JSON.parse(body) : {});
|
|
80
|
+
} catch {
|
|
81
|
+
reject(/* @__PURE__ */ new Error("the body is not JSON"));
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
req.on("error", reject);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
const json = (res, status, data) => {
|
|
88
|
+
res.writeHead(status, {
|
|
89
|
+
"content-type": "application/json",
|
|
90
|
+
"cache-control": "no-store"
|
|
91
|
+
});
|
|
92
|
+
res.end(JSON.stringify(data));
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Answer a request with the route it matches: false when none does. The core checks the token
|
|
96
|
+
* (`auth`), the query and the body before the route's code runs. A route returns what is sent as
|
|
97
|
+
* JSON; a stream route (`stream: true`) writes to `res` itself. An error it throws is sent with its
|
|
98
|
+
* `status` (default 500).
|
|
99
|
+
*/
|
|
100
|
+
async function dispatch(table, req, res, url, authorized) {
|
|
101
|
+
const forPath = table.filter((r) => r.path === url.pathname);
|
|
102
|
+
if (!forPath.length) return false;
|
|
103
|
+
const hit = forPath.find((r) => r.method === req.method);
|
|
104
|
+
if (!hit) {
|
|
105
|
+
res.setHeader("allow", forPath.map((r) => r.method).join(", "));
|
|
106
|
+
json(res, 405, { error: `use ${forPath.map((r) => r.method).join(" or ")}` });
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
const { route } = hit;
|
|
110
|
+
if (route.auth && !authorized(req)) {
|
|
111
|
+
json(res, 403, { error: "this needs the project's token: open a link from the command line, or send x-whiteboard-token" });
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
const query = fromQuery(route.query, url.searchParams);
|
|
116
|
+
const queryError = route.query ? checkFields(route.query, query, "query") : null;
|
|
117
|
+
if (queryError) {
|
|
118
|
+
json(res, 400, { error: queryError });
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
let body = {};
|
|
122
|
+
if (hit.method !== "GET" && hit.method !== "DELETE") {
|
|
123
|
+
const input = await readJson(req);
|
|
124
|
+
const bodyError = checkFields(route.body, input, "body");
|
|
125
|
+
if (bodyError) {
|
|
126
|
+
json(res, 400, { error: bodyError });
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
body = input;
|
|
130
|
+
}
|
|
131
|
+
if (route.stream) {
|
|
132
|
+
await route.run({
|
|
133
|
+
body,
|
|
134
|
+
query,
|
|
135
|
+
req,
|
|
136
|
+
res
|
|
137
|
+
});
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
const out = await route.run({
|
|
141
|
+
body,
|
|
142
|
+
query,
|
|
143
|
+
req
|
|
144
|
+
});
|
|
145
|
+
json(res, 200, out ?? { ok: true });
|
|
146
|
+
} catch (err) {
|
|
147
|
+
if (res.headersSent) {
|
|
148
|
+
res.end();
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
const e = err;
|
|
152
|
+
json(res, e?.status ?? 500, { error: e?.message ?? String(err) });
|
|
153
|
+
}
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
/** The routes for the docs: method, path, what it does, what it takes. */
|
|
157
|
+
const describeRoutes = (table) => table.map(({ method, path, route }) => ({
|
|
158
|
+
method,
|
|
159
|
+
path,
|
|
160
|
+
description: route.description ?? "",
|
|
161
|
+
auth: !!route.auth,
|
|
162
|
+
stream: !!route.stream,
|
|
163
|
+
body: route.body ?? null,
|
|
164
|
+
query: route.query ?? null
|
|
165
|
+
}));
|
|
166
|
+
/** The commands of a plugin as `whiteboard <name> [sub]`, checked. */
|
|
167
|
+
function pluginCommands(plugin) {
|
|
168
|
+
return Object.entries(plugin.commands ?? {}).map(([sub, command]) => {
|
|
169
|
+
const where = `plugin ${plugin.name}, command "${sub}"`;
|
|
170
|
+
if (sub && !/^[\w-]+$/.test(sub)) throw new Error(`${where}: use letters, digits, - and _`);
|
|
171
|
+
if (typeof command?.run !== "function") throw new Error(`${where} has no run function`);
|
|
172
|
+
for (const [name, o] of Object.entries(command.options ?? {})) parseType(o.type, `${where}, option ${name}`);
|
|
173
|
+
return {
|
|
174
|
+
plugin: plugin.name,
|
|
175
|
+
sub,
|
|
176
|
+
command,
|
|
177
|
+
name: [plugin.name, sub].filter(Boolean).join(" ")
|
|
178
|
+
};
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/** `[page] [--restart] [-- <arguments>]` */
|
|
182
|
+
function usage(command) {
|
|
183
|
+
const options = Object.entries(command.options ?? {}).map(([name, o]) => {
|
|
184
|
+
const { type } = parseType(o.type, name);
|
|
185
|
+
return `[--${name}${type === "boolean" ? "" : ` <${o.value ?? type}>`}]`;
|
|
186
|
+
});
|
|
187
|
+
return [
|
|
188
|
+
command.args ?? "",
|
|
189
|
+
...options,
|
|
190
|
+
command.rest ? `[-- ${command.rest}]` : ""
|
|
191
|
+
].filter(Boolean).join(" ");
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Parse a command's arguments by its declared options; throws with the usage on a wrong one. What
|
|
195
|
+
* follows `--` is passed on untouched, as `rest`, when the command takes it.
|
|
196
|
+
*/
|
|
197
|
+
function parseCommandArgs(command, all, name) {
|
|
198
|
+
const cut = all.indexOf("--");
|
|
199
|
+
const args = cut < 0 ? all : all.slice(0, cut);
|
|
200
|
+
const rest = cut < 0 ? [] : all.slice(cut + 1);
|
|
201
|
+
if (rest.length && !command.rest) throw new Error(`whiteboard ${name} takes nothing after --\nusage: whiteboard ${name} ${usage(command)}`);
|
|
202
|
+
const options = Object.fromEntries(Object.entries(command.options ?? {}).map(([key, o]) => {
|
|
203
|
+
const { type } = parseType(o.type, key);
|
|
204
|
+
return [key, {
|
|
205
|
+
type: type === "boolean" ? "boolean" : "string",
|
|
206
|
+
...o.short ? { short: o.short } : {}
|
|
207
|
+
}];
|
|
208
|
+
}));
|
|
209
|
+
let parsed;
|
|
210
|
+
try {
|
|
211
|
+
parsed = parseArgs({
|
|
212
|
+
args,
|
|
213
|
+
options,
|
|
214
|
+
allowPositionals: true,
|
|
215
|
+
strict: true
|
|
216
|
+
});
|
|
217
|
+
} catch (err) {
|
|
218
|
+
throw new Error(`${err.message}\nusage: whiteboard ${name} ${usage(command)}`);
|
|
219
|
+
}
|
|
220
|
+
const values = { ...parsed.values };
|
|
221
|
+
for (const [key, o] of Object.entries(command.options ?? {})) {
|
|
222
|
+
const { type, optional } = parseType(o.type, key);
|
|
223
|
+
if (values[key] === void 0) {
|
|
224
|
+
if (!optional && type !== "boolean") throw new Error(`--${key} is missing\nusage: whiteboard ${name} ${usage(command)}`);
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if (type === "number") {
|
|
228
|
+
values[key] = Number(values[key]);
|
|
229
|
+
if (!Number.isFinite(values[key])) throw new Error(`--${key} must be a number`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
options: values,
|
|
234
|
+
positionals: parsed.positionals,
|
|
235
|
+
rest
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
export { describeRoutes, dispatch, mountRoutes, parseCommandArgs, pluginCommands, usage };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
// src/running.ts
|
|
3
|
+
/** The port the last server of this project recorded, or null. */
|
|
4
|
+
function recordedPort(project) {
|
|
5
|
+
try {
|
|
6
|
+
return Number(JSON.parse(fs.readFileSync(project.serverFile, "utf8")).port) || null;
|
|
7
|
+
} catch {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/** The base URL of this project's running server, or null. `except`: a process to not count (the asking server itself). */
|
|
12
|
+
async function runningServer(project, { except } = {}) {
|
|
13
|
+
const port = recordedPort(project);
|
|
14
|
+
if (!port) return null;
|
|
15
|
+
const base = `http://localhost:${port}`;
|
|
16
|
+
try {
|
|
17
|
+
const res = await fetch(`${base}/api/health`, { signal: AbortSignal.timeout(800) });
|
|
18
|
+
const health = res.ok ? await res.json() : null;
|
|
19
|
+
return health?.dir === project.dir && health.pid !== except ? base : null;
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export { recordedPort, runningServer };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { DEFAULT_PORT } from "./config.js";
|
|
2
|
+
import { createServer } from "./server.js";
|
|
3
|
+
import { recordedPort, runningServer } from "./running.js";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import http from "node:http";
|
|
7
|
+
// src/serve.ts
|
|
8
|
+
/** Listen on the previous port, else the default, else the next free one; then record it in server.json. */
|
|
9
|
+
async function start(project) {
|
|
10
|
+
const other = await runningServer(project, { except: process.pid });
|
|
11
|
+
if (other) {
|
|
12
|
+
console.log(`whiteboard: ${project.name} is already served at ${other}`);
|
|
13
|
+
process.exit(0);
|
|
14
|
+
}
|
|
15
|
+
fs.mkdirSync(project.pagesDir, { recursive: true });
|
|
16
|
+
const wb = createServer(project);
|
|
17
|
+
await wb.config();
|
|
18
|
+
const server = http.createServer((req, res) => {
|
|
19
|
+
wb.handle(req, res);
|
|
20
|
+
});
|
|
21
|
+
const candidates = [...new Set([
|
|
22
|
+
recordedPort(project),
|
|
23
|
+
DEFAULT_PORT,
|
|
24
|
+
...Array.from({ length: 50 }, (_, i) => DEFAULT_PORT + 1 + i)
|
|
25
|
+
].filter((p) => !!p))];
|
|
26
|
+
for (const port of candidates) {
|
|
27
|
+
if (!await new Promise((resolve, reject) => {
|
|
28
|
+
const onError = (err) => {
|
|
29
|
+
server.off("listening", onListening);
|
|
30
|
+
err.code === "EADDRINUSE" ? resolve(false) : reject(err);
|
|
31
|
+
};
|
|
32
|
+
const onListening = () => {
|
|
33
|
+
server.off("error", onError);
|
|
34
|
+
resolve(true);
|
|
35
|
+
};
|
|
36
|
+
server.once("error", onError);
|
|
37
|
+
server.once("listening", onListening);
|
|
38
|
+
server.listen(port, "127.0.0.1");
|
|
39
|
+
})) continue;
|
|
40
|
+
fs.writeFileSync(project.serverFile, JSON.stringify({
|
|
41
|
+
port,
|
|
42
|
+
pid: process.pid
|
|
43
|
+
}, null, 2) + "\n");
|
|
44
|
+
try {
|
|
45
|
+
fs.unlinkSync(path.join(project.wb, "server.lock"));
|
|
46
|
+
} catch {}
|
|
47
|
+
const cleanup = () => {
|
|
48
|
+
try {
|
|
49
|
+
if (JSON.parse(fs.readFileSync(project.serverFile, "utf8")).pid === process.pid) fs.unlinkSync(project.serverFile);
|
|
50
|
+
} catch {}
|
|
51
|
+
};
|
|
52
|
+
process.on("exit", cleanup);
|
|
53
|
+
const yieldToOther = async () => {
|
|
54
|
+
if (await runningServer(project, { except: process.pid })) {
|
|
55
|
+
console.log("whiteboard: another server of this project took over");
|
|
56
|
+
process.exit(0);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
setTimeout(yieldToOther, 1500).unref();
|
|
60
|
+
setInterval(yieldToOther, 3e4).unref();
|
|
61
|
+
for (const signal of [
|
|
62
|
+
"SIGINT",
|
|
63
|
+
"SIGTERM",
|
|
64
|
+
"SIGHUP"
|
|
65
|
+
]) process.on(signal, () => process.exit(0));
|
|
66
|
+
console.log(`whiteboard: ${project.name} (${project.dir}) at http://localhost:${port}`);
|
|
67
|
+
return port;
|
|
68
|
+
}
|
|
69
|
+
throw new Error(`no free port from ${DEFAULT_PORT} to ${DEFAULT_PORT + 50}`);
|
|
70
|
+
}
|
|
71
|
+
export { start };
|