@bigmistqke/workpad 0.0.0-stage → 0.18.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 +781 -2
- package/bin/workpad.ts +1509 -0
- package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
- package/dist/bin/workpad.js +1190 -0
- package/dist/client/runtime.js +1194 -0
- package/dist/define.js +27 -0
- package/dist/plugins/alert/README.md +18 -0
- package/dist/plugins/alert/index.js +40 -0
- package/dist/plugins/alert/public/style.css +40 -0
- package/dist/plugins/ansi/README.md +36 -0
- package/dist/plugins/ansi/index.js +63 -0
- package/dist/plugins/ansi/public/style.css +28 -0
- package/dist/plugins/badge/README.md +32 -0
- package/dist/plugins/badge/index.js +28 -0
- package/dist/plugins/badge/public/style.css +30 -0
- package/dist/plugins/chat/README.md +81 -0
- package/dist/plugins/chat/index.js +96 -0
- package/dist/plugins/chat/public/client.js +3 -0
- package/dist/plugins/chat/public/style.css +143 -0
- package/dist/plugins/claude/README.md +116 -0
- package/dist/plugins/claude/channel.js +130 -0
- package/dist/plugins/claude/doctor.js +316 -0
- package/dist/plugins/claude/index.js +199 -0
- package/dist/plugins/claude/session.js +68 -0
- package/dist/plugins/code/README.md +54 -0
- package/dist/plugins/code/diff.js +75 -0
- package/dist/plugins/code/index.js +105 -0
- package/dist/plugins/code/public/client.js +1 -0
- package/dist/plugins/code/public/style.css +99 -0
- package/dist/plugins/comments/README.md +30 -0
- package/dist/plugins/comments/index.js +39 -0
- package/dist/plugins/comments/public/client.js +24 -0
- package/dist/plugins/comments/public/style.css +224 -0
- package/dist/plugins/details/README.md +24 -0
- package/dist/plugins/details/index.js +28 -0
- package/dist/plugins/details/public/style.css +7 -0
- package/dist/plugins/draft/README.md +14 -0
- package/dist/plugins/draft/index.js +27 -0
- package/dist/plugins/draft/public/style.css +21 -0
- package/dist/plugins/forge/README.md +22 -0
- package/dist/plugins/forge/index.js +83 -0
- package/dist/plugins/form/README.md +126 -0
- package/dist/plugins/form/index.js +179 -0
- package/dist/plugins/form/public/style.css +172 -0
- package/dist/plugins/grid/README.md +45 -0
- package/dist/plugins/grid/index.js +35 -0
- package/dist/plugins/grid/public/style.css +98 -0
- package/dist/plugins/iframe/README.md +18 -0
- package/dist/plugins/iframe/index.js +49 -0
- package/dist/plugins/iframe/public/style.css +28 -0
- package/dist/plugins/index.js +44 -0
- package/dist/plugins/lightbox/README.md +24 -0
- package/dist/plugins/lightbox/index.js +20 -0
- package/dist/plugins/lightbox/public/client.js +4 -0
- package/dist/plugins/lightbox/public/style.css +66 -0
- package/dist/plugins/mermaid/README.md +21 -0
- package/dist/plugins/mermaid/index.js +42 -0
- package/dist/plugins/mermaid/public/style.css +21 -0
- package/dist/plugins/opencode/README.md +48 -0
- package/dist/plugins/opencode/channel.js +92 -0
- package/dist/plugins/opencode/index.js +64 -0
- package/dist/plugins/opencode/shim.js +150 -0
- package/dist/plugins/quiet/README.md +26 -0
- package/dist/plugins/quiet/index.js +23 -0
- package/dist/plugins/tabs/README.md +44 -0
- package/dist/plugins/tabs/index.js +75 -0
- package/dist/plugins/tabs/public/client.js +1 -0
- package/dist/plugins/tabs/public/style.css +98 -0
- package/dist/plugins/terminal/README.md +63 -0
- package/dist/plugins/terminal/host.js +338 -0
- package/dist/plugins/terminal/index.js +170 -0
- package/dist/plugins/terminal/modes.js +32 -0
- package/dist/plugins/terminal/public/client.js +41 -0
- package/dist/plugins/terminal/public/style.css +511 -0
- package/dist/plugins/terminal/server.js +256 -0
- package/dist/plugins/terminal/sizes.js +58 -0
- package/dist/plugins/timeline/README.md +48 -0
- package/dist/plugins/timeline/index.js +83 -0
- package/dist/plugins/timeline/public/style.css +138 -0
- package/dist/plugins/toc/README.md +40 -0
- package/dist/plugins/toc/index.js +29 -0
- package/dist/plugins/toc/public/client.js +1 -0
- package/dist/plugins/toc/public/style.css +117 -0
- package/dist/plugins/window/README.md +51 -0
- package/dist/plugins/window/index.js +91 -0
- package/dist/solid/index.js +41 -0
- package/dist/src/agents.js +81 -0
- package/dist/src/anchors.js +52 -0
- package/dist/src/api.js +282 -0
- package/dist/src/archive.js +49 -0
- package/dist/src/auth.js +67 -0
- package/dist/src/build.js +159 -0
- package/dist/src/client/page/base.css +1762 -0
- package/dist/src/client/page/main.js +2098 -0
- package/dist/src/config.js +76 -0
- package/dist/src/document.js +93 -0
- package/dist/src/entries.js +264 -0
- package/dist/src/events.js +322 -0
- package/dist/src/files.js +47 -0
- package/dist/src/formstate.js +65 -0
- package/dist/src/help.js +211 -0
- package/dist/src/html.js +34 -0
- package/dist/src/hub.js +341 -0
- package/dist/src/icons.js +6 -0
- package/dist/src/listen.js +132 -0
- package/dist/src/listeners.js +64 -0
- package/dist/src/load.js +81 -0
- package/dist/src/loader.js +179 -0
- package/dist/src/migrate.js +314 -0
- package/dist/src/package.js +52 -0
- package/dist/src/pages/blocks.js +67 -0
- package/dist/src/pages/board.js +59 -0
- package/dist/src/pages/index.js +27 -0
- package/dist/src/pages/markdown.js +863 -0
- package/dist/src/pages/render.js +665 -0
- package/dist/src/pages/window.js +29 -0
- package/dist/src/plugins.js +283 -0
- package/dist/src/public.js +24 -0
- package/dist/src/rename.js +130 -0
- package/dist/src/running.js +146 -0
- package/dist/src/serve.js +188 -0
- package/dist/src/server.js +1105 -0
- package/dist/src/site.js +179 -0
- package/dist/src/state.js +155 -0
- package/dist/src/status.js +323 -0
- package/dist/src/thread.js +68 -0
- package/dist/src/watchdog.js +38 -0
- package/dist/src/ws.js +128 -0
- package/package.json +154 -4
- package/plugins/README.md +304 -0
- package/plugins/alert/README.md +18 -0
- package/plugins/alert/index.ts +50 -0
- package/plugins/alert/public/style.css +40 -0
- package/plugins/ansi/README.md +36 -0
- package/plugins/ansi/index.ts +95 -0
- package/plugins/ansi/public/style.css +28 -0
- package/plugins/badge/README.md +32 -0
- package/plugins/badge/index.ts +36 -0
- package/plugins/badge/public/style.css +30 -0
- package/plugins/chat/README.md +81 -0
- package/plugins/chat/autosize.ts +139 -0
- package/plugins/chat/client.tsx +187 -0
- package/plugins/chat/index.ts +146 -0
- package/plugins/chat/public/style.css +143 -0
- package/plugins/claude/README.md +116 -0
- package/plugins/claude/channel.ts +136 -0
- package/plugins/claude/doctor.ts +274 -0
- package/plugins/claude/index.ts +248 -0
- package/plugins/claude/session.ts +70 -0
- package/plugins/code/README.md +54 -0
- package/plugins/code/client.ts +73 -0
- package/plugins/code/diff.ts +96 -0
- package/plugins/code/index.ts +136 -0
- package/plugins/code/public/style.css +99 -0
- package/plugins/comments/README.md +30 -0
- package/plugins/comments/client.ts +723 -0
- package/plugins/comments/index.ts +48 -0
- package/plugins/comments/public/style.css +224 -0
- package/plugins/details/README.md +24 -0
- package/plugins/details/index.ts +30 -0
- package/plugins/details/public/style.css +7 -0
- package/plugins/draft/README.md +14 -0
- package/plugins/draft/index.ts +23 -0
- package/plugins/draft/public/style.css +21 -0
- package/plugins/forge/README.md +22 -0
- package/plugins/forge/index.ts +84 -0
- package/plugins/form/README.md +126 -0
- package/plugins/form/index.ts +199 -0
- package/plugins/form/public/style.css +172 -0
- package/plugins/grid/README.md +45 -0
- package/plugins/grid/index.ts +41 -0
- package/plugins/grid/public/style.css +98 -0
- package/plugins/iframe/README.md +18 -0
- package/plugins/iframe/index.ts +53 -0
- package/plugins/iframe/public/style.css +28 -0
- package/plugins/index.ts +49 -0
- package/plugins/lightbox/README.md +24 -0
- package/plugins/lightbox/client.ts +109 -0
- package/plugins/lightbox/index.ts +25 -0
- package/plugins/lightbox/public/style.css +66 -0
- package/plugins/mermaid/README.md +21 -0
- package/plugins/mermaid/index.ts +46 -0
- package/plugins/mermaid/public/style.css +21 -0
- package/plugins/opencode/README.md +48 -0
- package/plugins/opencode/channel.ts +112 -0
- package/plugins/opencode/index.ts +91 -0
- package/plugins/opencode/shim.ts +166 -0
- package/plugins/quiet/README.md +26 -0
- package/plugins/quiet/index.ts +28 -0
- package/plugins/tabs/README.md +44 -0
- package/plugins/tabs/client.ts +96 -0
- package/plugins/tabs/index.ts +103 -0
- package/plugins/tabs/public/style.css +98 -0
- package/plugins/terminal/README.md +63 -0
- package/plugins/terminal/client.ts +391 -0
- package/plugins/terminal/host.ts +434 -0
- package/plugins/terminal/index.ts +199 -0
- package/plugins/terminal/modes.ts +30 -0
- package/plugins/terminal/public/style.css +225 -0
- package/plugins/terminal/server.ts +266 -0
- package/plugins/terminal/sizes.ts +72 -0
- package/plugins/timeline/README.md +48 -0
- package/plugins/timeline/index.ts +82 -0
- package/plugins/timeline/public/style.css +138 -0
- package/plugins/toc/README.md +40 -0
- package/plugins/toc/client.ts +236 -0
- package/plugins/toc/index.ts +55 -0
- package/plugins/toc/public/style.css +117 -0
- package/plugins/window/README.md +51 -0
- package/plugins/window/index.ts +92 -0
- package/skills/workpad/SKILL.md +588 -0
- package/solid/index.tsx +80 -0
- package/src/agents.ts +133 -0
- package/src/anchors.ts +85 -0
- package/src/api.ts +444 -0
- package/src/archive.ts +75 -0
- package/src/auth.ts +99 -0
- package/src/build.ts +213 -0
- package/src/client/base.ts +19 -0
- package/src/client/forms.ts +420 -0
- package/src/client/markdown.ts +147 -0
- package/src/client/page/base.css +1762 -0
- package/src/client/page/board.ts +137 -0
- package/src/client/page/elsewhere.ts +153 -0
- package/src/client/page/fresh.ts +343 -0
- package/src/client/page/heading-link.ts +32 -0
- package/src/client/page/live.ts +134 -0
- package/src/client/page/main.ts +398 -0
- package/src/client/page/orphans.ts +64 -0
- package/src/client/page/place.ts +260 -0
- package/src/client/page/sort.ts +49 -0
- package/src/client/page/sticky.ts +58 -0
- package/src/client/page/theme.ts +36 -0
- package/src/client/page/view.ts +9 -0
- package/src/client/page/waiting.ts +278 -0
- package/src/client/page/window.ts +40 -0
- package/src/client/reactive.ts +19 -0
- package/src/client/read.ts +111 -0
- package/src/client/runtime.ts +499 -0
- package/src/client/scroll.ts +90 -0
- package/src/client/toast.ts +99 -0
- package/src/config.ts +111 -0
- package/src/define.ts +997 -0
- package/src/document.ts +191 -0
- package/src/entries.ts +352 -0
- package/src/events.ts +463 -0
- package/src/files.ts +74 -0
- package/src/formstate.ts +72 -0
- package/src/help.ts +238 -0
- package/src/html.ts +44 -0
- package/src/hub.ts +426 -0
- package/src/icons.ts +18 -0
- package/src/listen.ts +171 -0
- package/src/listeners.ts +89 -0
- package/src/load.ts +113 -0
- package/src/loader.ts +227 -0
- package/src/migrate.ts +352 -0
- package/src/package.ts +62 -0
- package/src/pages/blocks.ts +106 -0
- package/src/pages/board.ts +89 -0
- package/src/pages/index.ts +79 -0
- package/src/pages/markdown.ts +976 -0
- package/src/pages/render.ts +748 -0
- package/src/pages/window.ts +69 -0
- package/src/plugins.ts +319 -0
- package/src/public.ts +39 -0
- package/src/rename.ts +147 -0
- package/src/running.ts +171 -0
- package/src/serve.ts +221 -0
- package/src/server.ts +1385 -0
- package/src/site.ts +170 -0
- package/src/state.ts +327 -0
- package/src/status.ts +466 -0
- package/src/thread.ts +98 -0
- package/src/watchdog.ts +53 -0
- package/src/ws.ts +155 -0
package/dist/src/api.js
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { findProjectDir, project } from "./config.js";
|
|
2
|
+
import { machineServerFile } from "./entries.js";
|
|
3
|
+
import { projectServer, recordedOrigin, sharedServer } from "./running.js";
|
|
4
|
+
import { kindOf } from "./state.js";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
// src/api.ts
|
|
8
|
+
/** An error the server answered with: its status and what it said. */
|
|
9
|
+
var WorkpadError = class extends Error {
|
|
10
|
+
status;
|
|
11
|
+
constructor(message, status) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.status = status;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Connect to a workpad server: a URL (`'http://localhost:4777'`, `'https://workpad.local/rg/develop'`),
|
|
18
|
+
* a project's folder, or options. Without any: the project of the current folder (its own server, or
|
|
19
|
+
* the shared server's path for it), else the shared server. It asks the server once, to know what it
|
|
20
|
+
* is; a server that doesn't run is an error that says so.
|
|
21
|
+
*/
|
|
22
|
+
async function connect(target) {
|
|
23
|
+
const options = typeof target === "string" ? /^https?:\/\//.test(target) ? { url: target } : { dir: target } : target ?? {};
|
|
24
|
+
const at = await locate(options);
|
|
25
|
+
const wp = client(async () => at, options);
|
|
26
|
+
await wp.projects();
|
|
27
|
+
return wp;
|
|
28
|
+
}
|
|
29
|
+
/** Where `options` point: a URL as it is; a folder's project; else this folder's, else the shared server. */
|
|
30
|
+
async function locate(options) {
|
|
31
|
+
if (options.url) return probe(options.url);
|
|
32
|
+
const dir = options.shared ? null : findProjectDir(options.dir ?? process.cwd());
|
|
33
|
+
if (options.dir && !dir) throw new Error(`${options.dir} is not in a workpad project (no .workpad/ folder in it or above it)`);
|
|
34
|
+
if (dir) {
|
|
35
|
+
const url = await projectServer(project(dir));
|
|
36
|
+
if (!url) throw new Error(`no server serves ${dir}: \`workpad show <page>\` there starts its own, and the shared server is started outside the agents' sandboxes`);
|
|
37
|
+
return probe(url);
|
|
38
|
+
}
|
|
39
|
+
const shared = await sharedServer(machineServerFile());
|
|
40
|
+
if (!shared) throw new Error(`the shared server is not running${recordedOrigin(machineServerFile()) ? "" : " (it has no record in the machine folder)"}: give a project's folder or a server's url`);
|
|
41
|
+
return {
|
|
42
|
+
origin: shared.origin,
|
|
43
|
+
base: null
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** What a server at `url` is: the shared one (all its projects), or a project's, at its path. */
|
|
47
|
+
async function probe(url) {
|
|
48
|
+
const clean = url.replace(/\/+$/, "");
|
|
49
|
+
let health;
|
|
50
|
+
try {
|
|
51
|
+
health = await (await fetch(`${clean}/api/health`, { signal: AbortSignal.timeout(5e3) })).json();
|
|
52
|
+
} catch (err) {
|
|
53
|
+
throw new Error(`no workpad server answers at ${clean}: ${err.message}`);
|
|
54
|
+
}
|
|
55
|
+
const { origin, pathname } = new URL(clean);
|
|
56
|
+
if (health.hub) return {
|
|
57
|
+
origin: `${origin}${pathname === "/" ? "" : pathname}`,
|
|
58
|
+
base: null
|
|
59
|
+
};
|
|
60
|
+
const base = typeof health.base === "string" ? health.base : "";
|
|
61
|
+
const prefix = pathname.replace(/\/+$/, "");
|
|
62
|
+
return {
|
|
63
|
+
origin: `${origin}${prefix.endsWith(base) ? prefix.slice(0, prefix.length - base.length) : prefix}`,
|
|
64
|
+
base
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const query = (q) => {
|
|
68
|
+
const params = new URLSearchParams();
|
|
69
|
+
for (const [k, v] of Object.entries(q)) if (v != null && v !== "" && !(Array.isArray(v) && !v.length)) params.set(k, Array.isArray(v) ? v.join(",") : String(v));
|
|
70
|
+
const s = params.toString();
|
|
71
|
+
return s ? `?${s}` : "";
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* A client whose calls go to the server `target` says, asked for at the first call, so that one
|
|
75
|
+
* made before a server runs can start it then.
|
|
76
|
+
*/
|
|
77
|
+
function client(target, options = {}) {
|
|
78
|
+
let at = null;
|
|
79
|
+
const where = () => at ??= target().catch((err) => (at = null, Promise.reject(err)));
|
|
80
|
+
const agent = options.agent !== void 0 ? options.agent : process.env.WORKPAD_AGENT ?? null;
|
|
81
|
+
let known = null;
|
|
82
|
+
async function request(url, init) {
|
|
83
|
+
const res = await fetch(url, init);
|
|
84
|
+
const text = await res.text();
|
|
85
|
+
let body;
|
|
86
|
+
try {
|
|
87
|
+
body = text ? JSON.parse(text) : null;
|
|
88
|
+
} catch {
|
|
89
|
+
throw new WorkpadError(`${url}: not JSON (${res.status})`, res.status);
|
|
90
|
+
}
|
|
91
|
+
if (!res.ok) throw new WorkpadError(body?.error ?? res.statusText, res.status);
|
|
92
|
+
return body;
|
|
93
|
+
}
|
|
94
|
+
async function projects() {
|
|
95
|
+
const t = await where();
|
|
96
|
+
known = await request(`${t.origin}${t.base ?? ""}/api/projects`);
|
|
97
|
+
return known;
|
|
98
|
+
}
|
|
99
|
+
/** The project a call is about: the one connected to, else the one named (by its path, folder or name). */
|
|
100
|
+
async function projectOf(name) {
|
|
101
|
+
const t = await where();
|
|
102
|
+
const all = known ?? await projects();
|
|
103
|
+
if (t.base !== null) return all[0] ?? null;
|
|
104
|
+
if (name == null) return null;
|
|
105
|
+
const found = all.find((p) => p.base === name) ?? all.find((p) => p.dir === name) ?? (await projects()).find((p) => p.base === name || p.dir === name || p.label === name || p.name === name);
|
|
106
|
+
if (!found) throw new Error(`the server serves no project ${name}: it serves ${all.map((p) => p.base).join(", ")}`);
|
|
107
|
+
return found;
|
|
108
|
+
}
|
|
109
|
+
/** A project's own route. */
|
|
110
|
+
const at_ = async (p, route) => `${(await where()).origin}${p.base}${route}`;
|
|
111
|
+
/** A list: of the project named or connected to, else of every project (the shared server puts them together). */
|
|
112
|
+
async function list(what, q, project) {
|
|
113
|
+
const p = await projectOf(project);
|
|
114
|
+
const t = await where();
|
|
115
|
+
return request(`${p ? await at_(p, `/api/${what}`) : `${t.origin}/api/${what}`}${query(q)}`);
|
|
116
|
+
}
|
|
117
|
+
/** A route each project answers for its own: of the one named or connected to, else of each, put together. */
|
|
118
|
+
async function each(route, q, project) {
|
|
119
|
+
const p = await projectOf(project);
|
|
120
|
+
const ps = p ? [p] : known ?? await projects();
|
|
121
|
+
return (await Promise.all(ps.map(async (x) => (await request(`${await at_(x, route)}${query(q)}`)).map((item) => ({
|
|
122
|
+
...item,
|
|
123
|
+
project: x.base
|
|
124
|
+
}))))).flat();
|
|
125
|
+
}
|
|
126
|
+
/** A project's token, for its writes: given, or read from its folder. */
|
|
127
|
+
function tokenOf(p) {
|
|
128
|
+
const t = typeof options.token === "function" ? options.token(p) : options.token;
|
|
129
|
+
if (t) return t;
|
|
130
|
+
try {
|
|
131
|
+
return fs.readFileSync(path.join(p.dir, ".workpad", "token"), "utf8").trim();
|
|
132
|
+
} catch {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async function write(project, route, body) {
|
|
137
|
+
const p = await projectOf(project);
|
|
138
|
+
if (!p) throw new Error(`name the project: the server serves ${(known ?? []).map((x) => x.base).join(", ")}`);
|
|
139
|
+
const token = tokenOf(p);
|
|
140
|
+
return request(await at_(p, route), {
|
|
141
|
+
method: "POST",
|
|
142
|
+
headers: {
|
|
143
|
+
"content-type": "application/json",
|
|
144
|
+
...token ? { "x-workpad-token": token } : {}
|
|
145
|
+
},
|
|
146
|
+
body: JSON.stringify({
|
|
147
|
+
...body,
|
|
148
|
+
...agent ? { agent } : {}
|
|
149
|
+
})
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/** A form's page, name and project, from a ref: `page#name` (`#form:name` too), or the parts. */
|
|
153
|
+
function parse(ref) {
|
|
154
|
+
if (typeof ref !== "string") return ref;
|
|
155
|
+
const hash = ref.lastIndexOf("#");
|
|
156
|
+
if (hash < 0) throw new Error(`a form is <page>#<name>: ${ref}`);
|
|
157
|
+
return {
|
|
158
|
+
page: ref.slice(0, hash),
|
|
159
|
+
name: ref.slice(hash + 1).replace(/^form:/, "")
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
async function formWrite(action, ref, extra = {}) {
|
|
163
|
+
const f = parse(ref);
|
|
164
|
+
return write(f.project, `/api/forms/${action}`, {
|
|
165
|
+
page: f.page,
|
|
166
|
+
forms: [f.name],
|
|
167
|
+
...extra
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
async function* live(q = {}) {
|
|
171
|
+
const { project, signal, ...filter } = q;
|
|
172
|
+
const p = await projectOf(project);
|
|
173
|
+
const t = await where();
|
|
174
|
+
let since = filter.since ?? null;
|
|
175
|
+
const stop = new AbortController();
|
|
176
|
+
const onAbort = () => stop.abort();
|
|
177
|
+
signal?.addEventListener("abort", onAbort);
|
|
178
|
+
try {
|
|
179
|
+
while (!stop.signal.aborted) {
|
|
180
|
+
const url = `${p ? await at_(p, "/api/stream") : `${t.origin}/api/stream`}${query({
|
|
181
|
+
...filter,
|
|
182
|
+
since
|
|
183
|
+
})}`;
|
|
184
|
+
let res;
|
|
185
|
+
try {
|
|
186
|
+
res = await fetch(url, { signal: stop.signal });
|
|
187
|
+
} catch {
|
|
188
|
+
if (stop.signal.aborted) return;
|
|
189
|
+
await new Promise((r) => setTimeout(r, 1e3));
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (!res.ok || !res.body) throw new WorkpadError(`${url}: ${res.status} ${res.statusText}`, res.status);
|
|
193
|
+
const reader = res.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
194
|
+
let buf = "";
|
|
195
|
+
try {
|
|
196
|
+
for (;;) {
|
|
197
|
+
const { value, done } = await reader.read();
|
|
198
|
+
if (done) break;
|
|
199
|
+
buf += value;
|
|
200
|
+
let end;
|
|
201
|
+
while ((end = buf.indexOf("\n\n")) >= 0) {
|
|
202
|
+
const block = buf.slice(0, end);
|
|
203
|
+
buf = buf.slice(end + 2);
|
|
204
|
+
const data = /^data: (.*)$/m.exec(block)?.[1];
|
|
205
|
+
if (!/^event: event$/m.test(block) || !data) continue;
|
|
206
|
+
const e = JSON.parse(data);
|
|
207
|
+
since = e.id;
|
|
208
|
+
yield e;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
} catch {
|
|
212
|
+
if (stop.signal.aborted) return;
|
|
213
|
+
} finally {
|
|
214
|
+
reader.releaseLock();
|
|
215
|
+
}
|
|
216
|
+
if (!stop.signal.aborted) await new Promise((r) => setTimeout(r, 1e3));
|
|
217
|
+
}
|
|
218
|
+
} finally {
|
|
219
|
+
signal?.removeEventListener("abort", onAbort);
|
|
220
|
+
stop.abort();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
async url() {
|
|
225
|
+
const t = await where();
|
|
226
|
+
return `${t.origin}${t.base ?? ""}`;
|
|
227
|
+
},
|
|
228
|
+
projects,
|
|
229
|
+
pages: ({ project, ...q } = {}) => list("pages", q, project),
|
|
230
|
+
status: ({ project, ...q } = {}) => each("/api/status", q, project),
|
|
231
|
+
forms: ({ project, ...q } = {}) => list("forms", q, project),
|
|
232
|
+
async form(ref) {
|
|
233
|
+
const f = parse(ref);
|
|
234
|
+
return (await list("forms", {
|
|
235
|
+
page: f.page,
|
|
236
|
+
name: f.name
|
|
237
|
+
}, f.project)).find((x) => x.page === f.page) ?? null;
|
|
238
|
+
},
|
|
239
|
+
chats: ({ project, ...q } = {}) => list("chats", q, project),
|
|
240
|
+
async events({ project, ...q } = {}) {
|
|
241
|
+
return (await each("/api/events", q, project)).map((e) => ({
|
|
242
|
+
...e,
|
|
243
|
+
kind: kindOf(e)
|
|
244
|
+
}));
|
|
245
|
+
},
|
|
246
|
+
live,
|
|
247
|
+
subscriptions: ({ project, ...q } = {}) => list("subscriptions", q, project),
|
|
248
|
+
agents: ({ project } = {}) => list("agents", {}, project),
|
|
249
|
+
listeners: ({ project, ...q } = {}) => each("/api/listeners", q, project),
|
|
250
|
+
async anchors(page, { project } = {}) {
|
|
251
|
+
const p = await projectOf(project);
|
|
252
|
+
if (!p) throw new Error("name the project the page is in");
|
|
253
|
+
return request(`${await at_(p, "/api/anchors")}${query({ page })}`);
|
|
254
|
+
},
|
|
255
|
+
writePage: (page, markdown, { project } = {}) => write(project, "/api/page", {
|
|
256
|
+
page,
|
|
257
|
+
markdown
|
|
258
|
+
}),
|
|
259
|
+
hold: (ref, reason) => formWrite("hold", ref, { reason }).then((r) => r.event),
|
|
260
|
+
release: (ref) => formWrite("release", ref).then((r) => r.event),
|
|
261
|
+
settle: (ref) => formWrite("settle", ref),
|
|
262
|
+
async handled(events, { project } = {}) {
|
|
263
|
+
const all = Array.isArray(events) ? events : [events];
|
|
264
|
+
const byProject = /* @__PURE__ */ new Map();
|
|
265
|
+
for (const e of all) {
|
|
266
|
+
const key = typeof e === "string" ? project : e.project ?? project;
|
|
267
|
+
byProject.set(key, [...byProject.get(key) ?? [], typeof e === "string" ? e : e.id]);
|
|
268
|
+
}
|
|
269
|
+
const out = {
|
|
270
|
+
handled: [],
|
|
271
|
+
already: []
|
|
272
|
+
};
|
|
273
|
+
for (const [p, ids] of byProject) {
|
|
274
|
+
const r = await write(p, "/api/handled", { ids });
|
|
275
|
+
out.handled.push(...r.handled);
|
|
276
|
+
out.already.push(...r.already);
|
|
277
|
+
}
|
|
278
|
+
return out;
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
export { WorkpadError, client, connect, probe };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { isQuestionName } from "./status.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
// src/archive.ts
|
|
5
|
+
/** When it came, to the minute, in UTC: `2026-11-26 10:14`. */
|
|
6
|
+
const when = (e) => e.ts.slice(0, 16).replace("T", " ");
|
|
7
|
+
/** A list item: its head, then text on the lines under it, indented to stay in the item. */
|
|
8
|
+
const item = (head, text = "") => `- ${head}${text.trim() ? `\n\n${text.trim().replace(/^/gm, " ")}` : ""}`;
|
|
9
|
+
/** One answer to a form, in a line: its fields as given, and the button when it was another than Send. */
|
|
10
|
+
function answer(e) {
|
|
11
|
+
const own = Object.entries(e.data).filter(([k]) => !k.includes(":"));
|
|
12
|
+
const fields = own.filter(([, v]) => v != null && v !== "" && v !== false && !(Array.isArray(v) && !v.length)).map(([k, v]) => {
|
|
13
|
+
const value = Array.isArray(v) ? v.join(", ") : v === true ? "yes" : String(v);
|
|
14
|
+
return value.includes("\n") ? null : `${k}: ${value}`;
|
|
15
|
+
});
|
|
16
|
+
const long = own.filter(([, v]) => typeof v === "string" && v.includes("\n"));
|
|
17
|
+
const button = e.action && !["Send", "Submit"].includes(e.action) ? [`(${e.action})`] : [];
|
|
18
|
+
const line = [...fields.filter(Boolean), ...button].join(" · ") || "sent";
|
|
19
|
+
return item(`${when(e)}: ${line}`, long.map(([k, v]) => `${k}:\n\n${v}`).join("\n\n"));
|
|
20
|
+
}
|
|
21
|
+
/** The forms' answers: the reader's events of a question's type, by form, in the order they came. */
|
|
22
|
+
function answers(events) {
|
|
23
|
+
const byForm = /* @__PURE__ */ new Map();
|
|
24
|
+
for (const e of events) if (isQuestionName(e.type) && e.from !== "cli") byForm.set(e.type, [...byForm.get(e.type) ?? [], e]);
|
|
25
|
+
if (!byForm.size) return "";
|
|
26
|
+
return ["## Answers", ...[...byForm].map(([form, list]) => `### ${form}\n\n${list.map(answer).join("\n")}`)].join("\n\n");
|
|
27
|
+
}
|
|
28
|
+
/** The archived page: its markdown, then what was answered on it. */
|
|
29
|
+
async function archived(options) {
|
|
30
|
+
const { page, source, events, plugins, at = /* @__PURE__ */ new Date() } = options;
|
|
31
|
+
const parts = [answers(events)];
|
|
32
|
+
for (const p of plugins) if (p.archive) parts.push((await p.archive(events))?.trim() ?? "");
|
|
33
|
+
const said = parts.filter(Boolean);
|
|
34
|
+
return [
|
|
35
|
+
source.trimEnd(),
|
|
36
|
+
"---",
|
|
37
|
+
`# Archived`,
|
|
38
|
+
`The page \`${page}\`, archived ${at.toISOString().slice(0, 16).replace("T", " ")} (UTC), with what was answered on it.`,
|
|
39
|
+
...said.length ? said : ["Nothing was answered on it."]
|
|
40
|
+
].filter(Boolean).join("\n\n").concat("\n");
|
|
41
|
+
}
|
|
42
|
+
/** Where an archived page goes: `.workpad/archive/<page>-<date>.md`, `-2` and on for another that day. */
|
|
43
|
+
function archiveFile(wp, page, at = /* @__PURE__ */ new Date()) {
|
|
44
|
+
const base = path.join(wp, "archive", `${page}-${at.toISOString().slice(0, 10)}`);
|
|
45
|
+
let file = `${base}.md`;
|
|
46
|
+
for (let n = 2; fs.existsSync(file); n++) file = `${base}-${n}.md`;
|
|
47
|
+
return file;
|
|
48
|
+
}
|
|
49
|
+
export { archiveFile, archived, item, when };
|
package/dist/src/auth.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import crypto from "node:crypto";
|
|
4
|
+
// src/auth.ts
|
|
5
|
+
const COOKIE = "wp-token";
|
|
6
|
+
/** The project's token, made on first use. */
|
|
7
|
+
function projectToken(wp) {
|
|
8
|
+
const file = path.join(wp, "token");
|
|
9
|
+
try {
|
|
10
|
+
return fs.readFileSync(file, "utf8").trim();
|
|
11
|
+
} catch {}
|
|
12
|
+
const token = crypto.randomBytes(24).toString("base64url");
|
|
13
|
+
fs.writeFileSync(file, token + "\n", { mode: 384 });
|
|
14
|
+
return token;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* From a page of a workpad server on this machine, or from no page at all (the command line)?
|
|
18
|
+
* `origins`: the others a page may be at, as the machine config names them (a server in a
|
|
19
|
+
* container, reached at an address of its own: `https://workpad.local`).
|
|
20
|
+
*/
|
|
21
|
+
const sameSite = (req, origins = []) => {
|
|
22
|
+
const origin = req.headers.origin;
|
|
23
|
+
return !origin || /^http:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/.test(origin) || origins.includes(origin);
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* `base`: the path the project is served under (see ServerOptions), which its cookie is kept to.
|
|
27
|
+
* `origins`: the other origins its pages may be at (see sameSite), asked for each request.
|
|
28
|
+
*/
|
|
29
|
+
function createAuth(wp, base = "", origins = () => []) {
|
|
30
|
+
const token = projectToken(wp);
|
|
31
|
+
const same = (a, b) => typeof a === "string" && a.length === b.length && crypto.timingSafeEqual(Buffer.from(a), Buffer.from(b));
|
|
32
|
+
const cookies = (req) => Object.fromEntries((req.headers.cookie ?? "").split(";").map((c) => c.trim().split("=")).filter(([k]) => k));
|
|
33
|
+
/** Has this request the token, from this origin? No request (a page being built) has none. */
|
|
34
|
+
function authorized(req) {
|
|
35
|
+
if (!req) return false;
|
|
36
|
+
const jar = cookies(req);
|
|
37
|
+
if (!(same(jar[COOKIE], token) || same(req.headers["x-workpad-token"], token))) return false;
|
|
38
|
+
if (!sameSite(req, origins())) return false;
|
|
39
|
+
const site = req.headers["sec-fetch-site"];
|
|
40
|
+
if (site && site !== "same-origin" && site !== "none" && !opensPage(req)) return false;
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
/** Opening a page as the tab's document: no frame, no fetch, and not an API route. */
|
|
44
|
+
const opensPage = (req) => req.method === "GET" && req.headers["sec-fetch-mode"] === "navigate" && req.headers["sec-fetch-dest"] === "document" && !(req.url ?? "").startsWith("/api/");
|
|
45
|
+
/** The /_/auth route; false for any other path. */
|
|
46
|
+
function handle(req, res, p, q) {
|
|
47
|
+
if (p !== "/_/auth") return false;
|
|
48
|
+
if (!same(q.token, token)) {
|
|
49
|
+
res.writeHead(403, { "content-type": "text/plain" });
|
|
50
|
+
res.end("wrong token");
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
const to = typeof q.to === "string" && q.to.startsWith("/") && !q.to.startsWith("//") ? q.to : "/";
|
|
54
|
+
res.writeHead(302, {
|
|
55
|
+
"set-cookie": `${COOKIE}=${token}; Path=${base || "/"}; HttpOnly; SameSite=Lax; Max-Age=31536000`,
|
|
56
|
+
location: base + to
|
|
57
|
+
});
|
|
58
|
+
res.end();
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
authorized,
|
|
63
|
+
handle,
|
|
64
|
+
token
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export { createAuth, projectToken, sameSite };
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { RUNTIME, pageDocument, pluginParts } from "./document.js";
|
|
2
|
+
import { toPath } from "./loader.js";
|
|
3
|
+
import { PACKAGE_DIR } from "./package.js";
|
|
4
|
+
import { pageSource, within } from "./site.js";
|
|
5
|
+
import { stripTypeScriptTypes } from "node:module";
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
// src/build.ts
|
|
9
|
+
const ENGINE_DIR = PACKAGE_DIR;
|
|
10
|
+
const TYPESCRIPT = /\.m?ts$/i;
|
|
11
|
+
const typeScriptModule = (file) => stripTypeScriptTypes(fs.readFileSync(file, "utf8"));
|
|
12
|
+
/** What a build leaves out unless told otherwise: what is for writing a page, not for reading it. */
|
|
13
|
+
const BUILD_SKIP = [
|
|
14
|
+
"form",
|
|
15
|
+
"chat",
|
|
16
|
+
"comments",
|
|
17
|
+
"draft"
|
|
18
|
+
];
|
|
19
|
+
/** In the folder a build writes, so that a next build knows it may replace it. */
|
|
20
|
+
const BUILD_MARK = ".workpad-build";
|
|
21
|
+
async function build({ project, config, hooks: setUp, files: served }, options = {}) {
|
|
22
|
+
const cfg = await config();
|
|
23
|
+
if (cfg.errors.length) throw new Error(`the config failed to load: ${cfg.errors[0].message}`);
|
|
24
|
+
if (!cfg.pages) throw new Error("the config has no pages renderer");
|
|
25
|
+
const pages = cfg.pages;
|
|
26
|
+
const defined = (...xs) => xs.find((x) => x !== void 0);
|
|
27
|
+
const patterns = defined(options.pages, cfg.build.pages) ?? [];
|
|
28
|
+
const skip = new Set(defined(options.skip, cfg.build.skip) ?? BUILD_SKIP);
|
|
29
|
+
const outDir = path.resolve(project.dir, defined(options.out, cfg.build.out) ?? "site");
|
|
30
|
+
if (!patterns.length) throw new Error("nothing to build: name the pages, as globs from the project's folder (workpad build 'docs/**/*.md'), or set build.pages in the config");
|
|
31
|
+
const warnings = [];
|
|
32
|
+
const include = patterns.filter((p) => !p.startsWith("!"));
|
|
33
|
+
const exclude = patterns.filter((p) => p.startsWith("!")).map((p) => p.slice(1));
|
|
34
|
+
const files = [...new Set(include.flatMap((p) => fs.globSync(p, { cwd: project.dir }).map((f) => path.resolve(project.dir, f))))].filter((f) => /\.(md|markdown)$/i.test(f) && fs.statSync(f).isFile()).filter((f) => !exclude.some((g) => path.matchesGlob(path.relative(project.dir, f), g))).sort();
|
|
35
|
+
if (!files.length) throw new Error(`no markdown files match ${patterns.join(" ")}`);
|
|
36
|
+
const base = files.map(path.dirname).reduce((a, b) => {
|
|
37
|
+
while (!within(b, a)) a = path.dirname(a);
|
|
38
|
+
return a;
|
|
39
|
+
});
|
|
40
|
+
const outOf = (file) => {
|
|
41
|
+
const rel = path.relative(base, file);
|
|
42
|
+
return path.join(outDir, /^(readme|index)\.(md|markdown)$/i.test(path.basename(rel)) ? path.join(path.dirname(rel), "index.html") : rel.replace(/\.(md|markdown)$/i, ".html"));
|
|
43
|
+
};
|
|
44
|
+
const built = new Map(files.map((f) => [f, outOf(f)]));
|
|
45
|
+
if (fs.existsSync(outDir)) {
|
|
46
|
+
if (fs.readdirSync(outDir).length && !fs.existsSync(path.join(outDir, BUILD_MARK))) throw new Error(`${outDir} has files a build didn't write: give another folder (--out), or empty it`);
|
|
47
|
+
fs.rmSync(outDir, { recursive: true });
|
|
48
|
+
}
|
|
49
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
50
|
+
fs.writeFileSync(path.join(outDir, BUILD_MARK), "written by workpad build; the next build replaces this folder\n");
|
|
51
|
+
const copied = /* @__PURE__ */ new Map();
|
|
52
|
+
function copyAsset(file) {
|
|
53
|
+
const known = copied.get(file);
|
|
54
|
+
if (known) return known;
|
|
55
|
+
const rel = within(file, ENGINE_DIR) ? path.join("_", "workpad", path.relative(ENGINE_DIR, file)) : within(file, project.dir) ? path.join("_", "project", path.relative(project.dir, file)) : path.join("_", "files", path.basename(path.dirname(file)), path.basename(file));
|
|
56
|
+
const dest = path.join(outDir, TYPESCRIPT.test(rel) ? rel.replace(/\.m?ts$/i, ".js") : rel);
|
|
57
|
+
copied.set(file, dest);
|
|
58
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
59
|
+
if (TYPESCRIPT.test(file)) fs.writeFileSync(dest, typeScriptModule(file));
|
|
60
|
+
else fs.copyFileSync(file, dest);
|
|
61
|
+
if (/\.css$/i.test(file)) for (const m of fs.readFileSync(file, "utf8").matchAll(/url\(\s*['"]?([^'")]+)['"]?\s*\)/g)) {
|
|
62
|
+
const ref = m[1];
|
|
63
|
+
if (/^(data:|[a-z][a-z0-9+.-]*:|\/|#)/i.test(ref)) continue;
|
|
64
|
+
const target = path.resolve(path.dirname(file), ref.replace(/[?#].*$/, ""));
|
|
65
|
+
if (fs.existsSync(target) && fs.statSync(target).isFile()) copyAsset(target);
|
|
66
|
+
}
|
|
67
|
+
return dest;
|
|
68
|
+
}
|
|
69
|
+
/** a file beside the pages (an image), copied to its place below the site */
|
|
70
|
+
function copyBeside(file) {
|
|
71
|
+
if (!within(file, base)) return null;
|
|
72
|
+
const dest = path.join(outDir, path.relative(base, file));
|
|
73
|
+
if (!fs.existsSync(dest)) {
|
|
74
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
75
|
+
fs.copyFileSync(file, dest);
|
|
76
|
+
}
|
|
77
|
+
return dest;
|
|
78
|
+
}
|
|
79
|
+
const hooks = await setUp();
|
|
80
|
+
const result = {
|
|
81
|
+
out: outDir,
|
|
82
|
+
pages: [],
|
|
83
|
+
warnings
|
|
84
|
+
};
|
|
85
|
+
for (const [file, dest] of built) {
|
|
86
|
+
const here = path.dirname(dest);
|
|
87
|
+
const relTo = (target) => path.relative(here, target).split(path.sep).map(encodeURIComponent).join("/") || ".";
|
|
88
|
+
const assetHere = (ref) => relTo(copyAsset(toPath(ref)));
|
|
89
|
+
const urlFor = (abs) => {
|
|
90
|
+
for (const candidate of [abs, abs + ".md"]) {
|
|
91
|
+
if (!fs.existsSync(candidate)) continue;
|
|
92
|
+
if (fs.statSync(candidate).isDirectory()) {
|
|
93
|
+
const index = [...built.keys()].find((f) => path.dirname(f) === candidate && /^(readme|index)\.(md|markdown)$/i.test(path.basename(f)));
|
|
94
|
+
if (index) return relTo(built.get(index));
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (built.has(candidate)) return relTo(built.get(candidate));
|
|
98
|
+
if (/\.(md|markdown)$/i.test(candidate)) {
|
|
99
|
+
warnings.push(`${path.relative(project.dir, file)} links to ${path.relative(project.dir, candidate)}, which is not in the build`);
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
const copy = copyBeside(candidate);
|
|
103
|
+
if (copy) return relTo(copy);
|
|
104
|
+
warnings.push(`${path.relative(project.dir, file)} links to ${path.relative(project.dir, candidate)}, outside the built pages' folder`);
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
};
|
|
109
|
+
const id = within(file, project.pagesDir) ? path.relative(project.pagesDir, file).split(path.sep).join("/").replace(/\.(md|markdown)$/i, "") : "-/" + path.relative(project.dir, file).split(path.sep).join("/");
|
|
110
|
+
const stored = pageSource(id, file);
|
|
111
|
+
if (stored.frontmatterError) warnings.push(`${path.relative(project.dir, file)}: frontmatter: ${stored.frontmatterError}`);
|
|
112
|
+
const context = {
|
|
113
|
+
project: {
|
|
114
|
+
name: project.name,
|
|
115
|
+
dir: project.dir,
|
|
116
|
+
files: served()
|
|
117
|
+
},
|
|
118
|
+
asset: assetHere,
|
|
119
|
+
urlFor,
|
|
120
|
+
live: false,
|
|
121
|
+
skip
|
|
122
|
+
};
|
|
123
|
+
const rendered = await pages.render(stored, context);
|
|
124
|
+
const named = /^(readme|index)\.(md|markdown)$/i.test(path.basename(file)) ? path.basename(path.dirname(file)) : path.basename(file).replace(/\.(md|markdown)$/i, "");
|
|
125
|
+
const title = !rendered.title || rendered.title === id ? named : rendered.title;
|
|
126
|
+
const out = {
|
|
127
|
+
...rendered,
|
|
128
|
+
title,
|
|
129
|
+
html: String(rendered.html ?? ""),
|
|
130
|
+
head: String(rendered.head ?? "")
|
|
131
|
+
};
|
|
132
|
+
const parts = await pluginParts(hooks, null, {
|
|
133
|
+
asset: assetHere,
|
|
134
|
+
messages: [],
|
|
135
|
+
leaveOut: skip,
|
|
136
|
+
failed: (message) => warnings.push(`${path.relative(project.dir, file)}: ${message}`)
|
|
137
|
+
});
|
|
138
|
+
const doc = pageDocument(stored, {
|
|
139
|
+
page: true,
|
|
140
|
+
out,
|
|
141
|
+
notices: []
|
|
142
|
+
}, parts, {
|
|
143
|
+
live: false,
|
|
144
|
+
base: "",
|
|
145
|
+
asset: assetHere,
|
|
146
|
+
runtime: assetHere(RUNTIME),
|
|
147
|
+
title: project.name
|
|
148
|
+
});
|
|
149
|
+
fs.mkdirSync(here, { recursive: true });
|
|
150
|
+
fs.writeFileSync(dest, doc);
|
|
151
|
+
result.pages.push({
|
|
152
|
+
file,
|
|
153
|
+
to: dest
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
if (![...built.values()].includes(path.join(outDir, "index.html"))) warnings.push("no README.md or index.md in the top folder: the site has no index.html");
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
export { build };
|