@hyperfrontend/features/generators

generators

Pure code generators that turn a resolved feature config and parsed contract into staged output files.

API

ExportPurpose
generateShellStages the self-contained host connector package (entry, package.json, README, metadata).
generateMetadataStages the connector's metadata.json with a version-stamped, embedded contract.
generateFeatureModuleStages the write-once feature integration module (src/hyperfrontend.feature.ts).
generateContractTypesBridges 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 .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

NameTypeDescription
§config
ResolvedFeatureConfig
The resolved feature config naming the feature and contract path.
§contract
FeatureContract
The validated contract whose literals are preserved.
§tree
Tree
The VFS tree the declaration file is staged into.

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 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

NameTypeDescription
§config
ResolvedFeatureConfig
The resolved feature config.
§contract
FeatureContract
The validated feature contract driving the scaffolded stubs.
§tree
Tree
The VFS tree the integration module is staged into.

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 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

NameTypeDescription
§config
ResolvedFeatureConfig
The resolved feature config supplying name, version, and URL.
§contract
FeatureContract
The validated contract embedded for inspection.
§tree
Tree
The VFS tree the metadata file is staged into.

Example

Staging metadata for the clock feature

generateMetadata({ name: 'clock', version: '1.0.0', contract: './clock.contract.json', url: '/clock' }, contract, tree)
§function

generateShell(config: ResolvedFeatureConfig, contract: FeatureContract, tree: Tree): void

Stages the complete host connector package into the supplied VFS tree.
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

NameTypeDescription
§config
ResolvedFeatureConfig
The resolved feature config.
§contract
FeatureContract
The validated feature contract, inlined into the connector.
§tree
Tree
The VFS tree the connector files are staged into.

Example

Staging a connector for the clock feature

generateShell({ name: 'clock', version: '1.0.0', contract: './clock.contract.json', url: '/clock' }, contract, tree)