@contentbit/studio 1.0.0 → 2.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +19 -9
  2. package/dist/client/assets/api-aCc2x-IO.js +1 -0
  3. package/dist/client/assets/arrow-right-tp4VknZo.js +1 -0
  4. package/dist/client/assets/document-DIh3ZPXr.js +56 -0
  5. package/dist/client/assets/documents-CjBZYbQ4.js +1 -0
  6. package/dist/client/assets/file-code-corner-Fzc5liO9.js +1 -0
  7. package/dist/client/assets/file-text-B8O46COn.js +1 -0
  8. package/dist/client/assets/index-Cd04OFZT.js +11 -0
  9. package/dist/client/assets/page-BMU8eIrR.js +1 -0
  10. package/dist/client/assets/routes-WndCJoku.js +1 -0
  11. package/dist/client/assets/search-BnUPH8AI.js +1 -0
  12. package/dist/client/assets/styles-hAsz_paS.css +2 -0
  13. package/dist/client/assets/target-BMSXP2fU.js +1 -0
  14. package/dist/client/assets/templates-IJid1Zwh.js +1 -0
  15. package/dist/server/api.d.ts.map +1 -1
  16. package/dist/server/assets/_tanstack-start-manifest_v-WfZ3uz_l.js +69 -0
  17. package/dist/server/assets/api-CHfynRIj.js +342 -0
  18. package/dist/server/assets/{document-DSV89Ser.js → document-BjPXZ9gS.js} +2529 -1317
  19. package/dist/server/assets/{routes-FGdym0e5.js → documents-jT4KnSkA.js} +63 -112
  20. package/dist/server/assets/empty-plugin-adapters-Ctp1ZmyT.js +4 -0
  21. package/dist/server/assets/page--xw7NmtK.js +388 -0
  22. package/dist/server/assets/router-xI8HUWRI.js +125 -0
  23. package/dist/server/assets/routes-CfwU-Ww2.js +372 -0
  24. package/dist/server/assets/start-Dk-BJfGT.js +3 -0
  25. package/dist/server/assets/templates--9wK-MK9.js +123 -0
  26. package/dist/server/index.d.ts +2 -2
  27. package/dist/server/index.d.ts.map +1 -1
  28. package/dist/server/index.js +6104 -110
  29. package/dist/server/scan.d.ts +1 -2
  30. package/dist/server/scan.d.ts.map +1 -1
  31. package/dist/server/server.js +3150 -1878
  32. package/dist/server/site.d.ts +38 -0
  33. package/dist/server/site.d.ts.map +1 -0
  34. package/dist/server/types.d.ts +33 -31
  35. package/dist/server/types.d.ts.map +1 -1
  36. package/package.json +26 -15
  37. package/src/components/studio.test.ts +10 -0
  38. package/src/components/studio.tsx +209 -0
  39. package/src/lib/api.test.ts +80 -0
  40. package/src/lib/api.ts +68 -7
  41. package/src/routeTree.gen.ts +57 -3
  42. package/src/routes/document.tsx +34 -88
  43. package/src/routes/documents.tsx +433 -0
  44. package/src/routes/index.tsx +295 -414
  45. package/src/routes/page.tsx +401 -0
  46. package/src/routes/templates.tsx +104 -0
  47. package/src/server/api.ts +19 -3
  48. package/src/server/index.ts +31 -12
  49. package/src/server/scan.test.ts +31 -44
  50. package/src/server/scan.ts +56 -82
  51. package/src/server/site.test.ts +355 -0
  52. package/src/server/site.ts +164 -0
  53. package/src/server/types.ts +28 -30
  54. package/tsconfig.json +1 -1
  55. package/dist/client/assets/api-BX-WUPtV.js +0 -1
  56. package/dist/client/assets/document-BOMp4_F5.js +0 -65
  57. package/dist/client/assets/index-C0ybJ4zQ.js +0 -12
  58. package/dist/client/assets/routes-ACKdIhYm.js +0 -1
  59. package/dist/client/assets/styles-DogO4Wcf.css +0 -2
  60. package/dist/server/assets/_tanstack-start-manifest_v-BC1PNuB0.js +0 -25
  61. package/dist/server/assets/api-Bqt_atjc.js +0 -72
  62. package/dist/server/assets/document-BB_UYqNL.js +0 -9
  63. package/dist/server/assets/empty-plugin-adapters-De7E1vAI.js +0 -5
  64. package/dist/server/assets/router-BJiN6b7L.js +0 -63
  65. package/dist/server/assets/routes-p0tk6PAr.js +0 -20
  66. package/dist/server/assets/start-m8EQRpUf.js +0 -4
@@ -0,0 +1,401 @@
1
+ import { createFileRoute, Link } from '@tanstack/react-router'
2
+ import {
3
+ AlertTriangle,
4
+ ArrowLeft,
5
+ FileCode2,
6
+ Link2,
7
+ ListTree,
8
+ RefreshCw,
9
+ Target,
10
+ Globe,
11
+ } from 'lucide-react'
12
+ import type { ReactNode } from 'react'
13
+
14
+ import {
15
+ Badge,
16
+ ContentFindingItem,
17
+ Panel,
18
+ plural,
19
+ relativeTo,
20
+ SiteFindingItem,
21
+ StudioNav,
22
+ } from '../components/studio'
23
+ import { Button } from '../components/ui/button'
24
+ import { usePage } from '../lib/api'
25
+ import type { LinkOutTarget, PageContext } from '../server/site'
26
+
27
+ interface PageSearch {
28
+ path: string
29
+ }
30
+
31
+ export const Route = createFileRoute('/page')({
32
+ validateSearch: (search: Record<string, unknown>): PageSearch => ({
33
+ path: typeof search.path === 'string' ? search.path : '',
34
+ }),
35
+ component: PageView,
36
+ })
37
+
38
+ function PageView() {
39
+ const search = Route.useSearch()
40
+ const { data: page, error: loadError, refreshing, refresh } = usePage(search.path)
41
+ const error = search.path ? loadError : 'Missing page path.'
42
+
43
+ const context = page?.context.page === search.path ? page.context : undefined
44
+ const root = page?.root ?? ''
45
+
46
+ return (
47
+ <main className="min-h-svh bg-background text-foreground">
48
+ <header className="border-b bg-muted/30">
49
+ <div className="mx-auto flex max-w-7xl flex-col gap-5 px-5 py-5">
50
+ <StudioNav />
51
+ <div className="flex flex-col gap-3 md:flex-row md:items-center md:justify-between">
52
+ <Button asChild variant="outline" className="w-fit gap-2">
53
+ <Link to="/" search={{ q: '' }}>
54
+ <ArrowLeft className="size-4" />
55
+ Pages
56
+ </Link>
57
+ </Button>
58
+ <Button onClick={refresh} disabled={refreshing} className="w-fit gap-2">
59
+ <RefreshCw className={refreshing ? 'size-4 animate-spin' : 'size-4'} />
60
+ Refresh
61
+ </Button>
62
+ </div>
63
+ <div>
64
+ <p className="font-mono text-xs uppercase text-muted-foreground">page context</p>
65
+ <h1 className="mt-1 break-all font-mono text-2xl font-semibold tracking-tight">
66
+ {search.path || 'Built page'}
67
+ </h1>
68
+ {context && (
69
+ <>
70
+ {context.url && (
71
+ <a
72
+ href={context.url}
73
+ target="_blank"
74
+ rel="noreferrer"
75
+ className="mt-1 block break-all text-sm text-muted-foreground hover:underline"
76
+ >
77
+ {context.url}
78
+ </a>
79
+ )}
80
+ <p className="mt-1 text-sm">
81
+ Source:{' '}
82
+ {context.source ? (
83
+ <Link
84
+ to="/document"
85
+ search={{ path: context.source.file }}
86
+ className="font-mono underline underline-offset-4"
87
+ >
88
+ {relativeTo(root, context.source.file)}
89
+ </Link>
90
+ ) : (
91
+ <span className="text-muted-foreground">none</span>
92
+ )}
93
+ </p>
94
+ <div className="mt-3 flex flex-wrap gap-2 text-xs">
95
+ <Badge>{plural(context.words, 'word')}</Badge>
96
+ <Badge>{plural(context.linksIn.length, 'link')} in</Badge>
97
+ <Badge>{plural(context.linksOut.length, 'link')} out</Badge>
98
+ <Badge>{plural(context.findings.length, 'finding')}</Badge>
99
+ </div>
100
+ </>
101
+ )}
102
+ </div>
103
+ </div>
104
+ </header>
105
+
106
+ <section className="mx-auto grid max-w-7xl gap-5 px-5 py-5 xl:grid-cols-[minmax(0,1fr)_380px]">
107
+ <div className="min-w-0 space-y-5">
108
+ {error && (
109
+ <Panel title="Error" icon={<AlertTriangle className="size-4" />}>
110
+ <p className="text-sm text-destructive">{error}</p>
111
+ </Panel>
112
+ )}
113
+ {!context && !error && (
114
+ <Panel title="Loading" icon={<RefreshCw className="size-4" />}>
115
+ <p className="text-sm">Reading the page...</p>
116
+ </Panel>
117
+ )}
118
+ {context && (
119
+ <>
120
+ <Panel title="Served" icon={<Globe className="size-4" />}>
121
+ <Facts
122
+ rows={[
123
+ ['Title', context.served.title],
124
+ ['Description', context.served.description],
125
+ ['Canonical', context.served.canonical],
126
+ ['Lang', context.served.lang],
127
+ [
128
+ 'Robots',
129
+ `${context.served.robots.noindex ? 'noindex' : 'index'}, ${context.served.robots.nofollow ? 'nofollow' : 'follow'}`,
130
+ ],
131
+ [
132
+ 'Hreflang',
133
+ context.served.alternates
134
+ .map(({ hreflang, href }) => `${hreflang} ${href}`)
135
+ .join(', ') || undefined,
136
+ ],
137
+ ['Structured data', context.served.structuredData.join(', ') || undefined],
138
+ ]}
139
+ />
140
+ </Panel>
141
+
142
+ {context.declared && (
143
+ <Panel title="Declared" icon={<FileCode2 className="size-4" />}>
144
+ <Facts
145
+ rows={[
146
+ ['Title', context.declared.title],
147
+ ['Description', context.declared.description],
148
+ ['Type', context.declared.type],
149
+ ['Intent', context.declared.intent],
150
+ ['Primary keyword', context.declared.keywords?.primary],
151
+ ['Secondary keywords', context.declared.keywords?.secondary?.join(', ')],
152
+ ['LSI keywords', context.declared.keywords?.lsi?.join(', ')],
153
+ ]}
154
+ />
155
+ </Panel>
156
+ )}
157
+
158
+ <Panel
159
+ title={`Outline, ${plural(context.words, 'word')}`}
160
+ icon={<ListTree className="size-4" />}
161
+ >
162
+ <Outline context={context} />
163
+ </Panel>
164
+
165
+ <Panel title="Links out" icon={<Link2 className="size-4" />}>
166
+ <LinksOut context={context} />
167
+ </Panel>
168
+
169
+ <Panel title="Links in" icon={<Link2 className="size-4" />}>
170
+ <LinksIn context={context} />
171
+ </Panel>
172
+ </>
173
+ )}
174
+ </div>
175
+
176
+ {context && (
177
+ <aside className="space-y-5">
178
+ <Panel title="Findings" icon={<AlertTriangle className="size-4" />}>
179
+ {context.findings.length > 0 ? (
180
+ <ul className="space-y-3">
181
+ {context.findings.map((finding, index) => (
182
+ <SiteFindingItem
183
+ key={`${finding.code}-${index}`}
184
+ finding={finding}
185
+ root={root}
186
+ />
187
+ ))}
188
+ </ul>
189
+ ) : (
190
+ <p className="text-sm text-muted-foreground">No findings on this page.</p>
191
+ )}
192
+ </Panel>
193
+
194
+ {context.source && (
195
+ <Panel title="Markdown findings" icon={<FileCode2 className="size-4" />}>
196
+ {context.contentFindings.length > 0 ? (
197
+ <ul className="space-y-3">
198
+ {context.contentFindings.map((finding, index) => (
199
+ <ContentFindingItem key={`${finding.code}-${index}`} finding={finding} />
200
+ ))}
201
+ </ul>
202
+ ) : (
203
+ <p className="text-sm text-muted-foreground">No findings in its source.</p>
204
+ )}
205
+ </Panel>
206
+ )}
207
+
208
+ {context.contract && (
209
+ <Panel title="Contract" icon={<Target className="size-4" />}>
210
+ <Contract contract={context.contract} />
211
+ </Panel>
212
+ )}
213
+ </aside>
214
+ )}
215
+ </section>
216
+ </main>
217
+ )
218
+ }
219
+
220
+ function Facts({ rows }: { rows: Array<[string, string | undefined]> }) {
221
+ return (
222
+ <dl className="grid gap-x-4 gap-y-2 text-sm md:grid-cols-[10rem_1fr]">
223
+ {rows.map(([label, value]) => (
224
+ <Row key={label} label={label}>
225
+ {value ?? <span className="text-muted-foreground">none</span>}
226
+ </Row>
227
+ ))}
228
+ </dl>
229
+ )
230
+ }
231
+
232
+ function Row({ label, children }: { label: string; children: ReactNode }) {
233
+ return (
234
+ <>
235
+ <dt className="text-xs uppercase text-muted-foreground md:pt-0.5">{label}</dt>
236
+ <dd className="min-w-0 break-words">{children}</dd>
237
+ </>
238
+ )
239
+ }
240
+
241
+ function Outline({ context }: { context: PageContext }) {
242
+ return (
243
+ <div className="space-y-3 text-sm">
244
+ {context.intro && (
245
+ <p className="line-clamp-3 text-muted-foreground">
246
+ <span className="mr-2 font-mono text-xs uppercase">intro</span>
247
+ {context.intro}
248
+ </p>
249
+ )}
250
+ {context.outline.length === 0 && <p className="text-muted-foreground">No headings.</p>}
251
+ <ul className="space-y-2">
252
+ {context.outline.map((heading, index) => (
253
+ <li
254
+ key={`${heading.text}-${index}`}
255
+ style={{ paddingLeft: `${(heading.level - 1) * 1.25}rem` }}
256
+ >
257
+ <p>
258
+ <span className="mr-2 font-mono text-xs text-muted-foreground">h{heading.level}</span>
259
+ <span className="font-medium">{heading.text}</span>
260
+ {heading.id && (
261
+ <span className="ml-2 font-mono text-xs text-muted-foreground">#{heading.id}</span>
262
+ )}
263
+ <span className="ml-2 text-xs text-muted-foreground">
264
+ {plural(heading.words, 'word')}
265
+ </span>
266
+ </p>
267
+ {heading.body && (
268
+ <p className="mt-1 line-clamp-3 text-xs text-muted-foreground">{heading.body}</p>
269
+ )}
270
+ </li>
271
+ ))}
272
+ </ul>
273
+ </div>
274
+ )
275
+ }
276
+
277
+ function LinksOut({ context }: { context: PageContext }) {
278
+ if (context.linksOut.length === 0) {
279
+ return <p className="text-sm text-muted-foreground">No links.</p>
280
+ }
281
+ return (
282
+ <LinkTable headers={['Text', 'Target', 'Placement']}>
283
+ {context.linksOut.map(({ href, text, placement, target }, index) => (
284
+ <tr key={`${href}-${index}`} className="border-t align-top">
285
+ <td className="py-1.5 pr-3 break-words">{text || <Muted>no text</Muted>}</td>
286
+ <td className="py-1.5 pr-3 font-mono text-xs break-all">
287
+ <LinkTarget href={href} target={target} />
288
+ </td>
289
+ <td className="py-1.5 text-xs text-muted-foreground">{placement}</td>
290
+ </tr>
291
+ ))}
292
+ </LinkTable>
293
+ )
294
+ }
295
+
296
+ function LinksIn({ context }: { context: PageContext }) {
297
+ if (context.linksIn.length === 0) {
298
+ return <p className="text-sm text-muted-foreground">No built page links here.</p>
299
+ }
300
+ return (
301
+ <LinkTable headers={['From', 'Text', 'Placement']}>
302
+ {context.linksIn.map(({ from, text, anchor, placement }, index) => (
303
+ <tr key={`${from}-${index}`} className="border-t align-top">
304
+ <td className="py-1.5 pr-3 font-mono text-xs break-all">
305
+ <Link to="/page" search={{ path: from }} className="hover:underline">
306
+ {from}
307
+ </Link>
308
+ </td>
309
+ <td className="py-1.5 pr-3 break-words">
310
+ {text || <Muted>no text</Muted>}
311
+ {anchor !== undefined && (
312
+ <span className="ml-1 font-mono text-xs text-muted-foreground">#{anchor}</span>
313
+ )}
314
+ </td>
315
+ <td className="py-1.5 text-xs text-muted-foreground">{placement}</td>
316
+ </tr>
317
+ ))}
318
+ </LinkTable>
319
+ )
320
+ }
321
+
322
+ function LinkTable({ headers, children }: { headers: string[]; children: ReactNode }) {
323
+ return (
324
+ <div className="max-h-[32rem] overflow-auto">
325
+ <table className="w-full text-left text-sm">
326
+ <thead className="text-xs uppercase text-muted-foreground">
327
+ <tr>
328
+ {headers.map((header) => (
329
+ <th key={header} className="pb-2 pr-3 font-medium">
330
+ {header}
331
+ </th>
332
+ ))}
333
+ </tr>
334
+ </thead>
335
+ <tbody>{children}</tbody>
336
+ </table>
337
+ </div>
338
+ )
339
+ }
340
+
341
+ function LinkTarget({ href, target }: { href: string; target: LinkOutTarget }) {
342
+ if (target.kind === 'page') {
343
+ return (
344
+ <Link to="/page" search={{ path: target.page }} className="hover:underline">
345
+ {target.page}
346
+ {target.anchor !== undefined && `#${target.anchor}`}
347
+ </Link>
348
+ )
349
+ }
350
+ const label =
351
+ target.kind === 'file'
352
+ ? target.exists
353
+ ? 'a file in the build'
354
+ : 'a file missing from the build'
355
+ : target.kind === 'missing'
356
+ ? 'no built page'
357
+ : target.kind === 'host-route'
358
+ ? 'a host route'
359
+ : target.kind
360
+ return (
361
+ <>
362
+ {href}
363
+ <span
364
+ className={`ml-2 font-sans ${target.kind === 'missing' || (target.kind === 'file' && !target.exists) ? 'text-destructive' : 'text-muted-foreground'}`}
365
+ >
366
+ {label}
367
+ </span>
368
+ </>
369
+ )
370
+ }
371
+
372
+ function Contract({ contract }: { contract: NonNullable<PageContext['contract']> }) {
373
+ return (
374
+ <div className="space-y-3 text-sm">
375
+ <p>
376
+ Page type: <span className="font-medium">{contract.target.type ?? 'none'}</span>
377
+ </p>
378
+ <div>
379
+ <p className="mb-1 text-xs uppercase text-muted-foreground">Acceptance checks</p>
380
+ {contract.acceptanceChecks.length === 0 ? (
381
+ <p className="text-muted-foreground">None.</p>
382
+ ) : (
383
+ <ul className="space-y-1">
384
+ {contract.acceptanceChecks.map((check) => (
385
+ <li key={check} className="border bg-muted/40 px-2 py-1.5">
386
+ {check}
387
+ </li>
388
+ ))}
389
+ </ul>
390
+ )}
391
+ </div>
392
+ {contract.recommendedBlocks.length > 0 && (
393
+ <p>Recommended blocks: {contract.recommendedBlocks.join(', ')}.</p>
394
+ )}
395
+ </div>
396
+ )
397
+ }
398
+
399
+ function Muted({ children }: { children: ReactNode }) {
400
+ return <span className="text-muted-foreground">{children}</span>
401
+ }
@@ -0,0 +1,104 @@
1
+ import { createFileRoute, Link } from '@tanstack/react-router'
2
+ import { AlertTriangle, RefreshCw } from 'lucide-react'
3
+ import { NoBuild, Panel, plural, severityTone, StudioNav } from '../components/studio'
4
+ import { Button } from '../components/ui/button'
5
+ import { useSite } from '../lib/api'
6
+ import type { SiteFinding } from '../server/site'
7
+
8
+ export const Route = createFileRoute('/templates')({
9
+ component: TemplateFindings,
10
+ })
11
+
12
+ function TemplateFindings() {
13
+ const { data: site, error, refreshing, refresh } = useSite()
14
+
15
+ const findings = site?.kind === 'built' ? site.context.templateFindings : []
16
+
17
+ return (
18
+ <main className="min-h-svh bg-background text-foreground">
19
+ <section className="border-b bg-muted/30">
20
+ <div className="mx-auto flex max-w-7xl flex-col gap-6 px-5 py-6">
21
+ <StudioNav />
22
+ <div className="flex flex-col gap-4 md:flex-row md:items-end md:justify-between">
23
+ <div>
24
+ <p className="font-mono text-xs uppercase text-muted-foreground">contentbit studio</p>
25
+ <h1 className="mt-1 text-3xl font-semibold tracking-tight">Template findings</h1>
26
+ <p className="mt-2 max-w-2xl text-sm text-muted-foreground">
27
+ Findings the layout or a shared component renders rather than one page&apos;s
28
+ content, each reported once with every built page it affects.
29
+ </p>
30
+ </div>
31
+ <Button onClick={refresh} disabled={refreshing} className="w-fit gap-2">
32
+ <RefreshCw className={refreshing ? 'size-4 animate-spin' : 'size-4'} />
33
+ Refresh
34
+ </Button>
35
+ </div>
36
+ </div>
37
+ </section>
38
+
39
+ <section className="mx-auto flex max-w-7xl flex-col gap-4 px-5 py-5">
40
+ {error && (
41
+ <Panel title="Error" icon={<AlertTriangle className="size-4" />}>
42
+ <p className="text-sm text-destructive">{error}</p>
43
+ </Panel>
44
+ )}
45
+ {!site && !error && (
46
+ <div className="border p-4 text-sm text-muted-foreground">Reading the site...</div>
47
+ )}
48
+ {site?.kind === 'unbuilt' && <NoBuild {...site} />}
49
+ {site?.kind === 'built' && findings.length === 0 && (
50
+ <div className="border p-4 text-sm text-muted-foreground">
51
+ No template findings: no finding repeats across pages from the layout.
52
+ </div>
53
+ )}
54
+ {findings.map((finding, index) => (
55
+ <TemplateFinding key={`${finding.code}-${index}`} finding={finding} />
56
+ ))}
57
+ </section>
58
+ </main>
59
+ )
60
+ }
61
+
62
+ function TemplateFinding({ finding }: { finding: SiteFinding }) {
63
+ if (finding.origin.kind !== 'template') return null
64
+ const { element, pages } = finding.origin
65
+ const targets = new Map<string, string[]>()
66
+ for (const { page, target } of finding.occurrences ?? []) {
67
+ if (target !== undefined) targets.set(page, [...(targets.get(page) ?? []), target])
68
+ }
69
+ return (
70
+ <section className="border bg-background">
71
+ <div className="flex flex-col gap-1 border-b bg-muted/40 px-4 py-3 md:flex-row md:items-center md:justify-between">
72
+ <h2 className="text-sm font-semibold">
73
+ <span className={severityTone(finding.severity)}>{finding.severity}</span> {finding.code}
74
+ </h2>
75
+ <span className="text-xs text-muted-foreground">
76
+ <span className="mr-2 font-mono">{element}</span>
77
+ on {plural(pages.length, 'page')}
78
+ </span>
79
+ </div>
80
+ <div className="space-y-3 p-4 text-sm">
81
+ <p className="break-words">{finding.message}</p>
82
+ {finding.hint && <p className="text-xs text-muted-foreground">{finding.hint}</p>}
83
+ <ul className="grid max-h-72 gap-1 overflow-auto md:grid-cols-2">
84
+ {pages.map((path) => (
85
+ <li key={path} className="min-w-0">
86
+ <Link
87
+ to="/page"
88
+ search={{ path }}
89
+ className="break-all font-mono text-xs hover:underline"
90
+ >
91
+ {path}
92
+ </Link>
93
+ {targets.has(path) && (
94
+ <span className="ml-2 break-all font-mono text-xs text-muted-foreground">
95
+ {targets.get(path)?.join(', ')}
96
+ </span>
97
+ )}
98
+ </li>
99
+ ))}
100
+ </ul>
101
+ </div>
102
+ </section>
103
+ )
104
+ }
package/src/server/api.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { IncomingMessage, ServerResponse } from 'node:http'
2
2
 
3
- import { scanDocument, scanGraph, scanProject } from './scan.js'
3
+ import { scanDocument, scanProject } from './scan.js'
4
+ import { scanPage, scanSite } from './site.js'
4
5
  import type { StudioOptions } from './types.js'
5
6
 
6
7
  export async function handleStudioApiRequest(
@@ -23,8 +24,23 @@ export async function handleStudioApiRequest(
23
24
  return true
24
25
  }
25
26
 
26
- if (url.pathname === '/api/graph') {
27
- sendJson(res, 200, await scanGraph(options))
27
+ if (url.pathname === '/api/site') {
28
+ sendJson(res, 200, await scanSite(options))
29
+ return true
30
+ }
31
+
32
+ if (url.pathname === '/api/page') {
33
+ const path = url.searchParams.get('path')
34
+ if (!path) {
35
+ sendJson(res, 400, { error: 'Missing ?path=' })
36
+ return true
37
+ }
38
+ const page = await scanPage(options, path)
39
+ if (!page) {
40
+ sendJson(res, 404, { error: `The build has no page ${path}.` })
41
+ return true
42
+ }
43
+ sendJson(res, 200, page)
28
44
  return true
29
45
  }
30
46
 
@@ -1,10 +1,11 @@
1
1
  import { spawn } from 'node:child_process'
2
2
  import { existsSync } from 'node:fs'
3
+ import type { ServerResponse } from 'node:http'
3
4
  import { createRequire } from 'node:module'
4
5
  import { createServer as createNetServer, type AddressInfo } from 'node:net'
5
- import { dirname, isAbsolute, join, resolve } from 'node:path'
6
+ import { dirname, isAbsolute, join, resolve as resolvePath } from 'node:path'
6
7
  import { fileURLToPath } from 'node:url'
7
- import { createServer, type Plugin, type ViteDevServer } from 'vite'
8
+ import { createServer, type Connect, type Plugin, type ViteDevServer } from 'vite'
8
9
  import type { BlockComponent } from '@contentbit/react'
9
10
 
10
11
  import { handleStudioApiRequest } from './api.js'
@@ -15,10 +16,9 @@ export type {
15
16
  StudioDocument,
16
17
  StudioFileSummary,
17
18
  StudioFinding,
18
- StudioGraph,
19
19
  StudioProject,
20
20
  } from './types.js'
21
- export { scanDocument, scanGraph, scanProject } from './scan.js'
21
+ export { scanDocument, scanProject } from './scan.js'
22
22
 
23
23
  export interface StudioServer {
24
24
  url: string
@@ -47,10 +47,14 @@ export async function startStudio(options: StartStudioOptions): Promise<StudioSe
47
47
  cwd,
48
48
  registryPath: options.registryPath,
49
49
  includeGenericBlocks: options.includeGenericBlocks,
50
+ blocks: options.blocks,
50
51
  linkOptions: options.linkOptions,
51
- minSectionWords: options.minSectionWords,
52
- seoConfig: options.seoConfig,
53
- seoConfigPath: options.seoConfigPath,
52
+ loadSeo: options.loadSeo,
53
+ agentGuidanceFindings: options.agentGuidanceFindings,
54
+ build: options.build,
55
+ origin: options.origin,
56
+ site: options.site,
57
+ check: options.check,
54
58
  }
55
59
 
56
60
  const vite = await createServer({
@@ -127,7 +131,7 @@ function componentCandidates(options: {
127
131
  if (options.registryPath) {
128
132
  const registryPath = isAbsolute(options.registryPath)
129
133
  ? options.registryPath
130
- : resolve(options.cwd, options.registryPath)
134
+ : resolvePath(options.cwd, options.registryPath)
131
135
  dirs.add(dirname(registryPath))
132
136
  }
133
137
  dirs.add(join(options.cwd, 'blocks'))
@@ -154,14 +158,27 @@ function studioApiPlugin(options: StudioOptions): Plugin {
154
158
  name: 'contentbit-studio-api',
155
159
  configureServer(server) {
156
160
  server.middlewares.use((req, res, next) => {
157
- void handleStudioApiRequest(options, req, res).then((handled) => {
158
- if (!handled) next()
159
- })
161
+ void serveStudioApi(options, req, res, next)
160
162
  })
161
163
  },
162
164
  }
163
165
  }
164
166
 
167
+ async function serveStudioApi(
168
+ options: StudioOptions,
169
+ req: Connect.IncomingMessage,
170
+ res: ServerResponse,
171
+ next: Connect.NextFunction,
172
+ ): Promise<void> {
173
+ try {
174
+ if (await handleStudioApiRequest(options, req, res)) return
175
+ } catch (error) {
176
+ next(error)
177
+ return
178
+ }
179
+ next()
180
+ }
181
+
165
182
  async function freePort(host: string): Promise<number> {
166
183
  const server = createNetServer()
167
184
  await new Promise<void>((resolve, reject) => {
@@ -169,7 +186,9 @@ async function freePort(host: string): Promise<number> {
169
186
  server.listen(0, host, resolve)
170
187
  })
171
188
  const { port } = server.address() as AddressInfo
172
- await new Promise((resolve) => server.close(resolve))
189
+ await new Promise((resolve) => {
190
+ server.close(resolve)
191
+ })
173
192
  return port
174
193
  }
175
194