@hyperfrontend/features/nx/generators

generators

Nx generators for hyperfrontend features — init declares the SDK dependency in the consumer workspace, feature scaffolds a feature by delegating to the SDK's headless hf init.

import { featureGenerator, initGenerator } from '@hyperfrontend/features/nx/generators'

const installCallback = await initGenerator(tree, {})

Generators

GeneratorPurpose
initEnsures @hyperfrontend/features is declared in the root package.json; run automatically by nx add.
featureScaffolds the glue module, feature.config.json, and entry wiring for a feature, declaring the SDK dependency when missing.

Both generators stage every write into the Nx tree, so nx g ... --dry-run previews the full change set without touching the disk. When the consumer workspace has @nx/devkit installed, staged files are formatted with it and installs run through its installPackagesTask; otherwise built-in equivalents take over. Each generator returns a callback Nx runs after flushing, which installs dependencies only when the root manifest actually changed.

Usage

nx g @hyperfrontend/features:init
nx g @hyperfrontend/features:feature \
  --name=clock --contract=./clock.contract.json --entry=./src/main.ts --directory=apps/clock

See the init and feature docs for the full option tables.

API Reference

ƒ Functions

§function

featureGenerator(tree: Tree, options: FeatureGeneratorSchema): Promise<GeneratorCallback>

Scaffold a hyperfrontend feature by delegating to the SDK's hf init.
First ensures @hyperfrontend/features is declared in the workspace root package.json (an existing declaration is left untouched), then forwards options to runInit in headless mode with the SDK's tree seams backed by the Nx tree — every scaffolding write stages into Nx's virtual tree, so nx g ... --dry-run previews the full change set without touching the disk. When the consumer workspace has @nx/devkit installed, staged files are formatted with it before Nx flushes them. The returned callback — run by Nx only after flushing real changes — installs dependencies only when the manifest was changed by this run.

Parameters

NameTypeDescription
§tree
Tree
The Nx virtual file-system tree every write is staged into.
§options
FeatureGeneratorSchema
Generator options forwarded to the SDK runner.

Returns

Promise<GeneratorCallback>
The post-flush callback that installs when the manifest changed.

Example

Scaffold a feature in a project directory

nx generate \@hyperfrontend/features:feature \
  --name=clock --contract=./clock.contract.json --entry=./src/main.ts --directory=apps/clock
§function

initGenerator(tree: Tree, options: InitGeneratorSchema): Promise<GeneratorCallback>

Ensure the SDK package is declared in the consumer workspace's root package.json; the nx add flow runs this generator after installing the package.
A declaration in any dependency section satisfies the check and is left in its section untouched, so repeat runs are no-ops. When the package is undeclared it is added to dependencies — the SDK is a runtime dependency — pinned to a caret range on the running plugin's own version. Passing keepExistingVersions: false instead re-pins an existing declaration in its own section. When the consumer workspace has @nx/devkit installed, staged files are formatted with it before Nx flushes them.
All writes go through the tree, so --dry-run previews the manifest change without touching the disk. The returned callback — which Nx runs only after flushing real changes — installs dependencies only when the manifest actually changed (via the consumer's installPackagesTask when resolvable, else the built-in installer) and then verifies rollup's native platform binding, printing the exact fix when it is missing.

Parameters

NameTypeDescription
§tree
Tree
The Nx virtual file-system tree for the consumer workspace.
§options
InitGeneratorSchema
Generator options; see InitGeneratorSchema.

Returns

Promise<GeneratorCallback>
The post-flush callback that installs and runs the binding advisory.

Example

Initialize a workspace after installing the package

nx g @hyperfrontend/features:init

Interfaces

§interface

FeatureGeneratorSchema

Options for the feature generator; mirrors schema.json.

Properties

§contract:string
Path to the feature contract file, relative to the target directory.
§directory?:string
Directory to scaffold into, relative to the workspace root. Defaults to the root.
§entry:string
Entry file the generated glue import is wired into.
§name:string
Feature name.
§url?:string
URL the generated shell loads the feature from.
§version?:string
Feature version string.
§interface

InitGeneratorSchema

Options for the init generator; mirrors schema.json.

Properties

§keepExistingVersions?:boolean
Keep an existing declaration's range untouched instead of pinning it to the running plugin's version. Defaults to true.