@open-press/cli 1.0.0 → 1.1.1

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.
Files changed (175) hide show
  1. package/README.md +11 -12
  2. package/dist/cli.js +298 -79
  3. package/package.json +9 -7
  4. package/template/core/AGENTS.md +0 -130
  5. package/template/core/CHANGELOG.md +0 -218
  6. package/template/core/README.md +0 -43
  7. package/template/core/engine/cli.mjs +0 -96
  8. package/template/core/engine/commands/_shared.mjs +0 -199
  9. package/template/core/engine/commands/deploy.mjs +0 -31
  10. package/template/core/engine/commands/dev.mjs +0 -49
  11. package/template/core/engine/commands/doctor.mjs +0 -229
  12. package/template/core/engine/commands/export.mjs +0 -8
  13. package/template/core/engine/commands/image.mjs +0 -29
  14. package/template/core/engine/commands/inspect.mjs +0 -35
  15. package/template/core/engine/commands/pdf.mjs +0 -26
  16. package/template/core/engine/commands/preview.mjs +0 -26
  17. package/template/core/engine/commands/render.mjs +0 -17
  18. package/template/core/engine/commands/replace.mjs +0 -41
  19. package/template/core/engine/commands/search.mjs +0 -33
  20. package/template/core/engine/commands/skills-sync.mjs +0 -71
  21. package/template/core/engine/commands/typecheck.mjs +0 -67
  22. package/template/core/engine/commands/upgrade.mjs +0 -159
  23. package/template/core/engine/commands/validate.mjs +0 -17
  24. package/template/core/engine/document-export.mjs +0 -15
  25. package/template/core/engine/output/chrome-pdf.d.mts +0 -34
  26. package/template/core/engine/output/chrome-pdf.mjs +0 -450
  27. package/template/core/engine/output/deploy-sync.mjs +0 -15
  28. package/template/core/engine/output/fonts.mjs +0 -62
  29. package/template/core/engine/output/katex-assets.mjs +0 -45
  30. package/template/core/engine/output/page-block.mjs +0 -30
  31. package/template/core/engine/output/pdf-media.mjs +0 -45
  32. package/template/core/engine/output/public-assets.mjs +0 -19
  33. package/template/core/engine/output/static-server.mjs +0 -571
  34. package/template/core/engine/react/caption-numbering.mjs +0 -73
  35. package/template/core/engine/react/comment-endpoint.d.mts +0 -11
  36. package/template/core/engine/react/comment-endpoint.mjs +0 -102
  37. package/template/core/engine/react/comment-marker.mjs +0 -374
  38. package/template/core/engine/react/document-entry.mjs +0 -331
  39. package/template/core/engine/react/document-export.mjs +0 -512
  40. package/template/core/engine/react/http-json.mjs +0 -24
  41. package/template/core/engine/react/mdx-compile.mjs +0 -629
  42. package/template/core/engine/react/measurement-css.mjs +0 -157
  43. package/template/core/engine/react/object-entities.mjs +0 -204
  44. package/template/core/engine/react/pagination/allocator.mjs +0 -167
  45. package/template/core/engine/react/pagination/regions.mjs +0 -81
  46. package/template/core/engine/react/pagination-constants.mjs +0 -3
  47. package/template/core/engine/react/pagination.mjs +0 -9
  48. package/template/core/engine/react/pipeline/allocate.mjs +0 -217
  49. package/template/core/engine/react/pipeline/final-render.mjs +0 -94
  50. package/template/core/engine/react/pipeline/frame-measurement.mjs +0 -306
  51. package/template/core/engine/react/pipeline/press-tree.mjs +0 -135
  52. package/template/core/engine/react/press-tree-inspection.mjs +0 -172
  53. package/template/core/engine/react/project-asset-endpoint.d.mts +0 -10
  54. package/template/core/engine/react/project-asset-endpoint.mjs +0 -361
  55. package/template/core/engine/react/section-css.mjs +0 -56
  56. package/template/core/engine/react/source-edit-endpoint.d.mts +0 -10
  57. package/template/core/engine/react/source-edit-endpoint.mjs +0 -75
  58. package/template/core/engine/react/sources/heading-numbering.mjs +0 -132
  59. package/template/core/engine/react/sources/mdx-resolver.mjs +0 -439
  60. package/template/core/engine/react/style-discovery.mjs +0 -160
  61. package/template/core/engine/runtime/config.d.mts +0 -48
  62. package/template/core/engine/runtime/config.mjs +0 -172
  63. package/template/core/engine/runtime/file-utils.mjs +0 -114
  64. package/template/core/engine/runtime/file-walk.mjs +0 -22
  65. package/template/core/engine/runtime/inspection.mjs +0 -328
  66. package/template/core/engine/runtime/issue-report.mjs +0 -44
  67. package/template/core/engine/runtime/page-geometry.mjs +0 -131
  68. package/template/core/engine/runtime/path-utils.mjs +0 -20
  69. package/template/core/engine/runtime/source-text-tools.d.mts +0 -102
  70. package/template/core/engine/runtime/source-text-tools.mjs +0 -832
  71. package/template/core/engine/runtime/source-workspace.mjs +0 -168
  72. package/template/core/engine/runtime/validation.mjs +0 -183
  73. package/template/core/index.html +0 -13
  74. package/template/core/openpress.config.mjs +0 -8
  75. package/template/core/package.json +0 -89
  76. package/template/core/src/main.tsx +0 -16
  77. package/template/core/src/openpress/app/OpenPressApp.tsx +0 -296
  78. package/template/core/src/openpress/app/OpenPressRuntime.tsx +0 -102
  79. package/template/core/src/openpress/app/WorkspaceGalleryPage.tsx +0 -219
  80. package/template/core/src/openpress/app/index.ts +0 -2
  81. package/template/core/src/openpress/core/Frame.tsx +0 -91
  82. package/template/core/src/openpress/core/FrameContext.tsx +0 -26
  83. package/template/core/src/openpress/core/MdxArea.tsx +0 -34
  84. package/template/core/src/openpress/core/Press.tsx +0 -55
  85. package/template/core/src/openpress/core/Workspace.tsx +0 -36
  86. package/template/core/src/openpress/core/cn.ts +0 -4
  87. package/template/core/src/openpress/core/index.tsx +0 -47
  88. package/template/core/src/openpress/core/primitives.tsx +0 -91
  89. package/template/core/src/openpress/core/types.ts +0 -236
  90. package/template/core/src/openpress/core/useSource.ts +0 -28
  91. package/template/core/src/openpress/document-model/anchorMapModel.ts +0 -27
  92. package/template/core/src/openpress/document-model/documentIndexes.ts +0 -329
  93. package/template/core/src/openpress/document-model/documentTypes.ts +0 -147
  94. package/template/core/src/openpress/document-model/index.ts +0 -7
  95. package/template/core/src/openpress/document-model/objectEntityModel.ts +0 -55
  96. package/template/core/src/openpress/document-model/projectIdentityModel.ts +0 -15
  97. package/template/core/src/openpress/document-model/reactDocumentMetadataModel.ts +0 -27
  98. package/template/core/src/openpress/document-model/workspaceManifestModel.ts +0 -57
  99. package/template/core/src/openpress/manuscript/index.tsx +0 -238
  100. package/template/core/src/openpress/mdx/index.ts +0 -96
  101. package/template/core/src/openpress/numbering/index.ts +0 -294
  102. package/template/core/src/openpress/reader/PageThumbnailsPanel.tsx +0 -168
  103. package/template/core/src/openpress/reader/PublicReaderPage.tsx +0 -267
  104. package/template/core/src/openpress/reader/ReaderNavigationPanel.tsx +0 -123
  105. package/template/core/src/openpress/reader/index.ts +0 -11
  106. package/template/core/src/openpress/reader/pageViewportScaleModel.ts +0 -73
  107. package/template/core/src/openpress/reader/readerPageRegistry.ts +0 -41
  108. package/template/core/src/openpress/reader/readerPageRoute.ts +0 -21
  109. package/template/core/src/openpress/reader/readerScroll.ts +0 -92
  110. package/template/core/src/openpress/reader/readerStateModel.ts +0 -15
  111. package/template/core/src/openpress/reader/readerTypes.ts +0 -4
  112. package/template/core/src/openpress/reader/usePageViewportScale.ts +0 -119
  113. package/template/core/src/openpress/reader/usePanelState.ts +0 -56
  114. package/template/core/src/openpress/reader/useReaderHashSync.ts +0 -61
  115. package/template/core/src/openpress/reader/useReaderKeyboardNav.ts +0 -48
  116. package/template/core/src/openpress/reader/useReaderRuntime.ts +0 -146
  117. package/template/core/src/openpress/reader/useReaderScrollAnchor.ts +0 -64
  118. package/template/core/src/openpress/shared/Panel.tsx +0 -77
  119. package/template/core/src/openpress/shared/frameScheduler.ts +0 -32
  120. package/template/core/src/openpress/shared/index.ts +0 -4
  121. package/template/core/src/openpress/shared/numberUtils.ts +0 -3
  122. package/template/core/src/openpress/shared/runtimeMode.ts +0 -11
  123. package/template/core/src/openpress/workbench/Workbench.tsx +0 -506
  124. package/template/core/src/openpress/workbench/actions/DeploymentControl.tsx +0 -157
  125. package/template/core/src/openpress/workbench/actions/ExportImageControl.tsx +0 -96
  126. package/template/core/src/openpress/workbench/actions/PageZoomControl.tsx +0 -182
  127. package/template/core/src/openpress/workbench/actions/SearchControl.tsx +0 -345
  128. package/template/core/src/openpress/workbench/actions/deploymentStatusModel.ts +0 -112
  129. package/template/core/src/openpress/workbench/actions/index.ts +0 -6
  130. package/template/core/src/openpress/workbench/actions/useDeploymentWorkbench.ts +0 -136
  131. package/template/core/src/openpress/workbench/dialog/WorkbenchDialog.tsx +0 -72
  132. package/template/core/src/openpress/workbench/dialog/index.ts +0 -1
  133. package/template/core/src/openpress/workbench/document/components/DocumentPanel.tsx +0 -127
  134. package/template/core/src/openpress/workbench/document/components/InlineSourceEditorLayer.tsx +0 -207
  135. package/template/core/src/openpress/workbench/document/components/ReaderStage.tsx +0 -9
  136. package/template/core/src/openpress/workbench/document/hooks/useDocumentWorkbenchModel.ts +0 -34
  137. package/template/core/src/openpress/workbench/document/hooks/useInlineDocumentEditor.ts +0 -525
  138. package/template/core/src/openpress/workbench/document/index.ts +0 -10
  139. package/template/core/src/openpress/workbench/index.ts +0 -2
  140. package/template/core/src/openpress/workbench/inspector/InlineInspectorLayer.tsx +0 -459
  141. package/template/core/src/openpress/workbench/inspector/index.ts +0 -5
  142. package/template/core/src/openpress/workbench/inspector/inlineCommentModel.ts +0 -125
  143. package/template/core/src/openpress/workbench/inspector/inspectorGeometryModel.ts +0 -160
  144. package/template/core/src/openpress/workbench/inspector/inspectorModel.ts +0 -408
  145. package/template/core/src/openpress/workbench/inspector/useInspectorComments.ts +0 -254
  146. package/template/core/src/openpress/workbench/mentions/MentionSuggestionList.tsx +0 -41
  147. package/template/core/src/openpress/workbench/mentions/index.ts +0 -2
  148. package/template/core/src/openpress/workbench/mentions/useComposerMentions.ts +0 -185
  149. package/template/core/src/openpress/workbench/panels/Panel.tsx +0 -1
  150. package/template/core/src/openpress/workbench/panels/PendingCommentsPanel.tsx +0 -80
  151. package/template/core/src/openpress/workbench/panels/WorkbenchControlPanel.tsx +0 -29
  152. package/template/core/src/openpress/workbench/panels/index.ts +0 -3
  153. package/template/core/src/openpress/workbench/project/ProjectEntryPanel.tsx +0 -525
  154. package/template/core/src/openpress/workbench/project/ProjectPreviewDialog.tsx +0 -35
  155. package/template/core/src/openpress/workbench/project/index.ts +0 -2
  156. package/template/core/src/openpress/workbench/project/projectPreviewTypes.ts +0 -11
  157. package/template/core/src/openpress/workbench/project/projectSourceModel.ts +0 -24
  158. package/template/core/src/openpress/workbench/shell/WorkbenchShell.tsx +0 -167
  159. package/template/core/src/openpress/workbench/shell/index.ts +0 -1
  160. package/template/core/src/openpress/workbench/workbenchFormatters.ts +0 -120
  161. package/template/core/src/openpress/workbench/workbenchTypes.ts +0 -35
  162. package/template/core/src/styles/openpress/app-shell.css +0 -251
  163. package/template/core/src/styles/openpress/media-workspace.css +0 -230
  164. package/template/core/src/styles/openpress/print-route.css +0 -184
  165. package/template/core/src/styles/openpress/project-preview-panel.css +0 -924
  166. package/template/core/src/styles/openpress/public-viewer.css +0 -688
  167. package/template/core/src/styles/openpress/reader-runtime.css +0 -989
  168. package/template/core/src/styles/openpress/responsive.css +0 -245
  169. package/template/core/src/styles/openpress/workbench-panels.css +0 -707
  170. package/template/core/src/styles/openpress/workbench.css +0 -1255
  171. package/template/core/src/styles/openpress/workspace-gallery.css +0 -300
  172. package/template/core/src/styles/openpress.css +0 -15
  173. package/template/core/src/vite-env.d.ts +0 -9
  174. package/template/core/tsconfig.json +0 -40
  175. package/template/core/vite.config.ts +0 -584
@@ -1,199 +0,0 @@
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 { captureUrlPagesToPng, printUrlToPdf, stopChildProcess, waitForPrintReady } from "../output/chrome-pdf.mjs";
6
- import { loadConfig, publicPdfHref } from "../runtime/config.mjs";
7
- import { exportDocument } from "../document-export.mjs";
8
- import { optimizePdfMediaForStaticRoot } from "../output/pdf-media.mjs";
9
-
10
- export const ENGINE_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
11
- export const CLI_ENTRY = path.join(ENGINE_DIR, "cli.mjs");
12
- export const STATIC_SERVER = path.join(ENGINE_DIR, "output", "static-server.mjs");
13
-
14
- export function parseOptions(argv) {
15
- const options = {};
16
- const positional = [];
17
- for (let i = 0; i < argv.length; i += 1) {
18
- const value = argv[i];
19
- if (value === "--renderer") options.renderer = argv[++i];
20
- else if (value === "--host") options.host = argv[++i];
21
- else if (value === "--port") options.port = argv[++i];
22
- else if (value === "--dry-run") options.dryRun = true;
23
- else if (value === "--force") options.force = true;
24
- else if (value === "--confirm") options.confirm = true;
25
- else if (value === "--json") options.json = true;
26
- else if (value === "--no-cache") options.noCache = true;
27
- else if (value === "--no-deps") options.noDeps = true;
28
- else if (value === "--no-skills") options.noSkills = true;
29
- else if (value === "--no-build") options.noBuild = true;
30
- else if (value === "--apply") options.apply = true;
31
- else if (value === "--include-code") options.includeCode = true;
32
- else if (value === "--case-sensitive") options.caseSensitive = true;
33
- else if (value === "--scope") options.scope = argv[++i];
34
- else if (value === "--source") options.source = argv[++i];
35
- else if (value === "--output") options.output = argv[++i];
36
- else if (value.startsWith("--")) throw new Error(`Unknown option: ${value}`);
37
- else positional.push(value);
38
- }
39
- options.path = positional[0];
40
- options.positional = positional;
41
- return options;
42
- }
43
-
44
- export function formatDisplayPath(absolutePath) {
45
- const relative = path.relative(process.cwd(), absolutePath);
46
- if (!relative || relative.startsWith("..")) return absolutePath;
47
- return relative;
48
- }
49
-
50
- export function runCommand(commandName, commandArgs, cwd) {
51
- const result = spawnSync(commandName, commandArgs, { cwd, stdio: "inherit" });
52
- return result.status ?? 1;
53
- }
54
-
55
- export function formatNodeScriptCommand(root, scriptPath) {
56
- const relative = path.relative(root, scriptPath).replaceAll("\\", "/");
57
- const displayPath = relative && !relative.startsWith("../") ? relative : scriptPath;
58
- return `node ${displayPath}`;
59
- }
60
-
61
- export async function buildReactStatic({ root, noBuild = false, recurse, silent = false }) {
62
- if (noBuild) return 0;
63
- if (!silent) {
64
- return await recurse("render", [root, "--renderer", "react"]);
65
- }
66
-
67
- await exportDocument(root);
68
- const result = spawnSync("npx", ["vite", "build", "--config", "vite.config.ts"], {
69
- cwd: root,
70
- encoding: "utf8",
71
- });
72
- return result.status ?? 1;
73
- }
74
-
75
- export async function buildReactPdf({
76
- root,
77
- config,
78
- outPath,
79
- host = "127.0.0.1",
80
- port = "5185",
81
- noBuild = false,
82
- recurse,
83
- }) {
84
- config ??= await loadConfig(root);
85
- outPath ??= config.paths.pdf;
86
- const renderCode = await buildReactStatic({ root, noBuild, recurse });
87
- if (renderCode !== 0) throw new Error(`React render failed with exit code ${renderCode}`);
88
- await optimizePdfMediaForStaticRoot(config.paths.outputDir);
89
- await fs.mkdir(path.dirname(outPath), { recursive: true });
90
-
91
- const server = await startStaticServer(root, config, host, port);
92
- try {
93
- const pageCount = await printUrlToPdf({
94
- root,
95
- url: `http://${host}:${port}/?print=1`,
96
- outPath,
97
- waitForReady: waitForPrintReady,
98
- debuggingPortBase: 9300,
99
- debuggingPortRange: 600,
100
- profilePrefix: "chrome-pdf",
101
- });
102
- console.log(`${pageCount} OpenPress pages printed to PDF`);
103
- } finally {
104
- await stopChildProcess(server);
105
- }
106
-
107
- return { pdfPath: outPath };
108
- }
109
-
110
- export async function buildReactImages({
111
- root,
112
- config,
113
- outDir,
114
- host = "127.0.0.1",
115
- port = "5186",
116
- noBuild = false,
117
- recurse,
118
- }) {
119
- config ??= await loadConfig(root);
120
- outDir ??= path.join(config.paths.outputDir, "images");
121
- const renderCode = await buildReactStatic({ root, noBuild, recurse });
122
- if (renderCode !== 0) throw new Error(`React render failed with exit code ${renderCode}`);
123
- await fs.mkdir(outDir, { recursive: true });
124
-
125
- const server = await startStaticServer(root, config, host, port);
126
- try {
127
- const result = await captureUrlPagesToPng({
128
- root,
129
- url: `http://${host}:${port}/?print=1`,
130
- outDir,
131
- waitForReady: waitForPrintReady,
132
- debuggingPortBase: 9700,
133
- debuggingPortRange: 600,
134
- profilePrefix: "chrome-image",
135
- });
136
- console.log(`${result.files.length} OpenPress pages exported to PNG`);
137
- return { outDir, files: result.files, pageCount: result.pageCount };
138
- } finally {
139
- await stopChildProcess(server);
140
- }
141
- }
142
-
143
- export function startStaticServer(root, config, host, port) {
144
- return new Promise((resolve, reject) => {
145
- const child = spawn("node", [STATIC_SERVER, config.outputDir, "--host", host, "--port", port, "--workspace", "."], {
146
- cwd: root,
147
- shell: false,
148
- stdio: ["ignore", "pipe", "pipe"],
149
- });
150
- let settled = false;
151
- let stderr = "";
152
- const timer = setTimeout(() => {
153
- if (settled) return;
154
- settled = true;
155
- child.kill();
156
- reject(new Error(`Timed out waiting for OpenPress static server on ${host}:${port}`));
157
- }, 10000);
158
-
159
- child.stdout.on("data", (chunk) => {
160
- const text = String(chunk);
161
- if (!settled && text.includes("OpenPress static preview:")) {
162
- settled = true;
163
- clearTimeout(timer);
164
- resolve(child);
165
- }
166
- });
167
- child.stderr.on("data", (chunk) => {
168
- stderr += String(chunk);
169
- });
170
- child.on("error", (error) => {
171
- if (settled) return;
172
- settled = true;
173
- clearTimeout(timer);
174
- reject(error);
175
- });
176
- child.on("close", (code) => {
177
- if (settled) return;
178
- settled = true;
179
- clearTimeout(timer);
180
- reject(new Error(`OpenPress static server exited with code ${code ?? 1}: ${stderr}`));
181
- });
182
- });
183
- }
184
-
185
- export async function writePdfStageDeployConfig(root, source, config) {
186
- const deployRoot = path.resolve(root, source);
187
- const openpressDir = path.join(deployRoot, "openpress");
188
- await fs.mkdir(openpressDir, { recursive: true });
189
- await fs.writeFile(
190
- path.join(openpressDir, "deploy.json"),
191
- `${JSON.stringify({ pdf: publicPdfHref(config), deployed_at: new Date().toISOString() }, null, 2)}\n`,
192
- "utf8",
193
- );
194
- await fs.writeFile(
195
- path.join(deployRoot, "_headers"),
196
- `${publicPdfHref(config)}\n Content-Type: application/pdf\n Content-Disposition: inline; filename="${config.pdf.filename}"\n`,
197
- "utf8",
198
- );
199
- }
@@ -1,31 +0,0 @@
1
- import path from "node:path";
2
- import { deploySync } from "../output/deploy-sync.mjs";
3
- import { CLI_ENTRY, buildReactPdf, formatNodeScriptCommand, 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: ${formatNodeScriptCommand(root, CLI_ENTRY)} render . --renderer react`);
16
- console.log(`Step: deploy-sync (copy ${config.outputDir} → ${source})`);
17
- console.log(`Command: ${formatNodeScriptCommand(root, CLI_ENTRY)} 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
- }
@@ -1,49 +0,0 @@
1
- import { exportDocument } from "../document-export.mjs";
2
- import { diagnose } from "./doctor.mjs";
3
- import { CLI_ENTRY, formatNodeScriptCommand, runCommand } from "./_shared.mjs";
4
-
5
- export async function run({ root, options }) {
6
- const renderer = options.renderer ?? "react";
7
- if (renderer !== "react") {
8
- console.error(`Unknown renderer: ${renderer}`);
9
- return 2;
10
- }
11
- const host = options.host ?? "127.0.0.1";
12
- const port = options.port ?? "5173";
13
- const url = `http://${host}:${port}/?dev=1`;
14
- if (options.dryRun) {
15
- console.log(`OpenPress dev URL: ${url}`);
16
- if (!options.noBuild) {
17
- console.log(`Command: ${formatNodeScriptCommand(root, CLI_ENTRY)} export .`);
18
- }
19
- console.log(`Command: npx vite --force --config vite.config.ts --host ${host} --port ${port}`);
20
- return 0;
21
- }
22
- if (!options.noBuild) {
23
- await exportDocument(root);
24
- }
25
-
26
- // One-line update notice (24h cached, network failure is silent).
27
- await printDoctorNoticeIfStale(root);
28
-
29
- console.log(`OpenPress dev: ${url}`);
30
- return runCommand("npx", ["vite", "--force", "--config", "vite.config.ts", "--host", host, "--port", port], root);
31
- }
32
-
33
- async function printDoctorNoticeIfStale(root) {
34
- try {
35
- const report = await diagnose(root);
36
- if (!report.stale) return;
37
- const parts = [];
38
- if (report.coreUpdateAvailable) {
39
- parts.push(`@open-press/core ${report.coreVersion} → ${report.coreLatest}`);
40
- }
41
- if (report.pendingMigrations.length > 0) {
42
- parts.push(`${report.pendingMigrations.length} migration note(s)`);
43
- }
44
- if (parts.length === 0) return;
45
- console.log(`○ open-press: ${parts.join(" · ")} — run \`npx open-press doctor\` for details.`);
46
- } catch {
47
- // Doctor is informational only; never block dev.
48
- }
49
- }
@@ -1,229 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
3
- import path from "node:path";
4
-
5
- const CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 24h
6
- const CORE_PACKAGE = "@open-press/core";
7
-
8
- export async function run({ root, options }) {
9
- const json = Boolean(options?.json);
10
- const noCache = Boolean(options?.noCache);
11
-
12
- const report = await diagnose(root, { noCache });
13
-
14
- if (json) {
15
- process.stdout.write(JSON.stringify(report, null, 2) + "\n");
16
- } else {
17
- printHumanReport(report);
18
- }
19
-
20
- // Exit 0 even when stale — doctor is informational, not a gate.
21
- // Agents / CI can check report.stale or report.coreUpdateAvailable.
22
- return 0;
23
- }
24
-
25
- /**
26
- * Diagnose workspace against latest framework state.
27
- * Result shape:
28
- * {
29
- * coreVersion: "0.4.0", // installed
30
- * coreLatest: "0.5.0" | null, // null on network failure
31
- * coreUpdateAvailable: boolean,
32
- * skillsInstalled: ["openpress", ...],
33
- * skillsLockSource: "quan0715/open-press" | null,
34
- * pendingMigrations: ["0.5.0"], // versions with docs/migrations notes
35
- * stale: boolean, // either core or skills behind
36
- * cachedAt: ISO timestamp
37
- * }
38
- */
39
- export async function diagnose(root, { noCache = false } = {}) {
40
- const cachePath = path.join(root, ".openpress", "cache", "doctor.json");
41
-
42
- if (!noCache) {
43
- const cached = await readCached(cachePath);
44
- if (cached) return cached;
45
- }
46
-
47
- const coreVersion = await readCoreVersion(root);
48
- const coreLatest = await fetchCoreLatest();
49
- const skillsInstalled = await listInstalledSkills(root);
50
- const skillsLockSource = await readSkillsLockSource(root);
51
- const pendingMigrations = await listPendingMigrations(root, coreVersion, coreLatest);
52
-
53
- const coreUpdateAvailable = Boolean(
54
- coreVersion && coreLatest && coreVersion !== coreLatest && semverLt(coreVersion, coreLatest),
55
- );
56
-
57
- const report = {
58
- coreVersion,
59
- coreLatest,
60
- coreUpdateAvailable,
61
- skillsInstalled,
62
- skillsLockSource,
63
- pendingMigrations,
64
- stale: coreUpdateAvailable || pendingMigrations.length > 0,
65
- cachedAt: new Date().toISOString(),
66
- };
67
-
68
- await writeCached(cachePath, report).catch(() => {});
69
- return report;
70
- }
71
-
72
- async function readCached(cachePath) {
73
- try {
74
- const stats = await stat(cachePath);
75
- if (Date.now() - stats.mtimeMs > CACHE_TTL_MS) return null;
76
- return JSON.parse(await readFile(cachePath, "utf8"));
77
- } catch {
78
- return null;
79
- }
80
- }
81
-
82
- async function writeCached(cachePath, report) {
83
- await mkdir(path.dirname(cachePath), { recursive: true });
84
- await writeFile(cachePath, JSON.stringify(report, null, 2) + "\n", "utf8");
85
- }
86
-
87
- async function readCoreVersion(root) {
88
- // Try workspace package.json deps first; fall back to installed package.
89
- try {
90
- const pkg = JSON.parse(await readFile(path.join(root, "package.json"), "utf8"));
91
- const range = pkg.dependencies?.[CORE_PACKAGE] ?? pkg.devDependencies?.[CORE_PACKAGE];
92
- if (range) {
93
- // Try the installed version (more accurate than the range).
94
- try {
95
- const installed = JSON.parse(
96
- await readFile(path.join(root, "node_modules", CORE_PACKAGE, "package.json"), "utf8"),
97
- );
98
- return installed.version;
99
- } catch {
100
- return range.replace(/^[\^~>=<\s]+/, "");
101
- }
102
- }
103
- } catch {}
104
-
105
- // Self-bundled framework (cli scaffolded workspace): pkg.version is the framework version.
106
- try {
107
- const pkg = JSON.parse(await readFile(path.join(root, "package.json"), "utf8"));
108
- if (pkg.name === CORE_PACKAGE) return pkg.version;
109
- } catch {}
110
-
111
- return null;
112
- }
113
-
114
- async function fetchCoreLatest() {
115
- try {
116
- const res = await fetch(`https://registry.npmjs.org/${CORE_PACKAGE}/latest`, {
117
- headers: { Accept: "application/json" },
118
- signal: AbortSignal.timeout(5000),
119
- });
120
- if (!res.ok) return null;
121
- const data = await res.json();
122
- return typeof data.version === "string" ? data.version : null;
123
- } catch {
124
- return null;
125
- }
126
- }
127
-
128
- async function listInstalledSkills(root) {
129
- const skillsDir = path.join(root, ".agents", "skills");
130
- try {
131
- const { readdir } = await import("node:fs/promises");
132
- const entries = await readdir(skillsDir, { withFileTypes: true });
133
- return entries.filter((e) => e.isDirectory()).map((e) => e.name).sort();
134
- } catch {
135
- return [];
136
- }
137
- }
138
-
139
- async function readSkillsLockSource(root) {
140
- try {
141
- const lock = JSON.parse(await readFile(path.join(root, "skills-lock.json"), "utf8"));
142
- const sources = lock?.sources;
143
- if (Array.isArray(sources) && sources.length > 0) return sources[0]?.source ?? null;
144
- return null;
145
- } catch {
146
- return null;
147
- }
148
- }
149
-
150
- async function listPendingMigrations(root, currentVersion, latestVersion) {
151
- if (!currentVersion || !latestVersion || !semverLt(currentVersion, latestVersion)) return [];
152
- // Look for docs/migrations/<version>.md files for versions in (current, latest].
153
- const migrationsDir = path.join(root, "docs", "migrations");
154
- try {
155
- const { readdir } = await import("node:fs/promises");
156
- const files = await readdir(migrationsDir);
157
- return files
158
- .filter((f) => /^\d+\.\d+\.\d+\.md$/.test(f))
159
- .map((f) => f.replace(/\.md$/, ""))
160
- .filter((v) => semverGt(v, currentVersion) && !semverGt(v, latestVersion))
161
- .sort(semverCompare);
162
- } catch {
163
- return [];
164
- }
165
- }
166
-
167
- function semverParse(v) {
168
- const m = /^(\d+)\.(\d+)\.(\d+)/.exec(v);
169
- if (!m) return [0, 0, 0];
170
- return [Number(m[1]), Number(m[2]), Number(m[3])];
171
- }
172
- function semverCompare(a, b) {
173
- const A = semverParse(a);
174
- const B = semverParse(b);
175
- for (let i = 0; i < 3; i++) if (A[i] !== B[i]) return A[i] - B[i];
176
- return 0;
177
- }
178
- function semverLt(a, b) { return semverCompare(a, b) < 0; }
179
- function semverGt(a, b) { return semverCompare(a, b) > 0; }
180
-
181
- function printHumanReport(report) {
182
- const lines = [];
183
- lines.push("○ open-press doctor");
184
- lines.push("");
185
- lines.push("framework");
186
- if (report.coreVersion) {
187
- if (report.coreLatest === null) {
188
- lines.push(` ? @open-press/core: ${report.coreVersion} installed (couldn't check latest — offline?)`);
189
- } else if (report.coreUpdateAvailable) {
190
- lines.push(` ⚠ @open-press/core: ${report.coreVersion} installed → ${report.coreLatest} available`);
191
- } else {
192
- lines.push(` ✓ @open-press/core: ${report.coreVersion} (latest)`);
193
- }
194
- } else {
195
- lines.push(" ? @open-press/core: not detected in this workspace");
196
- }
197
- lines.push("");
198
- lines.push("skills");
199
- if (report.skillsInstalled.length === 0) {
200
- lines.push(" ? no skills installed under .agents/skills/");
201
- lines.push(" run: npx skills add quan0715/open-press");
202
- } else {
203
- lines.push(` ✓ ${report.skillsInstalled.length} skills installed`);
204
- if (report.skillsLockSource) {
205
- lines.push(` source: ${report.skillsLockSource}`);
206
- lines.push(" refresh: npx skills upgrade");
207
- }
208
- }
209
- lines.push("");
210
- lines.push("migrations");
211
- if (report.pendingMigrations.length === 0) {
212
- if (report.coreUpdateAvailable) {
213
- lines.push(` ✓ no breaking migrations documented for the ${report.coreLatest} window`);
214
- } else {
215
- lines.push(" ✓ up to date");
216
- }
217
- } else {
218
- lines.push(` ⚠ ${report.pendingMigrations.length} migration note(s) since your version:`);
219
- for (const v of report.pendingMigrations) lines.push(` - docs/migrations/${v}.md`);
220
- }
221
- lines.push("");
222
- if (report.stale) {
223
- lines.push("next");
224
- lines.push(" npx open-press upgrade # apply all updates (agent-driven)");
225
- lines.push(" npx open-press doctor --json # machine-readable output");
226
- lines.push("");
227
- }
228
- process.stdout.write(lines.join("\n"));
229
- }
@@ -1,8 +0,0 @@
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
- }
@@ -1,29 +0,0 @@
1
- import path from "node:path";
2
- import { CLI_ENTRY, STATIC_SERVER, buildReactImages, formatNodeScriptCommand } from "./_shared.mjs";
3
-
4
- export async function run({ root, config, options, recurse }) {
5
- const outputDir = options.output ? path.resolve(root, options.output) : path.join(config.paths.outputDir, "images");
6
- const host = options.host ?? "127.0.0.1";
7
- const port = options.port ?? "5186";
8
-
9
- if (options.dryRun) {
10
- console.log(`Command: ${formatNodeScriptCommand(root, CLI_ENTRY)} render . --renderer react`);
11
- console.log(`Command: ${formatNodeScriptCommand(root, STATIC_SERVER)} ${config.outputDir} --host ${host} --port ${port} --workspace .`);
12
- console.log(`Chrome image export URL: http://${host}:${port}/?print=1`);
13
- console.log(`Output: ${path.relative(root, path.join(outputDir, "page-001.png"))}`);
14
- return 0;
15
- }
16
-
17
- const result = await buildReactImages({
18
- root,
19
- config,
20
- outDir: outputDir,
21
- host,
22
- port,
23
- noBuild: options.noBuild,
24
- recurse,
25
- });
26
-
27
- console.log(`OpenPress images: ${path.relative(root, result.outDir)} (${result.files.length} pages)`);
28
- return 0;
29
- }
@@ -1,35 +0,0 @@
1
- import { inspectWorkspace } from "../runtime/inspection.mjs";
2
- import { exitCodeForIssueReport } from "../runtime/issue-report.mjs";
3
-
4
- export async function run({ root, config, options, recurse }) {
5
- const host = options.host ?? "127.0.0.1";
6
- const port = options.port ?? "5186";
7
- const url = `http://${host}:${port}/?print=1`;
8
-
9
- if (options.dryRun) {
10
- if (!options.noBuild) {
11
- console.log("Command: node engine/cli.mjs render . --renderer react");
12
- }
13
- console.log(`Command: node engine/output/static-server.mjs ${config.outputDir} --host ${host} --port ${port} --workspace .`);
14
- console.log(`Chrome inspection URL: ${url}`);
15
- return 0;
16
- }
17
-
18
- const report = await inspectWorkspace({ root, config, options, recurse });
19
- if (options.json) {
20
- console.log(JSON.stringify(report, null, 2));
21
- return exitCodeForIssueReport(report);
22
- }
23
-
24
- if (report.ok) {
25
- console.log(report.format());
26
- console.log(`Checked: ${report.checked.join(", ")}`);
27
- if (report.summary) {
28
- console.log(`Summary: ${JSON.stringify(report.summary)}`);
29
- }
30
- return 0;
31
- }
32
-
33
- console.log(report.format());
34
- return exitCodeForIssueReport(report);
35
- }
@@ -1,26 +0,0 @@
1
- import path from "node:path";
2
- import { CLI_ENTRY, STATIC_SERVER, buildReactPdf, formatNodeScriptCommand } from "./_shared.mjs";
3
-
4
- export async function run({ root, config, options, recurse }) {
5
- const outputPath = options.output ? path.resolve(root, options.output) : undefined;
6
- if (options.dryRun) {
7
- const relOutput = path.relative(root, outputPath ?? config.paths.pdf);
8
- const host = options.host ?? "127.0.0.1";
9
- const port = options.port ?? "5185";
10
- console.log(`Command: ${formatNodeScriptCommand(root, CLI_ENTRY)} render . --renderer react`);
11
- console.log(`Command: ${formatNodeScriptCommand(root, STATIC_SERVER)} ${config.outputDir} --host ${host} --port ${port} --workspace .`);
12
- console.log(`Command: Chrome --print-to-pdf=${relOutput} http://${host}:${port}/?print=1`);
13
- return 0;
14
- }
15
- const result = await buildReactPdf({
16
- root,
17
- config,
18
- outPath: outputPath,
19
- host: options.host,
20
- port: options.port,
21
- noBuild: options.noBuild,
22
- recurse,
23
- });
24
- console.log(`OpenPress PDF: ${path.relative(root, result.pdfPath)}`);
25
- return 0;
26
- }
@@ -1,26 +0,0 @@
1
- import { CLI_ENTRY, STATIC_SERVER, formatNodeScriptCommand, runCommand } from "./_shared.mjs";
2
-
3
- export async function run({ root, config, options, recurse }) {
4
- const renderer = options.renderer ?? "react";
5
- if (renderer !== "react") {
6
- console.error(`Unknown renderer: ${renderer}`);
7
- return 2;
8
- }
9
- const host = options.host ?? "127.0.0.1";
10
- const port = options.port ?? "5173";
11
- const url = `http://${host}:${port}`;
12
- if (options.dryRun) {
13
- console.log(`OpenPress preview URL: ${url}`);
14
- if (!options.noBuild) {
15
- console.log(`Command: ${formatNodeScriptCommand(root, CLI_ENTRY)} render . --renderer react`);
16
- }
17
- console.log(`Command: ${formatNodeScriptCommand(root, STATIC_SERVER)} ${config.outputDir} --host ${host} --port ${port} --workspace .`);
18
- return 0;
19
- }
20
- if (!options.noBuild) {
21
- const renderCode = await recurse("render", [root, "--renderer", renderer]);
22
- if (renderCode !== 0) return renderCode;
23
- }
24
- console.log(`OpenPress preview: ${url}`);
25
- return runCommand("node", [STATIC_SERVER, config.outputDir, "--host", host, "--port", port, "--workspace", "."], root);
26
- }
@@ -1,17 +0,0 @@
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
- if (options.dryRun) {
11
- console.log("Command: node engine/cli.mjs export .");
12
- console.log("Command: npx vite build --config vite.config.ts");
13
- return 0;
14
- }
15
- await exportDocument(root);
16
- return runCommand("npx", ["vite", "build", "--config", "vite.config.ts"], root);
17
- }