contentbit 0.2.0 → 0.4.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 +41 -6
- package/dist/bin.js +1115 -74
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +77 -22
- package/dist/commands/doctor.d.ts +3 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +215 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +62 -8
- package/dist/commands/links.d.ts +3 -0
- package/dist/commands/links.d.ts.map +1 -0
- package/dist/commands/links.js +97 -0
- package/dist/commands/render.d.ts.map +1 -1
- package/dist/commands/render.js +2 -2
- package/dist/commands/studio.d.ts +3 -0
- package/dist/commands/studio.d.ts.map +1 -0
- package/dist/commands/studio.js +76 -0
- package/dist/commands/validate.d.ts.map +1 -1
- package/dist/commands/validate.js +20 -1
- package/dist/link-options.d.ts +10 -0
- package/dist/link-options.d.ts.map +1 -0
- package/dist/link-options.js +31 -0
- package/dist/links-io.d.ts +3 -0
- package/dist/links-io.d.ts.map +1 -0
- package/dist/links-io.js +14 -0
- package/dist/run.d.ts +1 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +1115 -74
- package/package.json +6 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"studio.d.ts","sourceRoot":"","sources":["../../src/commands/studio.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AAInC,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAiE3E"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util';
|
|
2
|
+
import { glob } from 'tinyglobby';
|
|
3
|
+
import { linkResolverOptions } from '../link-options.js';
|
|
4
|
+
export async function studioCommand(args, io) {
|
|
5
|
+
const { values, positionals } = parseArgs({
|
|
6
|
+
args,
|
|
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);
|
|
26
|
+
if (port === null) {
|
|
27
|
+
io.stderr('studio: --port must be an integer between 0 and 65535.');
|
|
28
|
+
return 2;
|
|
29
|
+
}
|
|
30
|
+
const minSectionWords = parseMinSectionWords(values['min-section-words']);
|
|
31
|
+
if (minSectionWords === null) {
|
|
32
|
+
io.stderr('studio: --min-section-words must be a non-negative integer.');
|
|
33
|
+
return 2;
|
|
34
|
+
}
|
|
35
|
+
const files = await glob(positionals, { absolute: true });
|
|
36
|
+
if (files.length === 0) {
|
|
37
|
+
io.stderr(`studio: no files matched ${positionals.join(' ')}`);
|
|
38
|
+
return 2;
|
|
39
|
+
}
|
|
40
|
+
const { startStudio } = (await import('@contentbit/studio'));
|
|
41
|
+
const server = await startStudio({
|
|
42
|
+
globs: positionals,
|
|
43
|
+
registryPath: values.registry,
|
|
44
|
+
host: values.host,
|
|
45
|
+
...(port !== undefined ? { port } : {}),
|
|
46
|
+
open: !values['no-open'],
|
|
47
|
+
linkOptions: linkResolverOptions(values),
|
|
48
|
+
minSectionWords,
|
|
49
|
+
});
|
|
50
|
+
io.stdout(`contentbit studio running at ${server.url}`);
|
|
51
|
+
io.stdout('Press Ctrl+C to stop.');
|
|
52
|
+
const close = () => {
|
|
53
|
+
void server.close();
|
|
54
|
+
};
|
|
55
|
+
process.once('SIGINT', close);
|
|
56
|
+
process.once('SIGTERM', close);
|
|
57
|
+
await server.closed;
|
|
58
|
+
process.off('SIGINT', close);
|
|
59
|
+
process.off('SIGTERM', close);
|
|
60
|
+
return 0;
|
|
61
|
+
}
|
|
62
|
+
function parsePort(value) {
|
|
63
|
+
if (value === undefined)
|
|
64
|
+
return undefined;
|
|
65
|
+
if (!/^\d+$/.test(value))
|
|
66
|
+
return null;
|
|
67
|
+
const port = Number(value);
|
|
68
|
+
return port >= 0 && port <= 65535 ? port : null;
|
|
69
|
+
}
|
|
70
|
+
function parseMinSectionWords(value) {
|
|
71
|
+
if (value === undefined)
|
|
72
|
+
return undefined;
|
|
73
|
+
if (!/^\d+$/.test(value))
|
|
74
|
+
return null;
|
|
75
|
+
return Number(value);
|
|
76
|
+
}
|
|
@@ -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":"AAaA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AAKnC,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAwD7E"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { formatDiagnostic, parseDocument, stripFrontmatter, validateDocument, } from '@contentbit/core';
|
|
1
|
+
import { extractFrontmatter, formatDiagnostic, parseDocument, stripFrontmatter, validateDocument, validateLinks, } from '@contentbit/core';
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
3
|
import { parseArgs } from 'node:util';
|
|
4
4
|
import { glob } from 'tinyglobby';
|
|
5
|
+
import { linkResolverOptions } from '../link-options.js';
|
|
5
6
|
import { loadRegistry } from '../load-registry.js';
|
|
6
7
|
export async function validateCommand(args, io) {
|
|
7
8
|
const { values, positionals } = parseArgs({
|
|
@@ -10,6 +11,11 @@ export async function validateCommand(args, io) {
|
|
|
10
11
|
options: {
|
|
11
12
|
registry: { type: 'string' },
|
|
12
13
|
'strict-warnings': { type: 'boolean', default: false },
|
|
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' },
|
|
13
19
|
},
|
|
14
20
|
});
|
|
15
21
|
if (positionals.length === 0) {
|
|
@@ -22,13 +28,16 @@ export async function validateCommand(args, io) {
|
|
|
22
28
|
return 2;
|
|
23
29
|
}
|
|
24
30
|
const registry = await loadRegistry(values.registry);
|
|
31
|
+
const linkOptions = linkResolverOptions(values);
|
|
25
32
|
let errors = 0;
|
|
26
33
|
let warnings = 0;
|
|
34
|
+
const linkInputs = [];
|
|
27
35
|
for (const file of files.sort()) {
|
|
28
36
|
const source = await readFile(file, 'utf8');
|
|
29
37
|
// Frontmatter is metadata, not content: blanked (positions preserved) so
|
|
30
38
|
// block syntax inside YAML never produces diagnostics — matching what
|
|
31
39
|
// frontmatter-aware consumers like Astro validate from entry bodies.
|
|
40
|
+
linkInputs.push({ path: file, data: extractFrontmatter(source)?.data ?? {} });
|
|
32
41
|
const result = validateDocument(parseDocument(stripFrontmatter(source)), registry);
|
|
33
42
|
for (const d of result.diagnostics) {
|
|
34
43
|
io.stderr(formatDiagnostic(d, file));
|
|
@@ -38,6 +47,16 @@ export async function validateCommand(args, io) {
|
|
|
38
47
|
warnings++;
|
|
39
48
|
}
|
|
40
49
|
}
|
|
50
|
+
// Cross-file internal-link checks, only when the project uses linking.
|
|
51
|
+
if (linkInputs.some((i) => 'slug' in i.data)) {
|
|
52
|
+
for (const { file, diagnostic } of validateLinks(linkInputs, linkOptions)) {
|
|
53
|
+
io.stderr(formatDiagnostic(diagnostic, file));
|
|
54
|
+
if (diagnostic.severity === 'error')
|
|
55
|
+
errors++;
|
|
56
|
+
else if (diagnostic.severity === 'warning')
|
|
57
|
+
warnings++;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
41
60
|
io.stdout(`${files.length} file(s): ${errors} errors, ${warnings} warnings`);
|
|
42
61
|
if (errors > 0)
|
|
43
62
|
return 1;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LinkResolverOptions } from '@contentbit/core';
|
|
2
|
+
export interface LinkOptionValues {
|
|
3
|
+
'link-resolve'?: string | boolean;
|
|
4
|
+
'locale-field'?: string | boolean;
|
|
5
|
+
'slug-field'?: string | boolean;
|
|
6
|
+
'key-field'?: string | boolean;
|
|
7
|
+
'default-locale'?: string | boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function linkResolverOptions(values: LinkOptionValues): LinkResolverOptions;
|
|
10
|
+
//# sourceMappingURL=link-options.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export function linkResolverOptions(values) {
|
|
2
|
+
const out = {};
|
|
3
|
+
const resolve = stringValue(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['locale-field']);
|
|
10
|
+
const slugField = stringValue(values['slug-field']);
|
|
11
|
+
const keyField = stringValue(values['key-field']);
|
|
12
|
+
const defaultLocale = stringValue(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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links-io.d.ts","sourceRoot":"","sources":["../src/links-io.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAMrE,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAQ7E"}
|
package/dist/links-io.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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/run.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ export interface Io {
|
|
|
3
3
|
stderr(line: string): void;
|
|
4
4
|
writeFile(path: string, content: string): Promise<void>;
|
|
5
5
|
}
|
|
6
|
-
export declare const USAGE = "Usage: contentbit <init|validate|stats|render|instructions|docs|agents> [options]\n\n init [-t react|html|markdown|astro] [--md ...] [-y] [--no-install] [--no-page] [--no-agents]\n agents [--claude] [--no-agents-md]\n\n validate <globs...> [--registry <module.
|
|
6
|
+
export declare const USAGE = "Usage: contentbit <init|validate|doctor|studio|stats|render|instructions|docs|agents|links> [options]\n\n init [-t react|html|markdown|astro] [--md ...] [-y] [--no-install] [--no-page] [--no-agents]\n agents [--claude] [--no-agents-md]\n\n validate <globs...> [--registry <module.ts>] [--strict-warnings] [--link-resolve <mode>]\n doctor <globs...> [--registry <module.ts>] [--strict-warnings] [--json] [--min-section-words <n>] [--link-resolve <mode>]\n studio <globs...> [--registry <module.ts>] [--port <n>] [--host <host>] [--no-open] [--link-resolve <mode>]\n stats <globs...> [--registry <module.ts>] [--no-validate]\n render <file> --target html|markdown [--registry <module.ts>] [--out <file>]\n instructions [--audience llm|human] [--no-examples] [--registry <module.ts>] [--out <file>]\n docs [--registry <module.ts>] [--out <file>]\n links <globs...> [--fix] [--out <file>] [--link-resolve <mode>]";
|
|
7
7
|
export declare function run(argv: string[], io: Io): Promise<number>;
|
|
8
8
|
//# sourceMappingURL=run.d.ts.map
|
package/dist/run.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,EAAE;IACjB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACxD;AAED,eAAO,MAAM,KAAK,
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,EAAE;IACjB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACxD;AAED,eAAO,MAAM,KAAK,25BAYgD,CAAA;AAiBlE,wBAAsB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAcjE"}
|