contentbit 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +7 -2
  2. package/dist/bin.js +1609 -1616
  3. package/dist/cli-format.d.ts +17 -0
  4. package/dist/cli-format.d.ts.map +1 -0
  5. package/dist/cli-format.js +63 -0
  6. package/dist/commands/agents.d.ts.map +1 -1
  7. package/dist/commands/agents.js +9 -188
  8. package/dist/commands/docs.d.ts.map +1 -1
  9. package/dist/commands/docs.js +4 -1
  10. package/dist/commands/doctor.d.ts.map +1 -1
  11. package/dist/commands/doctor.js +80 -146
  12. package/dist/commands/init-targets.d.ts +27 -0
  13. package/dist/commands/init-targets.d.ts.map +1 -0
  14. package/dist/commands/init-targets.js +280 -0
  15. package/dist/commands/init.d.ts.map +1 -1
  16. package/dist/commands/init.js +26 -313
  17. package/dist/commands/instructions.d.ts.map +1 -1
  18. package/dist/commands/instructions.js +4 -1
  19. package/dist/commands/links.d.ts.map +1 -1
  20. package/dist/commands/links.js +18 -14
  21. package/dist/commands/render.d.ts.map +1 -1
  22. package/dist/commands/render.js +17 -10
  23. package/dist/commands/stats.d.ts.map +1 -1
  24. package/dist/commands/stats.js +33 -34
  25. package/dist/commands/studio.d.ts.map +1 -1
  26. package/dist/commands/studio.js +14 -12
  27. package/dist/commands/validate.d.ts.map +1 -1
  28. package/dist/commands/validate.js +39 -41
  29. package/dist/content-project.d.ts +32 -0
  30. package/dist/content-project.d.ts.map +1 -0
  31. package/dist/content-project.js +34 -0
  32. package/dist/load-registry.d.ts +4 -1
  33. package/dist/load-registry.d.ts.map +1 -1
  34. package/dist/load-registry.js +4 -2
  35. package/dist/run.d.ts +10 -1
  36. package/dist/run.d.ts.map +1 -1
  37. package/dist/run.js +1613 -1618
  38. package/package.json +4 -5
@@ -1,5 +1,6 @@
1
1
  import { parseArgs } from 'node:util';
2
- import { glob } from 'tinyglobby';
2
+ import { formatRows, section } from '../cli-format.js';
3
+ import { resolveContentFiles } from '../content-project.js';
3
4
  import { linkResolverOptions } from '../link-options.js';
4
5
  export async function studioCommand(args, io) {
5
6
  const { values, positionals } = parseArgs({
@@ -10,6 +11,7 @@ export async function studioCommand(args, io) {
10
11
  port: { type: 'string' },
11
12
  host: { type: 'string' },
12
13
  'no-open': { type: 'boolean', default: false },
14
+ 'no-generic-blocks': { type: 'boolean', default: false },
13
15
  'min-section-words': { type: 'string' },
14
16
  'link-resolve': { type: 'string' },
15
17
  'locale-field': { type: 'string' },
@@ -18,10 +20,6 @@ export async function studioCommand(args, io) {
18
20
  'default-locale': { type: 'string' },
19
21
  },
20
22
  });
21
- if (positionals.length === 0) {
22
- io.stderr('studio: provide at least one file or glob.');
23
- return 2;
24
- }
25
23
  const port = parsePort(values.port);
26
24
  if (port === null) {
27
25
  io.stderr('studio: --port must be an integer between 0 and 65535.');
@@ -32,23 +30,27 @@ export async function studioCommand(args, io) {
32
30
  io.stderr('studio: --min-section-words must be a non-negative integer.');
33
31
  return 2;
34
32
  }
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
- }
33
+ // Guard empty/no-match the same way the read-commands do; startStudio does its
34
+ // own globbing from `positionals`, so we only need the shared check here.
35
+ await resolveContentFiles(positionals, 'studio');
40
36
  const { startStudio } = (await import('@contentbit/studio'));
41
37
  const server = await startStudio({
42
38
  globs: positionals,
43
39
  registryPath: values.registry,
40
+ includeGenericBlocks: !values['no-generic-blocks'],
44
41
  host: values.host,
45
42
  ...(port !== undefined ? { port } : {}),
46
43
  open: !values['no-open'],
47
44
  linkOptions: linkResolverOptions(values),
48
45
  minSectionWords,
49
46
  });
50
- io.stdout(`contentbit studio running at ${server.url}`);
51
- io.stdout('Press Ctrl+C to stop.');
47
+ io.stdout([
48
+ section('contentbit studio'),
49
+ ...formatRows([
50
+ { label: 'URL', value: server.url, tone: 'info' },
51
+ { label: 'Stop', value: 'Ctrl+C' },
52
+ ]),
53
+ ].join('\n'));
52
54
  const close = () => {
53
55
  void server.close();
54
56
  };
@@ -1 +1 @@
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
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/commands/validate.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AAMnC,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CA6C7E"}
@@ -1,15 +1,14 @@
1
- import { extractFrontmatter, formatDiagnostic, parseDocument, stripFrontmatter, validateDocument, validateLinks, } from '@contentbit/core';
2
- import { readFile } from 'node:fs/promises';
3
1
  import { parseArgs } from 'node:util';
4
- import { glob } from 'tinyglobby';
2
+ import { formatDiagnosticForCli, formatRows, section } from '../cli-format.js';
3
+ import { loadContentProject } from '../content-project.js';
5
4
  import { linkResolverOptions } from '../link-options.js';
6
- import { loadRegistry } from '../load-registry.js';
7
5
  export async function validateCommand(args, io) {
8
6
  const { values, positionals } = parseArgs({
9
7
  args,
10
8
  allowPositionals: true,
11
9
  options: {
12
10
  registry: { type: 'string' },
11
+ 'no-generic-blocks': { type: 'boolean', default: false },
13
12
  'strict-warnings': { type: 'boolean', default: false },
14
13
  'link-resolve': { type: 'string' },
15
14
  'locale-field': { type: 'string' },
@@ -18,49 +17,48 @@ export async function validateCommand(args, io) {
18
17
  'default-locale': { type: 'string' },
19
18
  },
20
19
  });
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);
20
+ const { files, scan } = await loadContentProject({
21
+ cmd: 'validate',
22
+ positionals,
23
+ registry: values.registry,
24
+ includeGenericBlocks: !values['no-generic-blocks'],
25
+ linkOptions: linkResolverOptions(values),
26
+ scan: { includeStatsFindings: false },
27
+ });
32
28
  let errors = 0;
33
29
  let warnings = 0;
34
- const linkInputs = [];
35
- for (const file of files.sort()) {
36
- const source = await readFile(file, 'utf8');
37
- // Frontmatter is metadata, not content: blanked (positions preserved) so
38
- // block syntax inside YAML never produces diagnostics — matching what
39
- // frontmatter-aware consumers like Astro validate from entry bodies.
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
- }
30
+ for (const finding of scan.findings) {
31
+ io.stderr(formatDiagnosticForCli(diagnosticFromFinding(finding), finding.file));
32
+ if (finding.severity === 'error')
33
+ errors++;
34
+ else if (finding.severity === 'warning')
35
+ warnings++;
49
36
  }
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
- }
60
- io.stdout(`${files.length} file(s): ${errors} errors, ${warnings} warnings`);
37
+ io.stdout([
38
+ section('Validation'),
39
+ ...formatRows([
40
+ { label: 'Files', value: files.length },
41
+ { label: 'Errors', value: errors, tone: errors > 0 ? 'error' : 'success' },
42
+ { label: 'Warnings', value: warnings, tone: warnings > 0 ? 'warning' : 'success' },
43
+ ]),
44
+ ].join('\n'));
61
45
  if (errors > 0)
62
46
  return 1;
63
47
  if (warnings > 0 && values['strict-warnings'])
64
48
  return 1;
65
49
  return 0;
66
50
  }
51
+ function diagnosticFromFinding(finding) {
52
+ const line = finding.line ?? 1;
53
+ const column = finding.column ?? 1;
54
+ return {
55
+ code: finding.code,
56
+ severity: finding.severity,
57
+ message: finding.message,
58
+ ...(finding.hint ? { hint: finding.hint } : {}),
59
+ position: {
60
+ start: { line, column, offset: 0 },
61
+ end: { line, column, offset: 0 },
62
+ },
63
+ };
64
+ }
@@ -0,0 +1,32 @@
1
+ import { type BlockRegistry, type ContentProjectScan, type ContentProjectSourceFile, type LinkResolverOptions } from '@contentbit/core';
2
+ /** Glob the positionals into sorted absolute paths. Throws CliError (exit 2). */
3
+ export declare function resolveContentFiles(positionals: string[], cmd: string): Promise<string[]>;
4
+ export interface LoadContentProjectInput {
5
+ /** Command name, used to namespace input-error messages. */
6
+ cmd: string;
7
+ positionals: string[];
8
+ /** Path to a user `--registry` module, if any. */
9
+ registry?: string;
10
+ includeGenericBlocks: boolean;
11
+ linkOptions: LinkResolverOptions;
12
+ /** Forwarded to `scanContentProject` (per-command knobs). */
13
+ scan?: {
14
+ includeStatsFindings?: boolean;
15
+ minSectionWords?: number;
16
+ };
17
+ }
18
+ export interface LoadedContentProject {
19
+ files: string[];
20
+ registry: BlockRegistry;
21
+ sources: ContentProjectSourceFile[];
22
+ linkOptions: LinkResolverOptions;
23
+ scan: ContentProjectScan;
24
+ }
25
+ /**
26
+ * The "loaded content project" seam: turns (positional globs, flags) into a
27
+ * ready-to-use project — resolved files, loaded registry, read sources, and the
28
+ * produced content project scan. The single input path shared by the `validate`,
29
+ * `doctor`, and `stats` read-commands. Throws CliError on input failures.
30
+ */
31
+ export declare function loadContentProject(input: LoadContentProjectInput): Promise<LoadedContentProject>;
32
+ //# 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,EAEL,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,mBAAmB,EACzB,MAAM,kBAAkB,CAAA;AAOzB,iFAAiF;AACjF,wBAAsB,mBAAmB,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAS/F;AAED,MAAM,WAAW,uBAAuB;IACtC,4DAA4D;IAC5D,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,EAAE,MAAM,EAAE,CAAA;IACrB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,oBAAoB,EAAE,OAAO,CAAA;IAC7B,WAAW,EAAE,mBAAmB,CAAA;IAChC,6DAA6D;IAC7D,IAAI,CAAC,EAAE;QAAE,oBAAoB,CAAC,EAAE,OAAO,CAAC;QAAC,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CACpE;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,QAAQ,EAAE,aAAa,CAAA;IACvB,OAAO,EAAE,wBAAwB,EAAE,CAAA;IACnC,WAAW,EAAE,mBAAmB,CAAA;IAChC,IAAI,EAAE,kBAAkB,CAAA;CACzB;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,uBAAuB,GAC7B,OAAO,CAAC,oBAAoB,CAAC,CAa/B"}
@@ -0,0 +1,34 @@
1
+ import { scanContentProject, } from '@contentbit/core';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { glob } from 'tinyglobby';
4
+ import { loadRegistry } from './load-registry.js';
5
+ import { CliError } from './run.js';
6
+ /** Glob the positionals into sorted absolute paths. Throws CliError (exit 2). */
7
+ export async function resolveContentFiles(positionals, cmd) {
8
+ if (positionals.length === 0) {
9
+ throw new CliError(2, `${cmd}: provide at least one file or glob.`);
10
+ }
11
+ const files = (await glob(positionals, { absolute: true })).sort();
12
+ if (files.length === 0) {
13
+ throw new CliError(2, `${cmd}: no files matched ${positionals.join(' ')}`);
14
+ }
15
+ return files;
16
+ }
17
+ /**
18
+ * The "loaded content project" seam: turns (positional globs, flags) into a
19
+ * ready-to-use project — resolved files, loaded registry, read sources, and the
20
+ * produced content project scan. The single input path shared by the `validate`,
21
+ * `doctor`, and `stats` read-commands. Throws CliError on input failures.
22
+ */
23
+ export async function loadContentProject(input) {
24
+ const files = await resolveContentFiles(input.positionals, input.cmd);
25
+ const registry = await loadRegistry(input.registry, {
26
+ includeGenericBlocks: input.includeGenericBlocks,
27
+ });
28
+ const sources = await Promise.all(files.map(async (path) => ({ path, source: await readFile(path, 'utf8') })));
29
+ const scan = scanContentProject(sources, registry, {
30
+ linkOptions: input.linkOptions,
31
+ ...input.scan,
32
+ });
33
+ return { files, registry, sources, linkOptions: input.linkOptions, scan };
34
+ }
@@ -1,4 +1,7 @@
1
1
  import { type BlockRegistry } from '@contentbit/core';
2
+ export interface LoadRegistryOptions {
3
+ includeGenericBlocks?: boolean;
4
+ }
2
5
  /** Generic pack + optional user module (default export: BlockDefinition[]). */
3
- export declare function loadRegistry(registryPath?: string): Promise<BlockRegistry>;
6
+ export declare function loadRegistry(registryPath?: string, options?: LoadRegistryOptions): Promise<BlockRegistry>;
4
7
  //# sourceMappingURL=load-registry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"load-registry.d.ts","sourceRoot":"","sources":["../src/load-registry.ts"],"names":[],"mappings":"AACA,OAAO,EAA6C,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAGhG,+EAA+E;AAC/E,wBAAsB,YAAY,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAsBhF"}
1
+ {"version":3,"file":"load-registry.d.ts","sourceRoot":"","sources":["../src/load-registry.ts"],"names":[],"mappings":"AACA,OAAO,EAA6C,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAGhG,MAAM,WAAW,mBAAmB;IAClC,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED,+EAA+E;AAC/E,wBAAsB,YAAY,CAChC,YAAY,CAAC,EAAE,MAAM,EACrB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,aAAa,CAAC,CAuBxB"}
@@ -2,8 +2,10 @@ import { genericBlocks } from '@contentbit/blocks';
2
2
  import { createBlockRegistry } from '@contentbit/core';
3
3
  import { pathToFileURL } from 'node:url';
4
4
  /** Generic pack + optional user module (default export: BlockDefinition[]). */
5
- export async function loadRegistry(registryPath) {
6
- const registry = createBlockRegistry().use(genericBlocks());
5
+ export async function loadRegistry(registryPath, options = {}) {
6
+ const registry = createBlockRegistry();
7
+ if (options.includeGenericBlocks !== false)
8
+ registry.use(genericBlocks());
7
9
  if (registryPath) {
8
10
  let mod;
9
11
  try {
package/dist/run.d.ts CHANGED
@@ -3,6 +3,15 @@ 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|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>]";
6
+ /**
7
+ * A command-input failure with a chosen exit code and a ready-to-print message
8
+ * (e.g. no positionals, no files matched). `run()` prints the plain message and
9
+ * returns `exitCode`; any other throw is treated as an unexpected crash.
10
+ */
11
+ export declare class CliError extends Error {
12
+ readonly exitCode: number;
13
+ constructor(exitCode: number, message: string);
14
+ }
15
+ export declare const USAGE = "contentbit\n\nUsage:\n contentbit <command> [options]\n\nCommands:\n init scaffold Content Blocks into a project\n validate check Markdown blocks and internal links\n doctor inspect content health and repair suggestions\n studio browse content locally\n stats print document stats as JSON\n render render one file to plain Markdown\n instructions print LLM authoring instructions\n docs print human authoring docs\n agents install coding-agent guidance\n links build or fix the internal link index\n\nSetup:\n init [-t react|markdown|astro] [--md ...] [-y] [--no-install] [--no-page] [--no-agents]\n agents [--claude] [--no-agents-md]\n\nCommon:\n validate <globs...> [--registry <module.ts>] [--no-generic-blocks] [--strict-warnings] [--link-resolve <mode>]\n doctor <globs...> [--registry <module.ts>] [--no-generic-blocks] [--strict-warnings] [--json] [--min-section-words <n>] [--link-resolve <mode>]\n studio <globs...> [--registry <module.ts>] [--port <n>] [--host <host>] [--no-open] [--no-generic-blocks] [--link-resolve <mode>]\n stats <globs...> [--registry <module.ts>] [--no-generic-blocks] [--no-validate]\n render <file> [--target markdown] [--registry <module.ts>] [--no-generic-blocks] [--out <file>]\n instructions [--audience llm|human] [--no-examples] [--registry <module.ts>] [--no-generic-blocks] [--out <file>]\n docs [--registry <module.ts>] [--no-generic-blocks] [--out <file>]\n links <globs...> [--fix] [--out <file>] [--link-resolve <mode>]";
7
16
  export declare function run(argv: string[], io: Io): Promise<number>;
8
17
  //# 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,25BAYgD,CAAA;AAiBlE,wBAAsB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAcjE"}
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAEA,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;;;;GAIG;AACH,qBAAa,QAAS,SAAQ,KAAK;IAE/B,QAAQ,CAAC,QAAQ,EAAE,MAAM;gBAAhB,QAAQ,EAAE,MAAM,EACzB,OAAO,EAAE,MAAM;CAKlB;AAED,eAAO,MAAM,KAAK,yhDA6BgD,CAAA;AAiBlE,wBAAsB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAuBjE"}