@hyperfrontend/features/generatorsgenerators
Pure code generators that turn a resolved feature config and parsed contract into staged output files.
API
| Export | Purpose |
|---|---|
generateShell | Stages the self-contained host connector package (entry, package.json, README, metadata). |
generateMetadata | Stages the connector's metadata.json with a version-stamped, embedded contract. |
generateFeatureModule | Stages the write-once feature integration module (src/hyperfrontend.feature.ts). |
generateContractTypes | Bridges a .json contract to a sibling .d.ts of literal-type unions. |
Usage
import { createTree } from '@hyperfrontend/project-scope/vfs'
import { generateShell } from '@hyperfrontend/features/generators'
const tree = createTree('/tmp/clock-shell')
generateShell({ name: 'clock', version: '1.0.0', contract: './clock.contract.json', url: '/clock' }, contract, tree)API Reference
ƒ Functions
§function
generateContractTypes(config: ResolvedFeatureConfig, contract: FeatureContract, tree: Tree): void
Stages a
Only
.d.ts of literal-type declarations beside a JSON contract. Only
.json contracts need this bridge; .ts as const contracts derive types via typeof and are skipped (no file is staged). Pure: stages only into tree.Parameters
Example
Bridging a JSON contract to literal types
generateContractTypes({ name: 'clock', version: '1.0.0', contract: './clock.contract.json', url: '/clock' }, contract, tree)§function
generateFeatureModule(config: ResolvedFeatureConfig, contract: FeatureContract, tree: Tree): void
Stages the feature integration module into the consumer app (write-once).
Emits
Emits
src/hyperfrontend.feature.ts with one feature.on stub per accepted action and a commented feature.send example per emitted action. Uses Mode.SkipIfExists, so a re-run never clobbers the author's edits. The CLI owns inserting the marker-guarded import into the entry file.Parameters
Example
Scaffolding the integration module for the clock feature
generateFeatureModule({ name: 'clock', version: '1.0.0', contract: './clock.contract.json', url: '/clock' }, contract, tree)§function
generateMetadata(config: ResolvedFeatureConfig, contract: FeatureContract, tree: Tree): void
Stages the connector's
Stamps a canonical version string via
metadata.json describing the feature and its contract. Stamps a canonical version string via
@hyperfrontend/versioning and embeds the contract so humans and the registry can inspect the feature without unpacking the bundle.Parameters
Example
Staging metadata for the clock feature
generateMetadata({ name: 'clock', version: '1.0.0', contract: './clock.contract.json', url: '/clock' }, contract, tree)Stages the complete host connector package into the supplied VFS tree.
Emits the entry source, source-level
Emits the entry source, source-level
package.json, README.md, and (via generateMetadata) metadata.json. Pure: stages only into tree — the CLI owns temp-dir creation, bundling, and commit.Parameters
Example
Staging a connector for the clock feature
generateShell({ name: 'clock', version: '1.0.0', contract: './clock.contract.json', url: '/clock' }, contract, tree)