@contentbit/studio 0.5.0 → 0.6.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/dist/client/assets/api-DA8X6vBb.js +1 -0
- package/dist/client/assets/document-BJw10sM7.js +65 -0
- package/dist/client/assets/{index-DTXIZgkK.js → index-WzJZ-6CK.js} +2 -2
- package/dist/client/assets/routes-BWt7eK2V.js +1 -0
- package/dist/client/assets/styles-DogO4Wcf.css +2 -0
- package/dist/server/assets/{_tanstack-start-manifest_v-wPlN1Hjy.js → _tanstack-start-manifest_v-DyPYRepF.js} +4 -4
- package/dist/server/assets/{document-DjmCb_Rp.js → document-BB_UYqNL.js} +1 -1
- package/dist/server/assets/document-DSV89Ser.js +4704 -0
- package/dist/server/assets/{router-D4DnWGjU.js → router-BJiN6b7L.js} +3 -3
- package/dist/server/assets/{routes-BVJt9Z6a.js → routes-FGdym0e5.js} +28 -4
- package/dist/server/assets/{routes-6jOjWQ0D.js → routes-p0tk6PAr.js} +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +475 -124
- package/dist/server/scan.d.ts.map +1 -1
- package/dist/server/server.js +2 -2
- package/dist/server/types.d.ts +20 -2
- package/dist/server/types.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/routes/document.tsx +272 -1
- package/src/routes/index.tsx +21 -1
- package/src/server/index.ts +2 -0
- package/src/server/scan.test.ts +157 -1
- package/src/server/scan.ts +65 -131
- package/src/server/types.ts +20 -2
- package/dist/client/assets/api-MWiK2l_P.js +0 -1
- package/dist/client/assets/document-w62o-wDp.js +0 -1
- package/dist/client/assets/routes-Dg9spe-7.js +0 -1
- package/dist/client/assets/styles-DxZJz8Oi.css +0 -2
- package/dist/server/api.js +0 -47
- package/dist/server/assets/document-CxPFBdxd.js +0 -265
- package/dist/server/preview.js +0 -19
- package/dist/server/scan.js +0 -274
- package/dist/server/types.js +0 -1
package/dist/server/index.js
CHANGED
|
@@ -1,136 +1,487 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
1
|
+
// src/server/index.ts
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { dirname, isAbsolute as isAbsolute2, join as join2, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { createServer, searchForWorkspaceRoot } from "vite";
|
|
7
|
+
|
|
8
|
+
// src/server/scan.ts
|
|
9
|
+
import {
|
|
10
|
+
compareContentProjectFindings,
|
|
11
|
+
createLinkGraphView,
|
|
12
|
+
createSeoBrief,
|
|
13
|
+
readContentPageFacts,
|
|
14
|
+
summarizeContentProjectFindings
|
|
15
|
+
} from "@contentbit/core";
|
|
16
|
+
|
|
17
|
+
// ../project/dist/index.js
|
|
18
|
+
import { genericBlocks } from "@contentbit/blocks";
|
|
19
|
+
import { createBlockRegistry, scanContentProject } from "@contentbit/core";
|
|
20
|
+
import { readFile } from "node:fs/promises";
|
|
21
|
+
import { isAbsolute, join } from "node:path";
|
|
22
|
+
import { pathToFileURL } from "node:url";
|
|
23
|
+
import { glob } from "tinyglobby";
|
|
24
|
+
var ProjectLoadError = class extends Error {
|
|
25
|
+
exitCode;
|
|
26
|
+
constructor(exitCode, message) {
|
|
27
|
+
super(message);
|
|
28
|
+
this.exitCode = exitCode;
|
|
29
|
+
this.name = "ProjectLoadError";
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
async function resolveContentFiles(positionals, cmd, options = {}) {
|
|
33
|
+
if (positionals.length === 0) {
|
|
34
|
+
if (options.allowEmpty)
|
|
35
|
+
return [];
|
|
36
|
+
throw new ProjectLoadError(2, `${cmd}: provide at least one file or glob.`);
|
|
37
|
+
}
|
|
38
|
+
const files = (await glob(positionals, { absolute: true, cwd: options.cwd })).sort();
|
|
39
|
+
if (files.length === 0) {
|
|
40
|
+
if (options.allowEmpty)
|
|
41
|
+
return [];
|
|
42
|
+
throw new ProjectLoadError(2, `${cmd}: no files matched ${positionals.join(" ")}`);
|
|
43
|
+
}
|
|
44
|
+
return files;
|
|
45
|
+
}
|
|
46
|
+
async function loadRegistry(registryPath, options = {}) {
|
|
47
|
+
const registry = createBlockRegistry();
|
|
48
|
+
if (options.includeGenericBlocks !== false)
|
|
49
|
+
registry.use(genericBlocks());
|
|
50
|
+
if (!registryPath)
|
|
51
|
+
return registry;
|
|
52
|
+
const resolvedPath = isAbsolute(registryPath) ? registryPath : join(options.cwd ?? process.cwd(), registryPath);
|
|
53
|
+
let mod;
|
|
54
|
+
try {
|
|
55
|
+
mod = await import(pathToFileURL(resolvedPath).href);
|
|
56
|
+
} catch (err) {
|
|
57
|
+
if (err instanceof Error && "code" in err && err.code === "ERR_UNKNOWN_FILE_EXTENSION") {
|
|
58
|
+
throw new Error(`Importing a TypeScript registry needs Node 22.18+ (native type stripping): ${resolvedPath}`);
|
|
59
|
+
}
|
|
60
|
+
throw err;
|
|
61
|
+
}
|
|
62
|
+
if (!Array.isArray(mod.default)) {
|
|
63
|
+
throw new Error(`--registry module must default-export an array of block definitions: ${resolvedPath}`);
|
|
64
|
+
}
|
|
65
|
+
registry.use(mod.default);
|
|
66
|
+
return registry;
|
|
67
|
+
}
|
|
68
|
+
async function loadContentProject(input) {
|
|
69
|
+
const files = await resolveContentFiles(input.positionals, input.cmd, {
|
|
70
|
+
cwd: input.cwd,
|
|
71
|
+
allowEmpty: input.allowEmpty
|
|
72
|
+
});
|
|
73
|
+
const registry = await loadRegistry(input.registry, {
|
|
74
|
+
cwd: input.cwd,
|
|
75
|
+
includeGenericBlocks: input.includeGenericBlocks
|
|
76
|
+
});
|
|
77
|
+
const sources = await Promise.all(files.map(async (path) => ({ path, source: await readFile(path, "utf8") })));
|
|
78
|
+
const linkOptions = input.linkOptions ?? {};
|
|
79
|
+
const scan = scanContentProject(sources, registry, {
|
|
80
|
+
linkOptions,
|
|
81
|
+
...input.scan
|
|
82
|
+
});
|
|
83
|
+
return { files, registry, sources, linkOptions, scan };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/server/scan.ts
|
|
87
|
+
import { basename, relative } from "node:path";
|
|
88
|
+
|
|
89
|
+
// src/server/preview.ts
|
|
90
|
+
import { ContentBlocks } from "@contentbit/react";
|
|
91
|
+
import { createElement } from "react";
|
|
92
|
+
import { renderToStaticMarkup } from "react-dom/server";
|
|
93
|
+
import ReactMarkdown from "react-markdown";
|
|
94
|
+
import remarkGfm from "remark-gfm";
|
|
95
|
+
function renderStudioPreview(document, components = {}, _options = {}) {
|
|
96
|
+
return renderToStaticMarkup(
|
|
97
|
+
createElement(ContentBlocks, {
|
|
98
|
+
document,
|
|
99
|
+
components,
|
|
100
|
+
renderMarkdown,
|
|
101
|
+
fallback: CustomBlockFallback
|
|
102
|
+
})
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
function renderMarkdown(markdown) {
|
|
106
|
+
return createElement(ReactMarkdown, { remarkPlugins: [remarkGfm] }, markdown);
|
|
107
|
+
}
|
|
108
|
+
var CustomBlockFallback = ({ name, body }) => createElement(
|
|
109
|
+
"section",
|
|
110
|
+
{ className: "cb-custom-block", "data-cb-custom": name },
|
|
111
|
+
createElement("div", { className: "cb-custom-block-label" }, name),
|
|
112
|
+
createElement(
|
|
113
|
+
"div",
|
|
114
|
+
{ className: "cb-custom-block-body" },
|
|
115
|
+
body.trim().length > 0 ? renderMarkdown(body) : createElement("p", null, "No preview component for this custom block yet.")
|
|
116
|
+
)
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
// src/server/scan.ts
|
|
120
|
+
async function scanProject(options) {
|
|
121
|
+
const context = await scanContext(options);
|
|
122
|
+
const blockUsage = {};
|
|
123
|
+
let words = 0;
|
|
124
|
+
let blocks = 0;
|
|
125
|
+
let links = 0;
|
|
126
|
+
let missingAlt = 0;
|
|
127
|
+
let withPrimary = 0;
|
|
128
|
+
let withSecondary = 0;
|
|
129
|
+
for (const file of context.summaries) {
|
|
130
|
+
words += file.words;
|
|
131
|
+
blocks += file.blocks;
|
|
132
|
+
links += file.links;
|
|
133
|
+
missingAlt += file.missingAlt;
|
|
134
|
+
if (file.keywords?.primary) withPrimary++;
|
|
135
|
+
if ((file.keywords?.secondary?.length ?? 0) > 0) withSecondary++;
|
|
136
|
+
for (const [name, count] of Object.entries(file.blockNames)) {
|
|
137
|
+
blockUsage[name] = (blockUsage[name] ?? 0) + count;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const summary = summarize(context.findings);
|
|
141
|
+
return {
|
|
142
|
+
root: options.cwd ?? process.cwd(),
|
|
143
|
+
files: context.summaries,
|
|
144
|
+
summary: {
|
|
145
|
+
files: context.summaries.length,
|
|
146
|
+
errors: summary.errors,
|
|
147
|
+
warnings: summary.warnings,
|
|
148
|
+
suggestions: summary.suggestions,
|
|
149
|
+
words,
|
|
150
|
+
blocks,
|
|
151
|
+
links,
|
|
152
|
+
missingAlt
|
|
153
|
+
},
|
|
154
|
+
blockUsage,
|
|
155
|
+
keywordCoverage: {
|
|
156
|
+
total: context.summaries.length,
|
|
157
|
+
withPrimary,
|
|
158
|
+
withSecondary
|
|
159
|
+
},
|
|
160
|
+
...context.scan.linkGraph ? { linkGraph: context.scan.linkGraph } : {},
|
|
161
|
+
...context.scan.seo ? {
|
|
162
|
+
seo: {
|
|
163
|
+
schemaVersion: context.scan.seo.schemaVersion,
|
|
164
|
+
pages: context.scan.seo.pages.length,
|
|
165
|
+
existing: context.scan.seo.pages.filter((page) => page.source === "existing").length,
|
|
166
|
+
planned: context.scan.seo.pages.filter((page) => page.source === "planned").length,
|
|
167
|
+
findings: context.scan.seo.findings.length
|
|
168
|
+
}
|
|
169
|
+
} : {},
|
|
170
|
+
findings: context.findings
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
async function scanDocument(options, requestedPath) {
|
|
174
|
+
const context = await scanContext(options);
|
|
175
|
+
const file = findAllowedFile(context, options.cwd ?? process.cwd(), requestedPath);
|
|
176
|
+
if (!file) return null;
|
|
177
|
+
const scanned = context.scan.files.find((item) => item.path === file);
|
|
178
|
+
if (!scanned) return null;
|
|
179
|
+
const summary = context.summaries.find((item) => item.path === file);
|
|
180
|
+
if (!summary) return null;
|
|
181
|
+
const previewHtml = renderStudioPreview(
|
|
182
|
+
scanned.validation.document,
|
|
183
|
+
await options.previewComponents?.() ?? {},
|
|
184
|
+
{ includeGenericComponents: options.includeGenericBlocks !== false }
|
|
185
|
+
);
|
|
186
|
+
const page = context.index ? [...context.index.pages.values()].find((entry) => entry.path === file) : void 0;
|
|
187
|
+
const seoPage = context.scan.seo?.pages.find((entry) => entry.path === file);
|
|
188
|
+
const seoBrief = context.scan.seo && seoPage ? createSeoBrief(context.scan.seo, seoPage.id) : void 0;
|
|
189
|
+
return {
|
|
190
|
+
file: summary,
|
|
191
|
+
source: scanned.source,
|
|
192
|
+
frontmatter: scanned.frontmatter,
|
|
193
|
+
stats: scanned.stats,
|
|
194
|
+
findings: context.findings.filter((finding) => finding.file === file),
|
|
195
|
+
linksTo: page ? page.linkRefs.length > 0 ? page.linkRefs : page.linksTo : [],
|
|
196
|
+
linkedFrom: page ? page.linkedFromRefs.length > 0 ? page.linkedFromRefs : page.linkedFrom : [],
|
|
197
|
+
...seoBrief ? { seoBrief } : {},
|
|
198
|
+
previewHtml
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
async function scanGraph(options) {
|
|
202
|
+
const context = await scanContext(options);
|
|
203
|
+
if (!context.index) return { nodes: [], edges: [] };
|
|
204
|
+
const summaryByPath = new Map(context.summaries.map((summary) => [summary.path, summary]));
|
|
205
|
+
const view = createLinkGraphView(context.index, context.scan.linkDiagnostics ?? []);
|
|
206
|
+
const nodes = view.nodes.map((node) => ({
|
|
207
|
+
id: node.id,
|
|
208
|
+
label: node.label,
|
|
209
|
+
path: node.path,
|
|
210
|
+
status: summaryByPath.get(node.path)?.status ?? "healthy",
|
|
211
|
+
slug: node.slug,
|
|
212
|
+
...node.key ? { key: node.key } : {},
|
|
213
|
+
...node.locale ? { locale: node.locale } : {}
|
|
214
|
+
}));
|
|
215
|
+
const edges = view.edges;
|
|
216
|
+
return { nodes, edges };
|
|
217
|
+
}
|
|
218
|
+
async function scanContext(options) {
|
|
219
|
+
const cwd = options.cwd ?? process.cwd();
|
|
220
|
+
const project = await loadContentProject({
|
|
221
|
+
cmd: "studio",
|
|
222
|
+
positionals: options.globs,
|
|
223
|
+
cwd,
|
|
224
|
+
registry: options.registryPath,
|
|
225
|
+
includeGenericBlocks: options.includeGenericBlocks,
|
|
226
|
+
linkOptions: options.linkOptions,
|
|
227
|
+
scan: {
|
|
228
|
+
minSectionWords: options.minSectionWords,
|
|
229
|
+
seoConfig: options.seoConfig,
|
|
230
|
+
seoConfigPath: options.seoConfigPath
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
const { files, scan } = project;
|
|
234
|
+
const findings = scan.findings.map((finding) => findingFromProjectFinding(finding, cwd)).sort(compareFindings);
|
|
235
|
+
const summaries = scan.files.map(
|
|
236
|
+
(file) => fileSummary(
|
|
237
|
+
file.path,
|
|
238
|
+
cwd,
|
|
239
|
+
file.frontmatter,
|
|
240
|
+
file.stats,
|
|
241
|
+
findings.filter((finding) => finding.file === file.path),
|
|
242
|
+
options,
|
|
243
|
+
scan.seo?.pages.find((page) => page.path === file.path)
|
|
244
|
+
)
|
|
245
|
+
);
|
|
246
|
+
const index = scan.linkIndex;
|
|
247
|
+
findings.sort(compareFindings);
|
|
248
|
+
return { files, scan, findings, summaries, index };
|
|
249
|
+
}
|
|
250
|
+
function findingFromProjectFinding(finding, cwd) {
|
|
251
|
+
return {
|
|
252
|
+
severity: finding.severity,
|
|
253
|
+
source: finding.source,
|
|
254
|
+
code: finding.code,
|
|
255
|
+
file: finding.file,
|
|
256
|
+
relativePath: relativePath(cwd, finding.file),
|
|
257
|
+
...finding.line !== void 0 ? { line: finding.line } : {},
|
|
258
|
+
...finding.column !== void 0 ? { column: finding.column } : {},
|
|
259
|
+
message: finding.message,
|
|
260
|
+
...finding.hint ? { hint: finding.hint } : {}
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
function fileSummary(file, cwd, frontmatter, stats, findings, options, seoPage) {
|
|
264
|
+
const counts = summarize(findings);
|
|
265
|
+
const facts = readContentPageFacts(frontmatter, options.linkOptions);
|
|
266
|
+
return {
|
|
267
|
+
path: file,
|
|
268
|
+
relativePath: relativePath(cwd, file),
|
|
269
|
+
title: titleFor(file, frontmatter, stats),
|
|
270
|
+
...facts.slug ? { slug: facts.slug } : {},
|
|
271
|
+
...facts.key ? { key: facts.key } : {},
|
|
272
|
+
...facts.locale ? { locale: facts.locale } : {},
|
|
273
|
+
...facts.keywords ? { keywords: facts.keywords } : {},
|
|
274
|
+
words: stats.length.words,
|
|
275
|
+
readingMinutes: stats.length.readingMinutes,
|
|
276
|
+
blocks: stats.blocks.total,
|
|
277
|
+
blockNames: stats.blocks.byName,
|
|
278
|
+
links: stats.links.total,
|
|
279
|
+
externalLinks: stats.links.external,
|
|
280
|
+
missingAlt: stats.images.missingAlt,
|
|
281
|
+
...seoPage ? {
|
|
282
|
+
seo: {
|
|
283
|
+
id: seoPage.id,
|
|
284
|
+
source: seoPage.source,
|
|
285
|
+
...seoPage.type ? { type: seoPage.type } : {},
|
|
286
|
+
...seoPage.intent ? { intent: seoPage.intent } : {},
|
|
287
|
+
findings: findings.filter((finding) => finding.source === "seo").length
|
|
288
|
+
}
|
|
289
|
+
} : {},
|
|
290
|
+
findings: counts,
|
|
291
|
+
status: statusFor(counts)
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
function titleFor(file, frontmatter, stats) {
|
|
295
|
+
return stringValue(frontmatter.title) ?? stats.outline[0]?.text ?? basename(file);
|
|
296
|
+
}
|
|
297
|
+
function summarize(findings) {
|
|
298
|
+
return summarizeContentProjectFindings(findings);
|
|
299
|
+
}
|
|
300
|
+
function statusFor(findings) {
|
|
301
|
+
if (findings.errors > 0) return "error";
|
|
302
|
+
if (findings.warnings > 0) return "warning";
|
|
303
|
+
if (findings.suggestions > 0) return "suggestion";
|
|
304
|
+
return "healthy";
|
|
305
|
+
}
|
|
306
|
+
function findAllowedFile(context, cwd, requestedPath) {
|
|
307
|
+
return context.files.find(
|
|
308
|
+
(file) => file === requestedPath || relativePath(cwd, file) === requestedPath
|
|
309
|
+
) ?? null;
|
|
310
|
+
}
|
|
311
|
+
function compareFindings(a, b) {
|
|
312
|
+
return compareContentProjectFindings(a, b) || a.relativePath.localeCompare(b.relativePath) || (a.line ?? 0) - (b.line ?? 0) || (a.column ?? 0) - (b.column ?? 0) || a.code.localeCompare(b.code);
|
|
313
|
+
}
|
|
314
|
+
function stringValue(value) {
|
|
315
|
+
return typeof value === "string" && value.trim().length > 0 ? value : void 0;
|
|
316
|
+
}
|
|
317
|
+
function relativePath(cwd, file) {
|
|
318
|
+
const rel = relative(cwd, file);
|
|
319
|
+
return rel.startsWith("..") ? file : rel;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// src/server/api.ts
|
|
323
|
+
async function handleStudioApiRequest(options, req, res) {
|
|
324
|
+
if (!req.url) return false;
|
|
325
|
+
const url = new URL(req.url, "http://contentbit.local");
|
|
326
|
+
if (!url.pathname.startsWith("/api/")) return false;
|
|
327
|
+
try {
|
|
328
|
+
if (req.method !== "GET") {
|
|
329
|
+
sendJson(res, 405, { error: "Studio API is read-only." });
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
if (url.pathname === "/api/project") {
|
|
333
|
+
sendJson(res, 200, await scanProject(options));
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
if (url.pathname === "/api/graph") {
|
|
337
|
+
sendJson(res, 200, await scanGraph(options));
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
340
|
+
if (url.pathname === "/api/document") {
|
|
341
|
+
const path = url.searchParams.get("path");
|
|
342
|
+
if (!path) {
|
|
343
|
+
sendJson(res, 400, { error: "Missing ?path=" });
|
|
344
|
+
return true;
|
|
345
|
+
}
|
|
346
|
+
const document = await scanDocument(options, path);
|
|
347
|
+
if (!document) {
|
|
348
|
+
sendJson(res, 404, { error: "Document is not in the configured content set." });
|
|
349
|
+
return true;
|
|
350
|
+
}
|
|
351
|
+
sendJson(res, 200, document);
|
|
352
|
+
return true;
|
|
353
|
+
}
|
|
354
|
+
sendJson(res, 404, { error: "Unknown Studio API route." });
|
|
355
|
+
return true;
|
|
356
|
+
} catch (err) {
|
|
357
|
+
sendJson(res, 500, { error: err instanceof Error ? err.message : String(err) });
|
|
358
|
+
return true;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
function sendJson(res, status, body) {
|
|
362
|
+
res.statusCode = status;
|
|
363
|
+
res.setHeader("content-type", "application/json; charset=utf-8");
|
|
364
|
+
res.end(JSON.stringify(body, null, 2));
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// src/server/index.ts
|
|
368
|
+
async function startStudio(options) {
|
|
369
|
+
const root = findPackageRoot();
|
|
370
|
+
const host = options.host ?? "127.0.0.1";
|
|
371
|
+
const port = options.port ?? 4377;
|
|
372
|
+
const cwd = options.cwd ?? process.cwd();
|
|
373
|
+
const fsAllow = [.../* @__PURE__ */ new Set([root, searchForWorkspaceRoot(root), cwd])];
|
|
374
|
+
const apiOptions = {
|
|
375
|
+
globs: options.globs,
|
|
376
|
+
cwd,
|
|
377
|
+
registryPath: options.registryPath,
|
|
378
|
+
includeGenericBlocks: options.includeGenericBlocks,
|
|
379
|
+
linkOptions: options.linkOptions,
|
|
380
|
+
minSectionWords: options.minSectionWords,
|
|
381
|
+
seoConfig: options.seoConfig,
|
|
382
|
+
seoConfigPath: options.seoConfigPath
|
|
383
|
+
};
|
|
384
|
+
const vite = await createServer({
|
|
385
|
+
root,
|
|
386
|
+
configFile: join2(root, "vite.config.ts"),
|
|
387
|
+
plugins: [studioApiPlugin(apiOptions)],
|
|
388
|
+
server: {
|
|
389
|
+
host,
|
|
390
|
+
port,
|
|
391
|
+
strictPort: options.port !== void 0 && options.port !== 0,
|
|
392
|
+
open: false,
|
|
393
|
+
fs: {
|
|
394
|
+
allow: fsAllow
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
apiOptions.previewComponents = () => loadProjectComponents(vite, { cwd, registryPath: options.registryPath });
|
|
399
|
+
await vite.listen();
|
|
400
|
+
const address = vite.httpServer?.address();
|
|
401
|
+
const resolvedPort = typeof address === "object" && address ? address.port : port;
|
|
402
|
+
const url = `http://${host}:${resolvedPort}/`;
|
|
403
|
+
if (options.open !== false) openBrowser(url);
|
|
404
|
+
return {
|
|
405
|
+
url,
|
|
406
|
+
vite,
|
|
407
|
+
close: () => vite.close(),
|
|
408
|
+
closed: new Promise((resolve2) => {
|
|
409
|
+
vite.httpServer?.once("close", () => resolve2());
|
|
410
|
+
})
|
|
411
|
+
};
|
|
61
412
|
}
|
|
62
413
|
async function loadProjectComponents(vite, options) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
throw new Error(`Failed to load block components: ${candidate.path}`);
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
const maps = [mod.styledComponents, mod.blockComponents, mod.components, mod.default];
|
|
77
|
-
for (const components of maps) {
|
|
78
|
-
if (components && typeof components === 'object')
|
|
79
|
-
Object.assign(merged, components);
|
|
80
|
-
}
|
|
414
|
+
const merged = {};
|
|
415
|
+
for (const candidate of componentCandidates(options)) {
|
|
416
|
+
if (!existsSync(candidate.path)) continue;
|
|
417
|
+
let mod;
|
|
418
|
+
try {
|
|
419
|
+
mod = await vite.ssrLoadModule(candidate.path);
|
|
420
|
+
} catch {
|
|
421
|
+
if (!candidate.bestEffort)
|
|
422
|
+
throw new Error(`Failed to load block components: ${candidate.path}`);
|
|
423
|
+
continue;
|
|
81
424
|
}
|
|
82
|
-
|
|
425
|
+
const maps = [mod.styledComponents, mod.blockComponents, mod.components, mod.default];
|
|
426
|
+
for (const components of maps) {
|
|
427
|
+
if (components && typeof components === "object") Object.assign(merged, components);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return Object.keys(merged).length > 0 ? merged : void 0;
|
|
83
431
|
}
|
|
84
432
|
function componentCandidates(options) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
433
|
+
const dirs = /* @__PURE__ */ new Set();
|
|
434
|
+
if (options.registryPath) {
|
|
435
|
+
const registryPath = isAbsolute2(options.registryPath) ? options.registryPath : resolve(options.cwd, options.registryPath);
|
|
436
|
+
dirs.add(dirname(registryPath));
|
|
437
|
+
}
|
|
438
|
+
dirs.add(join2(options.cwd, "blocks"));
|
|
439
|
+
const rendererCandidates = [
|
|
440
|
+
join2(options.cwd, "components/content-blocks/content-renderer.tsx"),
|
|
441
|
+
join2(options.cwd, "src/components/content-blocks/content-renderer.tsx")
|
|
442
|
+
].map((path) => ({ path, bestEffort: true }));
|
|
443
|
+
const blockComponentCandidates = [...dirs].flatMap(
|
|
444
|
+
(dir) => [
|
|
445
|
+
join2(dir, "components.tsx"),
|
|
446
|
+
join2(dir, "components.ts"),
|
|
447
|
+
join2(dir, "preview.tsx"),
|
|
448
|
+
join2(dir, "preview.ts"),
|
|
449
|
+
join2(dir, "renderers.tsx"),
|
|
450
|
+
join2(dir, "renderers.ts")
|
|
451
|
+
].map((path) => ({ path, bestEffort: false }))
|
|
452
|
+
);
|
|
453
|
+
return [...rendererCandidates, ...blockComponentCandidates];
|
|
106
454
|
}
|
|
107
455
|
function studioApiPlugin(options) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
};
|
|
456
|
+
return {
|
|
457
|
+
name: "contentbit-studio-api",
|
|
458
|
+
configureServer(server) {
|
|
459
|
+
server.middlewares.use((req, res, next) => {
|
|
460
|
+
void handleStudioApiRequest(options, req, res).then((handled) => {
|
|
461
|
+
if (!handled) next();
|
|
462
|
+
});
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
};
|
|
119
466
|
}
|
|
120
467
|
function findPackageRoot() {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
dir = next;
|
|
129
|
-
}
|
|
468
|
+
let dir = dirname(fileURLToPath(import.meta.url));
|
|
469
|
+
for (; ; ) {
|
|
470
|
+
if (existsSync(join2(dir, "package.json"))) return dir;
|
|
471
|
+
const next = dirname(dir);
|
|
472
|
+
if (next === dir) throw new Error("Could not locate @contentbit/studio package root.");
|
|
473
|
+
dir = next;
|
|
474
|
+
}
|
|
130
475
|
}
|
|
131
476
|
function openBrowser(url) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
477
|
+
const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
|
|
478
|
+
const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
|
|
479
|
+
const child = spawn(command, args, { detached: true, stdio: "ignore" });
|
|
480
|
+
child.unref();
|
|
136
481
|
}
|
|
482
|
+
export {
|
|
483
|
+
scanDocument,
|
|
484
|
+
scanGraph,
|
|
485
|
+
scanProject,
|
|
486
|
+
startStudio
|
|
487
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../src/server/scan.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../src/server/scan.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EACV,cAAc,EAGd,WAAW,EAGX,aAAa,EACb,aAAa,EAEd,MAAM,YAAY,CAAA;AAUnB,wBAAsB,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CAwDhF;AAED,wBAAsB,YAAY,CAChC,OAAO,EAAE,aAAa,EACtB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAoChC;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC,CAiB5E"}
|
package/dist/server/server.js
CHANGED
|
@@ -3415,7 +3415,7 @@ var defaultSerovalPlugins = [
|
|
|
3415
3415
|
* the dev styles URL for route-scoped CSS collection.
|
|
3416
3416
|
*/
|
|
3417
3417
|
async function getStartManifest(matchedRoutes) {
|
|
3418
|
-
const { tsrStartManifest } = await import("./assets/_tanstack-start-manifest_v-
|
|
3418
|
+
const { tsrStartManifest } = await import("./assets/_tanstack-start-manifest_v-DyPYRepF.js");
|
|
3419
3419
|
const startManifest = tsrStartManifest();
|
|
3420
3420
|
let routes = startManifest.routes;
|
|
3421
3421
|
routes[rootRouteId];
|
|
@@ -5130,7 +5130,7 @@ var getBaseManifest = getProdBaseManifest;
|
|
|
5130
5130
|
var createEarlyHintsForRequest = createEarlyHintsCollector;
|
|
5131
5131
|
async function loadEntries() {
|
|
5132
5132
|
const [routerEntry, startEntry, pluginAdapters] = await Promise.all([
|
|
5133
|
-
import("./assets/router-
|
|
5133
|
+
import("./assets/router-BJiN6b7L.js"),
|
|
5134
5134
|
import("./assets/start-q50h9Mc3.js"),
|
|
5135
5135
|
import("./assets/empty-plugin-adapters-DKUlnwwl.js")
|
|
5136
5136
|
]);
|