@open-press/cli 0.3.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 +58 -0
- package/dist/cli.js +365 -0
- package/package.json +57 -0
- package/template/core/.turbo/turbo-test.log +341 -0
- package/template/core/CHANGELOG.md +11 -0
- package/template/core/README.md +36 -0
- package/template/core/engine/chrome-pdf.d.mts +34 -0
- package/template/core/engine/chrome-pdf.mjs +344 -0
- package/template/core/engine/cli.mjs +93 -0
- package/template/core/engine/commands/_shared.mjs +170 -0
- package/template/core/engine/commands/deploy.mjs +31 -0
- package/template/core/engine/commands/dev.mjs +26 -0
- package/template/core/engine/commands/export.mjs +8 -0
- package/template/core/engine/commands/init.mjs +24 -0
- package/template/core/engine/commands/inspect.mjs +35 -0
- package/template/core/engine/commands/migrate-to-react.mjs +27 -0
- package/template/core/engine/commands/pdf.mjs +26 -0
- package/template/core/engine/commands/preview.mjs +26 -0
- package/template/core/engine/commands/render.mjs +17 -0
- package/template/core/engine/commands/replace.mjs +41 -0
- package/template/core/engine/commands/search.mjs +33 -0
- package/template/core/engine/commands/typecheck.mjs +5 -0
- package/template/core/engine/commands/validate.mjs +17 -0
- package/template/core/engine/config.d.mts +40 -0
- package/template/core/engine/config.mjs +160 -0
- package/template/core/engine/deploy-sync.mjs +15 -0
- package/template/core/engine/document-export.mjs +15 -0
- package/template/core/engine/file-utils.mjs +106 -0
- package/template/core/engine/fonts.mjs +62 -0
- package/template/core/engine/init.mjs +90 -0
- package/template/core/engine/inspection.mjs +348 -0
- package/template/core/engine/issue-report.mjs +44 -0
- package/template/core/engine/katex-assets.mjs +45 -0
- package/template/core/engine/page-block.mjs +30 -0
- package/template/core/engine/page-renderer.mjs +217 -0
- package/template/core/engine/pdf-media.mjs +45 -0
- package/template/core/engine/public-assets.mjs +19 -0
- package/template/core/engine/react/chapter-css.mjs +53 -0
- package/template/core/engine/react/comment-endpoint.d.mts +11 -0
- package/template/core/engine/react/comment-endpoint.mjs +128 -0
- package/template/core/engine/react/comment-marker.mjs +306 -0
- package/template/core/engine/react/document-entry.mjs +253 -0
- package/template/core/engine/react/document-export.mjs +392 -0
- package/template/core/engine/react/mdx-compile.mjs +295 -0
- package/template/core/engine/react/measurement-css.mjs +44 -0
- package/template/core/engine/react/migrate-to-react.mjs +355 -0
- package/template/core/engine/react/pagination-constants.mjs +3 -0
- package/template/core/engine/react/pagination.mjs +121 -0
- package/template/core/engine/react/project-asset-endpoint.d.mts +10 -0
- package/template/core/engine/react/project-asset-endpoint.mjs +379 -0
- package/template/core/engine/react/workspace-discovery.mjs +156 -0
- package/template/core/engine/source-text-tools.mjs +280 -0
- package/template/core/engine/source-workspace.mjs +76 -0
- package/template/core/engine/static-server.mjs +493 -0
- package/template/core/engine/validation.mjs +172 -0
- package/template/core/index.html +13 -0
- package/template/core/openpress.config.mjs +12 -0
- package/template/core/package.json +86 -0
- package/template/core/src/main.tsx +16 -0
- package/template/core/src/openpress/App.tsx +127 -0
- package/template/core/src/openpress/composerMentions.ts +188 -0
- package/template/core/src/openpress/core/basePages.tsx +87 -0
- package/template/core/src/openpress/core/index.tsx +20 -0
- package/template/core/src/openpress/core/types.ts +71 -0
- package/template/core/src/openpress/frameScheduler.ts +32 -0
- package/template/core/src/openpress/indexes.ts +329 -0
- package/template/core/src/openpress/inspector.ts +282 -0
- package/template/core/src/openpress/pageRoute.ts +21 -0
- package/template/core/src/openpress/pagination.ts +845 -0
- package/template/core/src/openpress/projectIdentity.ts +15 -0
- package/template/core/src/openpress/projectSources.ts +24 -0
- package/template/core/src/openpress/projectWorkspace.tsx +919 -0
- package/template/core/src/openpress/publicPage.tsx +469 -0
- package/template/core/src/openpress/reactDocumentMetadata.ts +41 -0
- package/template/core/src/openpress/readerPageRegistry.ts +41 -0
- package/template/core/src/openpress/readerRuntime.ts +230 -0
- package/template/core/src/openpress/readerScroll.ts +92 -0
- package/template/core/src/openpress/readerState.ts +15 -0
- package/template/core/src/openpress/renderer.tsx +91 -0
- package/template/core/src/openpress/runtimeMode.ts +22 -0
- package/template/core/src/openpress/types.ts +112 -0
- package/template/core/src/openpress/workbench.tsx +1299 -0
- package/template/core/src/openpress/workbenchPanels.tsx +122 -0
- package/template/core/src/openpress/workbenchTypes.ts +4 -0
- package/template/core/src/styles/openpress/app-shell.css +251 -0
- package/template/core/src/styles/openpress/media-workspace.css +230 -0
- package/template/core/src/styles/openpress/print-route.css +186 -0
- package/template/core/src/styles/openpress/project-workspace.css +1318 -0
- package/template/core/src/styles/openpress/public-viewer.css +983 -0
- package/template/core/src/styles/openpress/reader-runtime.css +792 -0
- package/template/core/src/styles/openpress/responsive.css +384 -0
- package/template/core/src/styles/openpress/workbench-panels.css +558 -0
- package/template/core/src/styles/openpress/workbench.css +720 -0
- package/template/core/src/styles/openpress.css +14 -0
- package/template/core/src/vite-env.d.ts +9 -0
- package/template/core/tsconfig.json +37 -0
- package/template/core/vite.config.ts +512 -0
- package/template/skills/chinese-ai-writing-polish/SKILL.md +195 -0
- package/template/skills/claude-document/SKILL.md +66 -0
- package/template/skills/claude-document/starter/document/chapters/01-document-shape/chapter.tsx +30 -0
- package/template/skills/claude-document/starter/document/chapters/01-document-shape/content/01-document-shape.mdx +51 -0
- package/template/skills/claude-document/starter/document/chapters/02-review-loop/chapter.tsx +30 -0
- package/template/skills/claude-document/starter/document/chapters/02-review-loop/content/01-review-loop.mdx +31 -0
- package/template/skills/claude-document/starter/document/components/ChapterOpenerVisual.tsx +96 -0
- package/template/skills/claude-document/starter/document/components/Page.tsx +27 -0
- package/template/skills/claude-document/starter/document/design.md +142 -0
- package/template/skills/claude-document/starter/document/index.tsx +89 -0
- package/template/skills/claude-document/starter/document/media/README.md +13 -0
- package/template/skills/claude-document/starter/document/openpress.config.mjs +26 -0
- package/template/skills/claude-document/starter/document/theme/README.md +15 -0
- package/template/skills/claude-document/starter/document/theme/base/page-contract.css +525 -0
- package/template/skills/claude-document/starter/document/theme/base/print.css +93 -0
- package/template/skills/claude-document/starter/document/theme/base/typography.css +612 -0
- package/template/skills/claude-document/starter/document/theme/fonts.css +4 -0
- package/template/skills/claude-document/starter/document/theme/page-surfaces/back-cover.css +72 -0
- package/template/skills/claude-document/starter/document/theme/page-surfaces/chapter-opener.css +236 -0
- package/template/skills/claude-document/starter/document/theme/page-surfaces/cover.css +309 -0
- package/template/skills/claude-document/starter/document/theme/page-surfaces/toc.css +213 -0
- package/template/skills/claude-document/starter/document/theme/patterns/_chart-frame.css +53 -0
- package/template/skills/claude-document/starter/document/theme/patterns/figure-grid.css +68 -0
- package/template/skills/claude-document/starter/document/theme/patterns/table-utilities.css +66 -0
- package/template/skills/claude-document/starter/document/theme/shell/reader-controls.css +789 -0
- package/template/skills/claude-document/starter/document/theme/tokens.css +89 -0
- package/template/skills/claude-document/starter/openpress.config.mjs +5 -0
- package/template/skills/editorial-monograph/SKILL.md +73 -0
- package/template/skills/editorial-monograph/starter/document/chapters/01-product-and-use-cases/content/01-product-and-use-cases.mdx +31 -0
- package/template/skills/editorial-monograph/starter/document/chapters/02-workflow/content/01-workflow.mdx +89 -0
- package/template/skills/editorial-monograph/starter/document/chapters/03-agent-skills-contributors/content/01-agent-skills-contributors.mdx +52 -0
- package/template/skills/editorial-monograph/starter/document/chapters/04-validation-deploy/content/01-validation-deploy.mdx +39 -0
- package/template/skills/editorial-monograph/starter/document/components/ChapterOpenerVisual/index.tsx +76 -0
- package/template/skills/editorial-monograph/starter/document/components/Page.tsx +27 -0
- package/template/skills/editorial-monograph/starter/document/components/TokenSwatchGrid/index.tsx +46 -0
- package/template/skills/editorial-monograph/starter/document/components/TokenSwatchGrid/style.css +63 -0
- package/template/skills/editorial-monograph/starter/document/components/TypeSpecimen/index.tsx +38 -0
- package/template/skills/editorial-monograph/starter/document/components/TypeSpecimen/style.css +111 -0
- package/template/skills/editorial-monograph/starter/document/design.md +279 -0
- package/template/skills/editorial-monograph/starter/document/index.tsx +73 -0
- package/template/skills/editorial-monograph/starter/document/media/README.md +13 -0
- package/template/skills/editorial-monograph/starter/document/openpress.config.mjs +26 -0
- package/template/skills/editorial-monograph/starter/document/theme/README.md +11 -0
- package/template/skills/editorial-monograph/starter/document/theme/base/page-contract.css +505 -0
- package/template/skills/editorial-monograph/starter/document/theme/base/print.css +93 -0
- package/template/skills/editorial-monograph/starter/document/theme/base/typography.css +336 -0
- package/template/skills/editorial-monograph/starter/document/theme/fonts.css +3 -0
- package/template/skills/editorial-monograph/starter/document/theme/page-surfaces/back-cover.css +43 -0
- package/template/skills/editorial-monograph/starter/document/theme/page-surfaces/chapter-opener.css +205 -0
- package/template/skills/editorial-monograph/starter/document/theme/page-surfaces/cover.css +147 -0
- package/template/skills/editorial-monograph/starter/document/theme/page-surfaces/toc.css +139 -0
- package/template/skills/editorial-monograph/starter/document/theme/patterns/_chart-frame.css +49 -0
- package/template/skills/editorial-monograph/starter/document/theme/patterns/figure-grid.css +68 -0
- package/template/skills/editorial-monograph/starter/document/theme/patterns/table-utilities.css +66 -0
- package/template/skills/editorial-monograph/starter/document/theme/shell/reader-controls.css +761 -0
- package/template/skills/editorial-monograph/starter/document/theme/tokens.css +80 -0
- package/template/skills/editorial-monograph/starter/openpress.config.mjs +5 -0
- package/template/skills/openpress/SKILL.md +114 -0
- package/template/skills/openpress/references/cli-commands.md +31 -0
- package/template/skills/openpress/references/local-review.md +43 -0
- package/template/skills/openpress-deploy/SKILL.md +69 -0
- package/template/skills/openpress-deploy/references/cloudflare-pages.md +51 -0
- package/template/skills/openpress-design/SKILL.md +51 -0
- package/template/skills/openpress-design/references/pdf-safe-css.md +29 -0
- package/template/skills/openpress-design/references/responsive-fixed-layout.md +48 -0
- package/template/skills/openpress-design/references/theme-and-components.md +77 -0
- package/template/skills/openpress-diagram-drawing/SKILL.md +44 -0
- package/template/skills/openpress-diagram-drawing/references/diagram-patterns.md +93 -0
- package/template/skills/openpress-document-hierarchy/SKILL.md +81 -0
- package/template/skills/openpress-document-hierarchy/agents/openai.yaml +4 -0
- package/template/skills/openpress-document-hierarchy/references/data-structures-outline.md +115 -0
- package/template/skills/openpress-init/SKILL.md +84 -0
- package/template/skills/openpress-style-pack-contributor/SKILL.md +62 -0
- package/template/skills/openpress-style-pack-contributor/references/starter-contract.md +49 -0
- package/template/skills/openpress-update/SKILL.md +88 -0
- package/template/skills/openpress-writing/SKILL.md +68 -0
- package/template/skills/openpress-writing/references/source-and-writing-rules.md +120 -0
- package/template/skills/teaching-notes-writing/SKILL.md +54 -0
- package/template/skills/teaching-notes-writing/references/programming.md +65 -0
- package/template/skills/teaching-notes-writing/references/teaching-patterns.md +60 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
const CHROME_CANDIDATE_PATHS = {
|
|
7
|
+
darwin: [
|
|
8
|
+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
9
|
+
"/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta",
|
|
10
|
+
"/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
|
|
11
|
+
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
|
12
|
+
"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
|
|
13
|
+
],
|
|
14
|
+
linux: [
|
|
15
|
+
"/usr/bin/google-chrome",
|
|
16
|
+
"/usr/bin/google-chrome-stable",
|
|
17
|
+
"/usr/bin/chromium",
|
|
18
|
+
"/usr/bin/chromium-browser",
|
|
19
|
+
"/snap/bin/chromium",
|
|
20
|
+
"/opt/google/chrome/chrome",
|
|
21
|
+
],
|
|
22
|
+
win32: [
|
|
23
|
+
"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
|
|
24
|
+
"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",
|
|
25
|
+
],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const CHROME_BIN_NAMES = {
|
|
29
|
+
darwin: [],
|
|
30
|
+
linux: ["google-chrome", "google-chrome-stable", "chromium", "chromium-browser"],
|
|
31
|
+
win32: ["chrome.exe"],
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
let cachedChromePath = null;
|
|
35
|
+
|
|
36
|
+
function resolveChromePath() {
|
|
37
|
+
if (cachedChromePath) return cachedChromePath;
|
|
38
|
+
if (process.env.CHROME) {
|
|
39
|
+
cachedChromePath = process.env.CHROME;
|
|
40
|
+
return cachedChromePath;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const platform = process.platform;
|
|
44
|
+
const candidates = [...(CHROME_CANDIDATE_PATHS[platform] ?? [])];
|
|
45
|
+
|
|
46
|
+
if (platform === "win32") {
|
|
47
|
+
const roots = [process.env.PROGRAMFILES, process.env["PROGRAMFILES(X86)"], process.env.LOCALAPPDATA].filter(Boolean);
|
|
48
|
+
for (const root of roots) {
|
|
49
|
+
candidates.push(`${root}\\Google\\Chrome\\Application\\chrome.exe`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
for (const candidate of candidates) {
|
|
54
|
+
if (existsSync(candidate)) {
|
|
55
|
+
cachedChromePath = candidate;
|
|
56
|
+
return cachedChromePath;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const whichCommand = platform === "win32" ? "where" : "which";
|
|
61
|
+
for (const name of CHROME_BIN_NAMES[platform] ?? []) {
|
|
62
|
+
try {
|
|
63
|
+
const result = spawnSync(whichCommand, [name], { encoding: "utf8" });
|
|
64
|
+
const output = result.stdout?.trim().split(/\r?\n/)[0];
|
|
65
|
+
if (result.status === 0 && output && existsSync(output)) {
|
|
66
|
+
cachedChromePath = output;
|
|
67
|
+
return cachedChromePath;
|
|
68
|
+
}
|
|
69
|
+
} catch {
|
|
70
|
+
// continue
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const lines = [
|
|
75
|
+
`Cannot locate a Chrome / Chromium executable on ${platform}.`,
|
|
76
|
+
`Set the CHROME environment variable to your Chrome binary path, or install Chrome at one of:`,
|
|
77
|
+
...candidates.map((p) => ` - ${p}`),
|
|
78
|
+
];
|
|
79
|
+
throw new Error(lines.join("\n"));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const DEFAULT_PRINT_OPTIONS = {
|
|
83
|
+
printBackground: true,
|
|
84
|
+
displayHeaderFooter: false,
|
|
85
|
+
preferCSSPageSize: true,
|
|
86
|
+
paperWidth: 8.2677,
|
|
87
|
+
paperHeight: 11.6929,
|
|
88
|
+
marginTop: 0,
|
|
89
|
+
marginRight: 0,
|
|
90
|
+
marginBottom: 0,
|
|
91
|
+
marginLeft: 0,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export async function printUrlToPdf({
|
|
95
|
+
root,
|
|
96
|
+
url,
|
|
97
|
+
outPath,
|
|
98
|
+
chrome,
|
|
99
|
+
waitForReady = waitForPrintReady,
|
|
100
|
+
printOptions = {},
|
|
101
|
+
debuggingPortBase = 9600,
|
|
102
|
+
debuggingPortRange = 300,
|
|
103
|
+
profilePrefix = "chrome-pdf",
|
|
104
|
+
}) {
|
|
105
|
+
chrome ??= resolveChromePath();
|
|
106
|
+
await fs.mkdir(path.dirname(outPath), { recursive: true });
|
|
107
|
+
|
|
108
|
+
const debuggingPort = String(debuggingPortBase + Math.floor(Math.random() * debuggingPortRange));
|
|
109
|
+
const profileDir = path.join(root, ".openpress", "tmp", `${profilePrefix}-${process.pid}-${Date.now()}`);
|
|
110
|
+
await fs.mkdir(profileDir, { recursive: true });
|
|
111
|
+
|
|
112
|
+
const child = spawn(
|
|
113
|
+
chrome,
|
|
114
|
+
[
|
|
115
|
+
"--headless=new",
|
|
116
|
+
"--disable-gpu",
|
|
117
|
+
"--no-sandbox",
|
|
118
|
+
`--remote-debugging-port=${debuggingPort}`,
|
|
119
|
+
`--user-data-dir=${profileDir}`,
|
|
120
|
+
"about:blank",
|
|
121
|
+
],
|
|
122
|
+
{ cwd: root, stdio: ["ignore", "pipe", "pipe"] },
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
const tab = await waitForChromeTab(debuggingPort);
|
|
127
|
+
const client = await connectChromeDevTools(tab.webSocketDebuggerUrl);
|
|
128
|
+
try {
|
|
129
|
+
await client.send("Page.enable");
|
|
130
|
+
await client.send("Runtime.enable");
|
|
131
|
+
await client.send("Emulation.setEmulatedMedia", { media: "print" });
|
|
132
|
+
await client.send("Page.navigate", { url });
|
|
133
|
+
const readyResult = await waitForReady(client);
|
|
134
|
+
const result = await client.send("Page.printToPDF", {
|
|
135
|
+
...DEFAULT_PRINT_OPTIONS,
|
|
136
|
+
...printOptions,
|
|
137
|
+
});
|
|
138
|
+
await fs.writeFile(outPath, Buffer.from(String(result.data ?? ""), "base64"));
|
|
139
|
+
return readyResult;
|
|
140
|
+
} finally {
|
|
141
|
+
client.close();
|
|
142
|
+
}
|
|
143
|
+
} finally {
|
|
144
|
+
await stopChildProcess(child);
|
|
145
|
+
await cleanupChromeProfile(profileDir);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export async function evaluateUrlWithChrome({
|
|
150
|
+
root,
|
|
151
|
+
url,
|
|
152
|
+
chrome,
|
|
153
|
+
evaluate,
|
|
154
|
+
emulatedMedia,
|
|
155
|
+
debuggingPortBase = 9900,
|
|
156
|
+
debuggingPortRange = 300,
|
|
157
|
+
profilePrefix = "chrome-eval",
|
|
158
|
+
}) {
|
|
159
|
+
chrome ??= resolveChromePath();
|
|
160
|
+
|
|
161
|
+
const debuggingPort = String(debuggingPortBase + Math.floor(Math.random() * debuggingPortRange));
|
|
162
|
+
const profileDir = path.join(root, ".openpress", "tmp", `${profilePrefix}-${process.pid}-${Date.now()}`);
|
|
163
|
+
await fs.mkdir(profileDir, { recursive: true });
|
|
164
|
+
|
|
165
|
+
const child = spawn(
|
|
166
|
+
chrome,
|
|
167
|
+
[
|
|
168
|
+
"--headless=new",
|
|
169
|
+
"--disable-gpu",
|
|
170
|
+
"--no-sandbox",
|
|
171
|
+
`--remote-debugging-port=${debuggingPort}`,
|
|
172
|
+
`--user-data-dir=${profileDir}`,
|
|
173
|
+
"about:blank",
|
|
174
|
+
],
|
|
175
|
+
{ cwd: root, stdio: ["ignore", "pipe", "pipe"] },
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
try {
|
|
179
|
+
const tab = await waitForChromeTab(debuggingPort);
|
|
180
|
+
const client = await connectChromeDevTools(tab.webSocketDebuggerUrl);
|
|
181
|
+
try {
|
|
182
|
+
await client.send("Page.enable");
|
|
183
|
+
await client.send("Runtime.enable");
|
|
184
|
+
if (emulatedMedia) {
|
|
185
|
+
await client.send("Emulation.setEmulatedMedia", { media: emulatedMedia });
|
|
186
|
+
}
|
|
187
|
+
await client.send("Page.navigate", { url });
|
|
188
|
+
return await evaluate(client);
|
|
189
|
+
} finally {
|
|
190
|
+
client.close();
|
|
191
|
+
}
|
|
192
|
+
} finally {
|
|
193
|
+
await stopChildProcess(child);
|
|
194
|
+
await cleanupChromeProfile(profileDir);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export async function waitForPrintReady(client) {
|
|
199
|
+
const deadline = Date.now() + 30000;
|
|
200
|
+
while (Date.now() < deadline) {
|
|
201
|
+
const result = await client.send("Runtime.evaluate", {
|
|
202
|
+
returnByValue: true,
|
|
203
|
+
awaitPromise: true,
|
|
204
|
+
expression: `Promise.resolve().then(async () => {
|
|
205
|
+
const root = document.querySelector('[data-openpress-print-document="true"]');
|
|
206
|
+
const ready = root?.getAttribute('data-openpress-pagination') === 'ready';
|
|
207
|
+
if (!ready) return 0;
|
|
208
|
+
|
|
209
|
+
await document.fonts?.ready;
|
|
210
|
+
await Promise.all(Array.from(document.images).map(async (img) => {
|
|
211
|
+
if (!img.complete) {
|
|
212
|
+
await new Promise((resolve) => {
|
|
213
|
+
const settle = () => {
|
|
214
|
+
img.removeEventListener('load', settle);
|
|
215
|
+
img.removeEventListener('error', settle);
|
|
216
|
+
resolve();
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
img.addEventListener('load', settle, { once: true });
|
|
220
|
+
img.addEventListener('error', settle, { once: true });
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
await img.decode?.().catch(() => undefined);
|
|
225
|
+
}));
|
|
226
|
+
|
|
227
|
+
await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)));
|
|
228
|
+
|
|
229
|
+
const pages = Array.from(document.querySelectorAll('.openpress-public-page > .openpress-html-page'));
|
|
230
|
+
const contentFitsPageBody = (body) => {
|
|
231
|
+
const bodyBottom = body.getBoundingClientRect().bottom;
|
|
232
|
+
const contentBottom = Array.from(body.children).reduce((bottom, child) => {
|
|
233
|
+
if (getComputedStyle(child).display === 'none') return bottom;
|
|
234
|
+
const marginBottom = Number.parseFloat(getComputedStyle(child).marginBottom) || 0;
|
|
235
|
+
return Math.max(bottom, child.getBoundingClientRect().bottom + marginBottom);
|
|
236
|
+
}, body.getBoundingClientRect().top);
|
|
237
|
+
return contentBottom <= bodyBottom + 1;
|
|
238
|
+
};
|
|
239
|
+
const bodyOverflowSafe = pages.every((page) => {
|
|
240
|
+
const body = page.querySelector('.page-body');
|
|
241
|
+
return !body || contentFitsPageBody(body);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
return pages.length > 0 && bodyOverflowSafe ? pages.length : 0;
|
|
245
|
+
})`,
|
|
246
|
+
});
|
|
247
|
+
const count = Number(result.result?.value ?? 0);
|
|
248
|
+
if (count > 0) return count;
|
|
249
|
+
await delay(100);
|
|
250
|
+
}
|
|
251
|
+
throw new Error("Timed out waiting for OpenPress pagination before PDF export.");
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export async function stopChildProcess(child) {
|
|
255
|
+
if (child.exitCode !== null || child.signalCode !== null) return;
|
|
256
|
+
child.kill();
|
|
257
|
+
const closed = await waitForChildClose(child, 2500);
|
|
258
|
+
if (closed || child.exitCode !== null || child.signalCode !== null) return;
|
|
259
|
+
child.kill("SIGKILL");
|
|
260
|
+
await waitForChildClose(child, 2500);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async function waitForChromeTab(debuggingPort) {
|
|
264
|
+
const deadline = Date.now() + 10000;
|
|
265
|
+
let lastError;
|
|
266
|
+
while (Date.now() < deadline) {
|
|
267
|
+
try {
|
|
268
|
+
const response = await fetch(`http://127.0.0.1:${debuggingPort}/json/list`);
|
|
269
|
+
const tabs = await response.json();
|
|
270
|
+
const tab = tabs.find((item) => item.type === "page" && item.webSocketDebuggerUrl);
|
|
271
|
+
if (tab) return tab;
|
|
272
|
+
} catch (error) {
|
|
273
|
+
lastError = error;
|
|
274
|
+
}
|
|
275
|
+
await delay(100);
|
|
276
|
+
}
|
|
277
|
+
throw new Error(`Timed out waiting for Chrome DevTools${lastError ? `: ${lastError.message}` : ""}`);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
async function connectChromeDevTools(webSocketDebuggerUrl) {
|
|
281
|
+
const socket = new WebSocket(webSocketDebuggerUrl);
|
|
282
|
+
const pending = new Map();
|
|
283
|
+
let nextId = 0;
|
|
284
|
+
|
|
285
|
+
await new Promise((resolve, reject) => {
|
|
286
|
+
socket.addEventListener("open", resolve, { once: true });
|
|
287
|
+
socket.addEventListener("error", reject, { once: true });
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
socket.addEventListener("message", (event) => {
|
|
291
|
+
const message = JSON.parse(String(event.data));
|
|
292
|
+
if (!message.id || !pending.has(message.id)) return;
|
|
293
|
+
const callbacks = pending.get(message.id);
|
|
294
|
+
pending.delete(message.id);
|
|
295
|
+
if (message.error) callbacks?.reject(new Error(message.error.message ?? "Chrome DevTools command failed."));
|
|
296
|
+
else callbacks?.resolve(message.result ?? {});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
return {
|
|
300
|
+
send(method, params = {}) {
|
|
301
|
+
return new Promise((resolve, reject) => {
|
|
302
|
+
const id = ++nextId;
|
|
303
|
+
pending.set(id, { resolve, reject });
|
|
304
|
+
socket.send(JSON.stringify({ id, method, params }));
|
|
305
|
+
});
|
|
306
|
+
},
|
|
307
|
+
close() {
|
|
308
|
+
socket.close();
|
|
309
|
+
},
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function waitForChildClose(child, timeoutMs) {
|
|
314
|
+
if (child.exitCode !== null || child.signalCode !== null) return Promise.resolve(true);
|
|
315
|
+
return new Promise((resolve) => {
|
|
316
|
+
let settled = false;
|
|
317
|
+
const finish = (closed) => {
|
|
318
|
+
if (settled) return;
|
|
319
|
+
settled = true;
|
|
320
|
+
clearTimeout(timer);
|
|
321
|
+
child.off("close", onClose);
|
|
322
|
+
child.off("error", onError);
|
|
323
|
+
resolve(closed);
|
|
324
|
+
};
|
|
325
|
+
const onClose = () => finish(true);
|
|
326
|
+
const onError = () => finish(true);
|
|
327
|
+
const timer = setTimeout(() => finish(false), timeoutMs);
|
|
328
|
+
child.once("close", onClose);
|
|
329
|
+
child.once("error", onError);
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
async function cleanupChromeProfile(profileDir) {
|
|
334
|
+
try {
|
|
335
|
+
await fs.rm(profileDir, { recursive: true, force: true, maxRetries: 8, retryDelay: 150 });
|
|
336
|
+
} catch (error) {
|
|
337
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
338
|
+
console.warn(`Could not remove temporary Chrome profile ${profileDir}: ${message}`);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function delay(ms) {
|
|
343
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
344
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import * as deployCmd from "./commands/deploy.mjs";
|
|
4
|
+
import * as devCmd from "./commands/dev.mjs";
|
|
5
|
+
import * as exportCmd from "./commands/export.mjs";
|
|
6
|
+
import * as initCmd from "./commands/init.mjs";
|
|
7
|
+
import * as inspectCmd from "./commands/inspect.mjs";
|
|
8
|
+
import * as migrateToReactCmd from "./commands/migrate-to-react.mjs";
|
|
9
|
+
import * as pdfCmd from "./commands/pdf.mjs";
|
|
10
|
+
import * as previewCmd from "./commands/preview.mjs";
|
|
11
|
+
import * as replaceCmd from "./commands/replace.mjs";
|
|
12
|
+
import * as renderCmd from "./commands/render.mjs";
|
|
13
|
+
import * as searchCmd from "./commands/search.mjs";
|
|
14
|
+
import * as typecheckCmd from "./commands/typecheck.mjs";
|
|
15
|
+
import * as validateCmd from "./commands/validate.mjs";
|
|
16
|
+
import { parseOptions } from "./commands/_shared.mjs";
|
|
17
|
+
import { loadConfig } from "./config.mjs";
|
|
18
|
+
import { listStylePackSkills } from "./init.mjs";
|
|
19
|
+
import { discoverWorkspace } from "./validation.mjs";
|
|
20
|
+
|
|
21
|
+
const COMMANDS = {
|
|
22
|
+
init: initCmd,
|
|
23
|
+
"migrate-to-react": migrateToReactCmd,
|
|
24
|
+
validate: validateCmd,
|
|
25
|
+
inspect: inspectCmd,
|
|
26
|
+
search: searchCmd,
|
|
27
|
+
replace: replaceCmd,
|
|
28
|
+
export: exportCmd,
|
|
29
|
+
render: renderCmd,
|
|
30
|
+
dev: devCmd,
|
|
31
|
+
preview: previewCmd,
|
|
32
|
+
typecheck: typecheckCmd,
|
|
33
|
+
pdf: pdfCmd,
|
|
34
|
+
deploy: deployCmd,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const args = process.argv.slice(2);
|
|
38
|
+
const command = args.shift();
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
const code = await main(command, args);
|
|
42
|
+
process.exitCode = code;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
45
|
+
process.exitCode = 1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function main(commandName, argv) {
|
|
49
|
+
if (!commandName || ["-h", "--help"].includes(commandName)) {
|
|
50
|
+
await printHelp();
|
|
51
|
+
return commandName ? 0 : 2;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const handler = COMMANDS[commandName];
|
|
55
|
+
if (!handler) {
|
|
56
|
+
console.error(`Unknown command: ${commandName}`);
|
|
57
|
+
await printHelp();
|
|
58
|
+
return 2;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (handler.needsWorkspace === false) {
|
|
62
|
+
return handler.run({ argv });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const options = parseOptions(argv);
|
|
66
|
+
const root = await discoverWorkspace(options.path ?? ".");
|
|
67
|
+
const config = await loadConfig(root);
|
|
68
|
+
return handler.run({ root, config, options, recurse: main });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function printHelp() {
|
|
72
|
+
const packs = await listStylePackSkills();
|
|
73
|
+
const skillList = packs.length ? packs.join(" | ") : "(none installed)";
|
|
74
|
+
console.log(`Usage: node engine/cli.mjs <command> [path] [options]
|
|
75
|
+
|
|
76
|
+
Commands:
|
|
77
|
+
init <target> [--skill <name>] [--force]
|
|
78
|
+
migrate-to-react [path] [--dry-run] [--force] [--json]
|
|
79
|
+
validate
|
|
80
|
+
inspect [--json] [--no-build] [--dry-run]
|
|
81
|
+
search [path] <query> [--json] [--scope content|all]
|
|
82
|
+
replace [path] <from> <to> [--json] [--apply] [--scope content|all]
|
|
83
|
+
export
|
|
84
|
+
render --renderer react [--dry-run]
|
|
85
|
+
preview --renderer react [--host 127.0.0.1] [--port 5173] [--no-build] [--dry-run]
|
|
86
|
+
dev --renderer react [--host 127.0.0.1] [--port 5173] [--no-build] [--dry-run]
|
|
87
|
+
typecheck
|
|
88
|
+
pdf [--output <outputDir>/<pdf.filename>] [--no-build] [--dry-run]
|
|
89
|
+
deploy --confirm [--dry-run]
|
|
90
|
+
|
|
91
|
+
Style packs available for \`init --skill\`: ${skillList}
|
|
92
|
+
`);
|
|
93
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { printUrlToPdf, stopChildProcess, waitForPrintReady } from "../chrome-pdf.mjs";
|
|
6
|
+
import { loadConfig, publicPdfHref } from "../config.mjs";
|
|
7
|
+
import { exportDocument } from "../document-export.mjs";
|
|
8
|
+
import { optimizePdfMediaForStaticRoot } from "../pdf-media.mjs";
|
|
9
|
+
|
|
10
|
+
const ENGINE_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
11
|
+
const STATIC_SERVER = path.join(ENGINE_DIR, "static-server.mjs");
|
|
12
|
+
|
|
13
|
+
export function parseOptions(argv) {
|
|
14
|
+
const options = {};
|
|
15
|
+
const positional = [];
|
|
16
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
17
|
+
const value = argv[i];
|
|
18
|
+
if (value === "--renderer") options.renderer = argv[++i];
|
|
19
|
+
else if (value === "--host") options.host = argv[++i];
|
|
20
|
+
else if (value === "--port") options.port = argv[++i];
|
|
21
|
+
else if (value === "--dry-run") options.dryRun = true;
|
|
22
|
+
else if (value === "--force") options.force = true;
|
|
23
|
+
else if (value === "--confirm") options.confirm = true;
|
|
24
|
+
else if (value === "--json") options.json = true;
|
|
25
|
+
else if (value === "--no-build") options.noBuild = true;
|
|
26
|
+
else if (value === "--apply") options.apply = true;
|
|
27
|
+
else if (value === "--include-code") options.includeCode = true;
|
|
28
|
+
else if (value === "--case-sensitive") options.caseSensitive = true;
|
|
29
|
+
else if (value === "--scope") options.scope = argv[++i];
|
|
30
|
+
else if (value === "--source") options.source = argv[++i];
|
|
31
|
+
else if (value === "--output") options.output = argv[++i];
|
|
32
|
+
else if (value.startsWith("--")) throw new Error(`Unknown option: ${value}`);
|
|
33
|
+
else positional.push(value);
|
|
34
|
+
}
|
|
35
|
+
options.path = positional[0];
|
|
36
|
+
options.positional = positional;
|
|
37
|
+
return options;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function parseInitOptions(argv) {
|
|
41
|
+
const options = { force: false };
|
|
42
|
+
const positional = [];
|
|
43
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
44
|
+
const value = argv[i];
|
|
45
|
+
if (value === "--skill") options.skill = argv[++i];
|
|
46
|
+
else if (value === "--force") options.force = true;
|
|
47
|
+
else if (value.startsWith("--")) throw new Error(`Unknown option: ${value}`);
|
|
48
|
+
else positional.push(value);
|
|
49
|
+
}
|
|
50
|
+
options.target = positional[0];
|
|
51
|
+
return options;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function formatDisplayPath(absolutePath) {
|
|
55
|
+
const relative = path.relative(process.cwd(), absolutePath);
|
|
56
|
+
if (!relative || relative.startsWith("..")) return absolutePath;
|
|
57
|
+
return relative;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function runCommand(commandName, commandArgs, cwd) {
|
|
61
|
+
const result = spawnSync(commandName, commandArgs, { cwd, stdio: "inherit" });
|
|
62
|
+
return result.status ?? 1;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function buildReactStatic({ root, noBuild = false, recurse, silent = false }) {
|
|
66
|
+
if (noBuild) return 0;
|
|
67
|
+
if (!silent) {
|
|
68
|
+
return await recurse("render", [root, "--renderer", "react"]);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
await exportDocument(root);
|
|
72
|
+
const result = spawnSync("npx", ["vite", "build", "--config", "vite.config.ts"], {
|
|
73
|
+
cwd: root,
|
|
74
|
+
encoding: "utf8",
|
|
75
|
+
});
|
|
76
|
+
return result.status ?? 1;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function buildReactPdf({
|
|
80
|
+
root,
|
|
81
|
+
config,
|
|
82
|
+
outPath,
|
|
83
|
+
host = "127.0.0.1",
|
|
84
|
+
port = "5185",
|
|
85
|
+
noBuild = false,
|
|
86
|
+
recurse,
|
|
87
|
+
}) {
|
|
88
|
+
config ??= await loadConfig(root);
|
|
89
|
+
outPath ??= config.paths.pdf;
|
|
90
|
+
const renderCode = await buildReactStatic({ root, noBuild, recurse });
|
|
91
|
+
if (renderCode !== 0) throw new Error(`React render failed with exit code ${renderCode}`);
|
|
92
|
+
await optimizePdfMediaForStaticRoot(config.paths.outputDir);
|
|
93
|
+
await fs.mkdir(path.dirname(outPath), { recursive: true });
|
|
94
|
+
|
|
95
|
+
const server = await startStaticServer(root, config, host, port);
|
|
96
|
+
try {
|
|
97
|
+
const pageCount = await printUrlToPdf({
|
|
98
|
+
root,
|
|
99
|
+
url: `http://${host}:${port}/?print=1`,
|
|
100
|
+
outPath,
|
|
101
|
+
waitForReady: waitForPrintReady,
|
|
102
|
+
debuggingPortBase: 9300,
|
|
103
|
+
debuggingPortRange: 600,
|
|
104
|
+
profilePrefix: "chrome-pdf",
|
|
105
|
+
});
|
|
106
|
+
console.log(`${pageCount} OpenPress pages printed to PDF`);
|
|
107
|
+
} finally {
|
|
108
|
+
await stopChildProcess(server);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return { pdfPath: outPath };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function startStaticServer(root, config, host, port) {
|
|
115
|
+
return new Promise((resolve, reject) => {
|
|
116
|
+
const child = spawn("node", [STATIC_SERVER, config.outputDir, "--host", host, "--port", port, "--workspace", "."], {
|
|
117
|
+
cwd: root,
|
|
118
|
+
shell: false,
|
|
119
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
120
|
+
});
|
|
121
|
+
let settled = false;
|
|
122
|
+
let stderr = "";
|
|
123
|
+
const timer = setTimeout(() => {
|
|
124
|
+
if (settled) return;
|
|
125
|
+
settled = true;
|
|
126
|
+
child.kill();
|
|
127
|
+
reject(new Error(`Timed out waiting for OpenPress static server on ${host}:${port}`));
|
|
128
|
+
}, 10000);
|
|
129
|
+
|
|
130
|
+
child.stdout.on("data", (chunk) => {
|
|
131
|
+
const text = String(chunk);
|
|
132
|
+
if (!settled && text.includes("OpenPress static preview:")) {
|
|
133
|
+
settled = true;
|
|
134
|
+
clearTimeout(timer);
|
|
135
|
+
resolve(child);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
child.stderr.on("data", (chunk) => {
|
|
139
|
+
stderr += String(chunk);
|
|
140
|
+
});
|
|
141
|
+
child.on("error", (error) => {
|
|
142
|
+
if (settled) return;
|
|
143
|
+
settled = true;
|
|
144
|
+
clearTimeout(timer);
|
|
145
|
+
reject(error);
|
|
146
|
+
});
|
|
147
|
+
child.on("close", (code) => {
|
|
148
|
+
if (settled) return;
|
|
149
|
+
settled = true;
|
|
150
|
+
clearTimeout(timer);
|
|
151
|
+
reject(new Error(`OpenPress static server exited with code ${code ?? 1}: ${stderr}`));
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export async function writePdfStageDeployConfig(root, source, config) {
|
|
157
|
+
const deployRoot = path.resolve(root, source);
|
|
158
|
+
const openpressDir = path.join(deployRoot, "openpress");
|
|
159
|
+
await fs.mkdir(openpressDir, { recursive: true });
|
|
160
|
+
await fs.writeFile(
|
|
161
|
+
path.join(openpressDir, "deploy.json"),
|
|
162
|
+
`${JSON.stringify({ pdf: publicPdfHref(config), deployed_at: new Date().toISOString() }, null, 2)}\n`,
|
|
163
|
+
"utf8",
|
|
164
|
+
);
|
|
165
|
+
await fs.writeFile(
|
|
166
|
+
path.join(deployRoot, "_headers"),
|
|
167
|
+
`${publicPdfHref(config)}\n Content-Type: application/pdf\n Content-Disposition: inline; filename="${config.pdf.filename}"\n`,
|
|
168
|
+
"utf8",
|
|
169
|
+
);
|
|
170
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { deploySync } from "../deploy-sync.mjs";
|
|
3
|
+
import { buildReactPdf, runCommand, writePdfStageDeployConfig } from "./_shared.mjs";
|
|
4
|
+
|
|
5
|
+
export async function run({ root, config, options, recurse }) {
|
|
6
|
+
if (config.deploy.requiresConfirmation === true && !options.confirm) {
|
|
7
|
+
console.error("OpenPress deploy requires --confirm before updating a public Cloudflare Pages site.");
|
|
8
|
+
return 2;
|
|
9
|
+
}
|
|
10
|
+
const source = config.deploy.source;
|
|
11
|
+
const projectName = config.deploy.projectName;
|
|
12
|
+
const commitDirty = config.deploy.commitDirty;
|
|
13
|
+
if (options.dryRun) {
|
|
14
|
+
console.log("OpenPress deploy dry run");
|
|
15
|
+
console.log("Command: node engine/cli.mjs render . --renderer react");
|
|
16
|
+
console.log(`Step: deploy-sync (copy ${config.outputDir} → ${source})`);
|
|
17
|
+
console.log(`Command: node engine/cli.mjs pdf . --output ${source}/${config.pdf.filename}`);
|
|
18
|
+
console.log(`Step: write ${source}/openpress/deploy.json with deployment metadata`);
|
|
19
|
+
console.log(`Command: npx wrangler pages deploy ${source}${projectName ? ` --project-name=${projectName}` : ""}${commitDirty ? " --commit-dirty=true" : ""}`);
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
const renderCode = await recurse("render", [root, "--renderer", "react"]);
|
|
23
|
+
if (renderCode !== 0) return renderCode;
|
|
24
|
+
await deploySync(root, config.outputDir, source);
|
|
25
|
+
await buildReactPdf({ root, config, outPath: path.resolve(root, source, config.pdf.filename), noBuild: true, recurse });
|
|
26
|
+
await writePdfStageDeployConfig(root, source, config);
|
|
27
|
+
const wranglerArgs = ["wrangler", "pages", "deploy", source];
|
|
28
|
+
if (projectName) wranglerArgs.push(`--project-name=${projectName}`);
|
|
29
|
+
if (commitDirty) wranglerArgs.push("--commit-dirty=true");
|
|
30
|
+
return runCommand("npx", wranglerArgs, root);
|
|
31
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { exportDocument } from "../document-export.mjs";
|
|
2
|
+
import { runCommand } from "./_shared.mjs";
|
|
3
|
+
|
|
4
|
+
export async function run({ root, options }) {
|
|
5
|
+
const renderer = options.renderer ?? "react";
|
|
6
|
+
if (renderer !== "react") {
|
|
7
|
+
console.error(`Unknown renderer: ${renderer}`);
|
|
8
|
+
return 2;
|
|
9
|
+
}
|
|
10
|
+
const host = options.host ?? "127.0.0.1";
|
|
11
|
+
const port = options.port ?? "5173";
|
|
12
|
+
const url = `http://${host}:${port}/?dev=1`;
|
|
13
|
+
if (options.dryRun) {
|
|
14
|
+
console.log(`OpenPress dev URL: ${url}`);
|
|
15
|
+
if (!options.noBuild) {
|
|
16
|
+
console.log("Command: node engine/cli.mjs export .");
|
|
17
|
+
}
|
|
18
|
+
console.log(`Command: npx vite --config vite.config.ts --host ${host} --port ${port}`);
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
if (!options.noBuild) {
|
|
22
|
+
await exportDocument(root);
|
|
23
|
+
}
|
|
24
|
+
console.log(`OpenPress dev: ${url}`);
|
|
25
|
+
return runCommand("npx", ["vite", "--config", "vite.config.ts", "--host", host, "--port", port], root);
|
|
26
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { exportDocument } from "../document-export.mjs";
|
|
3
|
+
|
|
4
|
+
export async function run({ root }) {
|
|
5
|
+
const result = await exportDocument(root);
|
|
6
|
+
console.log(`OpenPress export: ${path.relative(root, result.documentPath)} (${result.pageCount} pages)`);
|
|
7
|
+
return 0;
|
|
8
|
+
}
|