argsbarg 6.0.1 → 6.0.2

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 (33) hide show
  1. package/CHANGELOG.md +14 -2
  2. package/README.md +3 -3
  3. package/docs/config-schema.md +15 -13
  4. package/docs/output-schema.md +67 -66
  5. package/examples/full-example/README.md +7 -7
  6. package/examples/full-example/bun.lock +0 -29
  7. package/examples/full-example/justfile +6 -3
  8. package/examples/full-example/package.json +0 -2
  9. package/examples/full-example/src/commands/status/__generated__/index.ts +5 -0
  10. package/examples/full-example/src/commands/status/command.ts +2 -2
  11. package/examples/full-example/src/commands/status/types.ts +1 -1
  12. package/examples/full-example/src/config/__generated__/index.ts +5 -0
  13. package/examples/full-example/src/program.ts +4 -4
  14. package/package.json +8 -1
  15. package/src/cli-tool/full-example-capabilities.test.ts +2 -1
  16. package/src/cli-tool/post-create.ts +3 -3
  17. package/src/cli-tool/program.ts +35 -0
  18. package/src/cli-tool/run-schemagen.ts +23 -0
  19. package/src/cli-tool/schemagen/cleanup.ts +60 -0
  20. package/{examples/full-example/scripts → src/cli-tool}/schemagen/discover-schema-roots.ts +13 -58
  21. package/src/cli-tool/schemagen/index.ts +3 -0
  22. package/src/cli-tool/schemagen/names.ts +22 -0
  23. package/src/cli-tool/schemagen/run.ts +108 -0
  24. package/src/cli-tool/schemagen/schemagen.test.ts +125 -0
  25. package/examples/full-example/schemas/configSchemas.ts +0 -6
  26. package/examples/full-example/schemas/outputSchemas.ts +0 -6
  27. package/examples/full-example/scripts/schemagen/discover-schema-roots.test.ts +0 -25
  28. package/examples/full-example/scripts/schemagen/naming.ts +0 -99
  29. package/examples/full-example/scripts/schemagen.ts +0 -91
  30. /package/examples/full-example/{schemas/generated/status.json → src/commands/status/__generated__/outputSchema.json} +0 -0
  31. /package/examples/full-example/src/commands/status/{schema-types.ts → schema.ts} +0 -0
  32. /package/examples/full-example/{schemas/generated/app-config.json → src/config/__generated__/configSchema.json} +0 -0
  33. /package/examples/full-example/src/config/{schema-types.ts → schema.ts} +0 -0
@@ -1,91 +0,0 @@
1
- /*
2
- Generate JSON Schema artifacts and bridge modules from discovered schema-types.ts roots.
3
- */
4
-
5
- import { mkdirSync, writeFileSync } from "node:fs";
6
- import { dirname, join } from "node:path";
7
- import { createGenerator } from "ts-json-schema-generator";
8
- import { discoverSchemaRoots, type SchemaRoot } from "./schemagen/discover-schema-roots.ts";
9
- import { jsonImportVar } from "./schemagen/naming.ts";
10
-
11
- const projectRoot = join(import.meta.dir, "..");
12
- const generatedDir = join(projectRoot, "schemas", "generated");
13
-
14
- function generateJson(root: SchemaRoot): Record<string, unknown> {
15
- const generator = createGenerator({
16
- path: join(projectRoot, root.path),
17
- type: root.typeName,
18
- tsconfig: join(projectRoot, "tsconfig.json"),
19
- topRef: false,
20
- skipTypeCheck: false,
21
- jsDoc: "extended",
22
- additionalProperties: root.kind === "config" ? false : undefined,
23
- });
24
- const schema = generator.createSchema(root.typeName) as Record<string, unknown>;
25
- if (root.kind === "config") {
26
- schema.additionalProperties = false;
27
- }
28
- return schema;
29
- }
30
-
31
- function writeBridge(path: string, scriptName: string, roots: SchemaRoot[], banner: string): void {
32
- /** Sort by import binding so Biome `organizeImports` does not reorder the bridge file. */
33
- const sorted = [...roots].sort((left, right) =>
34
- jsonImportVar(left.outfile).localeCompare(jsonImportVar(right.outfile)),
35
- );
36
- const lines = [`// Auto-generated by scripts/${scriptName} — do not edit by hand.`, ""];
37
- for (const root of sorted) {
38
- const varName = jsonImportVar(root.outfile);
39
- lines.push(`import ${varName} from "./generated/${root.outfile}";`);
40
- }
41
- if (sorted.length > 0) {
42
- lines.push("");
43
- }
44
- for (const root of sorted) {
45
- const varName = jsonImportVar(root.outfile);
46
- lines.push(`/** ${banner} \`${root.typeName}\`. */`);
47
- lines.push(`export const ${root.exportName} = ${varName} as Record<string, unknown>;`);
48
- lines.push("");
49
- }
50
- writeFileSync(path, `${lines.join("\n")}`);
51
- }
52
-
53
- const roots = discoverSchemaRoots(projectRoot);
54
- const configRoots = roots.filter((r) => r.kind === "config");
55
- const inputRoots = roots.filter((r) => r.kind === "input");
56
- const outputRoots = roots.filter((r) => r.kind === "output");
57
-
58
- mkdirSync(generatedDir, { recursive: true });
59
-
60
- for (const root of roots) {
61
- const schema = generateJson(root);
62
- const outPath = join(generatedDir, root.outfile);
63
- mkdirSync(dirname(outPath), { recursive: true });
64
- writeFileSync(outPath, `${JSON.stringify(schema, null, 2)}\n`);
65
- console.log(`wrote schemas/generated/${root.outfile} (${root.typeName})`);
66
- }
67
-
68
- writeBridge(
69
- join(projectRoot, "schemas", "configSchemas.ts"),
70
- "schemagen.ts",
71
- configRoots,
72
- "JSON Schema for program.appConfig.jsonSchema from",
73
- );
74
- if (inputRoots.length > 0) {
75
- writeBridge(
76
- join(projectRoot, "schemas", "inputSchemas.ts"),
77
- "schemagen.ts",
78
- inputRoots,
79
- "JSON Schema for leaf inputSchema from",
80
- );
81
- }
82
- writeBridge(
83
- join(projectRoot, "schemas", "outputSchemas.ts"),
84
- "schemagen.ts",
85
- outputRoots,
86
- "JSON Schema for leaf outputSchema from",
87
- );
88
-
89
- console.log(
90
- `config roots: ${configRoots.length}, input roots: ${inputRoots.length}, output roots: ${outputRoots.length}`,
91
- );