@dooc-dev/dooc 0.0.9 → 0.0.11
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 +29 -1
- package/dist/engine/compiler/bundle-urls.js +39 -5
- package/dist/engine/compiler/download-progress.d.ts +9 -0
- package/dist/engine/compiler/download-progress.js +12 -0
- package/dist/engine/compiler/public-file.d.ts +1 -1
- package/dist/engine/compiler/public-file.js +9 -1
- package/dist/engine/compiler/textfile-remote.js +19 -1
- package/dist/frontend/document-application.js +3 -2
- package/dist/server/cli.js +112 -15
- package/dist/server/editor-tools.d.ts +36 -1
- package/dist/server/editor-tools.js +6 -1
- package/dist/server/extensions.js +5 -0
- package/dist/server/git-workspace.d.ts +8 -0
- package/dist/server/git-workspace.js +375 -0
- package/dist/server/github-archive.d.ts +1 -0
- package/dist/server/github-archive.js +92 -0
- package/dist/server/languages.js +2 -1
- package/dist/server/operation-log.d.ts +4 -0
- package/dist/server/operation-log.js +45 -0
- package/dist/server/self.js +4 -47
- package/dist/server/serve.js +19 -11
- package/dist/server/static-client.js +2 -1
- package/dist/server/terminal.d.ts +22 -0
- package/dist/server/terminal.js +131 -0
- package/dist/server/workspace-server.js +7 -2
- package/dist/server/workspace-trust.d.ts +2 -0
- package/dist/server/workspace-trust.js +2 -0
- package/dist/workspace/editor-tools.d.ts +3 -3
- package/dist/workspace/editor-tools.js +25 -16
- package/dist/workspace-worker.global.js +11 -10
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -14,12 +14,40 @@ dooc turns a folder of Markdown, data files, and schema-backed records into one
|
|
|
14
14
|
| mise | `mise use -g github:dooc-dev/dooc@latest` |
|
|
15
15
|
| Homebrew | `brew tap dooc-dev/dooc https://github.com/dooc-dev/dooc && brew install dooc-dev/dooc/dooc` |
|
|
16
16
|
|
|
17
|
+
npm requires Node.js 22 or later. Standalone executables support Linux (glibc) and macOS on x64 and arm64. The curl installer writes to `~/.local/bin`; add it to `PATH` if needed.
|
|
18
|
+
|
|
19
|
+
## Start a project
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
mkdir my-docs && cd my-docs
|
|
23
|
+
dooc init
|
|
24
|
+
dooc edit
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Open the URL printed in the terminal and add your first page in the editor. Keep the command running while editing. `dooc view` opens the same workspace read-only.
|
|
28
|
+
|
|
29
|
+
After saving your pages, stop the editor with **Ctrl+C**, then check and build:
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
dooc check
|
|
33
|
+
dooc build html
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Share `dist/bundle.html` as a single file. `dooc check` validates local content; it does not fetch remote URLs.
|
|
37
|
+
|
|
17
38
|
## Documentation
|
|
18
39
|
|
|
19
40
|
```sh
|
|
20
|
-
dooc
|
|
41
|
+
dooc view dooc-docs --repo https://github.com/dooc-dev/dooc.git
|
|
42
|
+
dooc edit dooc-docs --repo https://github.com/dooc-dev/dooc.git
|
|
21
43
|
```
|
|
22
44
|
|
|
45
|
+
Requires Git and a network connection for the initial clone. Documentation is downloaded at runtime, separately from the npm package and standalone executable.
|
|
46
|
+
|
|
47
|
+
`view` downloads a fresh temporary read-only copy each time and removes it on exit. `edit` keeps a local clone and reopens your saved changes without fetching updates automatically; use the editor's Git tools to fetch and pull. Keep the command running while using either mode.
|
|
48
|
+
|
|
49
|
+
See [Commands](dooc-docs/contents/md/cli.md) for CLI options and Git workspace limitations, [Editor](dooc-docs/contents/md/editor.md) for editing and branch controls, and [Install](dooc-docs/contents/md/install.md) for updates.
|
|
50
|
+
|
|
23
51
|
## License
|
|
24
52
|
|
|
25
53
|
[MIT](LICENSE)
|
|
@@ -4,6 +4,7 @@ import valueParser from "postcss-value-parser";
|
|
|
4
4
|
import { embeddedImages, parseMdast } from "../core/markdown.js";
|
|
5
5
|
import { isRemoteTextfile } from "../core/textfile.js";
|
|
6
6
|
import { collectRefs } from "./dialect.js";
|
|
7
|
+
import { reportDownloadProgress } from "./download-progress.js";
|
|
7
8
|
import { createHash, fetchPublicFile, posix, readFileSync } from "./host.js";
|
|
8
9
|
import { assertNotIgnored } from "./ignored-files.js";
|
|
9
10
|
import { readManifest } from "./manifest.js";
|
|
@@ -74,11 +75,44 @@ export const embedBundleUrls = async (root, entries, resolvePlugin) => {
|
|
|
74
75
|
if (url.protocol === "https:" && ++downloads > 256)
|
|
75
76
|
throw new Error("Bundle exceeds 256 remote assets");
|
|
76
77
|
let type = "";
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
let data;
|
|
79
|
+
if (url.protocol === "bundle:") {
|
|
80
|
+
data = readFileSync(textfilePath(root, decodeURIComponent(url.pathname.slice(1))));
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
let received = 0;
|
|
84
|
+
let length;
|
|
85
|
+
reportDownloadProgress({ url: key, state: "start", received });
|
|
86
|
+
try {
|
|
87
|
+
data = await fetchPublicFile(url.href, (value) => {
|
|
88
|
+
type = value.split(";")[0]?.trim().toLowerCase() ?? "";
|
|
89
|
+
}, (size, value) => {
|
|
90
|
+
received = size;
|
|
91
|
+
length = value;
|
|
92
|
+
reportDownloadProgress({
|
|
93
|
+
url: key,
|
|
94
|
+
state: "progress",
|
|
95
|
+
received,
|
|
96
|
+
total: length,
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
reportDownloadProgress({
|
|
100
|
+
url: key,
|
|
101
|
+
state: "complete",
|
|
102
|
+
received: data.length,
|
|
103
|
+
total: length,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
reportDownloadProgress({
|
|
108
|
+
url: key,
|
|
109
|
+
state: "error",
|
|
110
|
+
received,
|
|
111
|
+
total: length,
|
|
112
|
+
});
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
82
116
|
if (url.protocol === "https:")
|
|
83
117
|
total += data.length;
|
|
84
118
|
if (total > 64 * 1024 * 1024)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type DownloadProgress = {
|
|
2
|
+
url: string;
|
|
3
|
+
state: "start" | "progress" | "complete" | "error";
|
|
4
|
+
received: number;
|
|
5
|
+
total?: number;
|
|
6
|
+
detail?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const setDownloadProgressListener: (value?: (event: DownloadProgress) => void) => void;
|
|
9
|
+
export declare const reportDownloadProgress: (event: DownloadProgress) => void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
let listener;
|
|
2
|
+
export const setDownloadProgressListener = (value) => {
|
|
3
|
+
listener = value;
|
|
4
|
+
};
|
|
5
|
+
export const reportDownloadProgress = (event) => {
|
|
6
|
+
try {
|
|
7
|
+
listener?.(event);
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
// Reporting must not interrupt downloads or replace their errors.
|
|
11
|
+
}
|
|
12
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Self-contained: the synchronous compiler also runs this function in a bounded child process. */
|
|
2
|
-
export declare function fetchPublicFile(source: string, contentType?: (type: string) => void): Promise<Buffer>;
|
|
2
|
+
export declare function fetchPublicFile(source: string, contentType?: (type: string) => void, progress?: (received: number, total?: number) => void): Promise<Buffer>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Self-contained: the synchronous compiler also runs this function in a bounded child process. */
|
|
2
|
-
export async function fetchPublicFile(source, contentType) {
|
|
2
|
+
export async function fetchPublicFile(source, contentType, progress) {
|
|
3
3
|
const { request } = await import("node:https");
|
|
4
4
|
const { lookup } = await import("node:dns/promises");
|
|
5
5
|
const { BlockList, isIP } = await import("node:net");
|
|
@@ -72,10 +72,18 @@ export async function fetchPublicFile(source, contentType) {
|
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
74
74
|
contentType?.(response.headers["content-type"] ?? "");
|
|
75
|
+
const length = response.headers["content-length"];
|
|
76
|
+
const total = typeof length === "string" &&
|
|
77
|
+
/^\d+$/.test(length) &&
|
|
78
|
+
Number.isSafeInteger(Number(length))
|
|
79
|
+
? Number(length)
|
|
80
|
+
: undefined;
|
|
81
|
+
progress?.(0, total);
|
|
75
82
|
const chunks = [];
|
|
76
83
|
let size = 0;
|
|
77
84
|
response.on("data", (chunk) => {
|
|
78
85
|
size += chunk.length;
|
|
86
|
+
progress?.(size, total);
|
|
79
87
|
if (size > 2 * 1024 * 1024) {
|
|
80
88
|
response.destroy();
|
|
81
89
|
reject(new Error("UNAVAILABLE"));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { allowedPreviewUrl } from "../core/previewers.js";
|
|
2
|
+
import { reportDownloadProgress } from "./download-progress.js";
|
|
2
3
|
import { execFileSync, fetchPublicFile } from "./host.js";
|
|
3
4
|
export class TextfileUnavailable extends Error {
|
|
4
5
|
reason;
|
|
@@ -65,10 +66,24 @@ export const readRemoteTextfileAsync = async (file, domains, refresh = false) =>
|
|
|
65
66
|
return active;
|
|
66
67
|
const task = (async () => {
|
|
67
68
|
let result;
|
|
69
|
+
let received = 0;
|
|
70
|
+
let total;
|
|
71
|
+
reportDownloadProgress({ url: source.url, state: "start", received });
|
|
68
72
|
try {
|
|
69
|
-
result = await fetchPublicFile(source.url)
|
|
73
|
+
result = await fetchPublicFile(source.url, undefined, (size, length) => {
|
|
74
|
+
received = size;
|
|
75
|
+
total = length;
|
|
76
|
+
reportDownloadProgress({ url: source.url, state: "progress", received, total });
|
|
77
|
+
});
|
|
78
|
+
reportDownloadProgress({
|
|
79
|
+
url: source.url,
|
|
80
|
+
state: "complete",
|
|
81
|
+
received: result.length,
|
|
82
|
+
total,
|
|
83
|
+
});
|
|
70
84
|
}
|
|
71
85
|
catch (error) {
|
|
86
|
+
reportDownloadProgress({ url: source.url, state: "error", received, total });
|
|
72
87
|
if (error.message === "BLOCKED")
|
|
73
88
|
throw new Error("External previews require a public network address");
|
|
74
89
|
result = new TextfileUnavailable(error.message === "NOT_FOUND" ? "missing" : "unreachable");
|
|
@@ -101,6 +116,7 @@ export const readRemoteTextfile = (file, domains, refresh = false) => {
|
|
|
101
116
|
return cached.result;
|
|
102
117
|
}
|
|
103
118
|
let result;
|
|
119
|
+
reportDownloadProgress({ url: source.url, state: "start", received: 0 });
|
|
104
120
|
try {
|
|
105
121
|
result = execFileSync(process.execPath, ["--input-type=module", "-e", FETCH, source.url], {
|
|
106
122
|
timeout: 12000,
|
|
@@ -108,8 +124,10 @@ export const readRemoteTextfile = (file, domains, refresh = false) => {
|
|
|
108
124
|
stdio: ["ignore", "pipe", "pipe"],
|
|
109
125
|
env: { PATH: process.env.PATH },
|
|
110
126
|
});
|
|
127
|
+
reportDownloadProgress({ url: source.url, state: "complete", received: result.length });
|
|
111
128
|
}
|
|
112
129
|
catch (error) {
|
|
130
|
+
reportDownloadProgress({ url: source.url, state: "error", received: 0 });
|
|
113
131
|
if (error.status === 45)
|
|
114
132
|
throw new Error("External previews require a public network address");
|
|
115
133
|
result = new TextfileUnavailable(error.status === 44 ? "missing" : "unreachable");
|
|
@@ -518,6 +518,7 @@ main { --doc-mono: var(--viewer-font, ${MONO_FONT}); }
|
|
|
518
518
|
.page-actions, .pane-actions { position: sticky; display: flex; align-items: center; justify-content: flex-end;
|
|
519
519
|
gap: 2px; height: 36px; padding: 0 24px; pointer-events: none; z-index: 5; }
|
|
520
520
|
:is(.page-actions, .pane-actions) > .pbtn { pointer-events: auto; background: var(--c-bg0); }
|
|
521
|
+
.pane-actions > .pbtn { background: inherit; }
|
|
521
522
|
.page-actions { top: 0; margin: -20px -24px -36px; }
|
|
522
523
|
.pbtn { flex: none; display: flex; align-items: center; justify-content: center; width: 28px; height: 28px;
|
|
523
524
|
padding: 0; color: var(--c-fg-faint); background: none; border: none; border-radius: 5px; cursor: pointer;
|
|
@@ -1197,7 +1198,7 @@ body.extensions-over #nav-extensions, body.extensions-over .extensions-dropzone
|
|
|
1197
1198
|
.resource-results:has([data-subformat-board]:not([hidden])) .resource-search { flex: 1 1 160px; max-width: 260px; height: 30px; box-sizing: border-box; gap: 8px; padding: 0 8px; border: 1px solid var(--c-line); border-radius: 4px; background: var(--c-bg0); }
|
|
1198
1199
|
.resource-results:has([data-subformat-board]:not([hidden])) .resource-search:focus-within { border-color: var(--c-accent); }
|
|
1199
1200
|
.resource-results:has([data-subformat-board]:not([hidden])) .resource-count { display: none; }
|
|
1200
|
-
.resources-pane:has([data-subformat-board]:not([hidden])) :is(.preview-content, .resource-library, .resource-results, [data-subformat-board]) { display: flex; flex-direction: column; flex: 1; }
|
|
1201
|
+
.resources-pane:has([data-subformat-board]:not([hidden])) :is(.preview-content, .resource-library, .resource-results, [data-subformat-board]):not([hidden]) { display: flex; flex-direction: column; flex: 1; }
|
|
1201
1202
|
.resources-pane:has([data-subformat-board]:not([hidden])) .preview-content { min-height: 100%; }
|
|
1202
1203
|
.resource-results:has(> .resource-empty:not([hidden])) [data-subformat-board] { flex: none; }
|
|
1203
1204
|
.resource-results:has(> .resource-empty:not([hidden])) .subformat-columns { display: none; }
|
|
@@ -1713,7 +1714,7 @@ body.edit #nav-groups { --nav-rail: 22px; --nav-icon-half: 9px; }
|
|
|
1713
1714
|
|
|
1714
1715
|
main.editor-workspace { padding: 0; height: 100vh; display: flex; flex-direction: column; position: sticky; top: 0; }
|
|
1715
1716
|
#split-preview[aria-pressed="true"] { color: var(--c-accent); background: var(--c-raised); }
|
|
1716
|
-
.pane-actions { flex-wrap: wrap; top: -20px; margin: -20px -24px 16px; padding: 4px 12px; min-height: 38px; height: auto; background:
|
|
1717
|
+
.pane-actions { flex-wrap: wrap; top: -20px; margin: -20px -24px 16px; padding: 4px 12px; min-height: 38px; height: auto; background: inherit; }
|
|
1717
1718
|
.pane-resource { min-width: 0; }
|
|
1718
1719
|
#preview-panes { display: flex; flex: 1; min-height: 0; }
|
|
1719
1720
|
#preview-panes[hidden] { display: none; }
|
package/dist/server/cli.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// CLI entry shared by npx and mise. The manifest defaults to ./dooc.yaml; project paths use its parent directory.
|
|
3
|
-
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
-
import { basename, dirname, join, resolve } from "node:path";
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
5
6
|
import { parseArgs } from "node:util";
|
|
7
|
+
import { setDownloadProgressListener } from "../engine/compiler/download-progress.js";
|
|
6
8
|
import { projectRoot } from "../engine/compiler/manifest.js";
|
|
7
9
|
import { isManifestFile, MANIFEST_FILE, serializeManifest, } from "../engine/core/content-metadata.js";
|
|
8
10
|
import { prebuilt } from "./assets.js";
|
|
11
|
+
import { terminal } from "./terminal.js";
|
|
9
12
|
process.env.NODE_ENV = prebuilt ? "production" : "development";
|
|
10
13
|
const USAGE = `usage: dooc <command>
|
|
11
14
|
|
|
12
15
|
commands:
|
|
13
16
|
init [path] create a manifest in a directory or at a manifest path
|
|
14
|
-
edit [
|
|
17
|
+
edit [path] [port] edit a local workspace or a path in a Git repository
|
|
18
|
+
--repo <git-url> resolve the path inside a cloned repository
|
|
15
19
|
--viewer-plugins <module> inject an external viewer plugin module
|
|
16
20
|
--shared <branch> several people edit; snapshots are recorded on <branch>
|
|
17
21
|
--tls-cert <pem> --tls-key <pem> serve over HTTPS (or DOOC_TLS_CERT / DOOC_TLS_KEY)
|
|
@@ -19,7 +23,8 @@ commands:
|
|
|
19
23
|
--client-origin <origin> permit the static client origin (default: http://localhost:5180)
|
|
20
24
|
client [port] serve the static client only (default: 5180)
|
|
21
25
|
--server <ws-url> connect to an optional workspace server
|
|
22
|
-
view [
|
|
26
|
+
view [path] [port] view a local workspace or a path in a Git repository
|
|
27
|
+
--repo <git-url> resolve the path inside a cloned repository
|
|
23
28
|
--viewer-plugins <module> inject an external viewer plugin module
|
|
24
29
|
--tls-cert <pem> --tls-key <pem> serve over HTTPS (or DOOC_TLS_CERT / DOOC_TLS_KEY)
|
|
25
30
|
build build the selected bundle (default <project>/dist)
|
|
@@ -50,10 +55,13 @@ commands:
|
|
|
50
55
|
--git-origin <module> inject gitOrigin from an external viewer plugin module
|
|
51
56
|
help, --help, -h show this help
|
|
52
57
|
|
|
53
|
-
Details: dooc <command> --help (init, build, check, plugin, font, self, mcp).
|
|
58
|
+
Details: dooc <command> --help (init, edit, view, server, client, build, export, check, plugin, font, self, mcp).
|
|
54
59
|
Default manifest: ./dooc.yaml. Named manifests (<name>.dooc.yaml) are also accepted.
|
|
60
|
+
Paths use the current directory, or the repository root when --repo is given.
|
|
61
|
+
Example: dooc view dooc-docs --repo https://github.com/dooc-dev/dooc.git
|
|
55
62
|
Paths and .dooc/ are relative to the selected manifest's directory.`;
|
|
56
63
|
const fail = (message) => {
|
|
64
|
+
terminal.close();
|
|
57
65
|
console.error(message);
|
|
58
66
|
process.exit(1);
|
|
59
67
|
};
|
|
@@ -62,6 +70,8 @@ const writeOut = (out, data) => {
|
|
|
62
70
|
writeFileSync(out, data);
|
|
63
71
|
};
|
|
64
72
|
const [command, ...args] = process.argv.slice(2);
|
|
73
|
+
if (["edit", "view", "self", "build", "server"].includes(command ?? ""))
|
|
74
|
+
setDownloadProgressListener(terminal.download);
|
|
65
75
|
switch (command) {
|
|
66
76
|
case "self": {
|
|
67
77
|
try {
|
|
@@ -91,7 +101,7 @@ options:
|
|
|
91
101
|
selfUpdate();
|
|
92
102
|
}
|
|
93
103
|
else {
|
|
94
|
-
|
|
104
|
+
terminal.info("Downloading documentation from GitHub...");
|
|
95
105
|
const { root, dispose } = await prepareSelfDocs();
|
|
96
106
|
process.once("exit", dispose);
|
|
97
107
|
process.once("SIGINT", () => process.exit(130));
|
|
@@ -286,9 +296,11 @@ options:
|
|
|
286
296
|
--help, -h show this help
|
|
287
297
|
|
|
288
298
|
dooc.yaml example:
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
299
|
+
system:
|
|
300
|
+
default_lang: jpn
|
|
301
|
+
languages: [jpn, eng]
|
|
302
|
+
themes: [light, dark]
|
|
303
|
+
center_contents: []
|
|
292
304
|
|
|
293
305
|
Checks:
|
|
294
306
|
render uses the viewer compiler
|
|
@@ -390,19 +402,87 @@ Report:
|
|
|
390
402
|
"tls-cert": { type: "string" },
|
|
391
403
|
"tls-key": { type: "string" },
|
|
392
404
|
shared: { type: "string" },
|
|
405
|
+
repo: { type: "string" },
|
|
406
|
+
help: { type: "boolean", short: "h" },
|
|
393
407
|
},
|
|
394
408
|
});
|
|
409
|
+
if (values.help) {
|
|
410
|
+
console.log(`usage: dooc ${command} [path] [port] [options]
|
|
411
|
+
|
|
412
|
+
path:
|
|
413
|
+
./dooc.yaml manifest (default); folders are also accepted
|
|
414
|
+
./docs folder containing dooc.yaml
|
|
415
|
+
docs/team.dooc.yaml named manifest
|
|
416
|
+
file:///home/me/docs local folder or manifest URL (without --repo)
|
|
417
|
+
|
|
418
|
+
Paths use the current directory, or the cloned repository root with --repo.
|
|
419
|
+
The repository's default branch is opened. Use the clone URL supplied by your Git host.
|
|
420
|
+
|
|
421
|
+
Remote sources require Git. Cloning finishes before the server starts.
|
|
422
|
+
Edit clones retain Git history and local changes, and reopen without fetching or resetting.
|
|
423
|
+
View clones are temporary and removed on exit.
|
|
424
|
+
|
|
425
|
+
options:
|
|
426
|
+
--repo <git-url> clone an HTTPS/SSH Git repository and resolve path inside it
|
|
427
|
+
--viewer-plugins <module> load an explicit local viewer plugin module
|
|
428
|
+
--tls-cert <pem> HTTPS certificate (requires --tls-key)
|
|
429
|
+
--tls-key <pem> HTTPS key (requires --tls-cert)
|
|
430
|
+
--shared <branch> record shared-workspace snapshots on a branch
|
|
431
|
+
--help, -h show this help
|
|
432
|
+
|
|
433
|
+
Example: dooc ${command} dooc-docs --repo https://github.com/dooc-dev/dooc.git`);
|
|
434
|
+
break;
|
|
435
|
+
}
|
|
436
|
+
if (positionals.length > 2)
|
|
437
|
+
throw new Error("Too many positional arguments");
|
|
438
|
+
const port = Number(positionals[1] ?? 5179);
|
|
439
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535)
|
|
440
|
+
throw new Error("Choose a port between 0 and 65535");
|
|
395
441
|
const cert = values["tls-cert"] ?? process.env.DOOC_TLS_CERT;
|
|
396
442
|
const key = values["tls-key"] ?? process.env.DOOC_TLS_KEY;
|
|
397
443
|
if (!cert !== !key)
|
|
398
444
|
throw new Error("--tls-cert and --tls-key must be given together");
|
|
399
|
-
|
|
400
|
-
|
|
445
|
+
let source = positionals[0];
|
|
446
|
+
const remote = values.repo !== undefined;
|
|
447
|
+
if (values.repo !== undefined) {
|
|
448
|
+
// A caller's Git context must never redirect operations outside the cloned repo.
|
|
449
|
+
for (const key of Object.keys(process.env))
|
|
450
|
+
if (/^GIT_(?:DIR|WORK_TREE|COMMON_DIR|INDEX_FILE|OBJECT_DIRECTORY|ALTERNATE_OBJECT_DIRECTORIES|NAMESPACE|CEILING_DIRECTORIES|CONFIG|CONFIG_PARAMETERS|CONFIG_COUNT|CONFIG_KEY_\d+|CONFIG_VALUE_\d+)$/.test(key))
|
|
451
|
+
delete process.env[key];
|
|
452
|
+
const { prepareGitWorkspace } = await import("./git-workspace.js");
|
|
453
|
+
const workspace = await prepareGitWorkspace(values.repo, command, {
|
|
454
|
+
path: source,
|
|
455
|
+
});
|
|
456
|
+
process.once("exit", workspace.dispose);
|
|
457
|
+
process.once("SIGINT", () => process.exit(130));
|
|
458
|
+
process.once("SIGTERM", () => process.exit(143));
|
|
459
|
+
source = workspace.manifest;
|
|
460
|
+
if (command === "edit")
|
|
461
|
+
terminal.info(`${workspace.reused ? "Reusing" : "Saved"} workspace: ${workspace.root}`);
|
|
462
|
+
}
|
|
463
|
+
else if (source && /^file:/i.test(source)) {
|
|
464
|
+
const url = new URL(source);
|
|
465
|
+
if (url.username || url.password || url.search || url.hash)
|
|
466
|
+
throw new Error("Local file URLs must not contain credentials, query or fragment");
|
|
467
|
+
source = fileURLToPath(url);
|
|
468
|
+
}
|
|
469
|
+
else if (source &&
|
|
470
|
+
!isAbsolute(source) &&
|
|
471
|
+
!existsSync(resolve(source)) &&
|
|
472
|
+
/^(?:[a-z][a-z\d+.-]*:|[^/\s]+@[^/\s]+:)/i.test(source)) {
|
|
473
|
+
throw new Error("Pass Git repository URLs with --repo <git-url>");
|
|
474
|
+
}
|
|
475
|
+
if (source && existsSync(resolve(source)) && statSync(resolve(source)).isDirectory())
|
|
476
|
+
source = join(source, MANIFEST_FILE);
|
|
477
|
+
process.env.DOCS_ROOT = projectRoot(source);
|
|
478
|
+
process.env.DOCS_HMR = remote && command === "view" ? "0" : "1";
|
|
479
|
+
process.env.DOOC_REMOTE_WORKSPACE = remote ? "1" : "0";
|
|
401
480
|
// serve.ts reads DOCS_ROOT at import time, so import it after the env is set.
|
|
402
481
|
const { startServer } = await import("./serve.js");
|
|
403
|
-
await startServer(command === "view" ? "preview" : "edit",
|
|
482
|
+
await startServer(command === "view" ? "preview" : "edit", port, values["viewer-plugins"] ?? process.env.DOOC_VIEWER_PLUGINS, ...(remote || (cert && key) || values.shared !== undefined
|
|
404
483
|
? [
|
|
405
484
|
{
|
|
485
|
+
...(remote ? { open: true } : {}),
|
|
406
486
|
...(cert && key
|
|
407
487
|
? { tls: { cert: resolve(cert), key: resolve(key) } }
|
|
408
488
|
: {}),
|
|
@@ -418,10 +498,27 @@ Report:
|
|
|
418
498
|
}
|
|
419
499
|
case "export": {
|
|
420
500
|
try {
|
|
421
|
-
|
|
501
|
+
const { positionals, values } = parseArgs({
|
|
502
|
+
args,
|
|
503
|
+
allowPositionals: true,
|
|
504
|
+
options: { help: { type: "boolean", short: "h" } },
|
|
505
|
+
});
|
|
506
|
+
if (values.help) {
|
|
507
|
+
console.log(`usage: dooc export [dooc.yaml] [out-dir]
|
|
508
|
+
|
|
509
|
+
Collect the workspace's source dependencies into bundle.zip.
|
|
510
|
+
Default manifest: ./dooc.yaml; named manifests are also accepted.
|
|
511
|
+
Default output directory: <project>/dist.
|
|
512
|
+
Configuration and plugins are not executed. Remote URLs stay unchanged; nothing is downloaded.
|
|
513
|
+
|
|
514
|
+
options:
|
|
515
|
+
--help, -h show this help`);
|
|
516
|
+
break;
|
|
517
|
+
}
|
|
518
|
+
if (positionals.length > 2)
|
|
422
519
|
throw new Error("export accepts a dooc.yaml path and an output directory");
|
|
423
|
-
const root = projectRoot(
|
|
424
|
-
const out = join(resolve(
|
|
520
|
+
const root = projectRoot(positionals[0]);
|
|
521
|
+
const out = join(resolve(positionals[1] ?? join(root, "dist")), "bundle.zip");
|
|
425
522
|
const { exportBundle } = await import("../engine/compiler/export.js");
|
|
426
523
|
writeOut(out, exportBundle(root));
|
|
427
524
|
console.log(out);
|
|
@@ -1 +1,36 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { codeBlockAt, isLocalHost, isLocalToolRequest, requestScheme, } from "../workspace/editor-tools.js";
|
|
2
|
+
export declare const runCodeTool: (root: string, body: string, position: number, action: "format" | "lint") => Promise<{
|
|
3
|
+
findings: {
|
|
4
|
+
range: [number, number];
|
|
5
|
+
message: string;
|
|
6
|
+
ruleId: string;
|
|
7
|
+
}[];
|
|
8
|
+
change?: undefined;
|
|
9
|
+
} | {
|
|
10
|
+
change: {
|
|
11
|
+
from: number;
|
|
12
|
+
to: number;
|
|
13
|
+
insert: string;
|
|
14
|
+
};
|
|
15
|
+
findings?: undefined;
|
|
16
|
+
}>;
|
|
17
|
+
export declare const validateCodeTools: (root: string, body: string) => Promise<{
|
|
18
|
+
changes: {
|
|
19
|
+
from: number;
|
|
20
|
+
to: number;
|
|
21
|
+
insert: string;
|
|
22
|
+
}[];
|
|
23
|
+
findings: {
|
|
24
|
+
range: [number, number];
|
|
25
|
+
message: string;
|
|
26
|
+
ruleId: string;
|
|
27
|
+
}[];
|
|
28
|
+
}>;
|
|
29
|
+
export declare const validateTextfileCode: (root: string, language: string, content: string) => Promise<{
|
|
30
|
+
content: string;
|
|
31
|
+
findings: {
|
|
32
|
+
range: [number, number];
|
|
33
|
+
message: string;
|
|
34
|
+
ruleId: string;
|
|
35
|
+
}[];
|
|
36
|
+
}>;
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import * as tools from "../workspace/editor-tools.js";
|
|
2
|
+
import { allowsWorkspaceCode } from "./workspace-trust.js";
|
|
3
|
+
export { codeBlockAt, isLocalHost, isLocalToolRequest, requestScheme, } from "../workspace/editor-tools.js";
|
|
4
|
+
export const runCodeTool = (root, body, position, action) => tools.runCodeTool(root, body, position, action, allowsWorkspaceCode());
|
|
5
|
+
export const validateCodeTools = (root, body) => tools.validateCodeTools(root, body, allowsWorkspaceCode());
|
|
6
|
+
export const validateTextfileCode = (root, language, content) => tools.validateTextfileCode(root, language, content, allowsWorkspaceCode());
|
|
@@ -8,6 +8,7 @@ import { textfilePath } from "../engine/compiler/textfile.js";
|
|
|
8
8
|
import { zip } from "../engine/compiler/zip.js";
|
|
9
9
|
import { extensionFile, extensionManifest, MAX_EXTENSION_BYTES, readExtensionZip, } from "../engine/core/extension-package.js";
|
|
10
10
|
import { validateViewerPlugins, } from "./plugin-config.js";
|
|
11
|
+
import { allowsWorkspaceCode } from "./workspace-trust.js";
|
|
11
12
|
export const EXTENSIONS_DIR = ".dooc/plugins";
|
|
12
13
|
const hash = (source) => createHash("sha256").update(source).digest("hex");
|
|
13
14
|
const unpack = (data) => readExtensionZip(data, async (bytes, size) => inflateRawSync(bytes, { maxOutputLength: Math.max(1, size) }));
|
|
@@ -134,6 +135,8 @@ export const createExtensionManager = (root, registry, initial, personal) => {
|
|
|
134
135
|
return { scope, items: items.sort((a, b) => a.name.localeCompare(b.name)) };
|
|
135
136
|
};
|
|
136
137
|
const activate = async (name, data, save, base) => {
|
|
138
|
+
if (!allowsWorkspaceCode())
|
|
139
|
+
throw new Error("Workspace plugins are disabled in remote sessions; use --viewer-plugins for an explicit local module");
|
|
137
140
|
const revision = hash(data);
|
|
138
141
|
if (!save && active.get(name)?.hash === revision)
|
|
139
142
|
return;
|
|
@@ -281,6 +284,8 @@ export const createExtensionManager = (root, registry, initial, personal) => {
|
|
|
281
284
|
};
|
|
282
285
|
return Object.assign(request, {
|
|
283
286
|
async restore() {
|
|
287
|
+
if (!allowsWorkspaceCode())
|
|
288
|
+
return [];
|
|
284
289
|
const approved = approval();
|
|
285
290
|
const errors = [];
|
|
286
291
|
for (const item of (await list()).items)
|