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
package/dist/commands/links.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { aliasReplacementsForPage, buildLinkIndex, extractFrontmatter, linkGraphSummary, serializeLinkIndex, validateLinks, } from '@contentbit/core';
|
|
2
|
-
import { mkdir, readFile } from 'node:fs/promises';
|
|
3
|
-
import { dirname, join } from 'node:path';
|
|
4
|
-
import { formatDiagnosticForCli, formatRows, section } from '../cli-format.js';
|
|
5
|
-
import { resolveContentFiles } from '../content-project.js';
|
|
6
|
-
import { linkResolverOptions } from '../link-options.js';
|
|
7
|
-
import { collectLinkInputs } from '../links-io.js';
|
|
8
|
-
export async function linksCommand(input, io) {
|
|
9
|
-
const files = await resolveContentFiles(input.globs, 'links');
|
|
10
|
-
const inputs = await collectLinkInputs(files);
|
|
11
|
-
const linkOptions = linkResolverOptions(input);
|
|
12
|
-
let errors = 0;
|
|
13
|
-
let warnings = 0;
|
|
14
|
-
for (const { file, diagnostic } of validateLinks(inputs, linkOptions)) {
|
|
15
|
-
io.stderr(formatDiagnosticForCli(diagnostic, file));
|
|
16
|
-
if (diagnostic.severity === 'error')
|
|
17
|
-
errors++;
|
|
18
|
-
else if (diagnostic.severity === 'warning')
|
|
19
|
-
warnings++;
|
|
20
|
-
}
|
|
21
|
-
const index = buildLinkIndex(inputs, linkOptions);
|
|
22
|
-
if (input.fix && errors > 0) {
|
|
23
|
-
io.stderr('links: --fix skipped because link errors must be resolved first.');
|
|
24
|
-
}
|
|
25
|
-
else if (input.fix && index.aliases.size > 0) {
|
|
26
|
-
for (const file of files) {
|
|
27
|
-
const source = await readFile(file, 'utf8');
|
|
28
|
-
const fm = extractFrontmatter(source);
|
|
29
|
-
if (!fm)
|
|
30
|
-
continue;
|
|
31
|
-
const lines = source.split('\n');
|
|
32
|
-
let changed = false;
|
|
33
|
-
// Only rewrite alias tokens inside the `linksTo:` block — never inside an
|
|
34
|
-
// `aliases:` list (which records the rename and must stay intact), and
|
|
35
|
-
// never in document body. Track whether we are within linksTo's scope:
|
|
36
|
-
// a top-level key resets it, dash-list / inline continuation keeps it.
|
|
37
|
-
let inLinksTo = false;
|
|
38
|
-
for (let i = 0; i < fm.lines.end && i < lines.length; i++) {
|
|
39
|
-
const line = lines[i];
|
|
40
|
-
const topKey = line.match(/^([A-Za-z0-9_.-]+):(.*)$/);
|
|
41
|
-
if (topKey)
|
|
42
|
-
inLinksTo = topKey[1] === 'linksTo';
|
|
43
|
-
if (!inLinksTo)
|
|
44
|
-
continue;
|
|
45
|
-
let next = line;
|
|
46
|
-
for (const [alias, current] of aliasReplacementsForPage(index, fm.data)) {
|
|
47
|
-
const re = new RegExp(`(^|[\\s\\[,'"-])${escapeRe(alias)}($|[\\s\\],'"])`, 'g');
|
|
48
|
-
next = next.replace(re, (_m, p1, p2) => `${p1}${current}${p2}`);
|
|
49
|
-
}
|
|
50
|
-
if (next !== line) {
|
|
51
|
-
lines[i] = next;
|
|
52
|
-
changed = true;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (changed) {
|
|
56
|
-
await io.writeFile(file, lines.join('\n'));
|
|
57
|
-
io.stdout(`fixed alias references in ${file}`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
const outPath = input.out ?? join(process.cwd(), '.contentbit', 'link-index.json');
|
|
62
|
-
// The default target lives in a .contentbit/ dir that may not exist yet, and
|
|
63
|
-
// the shared Io.writeFile is a thin fs wrapper that won't create it.
|
|
64
|
-
await mkdir(dirname(outPath), { recursive: true });
|
|
65
|
-
await io.writeFile(outPath, JSON.stringify(serializeLinkIndex(index), null, 2) + '\n');
|
|
66
|
-
const graph = linkGraphSummary(index);
|
|
67
|
-
io.stdout([
|
|
68
|
-
section('Link Index'),
|
|
69
|
-
...formatRows([
|
|
70
|
-
{ label: 'Pages', value: graph.pages },
|
|
71
|
-
{ label: 'Links', value: graph.links },
|
|
72
|
-
{ label: 'Orphans', value: graph.orphans, tone: graph.orphans > 0 ? 'warning' : 'success' },
|
|
73
|
-
{ label: 'Errors', value: errors, tone: errors > 0 ? 'error' : 'success' },
|
|
74
|
-
{ label: 'Warnings', value: warnings, tone: warnings > 0 ? 'warning' : 'success' },
|
|
75
|
-
]),
|
|
76
|
-
'',
|
|
77
|
-
section('Written'),
|
|
78
|
-
` ${outPath}`,
|
|
79
|
-
].join('\n'));
|
|
80
|
-
return errors > 0 ? 1 : 0;
|
|
81
|
-
}
|
|
82
|
-
function escapeRe(s) {
|
|
83
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
84
|
-
}
|
package/dist/commands/render.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { genericMarkdownRenderers } from '@contentbit/blocks';
|
|
2
|
-
import { parseDocument, renderToMarkdown, stripFrontmatter, validateDocument, } from '@contentbit/core';
|
|
3
|
-
import { readFile } from 'node:fs/promises';
|
|
4
|
-
import { formatDiagnosticForCli } from '../cli-format.js';
|
|
5
|
-
import { loadRegistry } from '../load-registry.js';
|
|
6
|
-
export async function renderCommand(input, io) {
|
|
7
|
-
if (!input.file || (input.target ?? 'markdown') !== 'markdown') {
|
|
8
|
-
io.stderr('render: usage: render <file> [--target markdown] ' +
|
|
9
|
-
'[--registry <module.ts>] [--no-generic-blocks] [--out <file>]');
|
|
10
|
-
return 2;
|
|
11
|
-
}
|
|
12
|
-
const includeGenericBlocks = !input.noGenericBlocks;
|
|
13
|
-
const registry = await loadRegistry(input.registry, { includeGenericBlocks });
|
|
14
|
-
const source = await readFile(input.file, 'utf8');
|
|
15
|
-
const result = validateDocument(parseDocument(stripFrontmatter(source)), registry);
|
|
16
|
-
if (!result.ok) {
|
|
17
|
-
for (const d of result.diagnostics)
|
|
18
|
-
io.stderr(formatDiagnosticForCli(d, input.file));
|
|
19
|
-
return 1;
|
|
20
|
-
}
|
|
21
|
-
const output = renderToMarkdown(result.document, {
|
|
22
|
-
renderers: includeGenericBlocks ? genericMarkdownRenderers : genericMarkdownFallbackRenderers,
|
|
23
|
-
});
|
|
24
|
-
if (input.out)
|
|
25
|
-
await io.writeFile(input.out, output);
|
|
26
|
-
else
|
|
27
|
-
io.stdout(output);
|
|
28
|
-
return 0;
|
|
29
|
-
}
|
|
30
|
-
const genericMarkdownFallbackRenderers = Object.fromEntries(Object.keys(genericMarkdownRenderers).map((name) => [
|
|
31
|
-
name,
|
|
32
|
-
((node) => `${node.body}\n`),
|
|
33
|
-
]));
|
package/dist/commands/stats.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { analyzeDocument } from '@contentbit/core';
|
|
2
|
-
import { readFile } from 'node:fs/promises';
|
|
3
|
-
import { loadContentProject, resolveContentFiles } from '../content-project.js';
|
|
4
|
-
export async function statsCommand(input, io) {
|
|
5
|
-
const all = input.noValidate
|
|
6
|
-
? await statsOnly(input.globs)
|
|
7
|
-
: await statsWithValidation(input, input.globs);
|
|
8
|
-
// A single file keeps the flat object shape; multiple files emit an array.
|
|
9
|
-
io.stdout(JSON.stringify(all.length === 1 ? all[0] : all, null, 2));
|
|
10
|
-
return 0;
|
|
11
|
-
}
|
|
12
|
-
/** Default path: cross the loaded-content-project seam so stats and the other
|
|
13
|
-
* read-commands share one validation path. */
|
|
14
|
-
async function statsWithValidation(input, positionals) {
|
|
15
|
-
const { scan } = await loadContentProject({
|
|
16
|
-
cmd: 'stats',
|
|
17
|
-
positionals,
|
|
18
|
-
registry: input.registry,
|
|
19
|
-
includeGenericBlocks: !input.noGenericBlocks,
|
|
20
|
-
linkOptions: {},
|
|
21
|
-
});
|
|
22
|
-
return scan.files.map((file) => {
|
|
23
|
-
let errors = 0;
|
|
24
|
-
let warnings = 0;
|
|
25
|
-
for (const d of file.validation.diagnostics) {
|
|
26
|
-
if (d.severity === 'error')
|
|
27
|
-
errors++;
|
|
28
|
-
else if (d.severity === 'warning')
|
|
29
|
-
warnings++;
|
|
30
|
-
}
|
|
31
|
-
return { ...file.stats, validation: { errors, warnings } };
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
/** `--no-validate`: stats only, no registry, no scan. */
|
|
35
|
-
async function statsOnly(positionals) {
|
|
36
|
-
const files = await resolveContentFiles(positionals, 'stats');
|
|
37
|
-
return Promise.all(files.map(async (file) => analyzeDocument(await readFile(file, 'utf8'), { path: file })));
|
|
38
|
-
}
|
package/dist/commands/studio.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { formatRows, section } from '../cli-format.js';
|
|
2
|
-
import { resolveContentFiles } from '../content-project.js';
|
|
3
|
-
import { linkResolverOptions } from '../link-options.js';
|
|
4
|
-
import { loadSeoConfig } from '../seo-config.js';
|
|
5
|
-
export async function studioCommand(input, io) {
|
|
6
|
-
const port = parsePort(input.port);
|
|
7
|
-
if (port === null) {
|
|
8
|
-
io.stderr('studio: --port must be an integer between 0 and 65535.');
|
|
9
|
-
return 2;
|
|
10
|
-
}
|
|
11
|
-
const minSectionWords = parseMinSectionWords(input.minSectionWords);
|
|
12
|
-
if (minSectionWords === null) {
|
|
13
|
-
io.stderr('studio: --min-section-words must be a non-negative integer.');
|
|
14
|
-
return 2;
|
|
15
|
-
}
|
|
16
|
-
// Guard empty/no-match the same way the read-commands do; startStudio does its
|
|
17
|
-
// own globbing from `positionals`, so we only need the shared check here.
|
|
18
|
-
await resolveContentFiles(input.globs, 'studio');
|
|
19
|
-
const seoConfig = await loadSeoConfig({ seoConfig: input.seoConfig, noSeo: input.noSeo });
|
|
20
|
-
const { startStudio } = (await import('@contentbit/studio'));
|
|
21
|
-
const studioOptions = {
|
|
22
|
-
globs: input.globs,
|
|
23
|
-
registryPath: input.registry,
|
|
24
|
-
includeGenericBlocks: !input.noGenericBlocks,
|
|
25
|
-
host: input.host,
|
|
26
|
-
...(port !== undefined ? { port } : {}),
|
|
27
|
-
open: !input.noOpen,
|
|
28
|
-
linkOptions: linkResolverOptions(input),
|
|
29
|
-
minSectionWords,
|
|
30
|
-
seoConfig: seoConfig.config,
|
|
31
|
-
seoConfigPath: seoConfig.path,
|
|
32
|
-
};
|
|
33
|
-
const server = await startStudio(studioOptions);
|
|
34
|
-
io.stdout([
|
|
35
|
-
section('contentbit studio'),
|
|
36
|
-
...formatRows([
|
|
37
|
-
{ label: 'URL', value: server.url, tone: 'info' },
|
|
38
|
-
{ label: 'Stop', value: 'Ctrl+C' },
|
|
39
|
-
]),
|
|
40
|
-
].join('\n'));
|
|
41
|
-
const close = () => {
|
|
42
|
-
void server.close();
|
|
43
|
-
};
|
|
44
|
-
process.once('SIGINT', close);
|
|
45
|
-
process.once('SIGTERM', close);
|
|
46
|
-
await server.closed;
|
|
47
|
-
process.off('SIGINT', close);
|
|
48
|
-
process.off('SIGTERM', close);
|
|
49
|
-
return 0;
|
|
50
|
-
}
|
|
51
|
-
function parsePort(value) {
|
|
52
|
-
if (value === undefined)
|
|
53
|
-
return undefined;
|
|
54
|
-
if (!/^\d+$/.test(value))
|
|
55
|
-
return null;
|
|
56
|
-
const port = Number(value);
|
|
57
|
-
return port >= 0 && port <= 65535 ? port : null;
|
|
58
|
-
}
|
|
59
|
-
function parseMinSectionWords(value) {
|
|
60
|
-
if (value === undefined)
|
|
61
|
-
return undefined;
|
|
62
|
-
if (!/^\d+$/.test(value))
|
|
63
|
-
return null;
|
|
64
|
-
return Number(value);
|
|
65
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { formatDiagnosticForCli, formatRows, section } from '../cli-format.js';
|
|
2
|
-
import { loadContentProject } from '../content-project.js';
|
|
3
|
-
import { linkResolverOptions } from '../link-options.js';
|
|
4
|
-
export async function validateCommand(input, io) {
|
|
5
|
-
const { files, scan } = await loadContentProject({
|
|
6
|
-
cmd: 'validate',
|
|
7
|
-
positionals: input.globs,
|
|
8
|
-
registry: input.registry,
|
|
9
|
-
includeGenericBlocks: !input.noGenericBlocks,
|
|
10
|
-
linkOptions: linkResolverOptions(input),
|
|
11
|
-
scan: { includeStatsFindings: false },
|
|
12
|
-
});
|
|
13
|
-
let errors = 0;
|
|
14
|
-
let warnings = 0;
|
|
15
|
-
for (const finding of scan.findings) {
|
|
16
|
-
io.stderr(formatDiagnosticForCli(diagnosticFromFinding(finding), finding.file));
|
|
17
|
-
if (finding.severity === 'error')
|
|
18
|
-
errors++;
|
|
19
|
-
else if (finding.severity === 'warning')
|
|
20
|
-
warnings++;
|
|
21
|
-
}
|
|
22
|
-
io.stdout([
|
|
23
|
-
section('Validation'),
|
|
24
|
-
...formatRows([
|
|
25
|
-
{ label: 'Files', value: files.length },
|
|
26
|
-
{ label: 'Errors', value: errors, tone: errors > 0 ? 'error' : 'success' },
|
|
27
|
-
{ label: 'Warnings', value: warnings, tone: warnings > 0 ? 'warning' : 'success' },
|
|
28
|
-
]),
|
|
29
|
-
].join('\n'));
|
|
30
|
-
if (errors > 0)
|
|
31
|
-
return 1;
|
|
32
|
-
if (warnings > 0 && input.strictWarnings)
|
|
33
|
-
return 1;
|
|
34
|
-
return 0;
|
|
35
|
-
}
|
|
36
|
-
function diagnosticFromFinding(finding) {
|
|
37
|
-
const line = finding.line ?? 1;
|
|
38
|
-
const column = finding.column ?? 1;
|
|
39
|
-
return {
|
|
40
|
-
code: finding.code,
|
|
41
|
-
severity: finding.severity,
|
|
42
|
-
message: finding.message,
|
|
43
|
-
...(finding.hint ? { hint: finding.hint } : {}),
|
|
44
|
-
position: {
|
|
45
|
-
start: { line, column, offset: 0 },
|
|
46
|
-
end: { line, column, offset: 0 },
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
}
|
package/dist/content-project.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { loadContentProject as loadProjectContent, ProjectLoadError, resolveContentFiles as resolveProjectContentFiles, } from '@contentbit/project';
|
|
2
|
-
import { CliError } from './run.js';
|
|
3
|
-
/** Glob the positionals into sorted absolute paths. Throws CliError (exit 2). */
|
|
4
|
-
export async function resolveContentFiles(positionals, cmd) {
|
|
5
|
-
return withCliErrors(() => resolveProjectContentFiles(positionals, cmd));
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* The "loaded content project" seam: turns (positional globs, flags) into a
|
|
9
|
-
* ready-to-use project — resolved files, loaded registry, read sources, and the
|
|
10
|
-
* produced content project scan. The single input path shared by the `validate`,
|
|
11
|
-
* `doctor`, and `stats` read-commands. Throws CliError on input failures.
|
|
12
|
-
*/
|
|
13
|
-
export async function loadContentProject(input) {
|
|
14
|
-
return withCliErrors(() => loadProjectContent(input));
|
|
15
|
-
}
|
|
16
|
-
async function withCliErrors(load) {
|
|
17
|
-
try {
|
|
18
|
-
return await load();
|
|
19
|
-
}
|
|
20
|
-
catch (err) {
|
|
21
|
-
if (err instanceof ProjectLoadError)
|
|
22
|
-
throw new CliError(err.exitCode, err.message);
|
|
23
|
-
throw err;
|
|
24
|
-
}
|
|
25
|
-
}
|
package/dist/link-options.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export function linkResolverOptions(values) {
|
|
2
|
-
const out = {};
|
|
3
|
-
const resolve = stringValue(values.linkResolve ?? values['link-resolve']);
|
|
4
|
-
if (resolve) {
|
|
5
|
-
if (!isResolveMode(resolve))
|
|
6
|
-
throw new Error(`invalid --link-resolve ${resolve}`);
|
|
7
|
-
out.resolve = resolve;
|
|
8
|
-
}
|
|
9
|
-
const localeField = stringValue(values.localeField ?? values['locale-field']);
|
|
10
|
-
const slugField = stringValue(values.slugField ?? values['slug-field']);
|
|
11
|
-
const keyField = stringValue(values.keyField ?? values['key-field']);
|
|
12
|
-
const defaultLocale = stringValue(values.defaultLocale ?? values['default-locale']);
|
|
13
|
-
if (localeField)
|
|
14
|
-
out.localeField = localeField;
|
|
15
|
-
if (slugField)
|
|
16
|
-
out.slugField = slugField;
|
|
17
|
-
if (keyField)
|
|
18
|
-
out.keyField = keyField;
|
|
19
|
-
if (defaultLocale)
|
|
20
|
-
out.defaultLocale = defaultLocale;
|
|
21
|
-
return out;
|
|
22
|
-
}
|
|
23
|
-
function stringValue(value) {
|
|
24
|
-
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
25
|
-
}
|
|
26
|
-
function isResolveMode(value) {
|
|
27
|
-
return (value === 'global-slug' ||
|
|
28
|
-
value === 'same-locale-slug' ||
|
|
29
|
-
value === 'same-locale-key' ||
|
|
30
|
-
value === 'prefer-same-locale-key-fallback-slug');
|
|
31
|
-
}
|
package/dist/links-io.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { extractFrontmatter } from '@contentbit/core';
|
|
2
|
-
import { readFile } from 'node:fs/promises';
|
|
3
|
-
// Read each file's frontmatter (head only — bodies are never parsed) into the
|
|
4
|
-
// LinkInput shape the core link functions consume. Files with no frontmatter
|
|
5
|
-
// contribute an empty data object (a non-participating page).
|
|
6
|
-
export async function collectLinkInputs(files) {
|
|
7
|
-
const inputs = [];
|
|
8
|
-
for (const path of files) {
|
|
9
|
-
const source = await readFile(path, 'utf8');
|
|
10
|
-
const fm = extractFrontmatter(source);
|
|
11
|
-
inputs.push({ path, data: fm?.data ?? {} });
|
|
12
|
-
}
|
|
13
|
-
return inputs;
|
|
14
|
-
}
|
package/dist/load-registry.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { loadRegistry } from '@contentbit/project';
|
package/dist/seo-config.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import { isAbsolute, join } from 'node:path';
|
|
3
|
-
import { pathToFileURL } from 'node:url';
|
|
4
|
-
export const DEFAULT_SEO_CONFIG = 'contentbit.seo.config.ts';
|
|
5
|
-
export async function loadSeoConfig(input = {}) {
|
|
6
|
-
if (input.noSeo)
|
|
7
|
-
return {};
|
|
8
|
-
const cwd = input.cwd ?? process.cwd();
|
|
9
|
-
const path = input.seoConfig
|
|
10
|
-
? isAbsolute(input.seoConfig)
|
|
11
|
-
? input.seoConfig
|
|
12
|
-
: join(cwd, input.seoConfig)
|
|
13
|
-
: join(cwd, DEFAULT_SEO_CONFIG);
|
|
14
|
-
if (!input.seoConfig && !existsSync(path))
|
|
15
|
-
return {};
|
|
16
|
-
const mod = (await import(pathToFileURL(path).href));
|
|
17
|
-
if (mod.default === undefined) {
|
|
18
|
-
throw new Error(`SEO config must default-export a config object: ${path}`);
|
|
19
|
-
}
|
|
20
|
-
return { config: mod.default, path };
|
|
21
|
-
}
|