contentbit 0.4.2 → 0.6.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.
- package/README.md +20 -2
- package/dist/bin.js +8183 -3889
- package/dist/cli-format.d.ts +17 -0
- package/dist/cli-format.d.ts.map +1 -0
- package/dist/cli-format.js +63 -0
- package/dist/commands/agents.d.ts +6 -1
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +13 -201
- package/dist/commands/brief.d.ts +12 -0
- package/dist/commands/brief.d.ts.map +1 -0
- package/dist/commands/brief.js +52 -0
- package/dist/commands/docs.d.ts +6 -1
- package/dist/commands/docs.d.ts.map +1 -1
- package/dist/commands/docs.js +5 -11
- package/dist/commands/doctor.d.ts +13 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +124 -166
- package/dist/commands/init-targets.d.ts +27 -0
- package/dist/commands/init-targets.d.ts.map +1 -0
- package/dist/commands/init-targets.js +280 -0
- package/dist/commands/init.d.ts +12 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +92 -340
- package/dist/commands/instructions.d.ts +8 -1
- package/dist/commands/instructions.d.ts.map +1 -1
- package/dist/commands/instructions.js +7 -15
- package/dist/commands/links.d.ts +7 -1
- package/dist/commands/links.d.ts.map +1 -1
- package/dist/commands/links.js +24 -37
- package/dist/commands/render.d.ts +8 -1
- package/dist/commands/render.d.ts.map +1 -1
- package/dist/commands/render.js +19 -24
- package/dist/commands/stats.d.ts +7 -1
- package/dist/commands/stats.d.ts.map +1 -1
- package/dist/commands/stats.js +28 -39
- package/dist/commands/studio.d.ts +13 -1
- package/dist/commands/studio.d.ts.map +1 -1
- package/dist/commands/studio.js +28 -39
- package/dist/commands/validate.d.ts +8 -1
- package/dist/commands/validate.d.ts.map +1 -1
- package/dist/commands/validate.js +39 -56
- package/dist/content-project.d.ts +12 -0
- package/dist/content-project.d.ts.map +1 -0
- package/dist/content-project.js +25 -0
- package/dist/link-options.d.ts +5 -0
- package/dist/link-options.d.ts.map +1 -1
- package/dist/link-options.js +5 -5
- package/dist/load-registry.d.ts +1 -3
- package/dist/load-registry.d.ts.map +1 -1
- package/dist/load-registry.js +1 -24
- package/dist/run.d.ts +10 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +9603 -5307
- package/dist/seo-config.d.ts +12 -0
- package/dist/seo-config.d.ts.map +1 -0
- package/dist/seo-config.js +21 -0
- package/package.json +6 -5
package/dist/commands/links.js
CHANGED
|
@@ -1,49 +1,28 @@
|
|
|
1
|
-
import { aliasReplacementsForPage, buildLinkIndex, extractFrontmatter,
|
|
1
|
+
import { aliasReplacementsForPage, buildLinkIndex, extractFrontmatter, linkGraphSummary, serializeLinkIndex, validateLinks, } from '@contentbit/core';
|
|
2
2
|
import { mkdir, readFile } from 'node:fs/promises';
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { formatDiagnosticForCli, formatRows, section } from '../cli-format.js';
|
|
5
|
+
import { resolveContentFiles } from '../content-project.js';
|
|
6
6
|
import { linkResolverOptions } from '../link-options.js';
|
|
7
7
|
import { collectLinkInputs } from '../links-io.js';
|
|
8
|
-
export async function linksCommand(
|
|
9
|
-
const
|
|
10
|
-
args,
|
|
11
|
-
allowPositionals: true,
|
|
12
|
-
options: {
|
|
13
|
-
out: { type: 'string' },
|
|
14
|
-
fix: { type: 'boolean', default: false },
|
|
15
|
-
'link-resolve': { type: 'string' },
|
|
16
|
-
'locale-field': { type: 'string' },
|
|
17
|
-
'slug-field': { type: 'string' },
|
|
18
|
-
'key-field': { type: 'string' },
|
|
19
|
-
'default-locale': { type: 'string' },
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
if (positionals.length === 0) {
|
|
23
|
-
io.stderr('links: provide at least one file or glob.');
|
|
24
|
-
return 2;
|
|
25
|
-
}
|
|
26
|
-
const files = (await glob(positionals, { absolute: true })).sort();
|
|
27
|
-
if (files.length === 0) {
|
|
28
|
-
io.stderr(`links: no files matched ${positionals.join(' ')}`);
|
|
29
|
-
return 2;
|
|
30
|
-
}
|
|
8
|
+
export async function linksCommand(input, io) {
|
|
9
|
+
const files = await resolveContentFiles(input.globs, 'links');
|
|
31
10
|
const inputs = await collectLinkInputs(files);
|
|
32
|
-
const linkOptions = linkResolverOptions(
|
|
11
|
+
const linkOptions = linkResolverOptions(input);
|
|
33
12
|
let errors = 0;
|
|
34
13
|
let warnings = 0;
|
|
35
14
|
for (const { file, diagnostic } of validateLinks(inputs, linkOptions)) {
|
|
36
|
-
io.stderr(
|
|
15
|
+
io.stderr(formatDiagnosticForCli(diagnostic, file));
|
|
37
16
|
if (diagnostic.severity === 'error')
|
|
38
17
|
errors++;
|
|
39
18
|
else if (diagnostic.severity === 'warning')
|
|
40
19
|
warnings++;
|
|
41
20
|
}
|
|
42
21
|
const index = buildLinkIndex(inputs, linkOptions);
|
|
43
|
-
if (
|
|
22
|
+
if (input.fix && errors > 0) {
|
|
44
23
|
io.stderr('links: --fix skipped because link errors must be resolved first.');
|
|
45
24
|
}
|
|
46
|
-
else if (
|
|
25
|
+
else if (input.fix && index.aliases.size > 0) {
|
|
47
26
|
for (const file of files) {
|
|
48
27
|
const source = await readFile(file, 'utf8');
|
|
49
28
|
const fm = extractFrontmatter(source);
|
|
@@ -79,17 +58,25 @@ export async function linksCommand(args, io) {
|
|
|
79
58
|
}
|
|
80
59
|
}
|
|
81
60
|
}
|
|
82
|
-
const outPath =
|
|
61
|
+
const outPath = input.out ?? join(process.cwd(), '.contentbit', 'link-index.json');
|
|
83
62
|
// The default target lives in a .contentbit/ dir that may not exist yet, and
|
|
84
63
|
// the shared Io.writeFile is a thin fs wrapper that won't create it.
|
|
85
64
|
await mkdir(dirname(outPath), { recursive: true });
|
|
86
65
|
await io.writeFile(outPath, JSON.stringify(serializeLinkIndex(index), null, 2) + '\n');
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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'));
|
|
93
80
|
return errors > 0 ? 1 : 0;
|
|
94
81
|
}
|
|
95
82
|
function escapeRe(s) {
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import type { Io } from '../run.js';
|
|
2
|
-
export
|
|
2
|
+
export interface RenderCommandInput {
|
|
3
|
+
file?: string;
|
|
4
|
+
target?: string;
|
|
5
|
+
registry?: string;
|
|
6
|
+
noGenericBlocks?: boolean;
|
|
7
|
+
out?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function renderCommand(input: RenderCommandInput, io: Io): Promise<number>;
|
|
3
10
|
//# sourceMappingURL=render.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/commands/render.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/commands/render.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AAKnC,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,kBAAkB,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAsBtF"}
|
package/dist/commands/render.js
CHANGED
|
@@ -1,38 +1,33 @@
|
|
|
1
1
|
import { genericMarkdownRenderers } from '@contentbit/blocks';
|
|
2
|
-
import {
|
|
3
|
-
import { renderToHtml } from '@contentbit/html';
|
|
2
|
+
import { parseDocument, renderToMarkdown, stripFrontmatter, validateDocument, } from '@contentbit/core';
|
|
4
3
|
import { readFile } from 'node:fs/promises';
|
|
5
|
-
import {
|
|
4
|
+
import { formatDiagnosticForCli } from '../cli-format.js';
|
|
6
5
|
import { loadRegistry } from '../load-registry.js';
|
|
7
|
-
export async function renderCommand(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
options: {
|
|
12
|
-
target: { type: 'string', default: 'html' },
|
|
13
|
-
registry: { type: 'string' },
|
|
14
|
-
out: { type: 'string' },
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
const file = positionals[0];
|
|
18
|
-
if (!file || (values.target !== 'html' && values.target !== 'markdown')) {
|
|
19
|
-
io.stderr('render: usage: render <file> --target html|markdown [--out <file>]');
|
|
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>]');
|
|
20
10
|
return 2;
|
|
21
11
|
}
|
|
22
|
-
const
|
|
23
|
-
const
|
|
12
|
+
const includeGenericBlocks = !input.noGenericBlocks;
|
|
13
|
+
const registry = await loadRegistry(input.registry, { includeGenericBlocks });
|
|
14
|
+
const source = await readFile(input.file, 'utf8');
|
|
24
15
|
const result = validateDocument(parseDocument(stripFrontmatter(source)), registry);
|
|
25
16
|
if (!result.ok) {
|
|
26
17
|
for (const d of result.diagnostics)
|
|
27
|
-
io.stderr(
|
|
18
|
+
io.stderr(formatDiagnosticForCli(d, input.file));
|
|
28
19
|
return 1;
|
|
29
20
|
}
|
|
30
|
-
const output =
|
|
31
|
-
?
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
await io.writeFile(
|
|
21
|
+
const output = renderToMarkdown(result.document, {
|
|
22
|
+
renderers: includeGenericBlocks ? genericMarkdownRenderers : genericMarkdownFallbackRenderers,
|
|
23
|
+
});
|
|
24
|
+
if (input.out)
|
|
25
|
+
await io.writeFile(input.out, output);
|
|
35
26
|
else
|
|
36
27
|
io.stdout(output);
|
|
37
28
|
return 0;
|
|
38
29
|
}
|
|
30
|
+
const genericMarkdownFallbackRenderers = Object.fromEntries(Object.keys(genericMarkdownRenderers).map((name) => [
|
|
31
|
+
name,
|
|
32
|
+
((node) => `${node.body}\n`),
|
|
33
|
+
]));
|
package/dist/commands/stats.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type { Io } from '../run.js';
|
|
2
|
-
export
|
|
2
|
+
export interface StatsCommandInput {
|
|
3
|
+
globs: string[];
|
|
4
|
+
registry?: string;
|
|
5
|
+
noGenericBlocks?: boolean;
|
|
6
|
+
noValidate?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function statsCommand(input: StatsCommandInput, io: Io): Promise<number>;
|
|
3
9
|
//# sourceMappingURL=stats.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../src/commands/stats.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../src/commands/stats.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AAOnC,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED,wBAAsB,YAAY,CAAC,KAAK,EAAE,iBAAiB,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAQpF"}
|
package/dist/commands/stats.js
CHANGED
|
@@ -1,49 +1,38 @@
|
|
|
1
|
-
import { analyzeDocument
|
|
1
|
+
import { analyzeDocument } from '@contentbit/core';
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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) => {
|
|
11
23
|
let errors = 0;
|
|
12
24
|
let warnings = 0;
|
|
13
|
-
for (const d of
|
|
25
|
+
for (const d of file.validation.diagnostics) {
|
|
14
26
|
if (d.severity === 'error')
|
|
15
27
|
errors++;
|
|
16
28
|
else if (d.severity === 'warning')
|
|
17
29
|
warnings++;
|
|
18
30
|
}
|
|
19
|
-
stats
|
|
20
|
-
}
|
|
21
|
-
return stats;
|
|
22
|
-
}
|
|
23
|
-
export async function statsCommand(args, io) {
|
|
24
|
-
const { values, positionals } = parseArgs({
|
|
25
|
-
args,
|
|
26
|
-
allowPositionals: true,
|
|
27
|
-
options: {
|
|
28
|
-
registry: { type: 'string' },
|
|
29
|
-
'no-validate': { type: 'boolean', default: false },
|
|
30
|
-
},
|
|
31
|
+
return { ...file.stats, validation: { errors, warnings } };
|
|
31
32
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (files.length === 0) {
|
|
38
|
-
io.stderr(`stats: no files matched ${positionals.join(' ')}`);
|
|
39
|
-
return 2;
|
|
40
|
-
}
|
|
41
|
-
const registry = values['no-validate'] ? null : await loadRegistry(values.registry);
|
|
42
|
-
const all = [];
|
|
43
|
-
for (const file of files.sort()) {
|
|
44
|
-
all.push(await fileStats(file, registry));
|
|
45
|
-
}
|
|
46
|
-
// A single file keeps the flat object shape; multiple files emit an array.
|
|
47
|
-
io.stdout(JSON.stringify(all.length === 1 ? all[0] : all, null, 2));
|
|
48
|
-
return 0;
|
|
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 })));
|
|
49
38
|
}
|
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
import type { Io } from '../run.js';
|
|
2
|
-
|
|
2
|
+
import { type LinkOptionValues } from '../link-options.js';
|
|
3
|
+
export interface StudioCommandInput extends LinkOptionValues {
|
|
4
|
+
globs: string[];
|
|
5
|
+
registry?: string;
|
|
6
|
+
port?: string;
|
|
7
|
+
host?: string;
|
|
8
|
+
noOpen?: boolean;
|
|
9
|
+
noGenericBlocks?: boolean;
|
|
10
|
+
minSectionWords?: string;
|
|
11
|
+
seoConfig?: string;
|
|
12
|
+
noSeo?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function studioCommand(input: StudioCommandInput, io: Io): Promise<number>;
|
|
3
15
|
//# sourceMappingURL=studio.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"studio.d.ts","sourceRoot":"","sources":["../../src/commands/studio.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"studio.d.ts","sourceRoot":"","sources":["../../src/commands/studio.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AAInC,OAAO,EAAuB,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAG/E,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB;IAC1D,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,kBAAkB,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAqDtF"}
|
package/dist/commands/studio.js
CHANGED
|
@@ -1,54 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { formatRows, section } from '../cli-format.js';
|
|
2
|
+
import { resolveContentFiles } from '../content-project.js';
|
|
3
3
|
import { linkResolverOptions } from '../link-options.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
allowPositionals: true,
|
|
8
|
-
options: {
|
|
9
|
-
registry: { type: 'string' },
|
|
10
|
-
port: { type: 'string' },
|
|
11
|
-
host: { type: 'string' },
|
|
12
|
-
'no-open': { type: 'boolean', default: false },
|
|
13
|
-
'min-section-words': { type: 'string' },
|
|
14
|
-
'link-resolve': { type: 'string' },
|
|
15
|
-
'locale-field': { type: 'string' },
|
|
16
|
-
'slug-field': { type: 'string' },
|
|
17
|
-
'key-field': { type: 'string' },
|
|
18
|
-
'default-locale': { type: 'string' },
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
if (positionals.length === 0) {
|
|
22
|
-
io.stderr('studio: provide at least one file or glob.');
|
|
23
|
-
return 2;
|
|
24
|
-
}
|
|
25
|
-
const port = parsePort(values.port);
|
|
4
|
+
import { loadSeoConfig } from '../seo-config.js';
|
|
5
|
+
export async function studioCommand(input, io) {
|
|
6
|
+
const port = parsePort(input.port);
|
|
26
7
|
if (port === null) {
|
|
27
8
|
io.stderr('studio: --port must be an integer between 0 and 65535.');
|
|
28
9
|
return 2;
|
|
29
10
|
}
|
|
30
|
-
const minSectionWords = parseMinSectionWords(
|
|
11
|
+
const minSectionWords = parseMinSectionWords(input.minSectionWords);
|
|
31
12
|
if (minSectionWords === null) {
|
|
32
13
|
io.stderr('studio: --min-section-words must be a non-negative integer.');
|
|
33
14
|
return 2;
|
|
34
15
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
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 });
|
|
40
20
|
const { startStudio } = (await import('@contentbit/studio'));
|
|
41
|
-
const
|
|
42
|
-
globs:
|
|
43
|
-
registryPath:
|
|
44
|
-
|
|
21
|
+
const studioOptions = {
|
|
22
|
+
globs: input.globs,
|
|
23
|
+
registryPath: input.registry,
|
|
24
|
+
includeGenericBlocks: !input.noGenericBlocks,
|
|
25
|
+
host: input.host,
|
|
45
26
|
...(port !== undefined ? { port } : {}),
|
|
46
|
-
open: !
|
|
47
|
-
linkOptions: linkResolverOptions(
|
|
27
|
+
open: !input.noOpen,
|
|
28
|
+
linkOptions: linkResolverOptions(input),
|
|
48
29
|
minSectionWords,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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'));
|
|
52
41
|
const close = () => {
|
|
53
42
|
void server.close();
|
|
54
43
|
};
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import type { Io } from '../run.js';
|
|
2
|
-
|
|
2
|
+
import { type LinkOptionValues } from '../link-options.js';
|
|
3
|
+
export interface ValidateCommandInput extends LinkOptionValues {
|
|
4
|
+
globs: string[];
|
|
5
|
+
registry?: string;
|
|
6
|
+
noGenericBlocks?: boolean;
|
|
7
|
+
strictWarnings?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function validateCommand(input: ValidateCommandInput, io: Io): Promise<number>;
|
|
3
10
|
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/commands/validate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/commands/validate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AAInC,OAAO,EAAuB,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE/E,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAC5D,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,oBAAoB,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CA+B1F"}
|
|
@@ -1,66 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { parseArgs } from 'node:util';
|
|
4
|
-
import { glob } from 'tinyglobby';
|
|
1
|
+
import { formatDiagnosticForCli, formatRows, section } from '../cli-format.js';
|
|
2
|
+
import { loadContentProject } from '../content-project.js';
|
|
5
3
|
import { linkResolverOptions } from '../link-options.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
'link-resolve': { type: 'string' },
|
|
15
|
-
'locale-field': { type: 'string' },
|
|
16
|
-
'slug-field': { type: 'string' },
|
|
17
|
-
'key-field': { type: 'string' },
|
|
18
|
-
'default-locale': { type: 'string' },
|
|
19
|
-
},
|
|
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 },
|
|
20
12
|
});
|
|
21
|
-
if (positionals.length === 0) {
|
|
22
|
-
io.stderr('validate: provide at least one file or glob.');
|
|
23
|
-
return 2;
|
|
24
|
-
}
|
|
25
|
-
const files = await glob(positionals, { absolute: true });
|
|
26
|
-
if (files.length === 0) {
|
|
27
|
-
io.stderr(`validate: no files matched ${positionals.join(' ')}`);
|
|
28
|
-
return 2;
|
|
29
|
-
}
|
|
30
|
-
const registry = await loadRegistry(values.registry);
|
|
31
|
-
const linkOptions = linkResolverOptions(values);
|
|
32
13
|
let errors = 0;
|
|
33
14
|
let warnings = 0;
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
linkInputs.push({ path: file, data: extractFrontmatter(source)?.data ?? {} });
|
|
41
|
-
const result = validateDocument(parseDocument(stripFrontmatter(source)), registry);
|
|
42
|
-
for (const d of result.diagnostics) {
|
|
43
|
-
io.stderr(formatDiagnostic(d, file));
|
|
44
|
-
if (d.severity === 'error')
|
|
45
|
-
errors++;
|
|
46
|
-
else if (d.severity === 'warning')
|
|
47
|
-
warnings++;
|
|
48
|
-
}
|
|
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++;
|
|
49
21
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
io.stdout(`${files.length} file(s): ${errors} errors, ${warnings} warnings`);
|
|
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'));
|
|
61
30
|
if (errors > 0)
|
|
62
31
|
return 1;
|
|
63
|
-
if (warnings > 0 &&
|
|
32
|
+
if (warnings > 0 && input.strictWarnings)
|
|
64
33
|
return 1;
|
|
65
34
|
return 0;
|
|
66
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
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type LoadedContentProject, type LoadContentProjectInput } from '@contentbit/project';
|
|
2
|
+
export type { LoadedContentProject, LoadContentProjectInput };
|
|
3
|
+
/** Glob the positionals into sorted absolute paths. Throws CliError (exit 2). */
|
|
4
|
+
export declare function resolveContentFiles(positionals: string[], cmd: string): Promise<string[]>;
|
|
5
|
+
/**
|
|
6
|
+
* The "loaded content project" seam: turns (positional globs, flags) into a
|
|
7
|
+
* ready-to-use project — resolved files, loaded registry, read sources, and the
|
|
8
|
+
* produced content project scan. The single input path shared by the `validate`,
|
|
9
|
+
* `doctor`, and `stats` read-commands. Throws CliError on input failures.
|
|
10
|
+
*/
|
|
11
|
+
export declare function loadContentProject(input: LoadContentProjectInput): Promise<LoadedContentProject>;
|
|
12
|
+
//# sourceMappingURL=content-project.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-project.d.ts","sourceRoot":"","sources":["../src/content-project.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC7B,MAAM,qBAAqB,CAAA;AAI5B,YAAY,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,CAAA;AAE7D,iFAAiF;AACjF,wBAAsB,mBAAmB,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAE/F;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,uBAAuB,GAC7B,OAAO,CAAC,oBAAoB,CAAC,CAE/B"}
|
|
@@ -0,0 +1,25 @@
|
|
|
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.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { LinkResolverOptions } from '@contentbit/core';
|
|
2
2
|
export interface LinkOptionValues {
|
|
3
|
+
linkResolve?: string | boolean;
|
|
4
|
+
localeField?: string | boolean;
|
|
5
|
+
slugField?: string | boolean;
|
|
6
|
+
keyField?: string | boolean;
|
|
7
|
+
defaultLocale?: string | boolean;
|
|
3
8
|
'link-resolve'?: string | boolean;
|
|
4
9
|
'locale-field'?: string | boolean;
|
|
5
10
|
'slug-field'?: string | boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link-options.d.ts","sourceRoot":"","sources":["../src/link-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAE3D,MAAM,WAAW,gBAAgB;IAC/B,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACjC,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACjC,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IAC/B,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IAC9B,gBAAgB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;CACpC;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,gBAAgB,GAAG,mBAAmB,CAgBjF"}
|
|
1
|
+
{"version":3,"file":"link-options.d.ts","sourceRoot":"","sources":["../src/link-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAE3D,MAAM,WAAW,gBAAgB;IAC/B,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IAC9B,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IAC9B,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IAC3B,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IAChC,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACjC,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACjC,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IAC/B,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IAC9B,gBAAgB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;CACpC;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,gBAAgB,GAAG,mBAAmB,CAgBjF"}
|
package/dist/link-options.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export function linkResolverOptions(values) {
|
|
2
2
|
const out = {};
|
|
3
|
-
const resolve = stringValue(values['link-resolve']);
|
|
3
|
+
const resolve = stringValue(values.linkResolve ?? values['link-resolve']);
|
|
4
4
|
if (resolve) {
|
|
5
5
|
if (!isResolveMode(resolve))
|
|
6
6
|
throw new Error(`invalid --link-resolve ${resolve}`);
|
|
7
7
|
out.resolve = resolve;
|
|
8
8
|
}
|
|
9
|
-
const localeField = stringValue(values['locale-field']);
|
|
10
|
-
const slugField = stringValue(values['slug-field']);
|
|
11
|
-
const keyField = stringValue(values['key-field']);
|
|
12
|
-
const defaultLocale = stringValue(values['default-locale']);
|
|
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
13
|
if (localeField)
|
|
14
14
|
out.localeField = localeField;
|
|
15
15
|
if (slugField)
|
package/dist/load-registry.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/** Generic pack + optional user module (default export: BlockDefinition[]). */
|
|
3
|
-
export declare function loadRegistry(registryPath?: string): Promise<BlockRegistry>;
|
|
1
|
+
export { loadRegistry, type LoadRegistryOptions } from '@contentbit/project';
|
|
4
2
|
//# sourceMappingURL=load-registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-registry.d.ts","sourceRoot":"","sources":["../src/load-registry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"load-registry.d.ts","sourceRoot":"","sources":["../src/load-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAA"}
|
package/dist/load-registry.js
CHANGED
|
@@ -1,24 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { createBlockRegistry } from '@contentbit/core';
|
|
3
|
-
import { pathToFileURL } from 'node:url';
|
|
4
|
-
/** Generic pack + optional user module (default export: BlockDefinition[]). */
|
|
5
|
-
export async function loadRegistry(registryPath) {
|
|
6
|
-
const registry = createBlockRegistry().use(genericBlocks());
|
|
7
|
-
if (registryPath) {
|
|
8
|
-
let mod;
|
|
9
|
-
try {
|
|
10
|
-
mod = (await import(pathToFileURL(registryPath).href));
|
|
11
|
-
}
|
|
12
|
-
catch (err) {
|
|
13
|
-
if (err instanceof Error && 'code' in err && err.code === 'ERR_UNKNOWN_FILE_EXTENSION') {
|
|
14
|
-
throw new Error(`Importing a TypeScript registry needs Node 22.18+ (native type stripping): ${registryPath}`);
|
|
15
|
-
}
|
|
16
|
-
throw err;
|
|
17
|
-
}
|
|
18
|
-
if (!Array.isArray(mod.default)) {
|
|
19
|
-
throw new Error(`--registry module must default-export an array of block definitions: ${registryPath}`);
|
|
20
|
-
}
|
|
21
|
-
registry.use(mod.default);
|
|
22
|
-
}
|
|
23
|
-
return registry;
|
|
24
|
-
}
|
|
1
|
+
export { loadRegistry } from '@contentbit/project';
|