@readme/cli 0.1.0 → 0.3.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 (57) hide show
  1. package/bin/git-format.js +80 -0
  2. package/bin/readme.js +1 -1
  3. package/package.json +54 -26
  4. package/src/bootstrap.js +9 -13
  5. package/src/cli.js +17 -11
  6. package/src/commands/components.js +35 -18
  7. package/src/commands/dev.js +12 -8
  8. package/src/commands/eyes.js +12 -8
  9. package/src/commands/import.js +2200 -2049
  10. package/src/commands/lint.js +33 -29
  11. package/src/commands/oas-bundle.js +6 -2
  12. package/src/commands/oas-sync.js +271 -161
  13. package/src/commands/oas-validate.js +10 -7
  14. package/src/commands/pretty.js +188 -165
  15. package/src/commands/setup.js +24 -26
  16. package/src/commands/versions.js +6 -2
  17. package/src/dev/app/[...slug]/page.js +1 -0
  18. package/src/dev/app/layout.js +18 -11
  19. package/src/dev/app/page.js +1 -0
  20. package/src/dev/lib/docs.js +27 -19
  21. package/src/dev/next.config.mjs +2 -2
  22. package/src/gha.js +7 -7
  23. package/src/prompts/index.js +16 -6
  24. package/src/utils/containment.js +87 -0
  25. package/src/utils/eyes.js +143 -51
  26. package/src/utils/git.js +3 -3
  27. package/src/utils/lint.js +39 -38
  28. package/src/utils/llms.js +94 -91
  29. package/src/utils/markdown.js +256 -0
  30. package/src/utils/marketplace.js +12 -5
  31. package/src/utils/multi-spinner.js +5 -7
  32. package/src/utils/promise-pool.js +7 -5
  33. package/src/utils/reporter.js +88 -94
  34. package/src/utils/setup-templates.js +12 -6
  35. package/src/utils/styles.js +2 -1
  36. package/src/utils/tamagotchi.js +257 -91
  37. package/src/utils/tips.js +18 -9
  38. package/src/utils/url-segs.js +46 -41
  39. package/src/validators/components.js +55 -63
  40. package/src/validators/content.js +16 -14
  41. package/src/validators/duplicates.js +6 -2
  42. package/src/validators/frontmatter.js +21 -29
  43. package/src/validators/links.js +4 -8
  44. package/src/validators/oas-reference.js +25 -18
  45. package/src/validators/oas-schema.js +2 -0
  46. package/src/validators/ordering.js +5 -5
  47. package/src/validators/recipes.js +4 -12
  48. package/vendor/git-format/CLAUDE.md +352 -0
  49. package/vendor/git-format/frontmatter.schema.json +199 -0
  50. package/src/commands/import-oas.test.js +0 -277
  51. package/src/commands/import.classify.test.js +0 -172
  52. package/src/commands/import.landing.test.js +0 -217
  53. package/src/commands/import.slug-planner.test.js +0 -86
  54. package/src/commands/import.staging.test.js +0 -230
  55. package/src/commands/import.test.js +0 -382
  56. package/src/utils/llms.test.js +0 -302
  57. package/src/utils/url-segs.test.js +0 -239
@@ -1,20 +1,20 @@
1
- import { collectFiles, runValidators } from '../utils/lint.js'
2
- import { createHumanReporter, createJsonReporter, createGithubReporter } from '../utils/reporter.js'
3
- import { printHeader, isAgenticCli } from '../utils/eyes.js'
4
- import * as styles from '../utils/styles.js'
5
- import { writeGithubActionsOutputs } from '../utils/gha-output.js'
6
- import pkg from '../../package.json' with { type: 'json' }
1
+ import pkg from '../../package.json' with { type: 'json' };
2
+ import { printHeader, isAgenticCli } from '../utils/eyes.js';
3
+ import { writeGithubActionsOutputs } from '../utils/gha-output.js';
4
+ import { collectFiles, runValidators } from '../utils/lint.js';
5
+ import { createHumanReporter, createJsonReporter, createGithubReporter } from '../utils/reporter.js';
6
+ import * as styles from '../utils/styles.js';
7
7
 
8
- export const command = 'lint'
9
- export const order = 1
10
- export const aliases = ['validate']
11
- export const category = 'Linting'
12
- export const description = 'Lint and validate your ReadMe docs'
8
+ export const command = 'lint';
9
+ export const order = 1;
10
+ export const aliases = ['validate'];
11
+ export const category = 'Linting';
12
+ export const description = 'Lint and validate your ReadMe docs';
13
13
 
14
14
  export function args(cmd) {
15
- cmd.option('--json', 'Output results as JSON (for CI and automation)')
16
- cmd.option('--github', 'Output a GitHub PR comment body as markdown')
17
- cmd.option('--fix', 'Automatically fix issues where possible')
15
+ cmd.option('--json', 'Output results as JSON (for CI and automation)');
16
+ cmd.option('--github', 'Output a GitHub PR comment body as markdown');
17
+ cmd.option('--fix', 'Automatically fix issues where possible');
18
18
  }
19
19
 
20
20
  /**
@@ -31,37 +31,41 @@ export function args(cmd) {
31
31
  * @returns {Promise<{ gitRoot: string, files: string[], results: object[], hasErrors: boolean }>}
32
32
  */
33
33
  export async function lint({ cwd, fix = false, nonInteractive = false, onFile, onBeforeCrossFile } = {}) {
34
- const gitRoot = cwd || process.cwd()
35
- const files = collectFiles(gitRoot)
36
- const results = await runValidators(files, gitRoot, { onFile, onBeforeCrossFile, fix, nonInteractive })
37
- const hasErrors = results.some((r) => r.severity !== 'warning')
38
- return { gitRoot, files, results, hasErrors }
34
+ const gitRoot = cwd || process.cwd();
35
+ const files = collectFiles(gitRoot);
36
+ const results = await runValidators(files, gitRoot, { onFile, onBeforeCrossFile, fix, nonInteractive });
37
+ const hasErrors = results.some(r => r.severity !== 'warning');
38
+ return { gitRoot, files, results, hasErrors };
39
39
  }
40
40
 
41
41
  export async function run(options, _cmd, ctx) {
42
- const { gitRoot } = ctx
42
+ const { gitRoot } = ctx;
43
43
 
44
44
  if (!options.json && !options.github && !isAgenticCli()) {
45
- printHeader({ version: pkg.version, binName: styles.binName(), indent: ' ' })
46
- console.log()
45
+ printHeader({ version: pkg.version, binName: styles.binName(), indent: ' ' });
46
+ console.log();
47
47
  }
48
48
 
49
- const reporter = options.github ? createGithubReporter() : options.json ? createJsonReporter() : createHumanReporter()
49
+ const reporter = options.github
50
+ ? createGithubReporter()
51
+ : options.json
52
+ ? createJsonReporter()
53
+ : createHumanReporter();
50
54
 
51
55
  const { files, results, hasErrors } = await lint({
52
56
  cwd: gitRoot,
53
57
  fix: options.fix,
54
- onFile: (f) => reporter.onFile(f),
58
+ onFile: f => reporter.onFile(f),
55
59
  onBeforeCrossFile: () => reporter.pause(),
56
- })
60
+ });
57
61
 
58
- reporter.finish(files.length, results, files, { fix: options.fix, gitRoot })
62
+ reporter.finish(files.length, results, files, { fix: options.fix, gitRoot });
59
63
 
60
- writeGithubActionsOutputs({ 'has-errors': String(hasErrors), results })
64
+ writeGithubActionsOutputs({ 'has-errors': String(hasErrors), results });
61
65
 
62
66
  if (hasErrors) {
63
67
  // Wait for stdout to flush (important when piped to a file), then exit
64
- await new Promise((resolve) => process.stdout.write('', resolve))
65
- process.exit(1)
68
+ await new Promise(resolve => process.stdout.write('', resolve));
69
+ process.exit(1);
66
70
  }
67
71
  }
@@ -1,7 +1,9 @@
1
1
  import fs from 'node:fs';
2
- import path from 'node:path';
3
2
  import { createRequire } from 'node:module';
3
+ import path from 'node:path';
4
+
4
5
  import { bundle } from '@readme/openapi-parser';
6
+
5
7
  import * as styles from '../utils/styles.js';
6
8
 
7
9
  const require = createRequire(import.meta.url);
@@ -61,7 +63,9 @@ export async function run(specArg, options) {
61
63
  const opCount = countOperations(spec);
62
64
  const rel = path.relative(process.cwd(), outPath);
63
65
  const shown = rel && !rel.startsWith('..') ? rel : outPath;
64
- styles.ok(`Bundled ${styles.bold(spec.info?.title || specArg)} (${opCount} ${opCount === 1 ? 'endpoint' : 'endpoints'}) → ${shown}`);
66
+ styles.ok(
67
+ `Bundled ${styles.bold(spec.info?.title || specArg)} (${opCount} ${opCount === 1 ? 'endpoint' : 'endpoints'}) → ${shown}`,
68
+ );
65
69
  return;
66
70
  }
67
71