@metaobjectsdev/codegen-ts 0.7.0-rc.12 → 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.map +1 -1
- package/dist/generators/docs-data-builder.js +23 -17
- package/dist/generators/docs-data-builder.js.map +1 -1
- package/dist/generators/docs-data.d.ts +34 -23
- package/dist/generators/docs-data.d.ts.map +1 -1
- package/dist/generators/docs-data.js +30 -0
- package/dist/generators/docs-data.js.map +1 -1
- package/dist/generators/docs-file.d.ts.map +1 -1
- package/dist/generators/docs-file.js +42 -34
- package/dist/generators/docs-file.js.map +1 -1
- package/dist/generators/template-generator.d.ts +4 -3
- package/dist/generators/template-generator.d.ts.map +1 -1
- package/dist/generators/template-generator.js +26 -7
- package/dist/generators/template-generator.js.map +1 -1
- package/dist/render-engine/framework-provider.d.ts.map +1 -1
- package/dist/render-engine/framework-provider.js +23 -18
- package/dist/render-engine/framework-provider.js.map +1 -1
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +1 -0
- package/dist/runner.js.map +1 -1
- package/package.json +4 -4
- package/src/generator.ts +9 -0
- package/src/generators/docs-data-builder.ts +24 -21
- package/src/generators/docs-data.ts +67 -26
- package/src/generators/docs-file.ts +49 -47
- package/src/generators/template-generator.ts +32 -10
- package/src/render-engine/framework-provider.ts +26 -17
- package/src/runner.ts +1 -0
|
@@ -17,34 +17,43 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
17
17
|
import { join, resolve, dirname } from "node:path";
|
|
18
18
|
import { fileURLToPath } from "node:url";
|
|
19
19
|
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
|
|
20
|
+
/** Canonical shipped template — used to verify a candidate framework
|
|
21
|
+
* templates directory actually contains our defaults. Without this check a
|
|
22
|
+
* hoisted-install layout (pnpm/bun workspaces) can walk up to a CONSUMER
|
|
23
|
+
* package.json and silently return a templates dir that doesn't exist. */
|
|
24
|
+
const CANONICAL_TEMPLATE_REL = "docs/entity-page.md.mustache";
|
|
25
|
+
|
|
26
|
+
/** Walk up from `start` until we find a `package.json` whose neighbour
|
|
27
|
+
* `templates/` directory contains our canonical shipped template (i.e., the
|
|
28
|
+
* codegen-ts package root). Works the same way from
|
|
29
|
+
* `src/render-engine/framework-provider.ts` (during dev) and
|
|
30
|
+
* `dist/render-engine/framework-provider.js` (after `npm install`). */
|
|
25
31
|
function findFrameworkTemplatesDir(start: string): string {
|
|
26
32
|
let dir = start;
|
|
27
|
-
|
|
33
|
+
while (true) {
|
|
28
34
|
const pkgJson = join(dir, "package.json");
|
|
29
35
|
if (existsSync(pkgJson)) {
|
|
30
|
-
|
|
36
|
+
const templatesDir = join(dir, "templates");
|
|
37
|
+
// Assert we landed at the codegen-ts package root, not a consumer's.
|
|
38
|
+
if (existsSync(join(templatesDir, CANONICAL_TEMPLATE_REL))) {
|
|
39
|
+
return templatesDir;
|
|
40
|
+
}
|
|
31
41
|
}
|
|
32
42
|
const parent = dirname(dir);
|
|
33
43
|
if (parent === dir) break;
|
|
34
44
|
dir = parent;
|
|
35
45
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
throw new Error(
|
|
47
|
+
`framework templates dir unresolved: walked up from ${start} without finding a package.json ` +
|
|
48
|
+
`whose templates/${CANONICAL_TEMPLATE_REL} exists. This usually means codegen-ts was installed ` +
|
|
49
|
+
`via a hoisted layout (pnpm/bun workspaces) into an unexpected location, or the published ` +
|
|
50
|
+
`tarball is missing the templates/ directory.`,
|
|
51
|
+
);
|
|
39
52
|
}
|
|
40
53
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
} catch {
|
|
45
|
-
return process.cwd();
|
|
46
|
-
}
|
|
47
|
-
})();
|
|
54
|
+
// In ESM (CLAUDE.md: "ESM only. No CommonJS."), `import.meta.url` is
|
|
55
|
+
// guaranteed to be a file: URL; no defensive try/catch needed.
|
|
56
|
+
const SELF_DIR = dirname(fileURLToPath(import.meta.url));
|
|
48
57
|
|
|
49
58
|
const FRAMEWORK_TEMPLATES_DIR = findFrameworkTemplatesDir(SELF_DIR);
|
|
50
59
|
|
package/src/runner.ts
CHANGED
|
@@ -174,6 +174,7 @@ export async function runGen(opts: RunGenOpts): Promise<RunGenResult> {
|
|
|
174
174
|
outputLayout: selfTarget.outputLayout,
|
|
175
175
|
},
|
|
176
176
|
renderContext,
|
|
177
|
+
...(projectRoot !== undefined && { projectRoot }),
|
|
177
178
|
warn: (msg) => warnings.push(`[${generator.name}] ${msg}`),
|
|
178
179
|
};
|
|
179
180
|
|