@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.
- package/README.md +11 -12
- package/dist/cli.js +298 -79
- package/package.json +9 -7
- package/template/core/AGENTS.md +0 -130
- package/template/core/CHANGELOG.md +0 -218
- package/template/core/README.md +0 -43
- package/template/core/engine/cli.mjs +0 -96
- package/template/core/engine/commands/_shared.mjs +0 -199
- package/template/core/engine/commands/deploy.mjs +0 -31
- package/template/core/engine/commands/dev.mjs +0 -49
- package/template/core/engine/commands/doctor.mjs +0 -229
- package/template/core/engine/commands/export.mjs +0 -8
- package/template/core/engine/commands/image.mjs +0 -29
- package/template/core/engine/commands/inspect.mjs +0 -35
- package/template/core/engine/commands/pdf.mjs +0 -26
- package/template/core/engine/commands/preview.mjs +0 -26
- package/template/core/engine/commands/render.mjs +0 -17
- package/template/core/engine/commands/replace.mjs +0 -41
- package/template/core/engine/commands/search.mjs +0 -33
- package/template/core/engine/commands/skills-sync.mjs +0 -71
- package/template/core/engine/commands/typecheck.mjs +0 -67
- package/template/core/engine/commands/upgrade.mjs +0 -159
- package/template/core/engine/commands/validate.mjs +0 -17
- package/template/core/engine/document-export.mjs +0 -15
- package/template/core/engine/output/chrome-pdf.d.mts +0 -34
- package/template/core/engine/output/chrome-pdf.mjs +0 -450
- package/template/core/engine/output/deploy-sync.mjs +0 -15
- package/template/core/engine/output/fonts.mjs +0 -62
- package/template/core/engine/output/katex-assets.mjs +0 -45
- package/template/core/engine/output/page-block.mjs +0 -30
- package/template/core/engine/output/pdf-media.mjs +0 -45
- package/template/core/engine/output/public-assets.mjs +0 -19
- package/template/core/engine/output/static-server.mjs +0 -571
- package/template/core/engine/react/caption-numbering.mjs +0 -73
- package/template/core/engine/react/comment-endpoint.d.mts +0 -11
- package/template/core/engine/react/comment-endpoint.mjs +0 -102
- package/template/core/engine/react/comment-marker.mjs +0 -374
- package/template/core/engine/react/document-entry.mjs +0 -331
- package/template/core/engine/react/document-export.mjs +0 -512
- package/template/core/engine/react/http-json.mjs +0 -24
- package/template/core/engine/react/mdx-compile.mjs +0 -629
- package/template/core/engine/react/measurement-css.mjs +0 -157
- package/template/core/engine/react/object-entities.mjs +0 -204
- package/template/core/engine/react/pagination/allocator.mjs +0 -167
- package/template/core/engine/react/pagination/regions.mjs +0 -81
- package/template/core/engine/react/pagination-constants.mjs +0 -3
- package/template/core/engine/react/pagination.mjs +0 -9
- package/template/core/engine/react/pipeline/allocate.mjs +0 -217
- package/template/core/engine/react/pipeline/final-render.mjs +0 -94
- package/template/core/engine/react/pipeline/frame-measurement.mjs +0 -306
- package/template/core/engine/react/pipeline/press-tree.mjs +0 -135
- package/template/core/engine/react/press-tree-inspection.mjs +0 -172
- package/template/core/engine/react/project-asset-endpoint.d.mts +0 -10
- package/template/core/engine/react/project-asset-endpoint.mjs +0 -361
- package/template/core/engine/react/section-css.mjs +0 -56
- package/template/core/engine/react/source-edit-endpoint.d.mts +0 -10
- package/template/core/engine/react/source-edit-endpoint.mjs +0 -75
- package/template/core/engine/react/sources/heading-numbering.mjs +0 -132
- package/template/core/engine/react/sources/mdx-resolver.mjs +0 -439
- package/template/core/engine/react/style-discovery.mjs +0 -160
- package/template/core/engine/runtime/config.d.mts +0 -48
- package/template/core/engine/runtime/config.mjs +0 -172
- package/template/core/engine/runtime/file-utils.mjs +0 -114
- package/template/core/engine/runtime/file-walk.mjs +0 -22
- package/template/core/engine/runtime/inspection.mjs +0 -328
- package/template/core/engine/runtime/issue-report.mjs +0 -44
- package/template/core/engine/runtime/page-geometry.mjs +0 -131
- package/template/core/engine/runtime/path-utils.mjs +0 -20
- package/template/core/engine/runtime/source-text-tools.d.mts +0 -102
- package/template/core/engine/runtime/source-text-tools.mjs +0 -832
- package/template/core/engine/runtime/source-workspace.mjs +0 -168
- package/template/core/engine/runtime/validation.mjs +0 -183
- package/template/core/index.html +0 -13
- package/template/core/openpress.config.mjs +0 -8
- package/template/core/package.json +0 -89
- package/template/core/src/main.tsx +0 -16
- package/template/core/src/openpress/app/OpenPressApp.tsx +0 -296
- package/template/core/src/openpress/app/OpenPressRuntime.tsx +0 -102
- package/template/core/src/openpress/app/WorkspaceGalleryPage.tsx +0 -219
- package/template/core/src/openpress/app/index.ts +0 -2
- package/template/core/src/openpress/core/Frame.tsx +0 -91
- package/template/core/src/openpress/core/FrameContext.tsx +0 -26
- package/template/core/src/openpress/core/MdxArea.tsx +0 -34
- package/template/core/src/openpress/core/Press.tsx +0 -55
- package/template/core/src/openpress/core/Workspace.tsx +0 -36
- package/template/core/src/openpress/core/cn.ts +0 -4
- package/template/core/src/openpress/core/index.tsx +0 -47
- package/template/core/src/openpress/core/primitives.tsx +0 -91
- package/template/core/src/openpress/core/types.ts +0 -236
- package/template/core/src/openpress/core/useSource.ts +0 -28
- package/template/core/src/openpress/document-model/anchorMapModel.ts +0 -27
- package/template/core/src/openpress/document-model/documentIndexes.ts +0 -329
- package/template/core/src/openpress/document-model/documentTypes.ts +0 -147
- package/template/core/src/openpress/document-model/index.ts +0 -7
- package/template/core/src/openpress/document-model/objectEntityModel.ts +0 -55
- package/template/core/src/openpress/document-model/projectIdentityModel.ts +0 -15
- package/template/core/src/openpress/document-model/reactDocumentMetadataModel.ts +0 -27
- package/template/core/src/openpress/document-model/workspaceManifestModel.ts +0 -57
- package/template/core/src/openpress/manuscript/index.tsx +0 -238
- package/template/core/src/openpress/mdx/index.ts +0 -96
- package/template/core/src/openpress/numbering/index.ts +0 -294
- package/template/core/src/openpress/reader/PageThumbnailsPanel.tsx +0 -168
- package/template/core/src/openpress/reader/PublicReaderPage.tsx +0 -267
- package/template/core/src/openpress/reader/ReaderNavigationPanel.tsx +0 -123
- package/template/core/src/openpress/reader/index.ts +0 -11
- package/template/core/src/openpress/reader/pageViewportScaleModel.ts +0 -73
- package/template/core/src/openpress/reader/readerPageRegistry.ts +0 -41
- package/template/core/src/openpress/reader/readerPageRoute.ts +0 -21
- package/template/core/src/openpress/reader/readerScroll.ts +0 -92
- package/template/core/src/openpress/reader/readerStateModel.ts +0 -15
- package/template/core/src/openpress/reader/readerTypes.ts +0 -4
- package/template/core/src/openpress/reader/usePageViewportScale.ts +0 -119
- package/template/core/src/openpress/reader/usePanelState.ts +0 -56
- package/template/core/src/openpress/reader/useReaderHashSync.ts +0 -61
- package/template/core/src/openpress/reader/useReaderKeyboardNav.ts +0 -48
- package/template/core/src/openpress/reader/useReaderRuntime.ts +0 -146
- package/template/core/src/openpress/reader/useReaderScrollAnchor.ts +0 -64
- package/template/core/src/openpress/shared/Panel.tsx +0 -77
- package/template/core/src/openpress/shared/frameScheduler.ts +0 -32
- package/template/core/src/openpress/shared/index.ts +0 -4
- package/template/core/src/openpress/shared/numberUtils.ts +0 -3
- package/template/core/src/openpress/shared/runtimeMode.ts +0 -11
- package/template/core/src/openpress/workbench/Workbench.tsx +0 -506
- package/template/core/src/openpress/workbench/actions/DeploymentControl.tsx +0 -157
- package/template/core/src/openpress/workbench/actions/ExportImageControl.tsx +0 -96
- package/template/core/src/openpress/workbench/actions/PageZoomControl.tsx +0 -182
- package/template/core/src/openpress/workbench/actions/SearchControl.tsx +0 -345
- package/template/core/src/openpress/workbench/actions/deploymentStatusModel.ts +0 -112
- package/template/core/src/openpress/workbench/actions/index.ts +0 -6
- package/template/core/src/openpress/workbench/actions/useDeploymentWorkbench.ts +0 -136
- package/template/core/src/openpress/workbench/dialog/WorkbenchDialog.tsx +0 -72
- package/template/core/src/openpress/workbench/dialog/index.ts +0 -1
- package/template/core/src/openpress/workbench/document/components/DocumentPanel.tsx +0 -127
- package/template/core/src/openpress/workbench/document/components/InlineSourceEditorLayer.tsx +0 -207
- package/template/core/src/openpress/workbench/document/components/ReaderStage.tsx +0 -9
- package/template/core/src/openpress/workbench/document/hooks/useDocumentWorkbenchModel.ts +0 -34
- package/template/core/src/openpress/workbench/document/hooks/useInlineDocumentEditor.ts +0 -525
- package/template/core/src/openpress/workbench/document/index.ts +0 -10
- package/template/core/src/openpress/workbench/index.ts +0 -2
- package/template/core/src/openpress/workbench/inspector/InlineInspectorLayer.tsx +0 -459
- package/template/core/src/openpress/workbench/inspector/index.ts +0 -5
- package/template/core/src/openpress/workbench/inspector/inlineCommentModel.ts +0 -125
- package/template/core/src/openpress/workbench/inspector/inspectorGeometryModel.ts +0 -160
- package/template/core/src/openpress/workbench/inspector/inspectorModel.ts +0 -408
- package/template/core/src/openpress/workbench/inspector/useInspectorComments.ts +0 -254
- package/template/core/src/openpress/workbench/mentions/MentionSuggestionList.tsx +0 -41
- package/template/core/src/openpress/workbench/mentions/index.ts +0 -2
- package/template/core/src/openpress/workbench/mentions/useComposerMentions.ts +0 -185
- package/template/core/src/openpress/workbench/panels/Panel.tsx +0 -1
- package/template/core/src/openpress/workbench/panels/PendingCommentsPanel.tsx +0 -80
- package/template/core/src/openpress/workbench/panels/WorkbenchControlPanel.tsx +0 -29
- package/template/core/src/openpress/workbench/panels/index.ts +0 -3
- package/template/core/src/openpress/workbench/project/ProjectEntryPanel.tsx +0 -525
- package/template/core/src/openpress/workbench/project/ProjectPreviewDialog.tsx +0 -35
- package/template/core/src/openpress/workbench/project/index.ts +0 -2
- package/template/core/src/openpress/workbench/project/projectPreviewTypes.ts +0 -11
- package/template/core/src/openpress/workbench/project/projectSourceModel.ts +0 -24
- package/template/core/src/openpress/workbench/shell/WorkbenchShell.tsx +0 -167
- package/template/core/src/openpress/workbench/shell/index.ts +0 -1
- package/template/core/src/openpress/workbench/workbenchFormatters.ts +0 -120
- package/template/core/src/openpress/workbench/workbenchTypes.ts +0 -35
- package/template/core/src/styles/openpress/app-shell.css +0 -251
- package/template/core/src/styles/openpress/media-workspace.css +0 -230
- package/template/core/src/styles/openpress/print-route.css +0 -184
- package/template/core/src/styles/openpress/project-preview-panel.css +0 -924
- package/template/core/src/styles/openpress/public-viewer.css +0 -688
- package/template/core/src/styles/openpress/reader-runtime.css +0 -989
- package/template/core/src/styles/openpress/responsive.css +0 -245
- package/template/core/src/styles/openpress/workbench-panels.css +0 -707
- package/template/core/src/styles/openpress/workbench.css +0 -1255
- package/template/core/src/styles/openpress/workspace-gallery.css +0 -300
- package/template/core/src/styles/openpress.css +0 -15
- package/template/core/src/vite-env.d.ts +0 -9
- package/template/core/tsconfig.json +0 -40
- package/template/core/vite.config.ts +0 -584
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { loadReactDocumentEntry } from "../react/document-entry.mjs";
|
|
4
|
-
import { walkFiles } from "./file-walk.mjs";
|
|
5
|
-
import { resolveDocumentRelativePath, rootRelativePath } from "./path-utils.mjs";
|
|
6
|
-
|
|
7
|
-
export { rootRelativePath };
|
|
8
|
-
|
|
9
|
-
export const REACT_MDX_CONTENT_EXTENSIONS = new Set([".mdx"]);
|
|
10
|
-
|
|
11
|
-
export async function resolveActiveSourceWorkspace(config) {
|
|
12
|
-
const reactEntry = await loadReactDocumentEntry(config.root);
|
|
13
|
-
if (!reactEntry) {
|
|
14
|
-
throw new Error(
|
|
15
|
-
"React/MDX document entry not found. Expected press/index.tsx with a Press default export before using workspace source tools.",
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
// Aggregate sources across every Press in the Workspace. Workspace
|
|
19
|
-
// tooling (validate, search, replace, inspect) walks the union — a
|
|
20
|
-
// multi-Press project's sources all live under the same press/ tree.
|
|
21
|
-
const aggregateSources = {};
|
|
22
|
-
for (const press of reactEntry.presses ?? []) {
|
|
23
|
-
if (press.sources && typeof press.sources === "object") {
|
|
24
|
-
Object.assign(aggregateSources, press.sources);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
const contentRoots = contentRootsFromSources(aggregateSources, reactEntry.config);
|
|
28
|
-
const sourceDir = firstDirectoryRoot(contentRoots) ?? reactEntry.config.paths.documentRoot;
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
kind: "react-mdx",
|
|
32
|
-
checkedName: "react-source",
|
|
33
|
-
config: reactEntry.config,
|
|
34
|
-
entryPath: reactEntry.entryPath,
|
|
35
|
-
sourceDir,
|
|
36
|
-
contentRoots,
|
|
37
|
-
contentExtensions: REACT_MDX_CONTENT_EXTENSIONS,
|
|
38
|
-
contentLabel: "React MDX chapter source",
|
|
39
|
-
missingCode: "react-source.missing",
|
|
40
|
-
emptyCode: "react-source.empty",
|
|
41
|
-
missingMessage: "Registered React MDX sources do not exist yet; create the files or roots declared in press/index.tsx `sources` before running export.",
|
|
42
|
-
emptyMessage: "Registered React MDX sources contain no `*.mdx` files; the document will export with zero source blocks.",
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export async function collectActiveContentFiles(sourceWorkspace, { skipUnderscoreFiles = false } = {}) {
|
|
47
|
-
const files = [];
|
|
48
|
-
const seen = new Set();
|
|
49
|
-
for (const root of sourceWorkspace.contentRoots ?? [{ kind: "dir", absolutePath: sourceWorkspace.sourceDir }]) {
|
|
50
|
-
const visit = async (absolutePath) => {
|
|
51
|
-
if (seen.has(absolutePath)) return;
|
|
52
|
-
if (!sourceWorkspace.contentExtensions.has(path.extname(absolutePath))) return;
|
|
53
|
-
const name = path.basename(absolutePath);
|
|
54
|
-
if (skipUnderscoreFiles && name.startsWith("_")) return;
|
|
55
|
-
seen.add(absolutePath);
|
|
56
|
-
files.push({
|
|
57
|
-
absolutePath,
|
|
58
|
-
name,
|
|
59
|
-
relativePath: rootRelativePath(sourceWorkspace.config, absolutePath),
|
|
60
|
-
sourceRelativePath: path.relative(root.basePath ?? path.dirname(absolutePath), absolutePath).replaceAll("\\", "/"),
|
|
61
|
-
text: await fs.readFile(absolutePath, "utf8"),
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
if (root.kind === "file") {
|
|
65
|
-
try {
|
|
66
|
-
const stat = await fs.stat(root.absolutePath);
|
|
67
|
-
if (stat.isFile()) await visit(root.absolutePath);
|
|
68
|
-
} catch (error) {
|
|
69
|
-
if (error?.code !== "ENOENT") throw error;
|
|
70
|
-
}
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
await walkFiles(root.absolutePath, visit);
|
|
74
|
-
}
|
|
75
|
-
files.sort((a, b) => a.relativePath.localeCompare(b.relativePath));
|
|
76
|
-
return files;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export async function sourceDirectoryExists(sourceWorkspace) {
|
|
80
|
-
const roots = sourceWorkspace.contentRoots ?? [{ kind: "dir", absolutePath: sourceWorkspace.sourceDir }];
|
|
81
|
-
for (const root of roots) {
|
|
82
|
-
try {
|
|
83
|
-
const stat = await fs.stat(root.absolutePath);
|
|
84
|
-
if (root.kind === "file" ? stat.isFile() : stat.isDirectory()) return true;
|
|
85
|
-
} catch (error) {
|
|
86
|
-
if (error?.code === "ENOENT") continue;
|
|
87
|
-
throw error;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function contentRootsFromSources(sources, config) {
|
|
94
|
-
const entries = Object.entries(sources ?? {});
|
|
95
|
-
if (entries.length === 0) {
|
|
96
|
-
return [{
|
|
97
|
-
kind: "dir",
|
|
98
|
-
absolutePath: config.paths.sourceDir,
|
|
99
|
-
basePath: config.paths.sourceDir,
|
|
100
|
-
sourceId: "default",
|
|
101
|
-
preset: "section-folders",
|
|
102
|
-
}];
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const roots = [];
|
|
106
|
-
for (const [sourceId, descriptor] of entries) {
|
|
107
|
-
if (!descriptor || descriptor.type !== "mdx") continue;
|
|
108
|
-
if (descriptor.preset === "section-folders") {
|
|
109
|
-
roots.push(directoryRoot(config, descriptor.root ?? "chapters", sourceId, descriptor.preset));
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
if (descriptor.preset === "section-files") {
|
|
113
|
-
roots.push(directoryRoot(config, descriptor.root ?? "content", sourceId, descriptor.preset));
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
if (descriptor.preset === "file-list") {
|
|
117
|
-
for (const file of descriptor.files ?? []) {
|
|
118
|
-
roots.push(fileRoot(config, file, sourceId, descriptor.preset));
|
|
119
|
-
}
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return dedupeRoots(roots);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function directoryRoot(config, rel, sourceId, preset) {
|
|
127
|
-
const absolutePath = resolveDocumentRelativePath(config.paths.documentRoot, rel, `Source "${sourceId}" ${preset} root`);
|
|
128
|
-
return {
|
|
129
|
-
kind: "dir",
|
|
130
|
-
absolutePath,
|
|
131
|
-
basePath: absolutePath,
|
|
132
|
-
sourceId,
|
|
133
|
-
preset,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function fileRoot(config, rel, sourceId, preset) {
|
|
138
|
-
if (typeof rel !== "string" || !rel.trim()) {
|
|
139
|
-
throw new Error(`Source "${sourceId}" file-list contains an empty or invalid entry.`);
|
|
140
|
-
}
|
|
141
|
-
if (!rel.endsWith(".mdx")) {
|
|
142
|
-
throw new Error(`Source "${sourceId}" file-list path "${rel}" must end with .mdx.`);
|
|
143
|
-
}
|
|
144
|
-
const absolutePath = resolveDocumentRelativePath(config.paths.documentRoot, rel, `Source "${sourceId}" file-list path "${rel}"`);
|
|
145
|
-
return {
|
|
146
|
-
kind: "file",
|
|
147
|
-
absolutePath,
|
|
148
|
-
basePath: path.dirname(absolutePath),
|
|
149
|
-
sourceId,
|
|
150
|
-
preset,
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function dedupeRoots(roots) {
|
|
155
|
-
const seen = new Set();
|
|
156
|
-
const out = [];
|
|
157
|
-
for (const root of roots) {
|
|
158
|
-
const key = `${root.kind}:${root.absolutePath}`;
|
|
159
|
-
if (seen.has(key)) continue;
|
|
160
|
-
seen.add(key);
|
|
161
|
-
out.push(root);
|
|
162
|
-
}
|
|
163
|
-
return out;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function firstDirectoryRoot(roots) {
|
|
167
|
-
return roots.find((root) => root.kind === "dir")?.absolutePath ?? null;
|
|
168
|
-
}
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { loadConfig } from "./config.mjs";
|
|
4
|
-
import { createIssue, createIssueReport } from "./issue-report.mjs";
|
|
5
|
-
import { collectSourceTextFiles } from "./source-text-tools.mjs";
|
|
6
|
-
import { collectActiveContentFiles, resolveActiveSourceWorkspace, sourceDirectoryExists } from "./source-workspace.mjs";
|
|
7
|
-
|
|
8
|
-
// Adapters that publish the document to a URL anyone on the internet can reach.
|
|
9
|
-
// `deploy.requiresConfirmation: true` is mandatory for these so an automated
|
|
10
|
-
// pipeline (or a careless command) cannot ship without an explicit human step.
|
|
11
|
-
// Adapters not in this set (local file copy, custom in-house tooling, null)
|
|
12
|
-
// can opt out of the confirmation gate.
|
|
13
|
-
const PUBLIC_DEPLOY_ADAPTERS = new Set([
|
|
14
|
-
"cloudflare-pages",
|
|
15
|
-
"github-pages",
|
|
16
|
-
"netlify",
|
|
17
|
-
"vercel",
|
|
18
|
-
]);
|
|
19
|
-
|
|
20
|
-
// A directory is an OpenPress workspace if it contains a
|
|
21
|
-
// press/index.tsx entry, or a package.json with an "openpress" field.
|
|
22
|
-
async function isWorkspaceRoot(dir) {
|
|
23
|
-
try {
|
|
24
|
-
await fs.access(path.join(dir, "press", "index.tsx"));
|
|
25
|
-
return true;
|
|
26
|
-
} catch {}
|
|
27
|
-
try {
|
|
28
|
-
const pkg = JSON.parse(await fs.readFile(path.join(dir, "package.json"), "utf8"));
|
|
29
|
-
if (pkg?.openpress && typeof pkg.openpress === "object") return true;
|
|
30
|
-
} catch {}
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export async function discoverWorkspace(startPath = ".") {
|
|
35
|
-
let current = path.resolve(startPath);
|
|
36
|
-
try {
|
|
37
|
-
const stat = await fs.stat(current);
|
|
38
|
-
if (!stat.isDirectory()) current = path.dirname(current);
|
|
39
|
-
} catch {
|
|
40
|
-
current = path.dirname(current);
|
|
41
|
-
}
|
|
42
|
-
while (true) {
|
|
43
|
-
if (await isWorkspaceRoot(current)) return current;
|
|
44
|
-
const parent = path.dirname(current);
|
|
45
|
-
if (parent === current) throw new Error(`No OpenPress workspace found from ${startPath}`);
|
|
46
|
-
current = parent;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export async function validateWorkspace(root) {
|
|
51
|
-
const config = await loadConfig(root);
|
|
52
|
-
const sourceWorkspace = await resolveActiveSourceWorkspace(config);
|
|
53
|
-
const activeConfig = sourceWorkspace.config;
|
|
54
|
-
const issues = [];
|
|
55
|
-
const checked = [];
|
|
56
|
-
const mark = (name) => {
|
|
57
|
-
if (!checked.includes(name)) checked.push(name);
|
|
58
|
-
};
|
|
59
|
-
const add = (level, code, message, filePath = null, detail = undefined) => issues.push(createIssue({ level, code, message, path: filePath, detail }));
|
|
60
|
-
|
|
61
|
-
mark("config");
|
|
62
|
-
for (const [key, target] of [
|
|
63
|
-
["sourceDir", sourceWorkspace.sourceDir],
|
|
64
|
-
["mediaDir", activeConfig.paths.mediaDir],
|
|
65
|
-
["themeDir", activeConfig.paths.themeDir],
|
|
66
|
-
["designDoc", activeConfig.paths.designDoc],
|
|
67
|
-
["componentsDir", activeConfig.paths.componentsDir],
|
|
68
|
-
]) {
|
|
69
|
-
if (!(await exists(target))) add("error", `config.${key}`, `Configured OpenPress path \`${key}\` does not exist.`, target);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
mark("design-doc");
|
|
73
|
-
const designDoc = activeConfig.paths.designDoc;
|
|
74
|
-
if (!(await exists(designDoc))) {
|
|
75
|
-
add("error", "design-doc.missing", "Design document must exist.", designDoc);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
mark("deploy-gate");
|
|
79
|
-
if (PUBLIC_DEPLOY_ADAPTERS.has(config.deploy.adapter) && config.deploy.requiresConfirmation !== true) {
|
|
80
|
-
add(
|
|
81
|
-
"error",
|
|
82
|
-
"deploy.confirmation",
|
|
83
|
-
`Public deploy adapter \`${config.deploy.adapter}\` must require user confirmation (set deploy.requiresConfirmation: true).`,
|
|
84
|
-
config.configPath,
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
mark(sourceWorkspace.checkedName);
|
|
89
|
-
if (!(typeof activeConfig.title === "string" && activeConfig.title.trim())) {
|
|
90
|
-
add("warning", "press.title", "<Press title> is missing in press/index.tsx; the workbench will show the default placeholder.", activeConfig.configPath);
|
|
91
|
-
}
|
|
92
|
-
if (!(await sourceDirectoryExists(sourceWorkspace))) {
|
|
93
|
-
add("warning", sourceWorkspace.missingCode, sourceWorkspace.missingMessage, sourceWorkspace.sourceDir);
|
|
94
|
-
} else {
|
|
95
|
-
const contentFiles = await collectActiveContentFiles(sourceWorkspace, { skipUnderscoreFiles: true });
|
|
96
|
-
if (contentFiles.length === 0) {
|
|
97
|
-
add("warning", sourceWorkspace.emptyCode, sourceWorkspace.emptyMessage, sourceWorkspace.sourceDir);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (sourceWorkspace.kind === "react-mdx") {
|
|
102
|
-
mark("react-comments");
|
|
103
|
-
const sourceFiles = await collectSourceTextFiles(activeConfig, { scope: "all" });
|
|
104
|
-
for (const file of sourceFiles) {
|
|
105
|
-
for (const marker of findCommentMarkers(file.text)) {
|
|
106
|
-
add(
|
|
107
|
-
"warning",
|
|
108
|
-
"react-comments.pending",
|
|
109
|
-
`Pending OpenPress comment \`${marker.id}\` remains in React source; run apply-comments or resolve it manually before publishing.`,
|
|
110
|
-
file.absolutePath,
|
|
111
|
-
{
|
|
112
|
-
id: marker.id,
|
|
113
|
-
line: marker.line,
|
|
114
|
-
path: file.path ?? file.relativePath,
|
|
115
|
-
},
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
mark("react-source");
|
|
122
|
-
const documentJsonPath = path.join(activeConfig.paths.publicDir, "document.json");
|
|
123
|
-
const exportedDocument = await readJsonIfExists(documentJsonPath);
|
|
124
|
-
const pressWarnings = exportedDocument?.source?.warnings;
|
|
125
|
-
if (Array.isArray(pressWarnings)) {
|
|
126
|
-
for (const warning of pressWarnings) {
|
|
127
|
-
const code = typeof warning?.code === "string" && warning.code ? warning.code : "warning";
|
|
128
|
-
add(
|
|
129
|
-
"warning",
|
|
130
|
-
`react-source.${code}`,
|
|
131
|
-
pressWarningMessage(warning),
|
|
132
|
-
documentJsonPath,
|
|
133
|
-
warning,
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return createIssueReport({
|
|
139
|
-
kind: "validation",
|
|
140
|
-
checked,
|
|
141
|
-
issues,
|
|
142
|
-
okMessage: "OpenPress validation OK",
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function findCommentMarkers(text) {
|
|
147
|
-
const markers = [];
|
|
148
|
-
const lines = String(text ?? "").split(/\r?\n/);
|
|
149
|
-
for (const [index, line] of lines.entries()) {
|
|
150
|
-
const match = line.match(/@openpress-comment\b[^}]*\bid="([^"]+)"/);
|
|
151
|
-
if (!match) continue;
|
|
152
|
-
markers.push({ id: match[1], line: index + 1 });
|
|
153
|
-
}
|
|
154
|
-
return markers;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function pressWarningMessage(warning) {
|
|
158
|
-
if (warning?.code === "chain-overflowed") {
|
|
159
|
-
return `Content chain \`${warning.chainId ?? "(unknown)"}\` overflowed during Press Tree allocation.`;
|
|
160
|
-
}
|
|
161
|
-
if (warning?.code === "chain-has-no-area") {
|
|
162
|
-
return `Content chain \`${warning.chainId ?? "(unknown)"}\` has blocks but no matching MdxArea.`;
|
|
163
|
-
}
|
|
164
|
-
return `Press Tree export warning: ${warning?.code ?? "warning"}.`;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
async function readJsonIfExists(filePath) {
|
|
168
|
-
try {
|
|
169
|
-
return JSON.parse(await fs.readFile(filePath, "utf8"));
|
|
170
|
-
} catch (error) {
|
|
171
|
-
if (error?.code === "ENOENT") return null;
|
|
172
|
-
throw error;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
async function exists(filePath) {
|
|
177
|
-
try {
|
|
178
|
-
await fs.access(filePath);
|
|
179
|
-
return true;
|
|
180
|
-
} catch {
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
}
|
package/template/core/index.html
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="zh-Hant">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
-
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
|
|
7
|
-
<title>OpenPress Workspace</title>
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<div id="root"></div>
|
|
11
|
-
<script type="module" src="/src/main.tsx"></script>
|
|
12
|
-
</body>
|
|
13
|
-
</html>
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// Legacy root pointer kept for older local workspaces. Current OpenPress
|
|
2
|
-
// workspaces use package.json "openpress" config plus a press/ source tree.
|
|
3
|
-
// Starter files are supplied by skills, not fetched by the core engine.
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
documentDir: "document",
|
|
7
|
-
config: "document/openpress.config.mjs",
|
|
8
|
-
};
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@open-press/core",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "open-press core — runtime primitives, CLI, and render pipeline for AI-first fixed-layout documents.",
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"author": "quan0715",
|
|
8
|
-
"homepage": "https://github.com/quan0715/open-press#readme",
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/quan0715/open-press.git",
|
|
12
|
-
"directory": "packages/core"
|
|
13
|
-
},
|
|
14
|
-
"bugs": {
|
|
15
|
-
"url": "https://github.com/quan0715/open-press/issues"
|
|
16
|
-
},
|
|
17
|
-
"keywords": [
|
|
18
|
-
"document",
|
|
19
|
-
"mdx",
|
|
20
|
-
"react",
|
|
21
|
-
"pdf",
|
|
22
|
-
"a4",
|
|
23
|
-
"fixed-layout",
|
|
24
|
-
"ai-first"
|
|
25
|
-
],
|
|
26
|
-
"main": "./src/openpress/core/index.tsx",
|
|
27
|
-
"types": "./src/openpress/core/index.tsx",
|
|
28
|
-
"exports": {
|
|
29
|
-
".": "./src/openpress/core/index.tsx",
|
|
30
|
-
"./mdx": "./src/openpress/mdx/index.ts",
|
|
31
|
-
"./manuscript": "./src/openpress/manuscript/index.tsx",
|
|
32
|
-
"./numbering": "./src/openpress/numbering/index.ts"
|
|
33
|
-
},
|
|
34
|
-
"bin": {
|
|
35
|
-
"open-press": "engine/cli.mjs"
|
|
36
|
-
},
|
|
37
|
-
"files": [
|
|
38
|
-
"engine",
|
|
39
|
-
"src/openpress",
|
|
40
|
-
"src/styles",
|
|
41
|
-
"index.html",
|
|
42
|
-
"vite.config.ts",
|
|
43
|
-
"tsconfig.json"
|
|
44
|
-
],
|
|
45
|
-
"publishConfig": {
|
|
46
|
-
"access": "public"
|
|
47
|
-
},
|
|
48
|
-
"scripts": {
|
|
49
|
-
"dev": "node engine/cli.mjs dev . --renderer react",
|
|
50
|
-
"build": "node engine/cli.mjs render . --renderer react",
|
|
51
|
-
"preview": "node engine/cli.mjs preview . --renderer react",
|
|
52
|
-
"typecheck": "node engine/cli.mjs typecheck .",
|
|
53
|
-
"test": "pnpm run test:node && pnpm run test:react",
|
|
54
|
-
"test:e2e:reader": "playwright test --config playwright.reader.config.ts",
|
|
55
|
-
"test:node": "node --test tests/*.test.mjs",
|
|
56
|
-
"test:react": "vitest run",
|
|
57
|
-
"openpress:image": "node engine/cli.mjs image .",
|
|
58
|
-
"openpress:pdf": "node engine/cli.mjs pdf .",
|
|
59
|
-
"openpress:deploy": "node engine/cli.mjs deploy .",
|
|
60
|
-
"openpress:deploy:dry-run": "node engine/cli.mjs deploy . --confirm --dry-run"
|
|
61
|
-
},
|
|
62
|
-
"dependencies": {
|
|
63
|
-
"@mdx-js/mdx": "^3.1.1",
|
|
64
|
-
"@mdx-js/react": "^3.1.1",
|
|
65
|
-
"html-to-image": "^1.11.13",
|
|
66
|
-
"js-yaml": "^4.1.1",
|
|
67
|
-
"katex": "^0.16.47",
|
|
68
|
-
"lucide-react": "^1.16.0",
|
|
69
|
-
"playwright": "^1.60.0",
|
|
70
|
-
"postcss": "^8.5.6",
|
|
71
|
-
"react": "^19.2.6",
|
|
72
|
-
"react-dom": "^19.2.6",
|
|
73
|
-
"rehype-katex": "^7.0.1",
|
|
74
|
-
"remark-gfm": "^4.0.1",
|
|
75
|
-
"remark-math": "^6.0.0"
|
|
76
|
-
},
|
|
77
|
-
"devDependencies": {
|
|
78
|
-
"@playwright/test": "^1.60.0",
|
|
79
|
-
"@testing-library/react": "^16.3.2",
|
|
80
|
-
"@types/node": "^25.8.0",
|
|
81
|
-
"@types/react": "^19.2.14",
|
|
82
|
-
"@types/react-dom": "^19.2.3",
|
|
83
|
-
"@vitejs/plugin-react": "^6.0.2",
|
|
84
|
-
"jsdom": "^26.1.0",
|
|
85
|
-
"typescript": "^6.0.3",
|
|
86
|
-
"vite": "^8.0.13",
|
|
87
|
-
"vitest": "^4.1.6"
|
|
88
|
-
}
|
|
89
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { StrictMode } from "react";
|
|
2
|
-
import { createRoot } from "react-dom/client";
|
|
3
|
-
import { OpenPressApp } from "./openpress/app";
|
|
4
|
-
import "./styles/openpress.css";
|
|
5
|
-
|
|
6
|
-
const rootElement = document.getElementById("root");
|
|
7
|
-
|
|
8
|
-
if (!rootElement) {
|
|
9
|
-
throw new Error("OpenPress renderer requires a #root element.");
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
createRoot(rootElement).render(
|
|
13
|
-
<StrictMode>
|
|
14
|
-
<OpenPressApp />
|
|
15
|
-
</StrictMode>,
|
|
16
|
-
);
|