contentbit 0.6.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/bin.js +8 -3
- package/dist/run.js +8 -3
- package/package.json +5 -6
- package/dist/cli-format.js +0 -63
- package/dist/commands/agents.js +0 -64
- package/dist/commands/brief.js +0 -52
- package/dist/commands/docs.js +0 -12
- package/dist/commands/doctor.js +0 -173
- package/dist/commands/init-targets.js +0 -280
- package/dist/commands/init.js +0 -382
- package/dist/commands/instructions.js +0 -15
- package/dist/commands/links.js +0 -84
- package/dist/commands/render.js +0 -33
- package/dist/commands/stats.js +0 -38
- package/dist/commands/studio.js +0 -65
- package/dist/commands/validate.js +0 -49
- package/dist/content-project.js +0 -25
- package/dist/link-options.js +0 -31
- package/dist/links-io.js +0 -14
- package/dist/load-registry.js +0 -1
- package/dist/seo-config.js +0 -21
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
export const TARGETS = ['react', 'markdown', 'astro'];
|
|
4
|
-
const RUNTIME_BASE = ['@contentbit/core', '@contentbit/blocks', 'zod'];
|
|
5
|
-
/** blocks/components.tsx — React components for custom blocks, next to their definitions. */
|
|
6
|
-
function blockComponentsTemplate(styled) {
|
|
7
|
-
const body = styled
|
|
8
|
-
? ` return (
|
|
9
|
-
<figure className="my-6 border-s-2 ps-4">
|
|
10
|
-
<blockquote className="text-lg italic">{ctx.renderMarkdown(data.markdown)}</blockquote>
|
|
11
|
-
<figcaption className="text-muted-foreground mt-2 text-sm">
|
|
12
|
-
— {String(node.props.author)}
|
|
13
|
-
{node.props.role ? \`, \${String(node.props.role)}\` : null}
|
|
14
|
-
</figcaption>
|
|
15
|
-
</figure>
|
|
16
|
-
)`
|
|
17
|
-
: ` return (
|
|
18
|
-
<figure style={{ margin: '1.5rem 0', borderLeft: '2px solid #d4d4d4', paddingLeft: '1rem' }}>
|
|
19
|
-
<blockquote style={{ fontStyle: 'italic' }}>{ctx.renderMarkdown(data.markdown)}</blockquote>
|
|
20
|
-
<figcaption style={{ marginTop: '0.5rem', fontSize: '0.875rem', opacity: 0.7 }}>
|
|
21
|
-
— {String(node.props.author)}
|
|
22
|
-
{node.props.role ? \`, \${String(node.props.role)}\` : null}
|
|
23
|
-
</figcaption>
|
|
24
|
-
</figure>
|
|
25
|
-
)`;
|
|
26
|
-
return `import type { BlockComponent, BlockComponentProps } from '@contentbit/react'
|
|
27
|
-
|
|
28
|
-
// One React component per custom block, keyed by block name. Definitions
|
|
29
|
-
// live in ./registry.ts — add a block there, add its component here, and
|
|
30
|
-
// the rest of the app never changes.
|
|
31
|
-
function QuoteBlock({ node, ctx }: BlockComponentProps) {
|
|
32
|
-
const data = node.data as { markdown: string }
|
|
33
|
-
${body}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const blockComponents: Record<string, BlockComponent> = {
|
|
37
|
-
quote: QuoteBlock,
|
|
38
|
-
}
|
|
39
|
-
`;
|
|
40
|
-
}
|
|
41
|
-
/** The wrapper component: styled pack or headless, with or without a Markdown lib. */
|
|
42
|
-
function reactComponent(styled, mdWired, blocksImport) {
|
|
43
|
-
const mdImport = mdWired ? "import ReactMarkdown from 'react-markdown'\n" : '';
|
|
44
|
-
const mdProp = mdWired
|
|
45
|
-
? '\n renderMarkdown={(md) => <ReactMarkdown>{md}</ReactMarkdown>}'
|
|
46
|
-
: `\n // TODO: plug your Markdown library in here, e.g. react-markdown.
|
|
47
|
-
// One function renders all prose: https://contentbit.dev/docs/guides/markdown
|
|
48
|
-
// renderMarkdown={(md) => <Markdown source={md} />}`;
|
|
49
|
-
const rendererImport = styled
|
|
50
|
-
? `\n// The styled pack installed by shadcn. Yours to edit.
|
|
51
|
-
import { ContentRenderer } from '@/components/content-blocks/content-renderer'`
|
|
52
|
-
: '';
|
|
53
|
-
const renderer = styled ? 'ContentRenderer' : 'ContentBlocks';
|
|
54
|
-
const reactImport = styled ? '' : "import { ContentBlocks } from '@contentbit/react'\n";
|
|
55
|
-
return `'use client'
|
|
56
|
-
|
|
57
|
-
import { genericBlocks } from '@contentbit/blocks'
|
|
58
|
-
import { createBlockRegistry, parseDocument, stripFrontmatter, validateDocument } from '@contentbit/core'
|
|
59
|
-
${reactImport}${mdImport}${rendererImport}
|
|
60
|
-
// Everything block-related lives in the blocks/ folder: definitions in
|
|
61
|
-
// registry.ts (shared with the validate CLI), components in components.tsx.
|
|
62
|
-
import customBlocks from '${blocksImport}/registry'
|
|
63
|
-
import { blockComponents } from '${blocksImport}/components'
|
|
64
|
-
|
|
65
|
-
const registry = createBlockRegistry().use(genericBlocks()).use(customBlocks)
|
|
66
|
-
|
|
67
|
-
export function Content({ source }: { source: string }) {
|
|
68
|
-
const result = validateDocument(parseDocument(stripFrontmatter(source)), registry)
|
|
69
|
-
return (
|
|
70
|
-
<${renderer}
|
|
71
|
-
document={result.document}
|
|
72
|
-
components={blockComponents}${mdProp}
|
|
73
|
-
/>
|
|
74
|
-
)
|
|
75
|
-
}
|
|
76
|
-
`;
|
|
77
|
-
}
|
|
78
|
-
/** Where the component and example page belong for the detected framework. */
|
|
79
|
-
function detectFramework(cwd, deps) {
|
|
80
|
-
if ((deps['@tanstack/react-start'] || deps['@tanstack/react-router']) &&
|
|
81
|
-
existsSync(join(cwd, 'src/routes'))) {
|
|
82
|
-
return {
|
|
83
|
-
framework: 'tanstack',
|
|
84
|
-
componentPath: 'src/components/content-blocks.tsx',
|
|
85
|
-
pagePath: 'src/routes/example.tsx',
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
if (deps.next) {
|
|
89
|
-
const appDir = existsSync(join(cwd, 'src/app')) ? 'src/app' : 'app';
|
|
90
|
-
if (existsSync(join(cwd, appDir))) {
|
|
91
|
-
return {
|
|
92
|
-
framework: 'next',
|
|
93
|
-
componentPath: 'components/content-blocks.tsx',
|
|
94
|
-
pagePath: `${appDir}/example/page.tsx`,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return { framework: null, componentPath: 'components/content-blocks.tsx', pagePath: null };
|
|
99
|
-
}
|
|
100
|
-
const TANSTACK_PAGE = `import { createFileRoute } from '@tanstack/react-router'
|
|
101
|
-
|
|
102
|
-
import { Content } from '../components/content-blocks'
|
|
103
|
-
// Vite's ?raw import inlines the Markdown as a string at build time.
|
|
104
|
-
import source from '../../content/example.md?raw'
|
|
105
|
-
|
|
106
|
-
export const Route = createFileRoute('/example')({ component: ExamplePage })
|
|
107
|
-
|
|
108
|
-
function ExamplePage() {
|
|
109
|
-
return (
|
|
110
|
-
<main style={{ maxWidth: '42rem', margin: '0 auto', padding: '3rem 1.5rem' }}>
|
|
111
|
-
<Content source={source} />
|
|
112
|
-
</main>
|
|
113
|
-
)
|
|
114
|
-
}
|
|
115
|
-
`;
|
|
116
|
-
const NEXT_PAGE = `import { readFile } from 'node:fs/promises'
|
|
117
|
-
|
|
118
|
-
// If your project has no "@/" path alias, switch to a relative import.
|
|
119
|
-
import { Content } from '@/components/content-blocks'
|
|
120
|
-
|
|
121
|
-
export default async function ExamplePage() {
|
|
122
|
-
const source = await readFile('content/example.md', 'utf8')
|
|
123
|
-
return (
|
|
124
|
-
<main style={{ maxWidth: '42rem', margin: '0 auto', padding: '3rem 1.5rem' }}>
|
|
125
|
-
<Content source={source} />
|
|
126
|
-
</main>
|
|
127
|
-
)
|
|
128
|
-
}
|
|
129
|
-
`;
|
|
130
|
-
const ASTRO_CONTENT_CONFIG = `import { defineCollection } from 'astro:content'
|
|
131
|
-
import { glob } from 'astro/loaders'
|
|
132
|
-
|
|
133
|
-
export const collections = {
|
|
134
|
-
articles: defineCollection({
|
|
135
|
-
// Astro's builtin Markdown loader. Entry bodies are parsed and validated
|
|
136
|
-
// where they render (see src/pages/example.astro); \`contentbit validate\`
|
|
137
|
-
// covers the same files in CI.
|
|
138
|
-
loader: glob({ pattern: '**/*.md', base: './content' }),
|
|
139
|
-
}),
|
|
140
|
-
}
|
|
141
|
-
`;
|
|
142
|
-
const ASTRO_QUOTE_BLOCK = `---
|
|
143
|
-
// The Astro component for the custom \`quote\` block defined in blocks/registry.ts.
|
|
144
|
-
// Block props arrive as component props; nested content arrives via <slot />.
|
|
145
|
-
interface Props {
|
|
146
|
-
author: string
|
|
147
|
-
role?: string
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const { author, role } = Astro.props
|
|
151
|
-
---
|
|
152
|
-
|
|
153
|
-
<figure style="margin: 1.5rem 0; border-left: 2px solid #d4d4d4; padding-left: 1rem;">
|
|
154
|
-
<blockquote style="font-style: italic;"><slot /></blockquote>
|
|
155
|
-
<figcaption style="margin-top: 0.5rem; font-size: 0.875rem; opacity: 0.7;">
|
|
156
|
-
— {author}{role ? \`, \${role}\` : null}
|
|
157
|
-
</figcaption>
|
|
158
|
-
</figure>
|
|
159
|
-
`;
|
|
160
|
-
/** The example page: styled pack renderer or the headless ContentBlocks. */
|
|
161
|
-
function astroPage(styled) {
|
|
162
|
-
const importLine = styled
|
|
163
|
-
? "import ContentRenderer from '../components/content-blocks/content-renderer.astro'"
|
|
164
|
-
: "import { ContentBlocks } from '@contentbit/astro/components'";
|
|
165
|
-
const renderer = styled ? 'ContentRenderer' : 'ContentBlocks';
|
|
166
|
-
return `---
|
|
167
|
-
import { genericBlocks } from '@contentbit/blocks'
|
|
168
|
-
import { createBlockRegistry, parseDocument, validateDocument } from '@contentbit/core'
|
|
169
|
-
import { getEntry } from 'astro:content'
|
|
170
|
-
|
|
171
|
-
${importLine}
|
|
172
|
-
|
|
173
|
-
// Definitions in blocks/registry.ts are shared with the validate CLI.
|
|
174
|
-
import customBlocks from '../../blocks/registry'
|
|
175
|
-
import QuoteBlock from '../../blocks/QuoteBlock.astro'
|
|
176
|
-
|
|
177
|
-
// Entry ids are the file path relative to the collection base, minus ".md".
|
|
178
|
-
const entry = await getEntry('articles', 'example')
|
|
179
|
-
if (!entry?.body) throw new Error('Entry "example" not found in the articles collection.')
|
|
180
|
-
|
|
181
|
-
const registry = createBlockRegistry().use(genericBlocks()).use(customBlocks)
|
|
182
|
-
// Static pages render at build time, so invalid blocks fail the build here.
|
|
183
|
-
const result = validateDocument(parseDocument(entry.body), registry)
|
|
184
|
-
---
|
|
185
|
-
|
|
186
|
-
<main style="max-width: 42rem; margin: 0 auto; padding: 3rem 1.5rem;">
|
|
187
|
-
<${renderer} document={result.document} components={{ quote: QuoteBlock }} />
|
|
188
|
-
</main>
|
|
189
|
-
`;
|
|
190
|
-
}
|
|
191
|
-
function runtimeWith(...extra) {
|
|
192
|
-
return [...RUNTIME_BASE, ...extra];
|
|
193
|
-
}
|
|
194
|
-
function reactRuntime(md) {
|
|
195
|
-
return runtimeWith('@contentbit/react', ...(md === 'none' ? [] : [md]));
|
|
196
|
-
}
|
|
197
|
-
async function createReactPlan(ctx) {
|
|
198
|
-
const files = [];
|
|
199
|
-
const layout = detectFramework(ctx.cwd, ctx.deps);
|
|
200
|
-
const componentsJsonPath = join(ctx.cwd, 'components.json');
|
|
201
|
-
const styled = !ctx.noStyled &&
|
|
202
|
-
existsSync(componentsJsonPath) &&
|
|
203
|
-
(await ctx.installStyledPack('@contentbit/generic-pack'));
|
|
204
|
-
const depth = layout.componentPath.split('/').length - 1;
|
|
205
|
-
const blocksImport = `${'../'.repeat(depth)}blocks`;
|
|
206
|
-
files.push(['blocks/components.tsx', blockComponentsTemplate(styled)]);
|
|
207
|
-
files.push([
|
|
208
|
-
layout.componentPath,
|
|
209
|
-
reactComponent(styled, ctx.md === 'react-markdown', blocksImport),
|
|
210
|
-
]);
|
|
211
|
-
if (!ctx.noPage && layout.pagePath) {
|
|
212
|
-
files.push([layout.pagePath, layout.framework === 'tanstack' ? TANSTACK_PAGE : NEXT_PAGE]);
|
|
213
|
-
}
|
|
214
|
-
const nextSteps = !ctx.noPage && layout.pagePath
|
|
215
|
-
? [' 2. Start the dev server and open /example to see the article rendered.']
|
|
216
|
-
: [
|
|
217
|
-
' 2. Render it: import { Content } from "./components/content-blocks"',
|
|
218
|
-
' <Content source={...content/example.md as a string} />',
|
|
219
|
-
];
|
|
220
|
-
nextSteps.push(' 3. Styled components: pnpm dlx shadcn@latest add @contentbit/generic-pack');
|
|
221
|
-
return { files, nextSteps };
|
|
222
|
-
}
|
|
223
|
-
async function createAstroPlan(ctx) {
|
|
224
|
-
const files = [['blocks/QuoteBlock.astro', ASTRO_QUOTE_BLOCK]];
|
|
225
|
-
const componentsJsonPath = join(ctx.cwd, 'components.json');
|
|
226
|
-
const styled = !ctx.noStyled &&
|
|
227
|
-
existsSync(componentsJsonPath) &&
|
|
228
|
-
(await ctx.installStyledPack('@contentbit/astro-pack'));
|
|
229
|
-
// Every config filename Astro resolves (src/content.config.* plus the legacy
|
|
230
|
-
// src/content/config.* location), so we never scaffold a second config that
|
|
231
|
-
// Astro would silently ignore.
|
|
232
|
-
const configCandidates = ['ts', 'mts', 'mjs', 'js'].flatMap((ext) => [
|
|
233
|
-
`src/content.config.${ext}`,
|
|
234
|
-
`src/content/config.${ext}`,
|
|
235
|
-
]);
|
|
236
|
-
const existingConfig = configCandidates.find((p) => existsSync(join(ctx.cwd, p)));
|
|
237
|
-
if (existingConfig) {
|
|
238
|
-
ctx.io.stdout(`content config exists (${existingConfig}); add this collection manually:`);
|
|
239
|
-
ctx.io.stdout(ASTRO_CONTENT_CONFIG);
|
|
240
|
-
ctx.io.stdout('the example page expects the "articles" collection above');
|
|
241
|
-
}
|
|
242
|
-
else {
|
|
243
|
-
files.push(['src/content.config.ts', ASTRO_CONTENT_CONFIG]);
|
|
244
|
-
}
|
|
245
|
-
if (!ctx.noPage)
|
|
246
|
-
files.push(['src/pages/example.astro', astroPage(styled)]);
|
|
247
|
-
return {
|
|
248
|
-
files,
|
|
249
|
-
nextSteps: [
|
|
250
|
-
' 2. Start the dev server and open /example to see the article rendered.',
|
|
251
|
-
' 3. Styled components: pnpm dlx shadcn@latest add @contentbit/astro-pack',
|
|
252
|
-
],
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
export const TARGET_ADAPTERS = {
|
|
256
|
-
react: {
|
|
257
|
-
markdownChoices: ['react-markdown', 'none'],
|
|
258
|
-
runtimeDependencies: reactRuntime,
|
|
259
|
-
createPlan: createReactPlan,
|
|
260
|
-
},
|
|
261
|
-
markdown: {
|
|
262
|
-
markdownChoices: ['none'],
|
|
263
|
-
runtimeDependencies: () => runtimeWith(),
|
|
264
|
-
createPlan: async () => ({
|
|
265
|
-
files: [],
|
|
266
|
-
nextSteps: [' 2. Render it: contentbit render content/example.md'],
|
|
267
|
-
}),
|
|
268
|
-
},
|
|
269
|
-
astro: {
|
|
270
|
-
// Astro projects usually reuse their host Markdown pipeline.
|
|
271
|
-
markdownChoices: ['none'],
|
|
272
|
-
runtimeDependencies: () => runtimeWith('@contentbit/astro'),
|
|
273
|
-
createPlan: createAstroPlan,
|
|
274
|
-
},
|
|
275
|
-
};
|
|
276
|
-
export function detectTarget(deps) {
|
|
277
|
-
const hasReact = Boolean(deps.react);
|
|
278
|
-
const hasAstro = Boolean(deps.astro);
|
|
279
|
-
return hasAstro ? 'astro' : hasReact ? 'react' : 'markdown';
|
|
280
|
-
}
|
package/dist/commands/init.js
DELETED
|
@@ -1,382 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
3
|
-
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import { loadRegistry } from '../load-registry.js';
|
|
6
|
-
import { installAgentIntegration } from './agents.js';
|
|
7
|
-
import { detectTarget, TARGET_ADAPTERS, TARGETS } from './init-targets.js';
|
|
8
|
-
const REGISTRY_TEMPLATE = `// Custom block definitions for this project. The CLI and your app share
|
|
9
|
-
// this module — Node 22.18+ imports TypeScript directly:
|
|
10
|
-
//
|
|
11
|
-
// contentbit validate "content/**/*.md" --registry ./blocks/registry.ts
|
|
12
|
-
//
|
|
13
|
-
// Definitions stay framework-free (the CLI and every render target use
|
|
14
|
-
// them); render components live next door in blocks/components.tsx or
|
|
15
|
-
// framework-specific component files copied from the shadcn registry.
|
|
16
|
-
// Docs: https://contentbit.dev/docs/guides/custom-blocks
|
|
17
|
-
import { defineBlock, markdownBody, type BlockDefinition } from '@contentbit/core'
|
|
18
|
-
import { z } from 'zod'
|
|
19
|
-
|
|
20
|
-
export const quote = defineBlock({
|
|
21
|
-
name: 'quote',
|
|
22
|
-
description: 'A pull quote with an author.',
|
|
23
|
-
props: z.object({
|
|
24
|
-
author: z.string().min(1),
|
|
25
|
-
role: z.string().optional(),
|
|
26
|
-
}),
|
|
27
|
-
content: markdownBody({ minLength: 3 }),
|
|
28
|
-
authoring: {
|
|
29
|
-
useWhen: ['Quoting a person to support a point'],
|
|
30
|
-
avoidWhen: ['Highlighting your own remark, use callout instead'],
|
|
31
|
-
example: ':::quote{author="Ada Lovelace"}\\nThe Analytical Engine weaves algebraic patterns.\\n:::',
|
|
32
|
-
},
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
export default [quote] satisfies BlockDefinition<unknown>[]
|
|
36
|
-
`;
|
|
37
|
-
const EXAMPLE_CONTENT = `---
|
|
38
|
-
slug: hello-content-blocks
|
|
39
|
-
linksTo:
|
|
40
|
-
- related-contentbit-workflows
|
|
41
|
-
aliases:
|
|
42
|
-
- getting-started-contentbit
|
|
43
|
-
keywords:
|
|
44
|
-
primary: validated Markdown blocks
|
|
45
|
-
secondary: [content workflow, agent writing]
|
|
46
|
-
---
|
|
47
|
-
|
|
48
|
-
# Hello, Content Blocks
|
|
49
|
-
|
|
50
|
-
Regular Markdown works everywhere. Blocks add validated structure:
|
|
51
|
-
|
|
52
|
-
:::callout{type="tip" title="Try breaking this file"}
|
|
53
|
-
Run the validate script and you will get file:line:col diagnostics.
|
|
54
|
-
:::
|
|
55
|
-
|
|
56
|
-
:::steps
|
|
57
|
-
1. Edit this file and add or break a block.
|
|
58
|
-
2. Run \`contentbit validate "content/**/*.md"\`.
|
|
59
|
-
3. Render it with the target you picked at init.
|
|
60
|
-
:::
|
|
61
|
-
|
|
62
|
-
This one is a **custom block**, defined in \`blocks/registry.ts\` and rendered
|
|
63
|
-
by the \`QuoteBlock\` component, in about twenty lines:
|
|
64
|
-
|
|
65
|
-
:::quote{author="Ada Lovelace" role="Notes on the Analytical Engine, 1843"}
|
|
66
|
-
The Analytical Engine weaves algebraic patterns just as the Jacquard loom
|
|
67
|
-
weaves flowers and leaves.
|
|
68
|
-
:::
|
|
69
|
-
`;
|
|
70
|
-
const RELATED_CONTENT = `---
|
|
71
|
-
slug: related-contentbit-workflows
|
|
72
|
-
linksTo:
|
|
73
|
-
- hello-content-blocks
|
|
74
|
-
keywords:
|
|
75
|
-
primary: contentbit workflow
|
|
76
|
-
secondary: [validation loop, internal links]
|
|
77
|
-
---
|
|
78
|
-
|
|
79
|
-
# Related contentbit workflows
|
|
80
|
-
|
|
81
|
-
This supporting page exists to show internal links in frontmatter. The link
|
|
82
|
-
graph is authored once with \`slug\` and \`linksTo\`, then contentbit derives
|
|
83
|
-
\`linkedFrom\` in \`.contentbit/link-index.json\`.
|
|
84
|
-
|
|
85
|
-
:::callout{type="note"}
|
|
86
|
-
Run \`contentbit links "content/**/*.md" --fix\` after renaming a page. Alias
|
|
87
|
-
references in \`linksTo\` are rewritten to the current slug, while \`aliases\`
|
|
88
|
-
stays as the rename record.
|
|
89
|
-
:::
|
|
90
|
-
`;
|
|
91
|
-
const SEO_CONFIG_TEMPLATE = `import { defineSeoConfig } from '@contentbit/core'
|
|
92
|
-
|
|
93
|
-
export default defineSeoConfig({
|
|
94
|
-
pageTypes: {
|
|
95
|
-
alternative: {
|
|
96
|
-
requiredFrontmatter: ['type', 'intent', 'keywords.primary'],
|
|
97
|
-
requiredSections: [
|
|
98
|
-
{ id: 'overview', headings: ['Overview', 'Summary'] },
|
|
99
|
-
{ id: 'alternatives', headings: ['Best alternatives', 'Top alternatives'] },
|
|
100
|
-
{ id: 'comparison', headings: ['Comparison', 'Feature comparison'] },
|
|
101
|
-
{ id: 'faq', headings: ['FAQ', 'Frequently asked questions'] },
|
|
102
|
-
],
|
|
103
|
-
requiredBlocks: ['comparison'],
|
|
104
|
-
recommendedBlocks: ['faq', 'key-metrics'],
|
|
105
|
-
minOutgoingLinks: 2,
|
|
106
|
-
},
|
|
107
|
-
comparison: {
|
|
108
|
-
requiredFrontmatter: ['type', 'intent', 'keywords.primary'],
|
|
109
|
-
requiredSections: [
|
|
110
|
-
{ id: 'overview', headings: ['Overview', 'Summary'] },
|
|
111
|
-
{ id: 'comparison', headings: ['Comparison', 'Feature comparison'] },
|
|
112
|
-
{ id: 'recommendation', headings: ['Recommendation', 'Which should you choose?'] },
|
|
113
|
-
],
|
|
114
|
-
requiredBlocks: ['comparison'],
|
|
115
|
-
recommendedBlocks: ['faq'],
|
|
116
|
-
minOutgoingLinks: 2,
|
|
117
|
-
},
|
|
118
|
-
integration: {
|
|
119
|
-
requiredFrontmatter: ['type', 'intent', 'keywords.primary'],
|
|
120
|
-
requiredSections: [
|
|
121
|
-
{ id: 'overview', headings: ['Overview', 'Summary'] },
|
|
122
|
-
{ id: 'setup', headings: ['Setup', 'How to connect'] },
|
|
123
|
-
{ id: 'use-cases', headings: ['Use cases', 'Common workflows'] },
|
|
124
|
-
],
|
|
125
|
-
recommendedBlocks: ['steps', 'faq'],
|
|
126
|
-
minOutgoingLinks: 2,
|
|
127
|
-
},
|
|
128
|
-
'use-case': {
|
|
129
|
-
requiredFrontmatter: ['type', 'intent', 'keywords.primary'],
|
|
130
|
-
requiredSections: [
|
|
131
|
-
{ id: 'overview', headings: ['Overview', 'Summary'] },
|
|
132
|
-
{ id: 'workflow', headings: ['Workflow', 'How it works'] },
|
|
133
|
-
{ id: 'outcomes', headings: ['Outcomes', 'Results'] },
|
|
134
|
-
],
|
|
135
|
-
recommendedBlocks: ['steps', 'key-metrics'],
|
|
136
|
-
minOutgoingLinks: 2,
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
pages: {},
|
|
140
|
-
})
|
|
141
|
-
`;
|
|
142
|
-
function detectPackageManager(cwd) {
|
|
143
|
-
// The project's lockfile outranks however the CLI itself was launched.
|
|
144
|
-
const locks = [
|
|
145
|
-
['pnpm-lock.yaml', 'pnpm'],
|
|
146
|
-
['yarn.lock', 'yarn'],
|
|
147
|
-
['bun.lock', 'bun'],
|
|
148
|
-
['bun.lockb', 'bun'],
|
|
149
|
-
['package-lock.json', 'npm'],
|
|
150
|
-
];
|
|
151
|
-
for (const [file, pm] of locks) {
|
|
152
|
-
if (existsSync(join(cwd, file)))
|
|
153
|
-
return pm;
|
|
154
|
-
}
|
|
155
|
-
const agent = process.env.npm_config_user_agent ?? '';
|
|
156
|
-
for (const pm of ['pnpm', 'yarn', 'bun']) {
|
|
157
|
-
if (agent.startsWith(pm))
|
|
158
|
-
return pm;
|
|
159
|
-
}
|
|
160
|
-
return 'npm';
|
|
161
|
-
}
|
|
162
|
-
function installArgs(pm, dev, pkgs) {
|
|
163
|
-
const add = pm === 'npm' ? 'install' : 'add';
|
|
164
|
-
return dev ? [add, '-D', ...pkgs] : [add, ...pkgs];
|
|
165
|
-
}
|
|
166
|
-
function dlxCommand(pm) {
|
|
167
|
-
if (pm === 'pnpm')
|
|
168
|
-
return ['pnpm', ['dlx']];
|
|
169
|
-
if (pm === 'yarn')
|
|
170
|
-
return ['yarn', ['dlx']];
|
|
171
|
-
if (pm === 'bun')
|
|
172
|
-
return ['bunx', []];
|
|
173
|
-
return ['npx', ['--yes']];
|
|
174
|
-
}
|
|
175
|
-
function runInstall(pm, args, cwd) {
|
|
176
|
-
return new Promise((resolve) => {
|
|
177
|
-
const child = spawn(pm, args, { cwd, stdio: 'inherit', shell: process.platform === 'win32' });
|
|
178
|
-
child.on('close', (code) => resolve(code ?? 1));
|
|
179
|
-
child.on('error', () => resolve(1));
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
/** Wire the @contentbit shadcn registry and install a styled pack. Returns true on success. */
|
|
183
|
-
async function installStyledPack(cwd, pack, noInstall, io) {
|
|
184
|
-
const componentsJsonPath = join(cwd, 'components.json');
|
|
185
|
-
const componentsJson = JSON.parse(await readFile(componentsJsonPath, 'utf8'));
|
|
186
|
-
componentsJson.registries ??= {};
|
|
187
|
-
if (!componentsJson.registries['@contentbit']) {
|
|
188
|
-
componentsJson.registries['@contentbit'] = 'https://contentbit.dev/r/{name}.json';
|
|
189
|
-
await writeFile(componentsJsonPath, `${JSON.stringify(componentsJson, null, 2)}\n`, 'utf8');
|
|
190
|
-
io.stdout('added @contentbit registry to components.json');
|
|
191
|
-
}
|
|
192
|
-
if (noInstall) {
|
|
193
|
-
io.stdout(`skipped: shadcn add ${pack}`);
|
|
194
|
-
return true;
|
|
195
|
-
}
|
|
196
|
-
const [bin, prefix] = dlxCommand(detectPackageManager(cwd));
|
|
197
|
-
io.stdout(`installing the styled pack: shadcn add ${pack}`);
|
|
198
|
-
const code = await runInstall(bin, [...prefix, 'shadcn@latest', 'add', pack, '--yes'], cwd);
|
|
199
|
-
if (code !== 0)
|
|
200
|
-
io.stderr('styled pack install failed; falling back to the headless renderer');
|
|
201
|
-
return code === 0;
|
|
202
|
-
}
|
|
203
|
-
/** Write a file unless it already exists; returns what happened for the summary. */
|
|
204
|
-
async function scaffold(path, content) {
|
|
205
|
-
try {
|
|
206
|
-
await readFile(path, 'utf8');
|
|
207
|
-
return 'skipped';
|
|
208
|
-
}
|
|
209
|
-
catch {
|
|
210
|
-
await mkdir(join(path, '..'), { recursive: true });
|
|
211
|
-
await writeFile(path, content, 'utf8');
|
|
212
|
-
return 'created';
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
export async function initCommand(input, io) {
|
|
216
|
-
const cwd = input.cwd ?? process.cwd();
|
|
217
|
-
// A project to init into is required.
|
|
218
|
-
let pkg;
|
|
219
|
-
const pkgPath = join(cwd, 'package.json');
|
|
220
|
-
try {
|
|
221
|
-
pkg = JSON.parse(await readFile(pkgPath, 'utf8'));
|
|
222
|
-
}
|
|
223
|
-
catch {
|
|
224
|
-
io.stderr('No package.json found. Run this inside a project (npm init first).');
|
|
225
|
-
return 1;
|
|
226
|
-
}
|
|
227
|
-
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
228
|
-
// Resolve the render target: flag > prompt (interactive) > detection.
|
|
229
|
-
const detected = detectTarget(deps);
|
|
230
|
-
let target;
|
|
231
|
-
if (input.target) {
|
|
232
|
-
if (!TARGETS.includes(input.target)) {
|
|
233
|
-
io.stderr(`Unknown target "${input.target}". Use one of: ${TARGETS.join(', ')}`);
|
|
234
|
-
return 2;
|
|
235
|
-
}
|
|
236
|
-
target = input.target;
|
|
237
|
-
}
|
|
238
|
-
else if (!input.yes && process.stdin.isTTY && process.stdout.isTTY) {
|
|
239
|
-
const { isCancel, select } = await import('@clack/prompts');
|
|
240
|
-
const answer = await select({
|
|
241
|
-
message: 'Render target?',
|
|
242
|
-
initialValue: detected,
|
|
243
|
-
options: [
|
|
244
|
-
{ value: 'react', label: 'React', hint: 'ContentBlocks component' },
|
|
245
|
-
{ value: 'astro', label: 'Astro', hint: 'content collections + .astro components' },
|
|
246
|
-
{ value: 'markdown', label: 'Plain Markdown', hint: 'fallback rendering only' },
|
|
247
|
-
],
|
|
248
|
-
});
|
|
249
|
-
if (isCancel(answer))
|
|
250
|
-
return 1;
|
|
251
|
-
target = answer;
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
target = detected;
|
|
255
|
-
}
|
|
256
|
-
const adapter = TARGET_ADAPTERS[target];
|
|
257
|
-
// Resolve the Markdown library: flag > prompt (interactive) > target default.
|
|
258
|
-
// The default gives working prose rendering out of the box; 'none' opts out.
|
|
259
|
-
const choices = adapter.markdownChoices;
|
|
260
|
-
let md;
|
|
261
|
-
if (input.md) {
|
|
262
|
-
if (!choices.includes(input.md)) {
|
|
263
|
-
io.stderr(`Unknown markdown library "${input.md}". Use one of: ${choices.join(', ')}`);
|
|
264
|
-
return 2;
|
|
265
|
-
}
|
|
266
|
-
md = input.md;
|
|
267
|
-
}
|
|
268
|
-
else if (choices.length > 1 && !input.yes && process.stdin.isTTY && process.stdout.isTTY) {
|
|
269
|
-
const { isCancel, select } = await import('@clack/prompts');
|
|
270
|
-
const answer = await select({
|
|
271
|
-
message: 'Markdown library for prose rendering?',
|
|
272
|
-
initialValue: choices[0],
|
|
273
|
-
options: choices.map((c) => ({
|
|
274
|
-
value: c,
|
|
275
|
-
label: c,
|
|
276
|
-
hint: c === 'none' ? 'wire one yourself later' : 'installed and wired for you',
|
|
277
|
-
})),
|
|
278
|
-
});
|
|
279
|
-
if (isCancel(answer))
|
|
280
|
-
return 1;
|
|
281
|
-
md = answer;
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
md = choices[0];
|
|
285
|
-
}
|
|
286
|
-
// Install runtime packages plus the CLI as a dev dependency.
|
|
287
|
-
const runtime = adapter.runtimeDependencies(md);
|
|
288
|
-
if (input.noInstall) {
|
|
289
|
-
io.stdout(`skipped install: ${runtime.join(' ')} + contentbit (dev)`);
|
|
290
|
-
}
|
|
291
|
-
else {
|
|
292
|
-
const pm = detectPackageManager(cwd);
|
|
293
|
-
io.stdout(`installing with ${pm}: ${runtime.join(' ')}`);
|
|
294
|
-
if ((await runInstall(pm, installArgs(pm, false, runtime), cwd)) !== 0) {
|
|
295
|
-
io.stderr('install failed');
|
|
296
|
-
return 1;
|
|
297
|
-
}
|
|
298
|
-
if ((await runInstall(pm, installArgs(pm, true, ['contentbit']), cwd)) !== 0) {
|
|
299
|
-
io.stderr('install failed');
|
|
300
|
-
return 1;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
const plan = await adapter.createPlan({
|
|
304
|
-
cwd,
|
|
305
|
-
deps,
|
|
306
|
-
md,
|
|
307
|
-
noPage: Boolean(input.noPage),
|
|
308
|
-
noStyled: Boolean(input.noStyled),
|
|
309
|
-
io,
|
|
310
|
-
installStyledPack: (pack) => installStyledPack(cwd, pack, Boolean(input.noInstall), io),
|
|
311
|
-
});
|
|
312
|
-
// Scaffold project files; never overwrite.
|
|
313
|
-
const files = [
|
|
314
|
-
['blocks/registry.ts', REGISTRY_TEMPLATE],
|
|
315
|
-
['content/example.md', EXAMPLE_CONTENT],
|
|
316
|
-
['content/related.md', RELATED_CONTENT],
|
|
317
|
-
...plan.files,
|
|
318
|
-
];
|
|
319
|
-
if (input.seo)
|
|
320
|
-
files.push(['contentbit.seo.config.ts', SEO_CONFIG_TEMPLATE]);
|
|
321
|
-
for (const [rel, content] of files) {
|
|
322
|
-
const result = await scaffold(join(cwd, rel), content);
|
|
323
|
-
io.stdout(`${result}: ${rel}`);
|
|
324
|
-
}
|
|
325
|
-
// Wire content scripts.
|
|
326
|
-
const fresh = JSON.parse(await readFile(pkgPath, 'utf8'));
|
|
327
|
-
fresh.scripts ??= {};
|
|
328
|
-
if (!fresh.scripts['content:check']) {
|
|
329
|
-
fresh.scripts['content:check'] =
|
|
330
|
-
'contentbit validate "content/**/*.md" --registry ./blocks/registry.ts';
|
|
331
|
-
io.stdout('added script: content:check');
|
|
332
|
-
}
|
|
333
|
-
if (!fresh.scripts['content:links']) {
|
|
334
|
-
fresh.scripts['content:links'] = 'contentbit links "content/**/*.md"';
|
|
335
|
-
io.stdout('added script: content:links');
|
|
336
|
-
}
|
|
337
|
-
if (!fresh.scripts['content:doctor']) {
|
|
338
|
-
fresh.scripts['content:doctor'] =
|
|
339
|
-
'contentbit doctor "content/**/*.md" --registry ./blocks/registry.ts';
|
|
340
|
-
io.stdout('added script: content:doctor');
|
|
341
|
-
}
|
|
342
|
-
if (!fresh.scripts.studio) {
|
|
343
|
-
fresh.scripts.studio = 'contentbit studio "content/**/*.md" --registry ./blocks/registry.ts';
|
|
344
|
-
io.stdout('added script: studio');
|
|
345
|
-
}
|
|
346
|
-
if (!pkg.scripts?.['content:check'] ||
|
|
347
|
-
!pkg.scripts?.['content:links'] ||
|
|
348
|
-
!pkg.scripts?.['content:doctor'] ||
|
|
349
|
-
!pkg.scripts?.studio) {
|
|
350
|
-
await writeFile(pkgPath, `${JSON.stringify(fresh, null, 2)}\n`, 'utf8');
|
|
351
|
-
}
|
|
352
|
-
// Generate the LLM authoring guide from the registry, ready to paste into a prompt.
|
|
353
|
-
let registry;
|
|
354
|
-
try {
|
|
355
|
-
// Include the scaffolded custom blocks so the guide covers them too.
|
|
356
|
-
registry = await loadRegistry(join(cwd, 'blocks/registry.ts'));
|
|
357
|
-
}
|
|
358
|
-
catch {
|
|
359
|
-
registry = await loadRegistry(); // packages not installed yet (--no-install)
|
|
360
|
-
}
|
|
361
|
-
const guide = registry.toAuthoringGuide({ audience: 'llm', includeExamples: true });
|
|
362
|
-
await writeFile(join(cwd, 'contentbit-guide.md'), guide, 'utf8');
|
|
363
|
-
io.stdout('created: contentbit-guide.md (LLM authoring instructions)');
|
|
364
|
-
// Coding-agent integration: an AGENTS.md block for every agent, plus Claude
|
|
365
|
-
// Code skills when a .claude/ directory exists. `contentbit agents` refreshes.
|
|
366
|
-
if (!input.noAgents) {
|
|
367
|
-
await installAgentIntegration(cwd, {}, io);
|
|
368
|
-
io.stdout('Agent integration installed — try asking your agent:');
|
|
369
|
-
io.stdout(' "write a blog post about X" or "audit my content"');
|
|
370
|
-
}
|
|
371
|
-
io.stdout('');
|
|
372
|
-
io.stdout('Done. Next steps:');
|
|
373
|
-
const pm = detectPackageManager(cwd);
|
|
374
|
-
io.stdout(` 1. Browse content locally: ${pm} run studio`);
|
|
375
|
-
io.stdout(` Inspect content health: ${pm} run content:doctor`);
|
|
376
|
-
io.stdout(` Validate the starter content: ${pm} run content:check`);
|
|
377
|
-
io.stdout(` Build the link index: ${pm} run content:links`);
|
|
378
|
-
for (const line of plan.nextSteps)
|
|
379
|
-
io.stdout(line);
|
|
380
|
-
io.stdout(' Docs: https://contentbit.dev/docs');
|
|
381
|
-
return 0;
|
|
382
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { loadRegistry } from '../load-registry.js';
|
|
2
|
-
export async function instructionsCommand(input, io) {
|
|
3
|
-
const registry = await loadRegistry(input.registry, {
|
|
4
|
-
includeGenericBlocks: !input.noGenericBlocks,
|
|
5
|
-
});
|
|
6
|
-
const guide = registry.toAuthoringGuide({
|
|
7
|
-
audience: input.audience === 'human' ? 'human' : 'llm',
|
|
8
|
-
includeExamples: !input.noExamples,
|
|
9
|
-
});
|
|
10
|
-
if (input.out)
|
|
11
|
-
await io.writeFile(input.out, guide);
|
|
12
|
-
else
|
|
13
|
-
io.stdout(guide);
|
|
14
|
-
return 0;
|
|
15
|
-
}
|