@conformetry/generation
v0.0.32
Published
Template rendering and file generation runtime for Conformetry
Maintainers
Readme
👔 Conformetry Generation
The generation runtime for Conformetry: it walks a template tree, renders every path and every file, and writes the result.
npm install --save-dev @conformetry/generationUsage
import { GenerationService } from "@conformetry/generation";
const result = await generationService.runGenerator({
definition: {
name: "nestjs-service-module",
templateDirectoryPath: "templates/nestjs-service-module",
},
inputs: { name: "billing" },
instancePath: "packages/billing/src/modules",
});
// → { generatedFilePaths: [...], outputDirectoryPath: "..." }The lifecycle is preGenerate → render → postGenerate → format, and the
returned file paths are sorted.
Rendering
RenderingService is the single owner of template substitution across the
whole toolchain. Generation renders templates to create files; validation
renders the same templates to compare against files that already exist. Both
must substitute identically or validation would flag the files the generator
itself produced — which is why neither reimplements this.
Contents and paths are both rendered with
mustache, HTML escaping disabled so substituted
values cannot corrupt source code. buildNameSubstitutions derives
nameCamelCase, nameKebabCase, namePascalCase, and nameSnakeCase from a
single name; callers merge their own inputs over the result, so an explicit
input of the same key always wins.
An interpolated placeholder nobody supplied raises
MissingSubstitutionError. Mustache would otherwise render it as an empty string rather than leaving the token visible, and because generation and validation render identically, both halves of the loop lost the same value and agreed that nothing was wrong. A hole rendered into both sides of a comparison is not something that comparison can report, so the renderer refuses instead. Validation never renders the hole either: it reads the missing value from the instance, and reports when it cannot.Section tags are exempt, deliberately:
{{#field}}and{{^field}}are conditionals, so an absent name is how a template asks for a block to be skipped or taken. A supplied value that is the empty string is an answer too — only an absent key is a hole. Together those are how a template says "optional": ask with a section, interpolate inside it.
Paths once used a __field__ syntax of their own, on the assumption that
braces were not portable across filesystems. They are — and the separate syntax
could not tell a placeholder from a Python dunder, so a template shipping
__init__.py depended on init never being a substitution.
Adapters
Filesystem and formatter access go through FileSystemAdapter and
FormatterAdapter, defaulting to disk and a no-op. That is how
@conformetry/nx reuses this runtime unchanged
against an Nx generator Tree. Rendering deliberately is not an adapter, for
the reason above.
Exports
GenerationService, RenderingService, their modules, and the
FileSystemAdapter, FormatterAdapter, GeneratorDefinition, and
Substitutions types.
Test
nx run conformetry-generation:vitestLicense
MIT — see LICENSE.
👔 Conformetry
This project was generated from the nestjs-service-project conformetry template.
🔭 Callidescope
Call stacks traced through projects/ic-suite/conformetry/conformetry-generation, deepest first. Each frame shows what it takes, what it returns, and what its documentation says.
| Measure | Value | | --- | --- | | Callables | 13 | | Files | 11 | | Calls traced | 10 | | Call stacks | 1 | | Deepest stack | 2 | | Stacks through recursion | 0 | | Unfollowable calls | 2 |
Limits
What this project is judged against, as declared in its own callidescope.config.ts.
| Limit | Value |
| --- | --- |
| maximumDepth | 8 |
| maximumBreadth | 4 |
Call stacks (depth)
1. GenerationService.listDirectory — depth 2 · orphan-root
🚀 GenerationService.listDirectory(directoryPath: string): Promise<DirectoryEntry[]> [projects/ic-suite/conformetry/conformetry-generation/src/modules/generation/generation.service.ts:38]
└─> GenerationService.map(…)(entry: Dirent<string>): { isDirectory: boolean; name: string; } [projects/ic-suite/conformetry/conformetry-generation/src/modules/generation/generation.service.ts:41]Breadth
| Callable | Breadth | Calls directly | Location |
| --- | --- | --- | --- |
| GenerationService.runGenerator | 4 | GenerationService.resolveAdapters, GenerationService.normalizeInputs, GenerationService.buildSubstitutions, GenerationService.renderDirectory | projects/ic-suite/conformetry/conformetry-generation/src/modules/generation/generation.service.ts:190 |
| GenerationService.renderDirectory | 2 | ConfigurationService.renderPath, GenerationService.renderFile | projects/ic-suite/conformetry/conformetry-generation/src/modules/generation/generation.service.ts:104 |
| GenerationService.listDirectory | 1 | GenerationService.map(…) | projects/ic-suite/conformetry/conformetry-generation/src/modules/generation/generation.service.ts:38 |
| Callable | Breadth | Calls directly | Location |
| --- | --- | --- | --- |
| GenerationService.buildSubstitutions | 1 | ConfigurationService.buildNameSubstitutions | projects/ic-suite/conformetry/conformetry-generation/src/modules/generation/generation.service.ts:74 |
| GenerationService.renderFile | 1 | ConfigurationService.renderContent | projects/ic-suite/conformetry/conformetry-generation/src/modules/generation/generation.service.ts:153 |
🕸️ Codependix
Dependency graphs exported by codependix, regenerated by nx run configuration:codependix:write.
Nx Neighborhood
graph LR
conformetry_cli["conformetry-cli"]
conformetry_configuration["conformetry-configuration"]
conformetry_examples["conformetry-examples"]
conformetry_generation["conformetry-generation"]
conformetry_nx["conformetry-nx"]
conformetry_cli --> conformetry_generation
conformetry_examples --> conformetry_generation
conformetry_generation --> conformetry_configuration
conformetry_nx --> conformetry_generation
classDef subject fill:#7c3aed,color:#fff,stroke:#4c1d95,stroke-width:2px
class conformetry_generation subjectNestJS Module Graph
flowchart LR
ConfigurationModule
GenerationModule
InputModule
InstanceDiscoveryModule
InstanceGroupModule
RenderingModule
TemplateDiscoveryModule
ConfigurationModule --> InputModule
ConfigurationModule --> InstanceDiscoveryModule
ConfigurationModule --> InstanceGroupModule
ConfigurationModule --> RenderingModule
ConfigurationModule --> TemplateDiscoveryModule
GenerationModule --> ConfigurationModule
InstanceDiscoveryModule --> InstanceGroupModule
InstanceDiscoveryModule --> RenderingModule
InstanceDiscoveryModule --> TemplateDiscoveryModule
TemplateDiscoveryModule --> RenderingModuleFile Imports
graph LR
file_callidescope_config_ts["callidescope.config.ts"]
file_codependix_config_ts["codependix.config.ts"]
file_codometer_config_ts["codometer.config.ts"]
file_eslint_config_ts["eslint.config.ts"]
file_src_index_ts["src/index.ts"]
file_src_modules_generation_generation_constants_ts["src/modules/generation/generation.constants.ts"]
file_src_modules_generation_generation_module_ts["src/modules/generation/generation.module.ts"]
file_src_modules_generation_generation_module_unit_test_ts["src/modules/generation/generation.module.unit.test.ts"]
file_src_modules_generation_generation_service_ts["src/modules/generation/generation.service.ts"]
file_src_modules_generation_generation_service_unit_test_ts["src/modules/generation/generation.service.unit.test.ts"]
file_src_modules_generation_generation_types_ts["src/modules/generation/generation.types.ts"]
file_testing_mocks_ts["testing/mocks.ts"]
file_testing_setup_ts["testing/setup.ts"]
file_vite_config_ts["vite.config.ts"]
file_vitest_config_ts["vitest.config.ts"]
file_src_modules_generation_generation_module_ts --> file_src_modules_generation_generation_service_ts
file_src_modules_generation_generation_module_unit_test_ts --> file_src_modules_generation_generation_module_ts
file_src_modules_generation_generation_service_ts --> file_src_modules_generation_generation_types_ts
file_src_modules_generation_generation_service_unit_test_ts --> file_src_modules_generation_generation_service_ts
file_src_modules_generation_generation_service_unit_test_ts --> file_src_modules_generation_generation_types_ts⏲️ Codometer
Project
Measured Targets
TypeScript
JavaScript
Python
JSON
YAML
TOML
Shell
SQL
HCL
CSS
Conventions
Jupyter
Markdown
