@metaobjectsdev/codegen-ts 0.7.0-rc.11 → 0.7.0-rc.13
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/dist/generator.d.ts +9 -0
- package/dist/generator.d.ts.map +1 -1
- package/dist/generator.js.map +1 -1
- package/dist/generators/docs-data-builder.d.ts +16 -0
- package/dist/generators/docs-data-builder.d.ts.map +1 -0
- package/dist/generators/docs-data-builder.js +381 -0
- package/dist/generators/docs-data-builder.js.map +1 -0
- package/dist/generators/docs-data.d.ts +98 -0
- package/dist/generators/docs-data.d.ts.map +1 -0
- package/dist/generators/docs-data.js +43 -0
- package/dist/generators/docs-data.js.map +1 -0
- package/dist/generators/docs-file.d.ts +1 -1
- package/dist/generators/docs-file.d.ts.map +1 -1
- package/dist/generators/docs-file.js +59 -34
- package/dist/generators/docs-file.js.map +1 -1
- package/dist/generators/index.d.ts +3 -0
- package/dist/generators/index.d.ts.map +1 -1
- package/dist/generators/index.js +2 -0
- package/dist/generators/index.js.map +1 -1
- package/dist/generators/template-generator.d.ts +41 -0
- package/dist/generators/template-generator.d.ts.map +1 -0
- package/dist/generators/template-generator.js +62 -0
- package/dist/generators/template-generator.js.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/overwrite-policy.d.ts +39 -2
- package/dist/overwrite-policy.d.ts.map +1 -1
- package/dist/overwrite-policy.js +233 -13
- package/dist/overwrite-policy.js.map +1 -1
- package/dist/render-engine/framework-provider.d.ts +28 -0
- package/dist/render-engine/framework-provider.d.ts.map +1 -0
- package/dist/render-engine/framework-provider.js +104 -0
- package/dist/render-engine/framework-provider.js.map +1 -0
- package/dist/runner.d.ts +15 -1
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +44 -6
- package/dist/runner.js.map +1 -1
- package/dist/templates/docs-file.d.ts +5 -36
- package/dist/templates/docs-file.d.ts.map +1 -1
- package/dist/templates/docs-file.js +33 -447
- package/dist/templates/docs-file.js.map +1 -1
- package/package.json +5 -5
- package/src/generator.ts +9 -0
- package/src/generators/docs-data-builder.ts +470 -0
- package/src/generators/docs-data.ts +154 -0
- package/src/generators/docs-file.ts +64 -41
- package/src/generators/index.ts +15 -0
- package/src/generators/template-generator.ts +106 -0
- package/src/index.ts +33 -2
- package/src/overwrite-policy.ts +325 -14
- package/src/render-engine/framework-provider.ts +107 -0
- package/src/runner.ts +65 -6
- package/src/templates/docs-file.ts +36 -537
- package/templates/docs/entity-page.md.mustache +54 -0
|
@@ -1,52 +1,77 @@
|
|
|
1
1
|
// docsFile() — emits `<Entity>.md` next to each generated entity module.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
// page
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
// rc.12+: structured around a shared Mustache template at
|
|
4
|
+
// `templates/docs/entity-page.md.mustache` + a data builder at
|
|
5
|
+
// `docs-data-builder.ts`. Adopters can override the framework template by
|
|
6
|
+
// dropping their own `templates/docs/entity-page.md.mustache` into the
|
|
7
|
+
// project root (resolved via the project-then-framework provider chain).
|
|
8
|
+
//
|
|
9
|
+
// docsFile() calls `render()` directly rather than wrapping
|
|
10
|
+
// `templateGenerator()` because the per-entity output path depends on
|
|
11
|
+
// `GenContext.config.outputLayout`, which the generic templateGenerator
|
|
12
|
+
// `walk(root)` signature doesn't expose. Other future docs-style adopters
|
|
13
|
+
// with ctx-free walks (single-file aggregators, etc.) compose
|
|
14
|
+
// `templateGenerator()` directly.
|
|
15
|
+
//
|
|
16
|
+
// The conformance fixture (`fixtures/conformance/docs-file-basic`) gates
|
|
17
|
+
// byte-identity — the codegen output must match the hand-coded rc.11
|
|
18
|
+
// byte-for-byte. If you're hacking on this and the conformance test
|
|
19
|
+
// breaks, the refactor is the bug, not the fixture.
|
|
20
|
+
import { render } from "@metaobjectsdev/render";
|
|
11
21
|
import { entityOutputPath } from "../import-path.js";
|
|
22
|
+
import { projectProvider } from "../render-engine/framework-provider.js";
|
|
23
|
+
import { buildEntityDocData } from "./docs-data-builder.js";
|
|
24
|
+
/** The names of the generators that may emit sibling files for an entity.
|
|
25
|
+
* We always list them in the "Generated code" section — adopters cross-
|
|
26
|
+
* reference their own metaobjects.config.ts to confirm which are wired in.
|
|
27
|
+
* Matches the rc.11 behavior. */
|
|
28
|
+
const KNOWN_SIBLING_GENERATORS = new Set([
|
|
29
|
+
"queries-file",
|
|
30
|
+
"routes-file",
|
|
31
|
+
"routes-file-hono",
|
|
32
|
+
]);
|
|
33
|
+
const TEMPLATE_REF = "docs/entity-page.md";
|
|
12
34
|
export const docsFile = function docsFile(opts) {
|
|
13
35
|
const generator = {
|
|
14
36
|
name: "docs-file",
|
|
15
|
-
generate
|
|
37
|
+
async generate(ctx) {
|
|
16
38
|
if (!ctx.renderContext) {
|
|
17
39
|
throw new Error("docs-file: renderContext is required (provided by runGen)");
|
|
18
40
|
}
|
|
19
41
|
const rc = ctx.renderContext;
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
42
|
+
const provider = projectProvider(ctx.projectRoot ?? process.cwd());
|
|
43
|
+
const layout = ctx.config.outputLayout ?? "flat";
|
|
44
|
+
return ctx.loadedRoot.objects().filter(ctx.matches).map((entity) => {
|
|
45
|
+
const path = entityOutputPath(layout, entity.package, `${entity.name}.md`);
|
|
46
|
+
const payload = buildEntityDocData(entity, {
|
|
24
47
|
dialect: rc.dialect,
|
|
25
|
-
|
|
48
|
+
...(rc.columnNamingStrategy !== undefined && {
|
|
49
|
+
columnNamingStrategy: rc.columnNamingStrategy,
|
|
50
|
+
}),
|
|
26
51
|
loadedRoot: rc.loadedRoot,
|
|
27
|
-
generatorNames,
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
|
|
52
|
+
generatorNames: KNOWN_SIBLING_GENERATORS,
|
|
53
|
+
});
|
|
54
|
+
let content;
|
|
55
|
+
try {
|
|
56
|
+
content = render({
|
|
57
|
+
ref: TEMPLATE_REF,
|
|
58
|
+
payload,
|
|
59
|
+
provider,
|
|
60
|
+
format: "markdown",
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
65
|
+
throw new Error(`docs-file: failed rendering '${TEMPLATE_REF}' for '${path}': ${msg}`, { cause: err instanceof Error ? err : undefined });
|
|
66
|
+
}
|
|
67
|
+
return { path, content };
|
|
68
|
+
});
|
|
69
|
+
},
|
|
31
70
|
};
|
|
32
|
-
if (opts?.filter)
|
|
71
|
+
if (opts?.filter)
|
|
33
72
|
generator.filter = opts.filter;
|
|
34
|
-
|
|
35
|
-
if (opts?.target) {
|
|
73
|
+
if (opts?.target)
|
|
36
74
|
generator.target = opts.target;
|
|
37
|
-
}
|
|
38
75
|
return generator;
|
|
39
76
|
};
|
|
40
|
-
/**
|
|
41
|
-
* `GenContext` does not currently carry the full generator list — that lives on
|
|
42
|
-
* the resolved config inside the runner. Rather than thread a new field through
|
|
43
|
-
* just to populate one optional markdown section, we always list every
|
|
44
|
-
* potential companion. The "Generated code" section becomes "files that may be
|
|
45
|
-
* generated alongside this one" — adopters cross-reference their own
|
|
46
|
-
* `metaobjects.config.ts` to confirm which they actually wired in. This matches
|
|
47
|
-
* the spec guidance "list them all and let the reader figure out which exist."
|
|
48
|
-
*/
|
|
49
|
-
function readGeneratorNames(_ctx) {
|
|
50
|
-
return new Set(["queries-file", "routes-file", "routes-file-hono"]);
|
|
51
|
-
}
|
|
52
77
|
//# sourceMappingURL=docs-file.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"docs-file.js","sourceRoot":"","sources":["../../src/generators/docs-file.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,EAAE;AACF,+
|
|
1
|
+
{"version":3,"file":"docs-file.js","sourceRoot":"","sources":["../../src/generators/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AAC,MAAM,CAAC;IACjD,OAAO,SAAS,CAAC;AACnB,CAAmC,CAAC"}
|
|
@@ -7,4 +7,7 @@ export { mermaidErDiagram, type MermaidErOptions } from "./mermaid-er.js";
|
|
|
7
7
|
export { promptRender, type PromptRenderOpts } from "./prompt-render-file.js";
|
|
8
8
|
export { outputParser, type OutputParserOpts } from "./output-parser-file.js";
|
|
9
9
|
export { docsFile, type DocsFileOpts } from "./docs-file.js";
|
|
10
|
+
export { templateGenerator, type TemplateGeneratorOpts, type TemplateWalkResult, type TemplateFormat, } from "./template-generator.js";
|
|
11
|
+
export type { EntityDocData, StorageFieldDoc, IdentityDoc, RelationshipDoc, UsedByDoc, GeneratedFileDoc, } from "./docs-data.js";
|
|
12
|
+
export { buildEntityDocData } from "./docs-data-builder.js";
|
|
10
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EACL,iBAAiB,EACjB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,cAAc,GACpB,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACV,aAAa,EACb,eAAe,EACf,WAAW,EACX,eAAe,EACf,SAAS,EACT,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/generators/index.js
CHANGED
|
@@ -7,4 +7,6 @@ export { mermaidErDiagram } from "./mermaid-er.js";
|
|
|
7
7
|
export { promptRender } from "./prompt-render-file.js";
|
|
8
8
|
export { outputParser } from "./output-parser-file.js";
|
|
9
9
|
export { docsFile } from "./docs-file.js";
|
|
10
|
+
export { templateGenerator, } from "./template-generator.js";
|
|
11
|
+
export { buildEntityDocData } from "./docs-data-builder.js";
|
|
10
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAuB,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAwB,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAuB,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,cAAc,EAA2B,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAE,MAAM,EAAmB,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAyB,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAyB,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAyB,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAqB,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAuB,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAwB,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAuB,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,cAAc,EAA2B,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAE,MAAM,EAAmB,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAyB,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAyB,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAyB,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAqB,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EACL,iBAAiB,GAIlB,MAAM,yBAAyB,CAAC;AASjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { MetaRoot, MetaObject } from "@metaobjectsdev/metadata";
|
|
2
|
+
import { type Provider, type RenderFormat } from "@metaobjectsdev/render";
|
|
3
|
+
import type { GeneratorFactory } from "../generator.js";
|
|
4
|
+
export type TemplateFormat = RenderFormat;
|
|
5
|
+
export interface TemplateWalkResult {
|
|
6
|
+
/** The data dict to render against. Templates reference its keys; the
|
|
7
|
+
* shape is the public-API contract template authors consume. */
|
|
8
|
+
data: object;
|
|
9
|
+
/** Output path RELATIVE to the generator's target outDir. */
|
|
10
|
+
outputPath: string;
|
|
11
|
+
}
|
|
12
|
+
export interface TemplateGeneratorOpts {
|
|
13
|
+
/** kebab-case identifier; surfaces in diagnostics and the overwrite-policy
|
|
14
|
+
* per-file snapshot key. */
|
|
15
|
+
name: string;
|
|
16
|
+
/** Walk the loaded metadata tree and produce `{ data, outputPath }` tuples
|
|
17
|
+
* — one per emitted file. Pattern A (per-entity), pattern B (single
|
|
18
|
+
* aggregator), pattern C (mixed), pattern D (filter inline) all fit. */
|
|
19
|
+
walk: (root: MetaRoot) => TemplateWalkResult[] | Promise<TemplateWalkResult[]>;
|
|
20
|
+
/** Template reference. Resolved by the configured Provider chain — by
|
|
21
|
+
* default the project's `templates/<ref>.mustache` first, then the
|
|
22
|
+
* framework defaults at `codegen-ts/templates/<ref>.mustache`. */
|
|
23
|
+
template: string;
|
|
24
|
+
/** Drives the render engine's escaper. Defaults to "text". */
|
|
25
|
+
format?: TemplateFormat;
|
|
26
|
+
/** Optional per-entity filter for adopters who want to scope a generator
|
|
27
|
+
* via the standard `Generator.filter` plumbing. Not consulted by the
|
|
28
|
+
* default `walk` — adopters apply filters inside their walk function. */
|
|
29
|
+
filter?: (entity: MetaObject) => boolean;
|
|
30
|
+
/** Override the Provider used for template resolution. When omitted the
|
|
31
|
+
* generator resolves via `projectProvider(ctx.projectRoot)`, which layers
|
|
32
|
+
* the project's `templates/` over the framework defaults. (The project
|
|
33
|
+
* root is the directory holding `.metaobjects/config.json`, threaded
|
|
34
|
+
* through `GenContext` by the runner. Adopters needing a different
|
|
35
|
+
* lookup chain can pass an explicit provider.) */
|
|
36
|
+
provider?: Provider;
|
|
37
|
+
/** Optional named target — same as the other generators. */
|
|
38
|
+
target?: string;
|
|
39
|
+
}
|
|
40
|
+
export declare const templateGenerator: GeneratorFactory<TemplateGeneratorOpts>;
|
|
41
|
+
//# sourceMappingURL=template-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-generator.d.ts","sourceRoot":"","sources":["../../src/generators/template-generator.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAU,KAAK,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAClF,OAAO,KAAK,EAAsC,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAG5F,MAAM,MAAM,cAAc,GAAG,YAAY,CAAC;AAE1C,MAAM,WAAW,kBAAkB;IACjC;qEACiE;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC;iCAC6B;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb;;6EAEyE;IACzE,IAAI,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,kBAAkB,EAAE,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAC/E;;uEAEmE;IACnE,QAAQ,EAAE,MAAM,CAAC;IACjB,8DAA8D;IAC9D,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB;;8EAE0E;IAC1E,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC;IACzC;;;;;uDAKmD;IACnD,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,iBAAiB,EA8CzB,gBAAgB,CAAC,qBAAqB,CAAC,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// templateGenerator() — the missing primitive identified by the
|
|
2
|
+
// template-driven-codegen design (2026-05-28). Walks the loaded MetaRoot
|
|
3
|
+
// → renders shared Mustache templates via @metaobjectsdev/render → emits
|
|
4
|
+
// EmittedFile[]. Same Generator interface as the per-port hand-coded
|
|
5
|
+
// generators; just adds the "Mustache template" + "walk that yields a
|
|
6
|
+
// data dict per output" primitives.
|
|
7
|
+
//
|
|
8
|
+
// Design line we adopted (from the design doc):
|
|
9
|
+
// Code → hand-coded generators (ts-poet, idiomatic per-port).
|
|
10
|
+
// Documents → templateGenerator (shared Mustache templates).
|
|
11
|
+
//
|
|
12
|
+
// docsFile() is the first templateGenerator instance (rc.12). OpenAPI specs,
|
|
13
|
+
// Mermaid diagrams, HTML doc sites, etc. follow as templates + a walk
|
|
14
|
+
// function each.
|
|
15
|
+
import { render } from "@metaobjectsdev/render";
|
|
16
|
+
import { projectProvider } from "../render-engine/framework-provider.js";
|
|
17
|
+
export const templateGenerator = function templateGenerator(opts) {
|
|
18
|
+
const fmt = opts.format ?? "text";
|
|
19
|
+
const generator = {
|
|
20
|
+
name: opts.name,
|
|
21
|
+
async generate(ctx) {
|
|
22
|
+
let provider;
|
|
23
|
+
if (opts.provider !== undefined) {
|
|
24
|
+
provider = opts.provider;
|
|
25
|
+
}
|
|
26
|
+
else if (ctx.projectRoot !== undefined) {
|
|
27
|
+
provider = projectProvider(ctx.projectRoot);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
ctx.warn("templateGenerator: ctx.projectRoot is undefined; falling back to process.cwd() for project-template resolution. " +
|
|
31
|
+
"Project-scoped template overrides will resolve relative to the current working directory, which is fragile under " +
|
|
32
|
+
"`meta gen` invoked from a sub-directory. Drive via runGen(opts.projectRoot) to remove this warning.");
|
|
33
|
+
provider = projectProvider(process.cwd());
|
|
34
|
+
}
|
|
35
|
+
const walkRes = await opts.walk(ctx.loadedRoot);
|
|
36
|
+
const files = [];
|
|
37
|
+
for (const { data, outputPath } of walkRes) {
|
|
38
|
+
let content;
|
|
39
|
+
try {
|
|
40
|
+
content = render({
|
|
41
|
+
ref: opts.template,
|
|
42
|
+
payload: data,
|
|
43
|
+
provider,
|
|
44
|
+
format: fmt,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
49
|
+
throw new Error(`templateGenerator(${opts.name}) failed rendering '${opts.template}' for '${outputPath}': ${msg}`, { cause: err instanceof Error ? err : undefined });
|
|
50
|
+
}
|
|
51
|
+
files.push({ path: outputPath, content });
|
|
52
|
+
}
|
|
53
|
+
return files;
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
if (opts.filter)
|
|
57
|
+
generator.filter = opts.filter;
|
|
58
|
+
if (opts.target)
|
|
59
|
+
generator.target = opts.target;
|
|
60
|
+
return generator;
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=template-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-generator.js","sourceRoot":"","sources":["../../src/generators/template-generator.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,yEAAyE;AACzE,yEAAyE;AACzE,qEAAqE;AACrE,sEAAsE;AACtE,oCAAoC;AACpC,EAAE;AACF,gDAAgD;AAChD,gEAAgE;AAChE,+DAA+D;AAC/D,EAAE;AACF,6EAA6E;AAC7E,sEAAsE;AACtE,iBAAiB;AAGjB,OAAO,EAAE,MAAM,EAAoC,MAAM,wBAAwB,CAAC;AAElF,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAyCzE,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAA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,CAAC,IAAI,uBAAuB,IAAI,CAAC,QAAQ,UAAU,UAAU,MAAM,GAAG,EAAE,EACjG,EAAE,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,CAClD,CAAC;gBACJ,CAAC;gBACD,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC;YAC5C,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;IACF,IAAI,IAAI,CAAC,MAAM;QAAE,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAChD,IAAI,IAAI,CAAC,MAAM;QAAE,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAChD,OAAO,SAAS,CAAC;AACnB,CAA4C,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -12,8 +12,8 @@ export type { RelationEntry, RelationMap } from "./relation-resolver.js";
|
|
|
12
12
|
export { buildRelationMap } from "./relation-resolver.js";
|
|
13
13
|
export type { RenderContext } from "./render-context.js";
|
|
14
14
|
export { makeRenderContext } from "./render-context.js";
|
|
15
|
-
export type { WriteStatus, WriteResult, MergeStrategy } from "./overwrite-policy.js";
|
|
16
|
-
export { decideAndWrite } from "./overwrite-policy.js";
|
|
15
|
+
export type { WriteStatus, WriteResult, MergeStrategy, BaselineMode, DecideAndWriteOpts, } from "./overwrite-policy.js";
|
|
16
|
+
export { decideAndWrite, GitMissingError } from "./overwrite-policy.js";
|
|
17
17
|
export { CodegenError } from "./errors.js";
|
|
18
18
|
export { GENERATED_HEADER, EXTRA_SUFFIX, DEFAULT_OUT_DIR } from "./constants.js";
|
|
19
19
|
export { formatTs } from "./format.js";
|
|
@@ -27,4 +27,8 @@ export { emitViewDdl } from "./projection/view-ddl-emit.js";
|
|
|
27
27
|
export type { EmitOptions as ViewDdlEmitOptions } from "./projection/view-ddl-emit.js";
|
|
28
28
|
export type { JoinNode, JoinTree, SelectColumn, SelectSpec, ViewSpec } from "./projection/view-spec.js";
|
|
29
29
|
export { generatePayloadInterfaces, generatePayloadInterfacesBatch, generateRenderHandle } from "./payload-codegen.js";
|
|
30
|
+
export { templateGenerator, type TemplateGeneratorOpts, type TemplateWalkResult, type TemplateFormat, } from "./generators/template-generator.js";
|
|
31
|
+
export { FileSystemProvider, ProviderChain, frameworkTemplatesProvider, projectProvider, } from "./render-engine/framework-provider.js";
|
|
32
|
+
export type { EntityDocData, StorageFieldDoc, IdentityDoc, RelationshipDoc, UsedByDoc, GeneratedFileDoc, } from "./generators/docs-data.js";
|
|
33
|
+
export { buildEntityDocData } from "./generators/docs-data-builder.js";
|
|
30
34
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE5D,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAC3F,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEvD,YAAY,EAAE,oBAAoB,EAAE,8BAA8B,EAAE,iBAAiB,EAAE,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACtL,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAExE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,YAAY,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,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oC,CAAC;AAC5C,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,0BAA0B,EAC1B,eAAe,GAChB,MAAM,uCAAuC,CAAC;AAC/C,YAAY,EACV,aAAa,EACb,eAAe,EACf,WAAW,EACX,eAAe,EACf,SAAS,EACT,gBAAgB,GACjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ export { mapColumnType } from "./column-mapper.js";
|
|
|
9
9
|
export { buildPkMap } from "./pk-resolver.js";
|
|
10
10
|
export { buildRelationMap } from "./relation-resolver.js";
|
|
11
11
|
export { makeRenderContext } from "./render-context.js";
|
|
12
|
-
export { decideAndWrite } from "./overwrite-policy.js";
|
|
12
|
+
export { decideAndWrite, GitMissingError } from "./overwrite-policy.js";
|
|
13
13
|
export { CodegenError } from "./errors.js";
|
|
14
14
|
export { GENERATED_HEADER, EXTRA_SUFFIX, DEFAULT_OUT_DIR } from "./constants.js";
|
|
15
15
|
export { formatTs } from "./format.js";
|
|
@@ -20,4 +20,10 @@ export { extractViewSpec } from "./projection/extract-view-spec.js";
|
|
|
20
20
|
export { emitViewDdl } from "./projection/view-ddl-emit.js";
|
|
21
21
|
// Prompt construction (FR-004): typed payload + render-handle codegen.
|
|
22
22
|
export { generatePayloadInterfaces, generatePayloadInterfacesBatch, generateRenderHandle } from "./payload-codegen.js";
|
|
23
|
+
// Template-driven codegen (rc.12). Factory + framework Provider for adopters
|
|
24
|
+
// who want to wire their own templateGenerator instances. The default
|
|
25
|
+
// docsFile() uses this internally.
|
|
26
|
+
export { templateGenerator, } from "./generators/template-generator.js";
|
|
27
|
+
export { FileSystemProvider, ProviderChain, frameworkTemplatesProvider, projectProvider, } from "./render-engine/framework-provider.js";
|
|
28
|
+
export { buildEntityDocData } from "./generators/docs-data-builder.js";
|
|
23
29
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,EAAE;AACF,yCAAyC;AACzC,wEAAwE;AAExE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGvD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAGxE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,EAAE;AACF,yCAAyC;AACzC,wEAAwE;AAExE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGvD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAGxE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AASxD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjF,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAE1G,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAGxM,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAEpE,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAG5D,uEAAuE;AACvE,OAAO,EAAE,yBAAyB,EAAE,8BAA8B,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEvH,6EAA6E;AAC7E,sEAAsE;AACtE,mCAAmC;AACnC,OAAO,EACL,iBAAiB,GAIlB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,0BAA0B,EAC1B,eAAe,GAChB,MAAM,uCAAuC,CAAC;AAS/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC"}
|
|
@@ -1,8 +1,45 @@
|
|
|
1
|
-
export type WriteStatus = "new" | "overwrite" | "refused" | "skipped";
|
|
1
|
+
export type WriteStatus = "new" | "unchanged" | "overwrite" | "merged" | "conflict" | "refused" | "skipped";
|
|
2
|
+
/**
|
|
3
|
+
* "overwrite" — default; three-way merge if .gen-state exists, else write-if-
|
|
4
|
+
* different / first-time-existing flow.
|
|
5
|
+
* "skip-existing" — never write over an existing file; status "skipped".
|
|
6
|
+
* Useful for `meta gen --dry-run` style flows.
|
|
7
|
+
*/
|
|
2
8
|
export type MergeStrategy = "overwrite" | "skip-existing";
|
|
9
|
+
/** "default" — the standard three-way merge flow described in the file header.
|
|
10
|
+
* "fresh" — opt-in via `meta gen --baseline=fresh`. When .gen-state is absent
|
|
11
|
+
* but the file exists, OVERWRITE with fresh content and seed .gen-state from
|
|
12
|
+
* the fresh content (caveat 3 escape hatch). */
|
|
13
|
+
export type BaselineMode = "default" | "fresh";
|
|
14
|
+
export interface DecideAndWriteOpts {
|
|
15
|
+
strategy?: MergeStrategy;
|
|
16
|
+
/** Absolute path to the .gen-state/ root for this project. When undefined,
|
|
17
|
+
* we fall back to a process-isolated tmpdir — fine for tests but the CLI
|
|
18
|
+
* always supplies the real project value via runGen(). */
|
|
19
|
+
genStateDir?: string;
|
|
20
|
+
/** Path the snapshot is keyed by — usually the path relative to the
|
|
21
|
+
* project root, but ANY stable identifier works. When undefined, derived
|
|
22
|
+
* from `path` (so unit tests can call without supplying it). */
|
|
23
|
+
outputRelPath?: string;
|
|
24
|
+
/** First-time-existing-file behavior. */
|
|
25
|
+
baseline?: BaselineMode;
|
|
26
|
+
}
|
|
3
27
|
export interface WriteResult {
|
|
4
28
|
path: string;
|
|
5
29
|
status: WriteStatus;
|
|
30
|
+
/** Present when status is "conflict" — human-readable hint identifying the
|
|
31
|
+
* file the user must resolve. */
|
|
32
|
+
conflictHint?: string;
|
|
33
|
+
}
|
|
34
|
+
/** Thrown when git is unavailable. Surfaces as a clear CLI error rather than
|
|
35
|
+
* a generic ENOENT halfway through a regen. */
|
|
36
|
+
export declare class GitMissingError extends Error {
|
|
37
|
+
constructor();
|
|
6
38
|
}
|
|
7
|
-
|
|
39
|
+
/**
|
|
40
|
+
* The main entry point. Backward-compatible with the rc.11 signature: passing
|
|
41
|
+
* a `MergeStrategy` string as the third argument continues to work; passing
|
|
42
|
+
* an options object opts into three-way merge.
|
|
43
|
+
*/
|
|
44
|
+
export declare function decideAndWrite(path: string, content: string, optsOrStrategy?: DecideAndWriteOpts | MergeStrategy): WriteResult;
|
|
8
45
|
//# sourceMappingURL=overwrite-policy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overwrite-policy.d.ts","sourceRoot":"","sources":["../src/overwrite-policy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"overwrite-policy.d.ts","sourceRoot":"","sources":["../src/overwrite-policy.ts"],"names":[],"mappings":"AAqCA,MAAM,MAAM,WAAW,GACnB,KAAK,GACL,WAAW,GACX,WAAW,GACX,QAAQ,GACR,UAAU,GACV,SAAS,GACT,SAAS,CAAC;AAEd;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,eAAe,CAAC;AAE1D;;;iDAGiD;AACjD,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,OAAO,CAAC;AAE/C,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB;;+DAE2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;qEAEiE;IACjE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC;IACpB;sCACkC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAoED;gDACgD;AAChD,qBAAa,eAAgB,SAAQ,KAAK;;CAQzC;AAsFD;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,cAAc,GAAE,kBAAkB,GAAG,aAAkB,GACtD,WAAW,CAgGb"}
|