Workspace maintenance and release generators
The workspace generators keep Spartan's internal libraries and supporting products in sync. They scaffold Brain and Helm entry points, connect Helm components to exports, stories, and docs, turn examples into public code data, update contributor records, migrate older class-merging code, refresh installed Helm libraries, and align publishable package versions before a release. This page is a child of Spartan CLI and workspace generators and relates to UI library generation.
Generator role
The tools package exposes Nx generators through libs/…/generators.json. These generators change the repository workspace rather than install a component into an outside application. Their main value is to keep several views of one feature aligned: library entry points, the Storybook example, the documentation page, and generated data used by the docs site.
The repository groups the generators by the work they support:
| Area | Main generators | Result |
|---|---|---|
| Library structure | brain-secondary-entrypoint, helm-secondary-entrypoint | New public entry points for Brain or Helm |
| Helm feature files | helm-component, helm-directive | Styled component or directive files with public exports |
| Examples and docs | helm-story, helm-documentation | Storybook story and documentation page scaffolds |
| Docs data | generate-primitive-snippets | Per-component example code and StackBlitz helper data |
| Repository records | update-contributors | Contributor lists in the README and home page |
| Workspace migration | healthcheck, migrate-cn, migrate-helm-libraries | Reports and repairs for generated libraries and their dependencies |
| Release state | set-release-version | One version across the publishable packages |
Feature scaffolding
Brain entry points
The Brain entry-point generator adds a secondary entry point to the headless library. A secondary entry point is a separately importable public area of a package, so a new Brain feature can have a focused import path without changing the package's main entry point. Contributors use nx g @spartan-ng/tools:brain-secondary-entrypoint --name=feature-name for this task.
References: libs/…/generator.ts• L5-14 libs/…/schema.json• L6-17 CONTRIBUTING.md• L66-73
Helm entry points
The Helm entry-point generator creates the workspace shape for a styled feature and can add its related surfaces in one pass. It creates the library entry point, adds a CLI generator wrapper for later consumer use, and then conditionally creates a story, a component or directive, and a documentation page. The default path includes a story and documentation page but no component or directive unless the caller selects one.
The feature options express the intended set of surfaces:
| Option | Role |
|---|---|
name | Names the Helm entry point |
story | Controls the Storybook story scaffold |
generate | Selects component, directive, or none |
documentation | Controls the docs page scaffold |
description | Supplies the docs page summary |
References: libs/…/generator.ts• L9-76 libs/…/schema.json• L6-38 CONTRIBUTING.md• L75-82
Helm exports
The component and directive generators turn a name into a starter Helm surface and register it with the selected entry point. Registration matters because a generated file is not a usable public feature until the entry point exports it and includes it in the entry point's import collection. Both generators then format the workspace.
References: libs/…/generator.ts• L6-31 libs/…/generator.ts• L6-30 libs/…/hlm-__fileName__.component.ts.template• L1-16 libs/…/hlm-__fileName__.directive.ts.template• L1-17
Generated UI surfaces
The UI library templates provide the shared styled layer for generated Helm primitives. They keep Brain behavior as the base while giving each generated control a common class-merging contract through cn, shared hlm utilities, and consumer class inputs. The templates also cover common form state, labels, focus behavior, responsive layouts, paging, overlays, and notification surfaces so generated libraries follow the same product conventions.
The supported-library catalog supplies the peer dependency contract for each primitive. This contract tells a generated library which Angular, Brain, icon, utility, and feature packages it needs at runtime. The migrate-helm-libraries generator uses the same catalog when it recreates installed libraries.
References: libs/…/hlm.ts.template• L1-27 libs/…/hlm-button.ts.template• L8-61 libs/…/hlm-checkbox.ts.template• L29-153 libs/…/hlm-sidebar.service.ts.template• L16-115 libs/…/supported-ui-libraries.json• L1-25
Examples and documentation
Storybook stories
The story generator creates a Storybook story under apps/ui-storybook/stories and connects it to the Helm entry point. It derives the display title and import collection name from the entry-point name, while the generated story provides the place for a contributor to add the actual example. Storybook discovers these story files through its application configuration, so this scaffold becomes part of the component review surface.
References: libs/…/generator.ts• L5-29 libs/…/__fileName__.stories.ts.template• L1-24 apps/…/main.ts• L1-13 apps/…/project.json• L9-37
Documentation pages
The documentation generator creates the route, preview, and server-loading pieces for a Helm feature under the documentation application. The page presents a preview and code view, links the installation and usage areas to the component name, and loads component data by the same name. The preview scaffold also defines the import and starter-code values that later become the feature's usage example.
The normal application build and serve flows run documentation and snippet generation first. This makes generated data a build input for the docs site rather than an optional manual step.
References: libs/…/generator.ts• L5-16 libs/…/__fileName__.page.ts.template• L19-98 libs/…/__fileName__.preview.ts.template• L1-22 libs/…/__fileName__.server.ts.template• L1-3 apps/…/project.json• L9-17 apps/…/project.json• L35-37
Documentation data
Primitive snippets
The primitive-snippet generator converts documentation examples into data that the documentation application can load by component name. It scans preview and example files, removes the exported metadata used to describe an example, and keeps the component source as a clean code sample. A file with the primitive name supplies the default sample; named variants become separate sample keys.
The generator also follows relative imports in multi-file examples. It records those sibling files in stackblitz-example-files.json so the “open in StackBlitz” flow can rebuild an example with its supporting source. The output is split into one JSON file per component under apps/app/src/public/data/primitives-snippets, which lets a missing component slice behave as empty data without blocking other docs pages.
The data path is:
flowchart LR
E[Preview and example files] --> X[Primitive snippet generator]
X --> S[Per-component snippet JSON]
X --> B[StackBlitz sibling-file JSON]
S --> D[Documentation loader]
B --> T[StackBlitz project builder]
References: libs/…/generator.ts• L104-120 libs/…/generator.ts• L136-153 libs/…/generator.ts• L193-233 libs/…/write-per-component-data.ts• L1-10 apps/…/component-docs-loader.ts• L7-29 apps/…/open-in-stackblitz-button.ts• L49-80
Workspace migrations
Healthcheck execution
The healthcheck generator runs a set of workspace checks and reports each result before applying repairs. A fixable warning can run automatically or after a prompt, while warnings that need code decisions remain for the contributor. Formatting runs after repairs, and package installation is scheduled when a repair changes package metadata.
The class-merging check limits its scan to generated Helm sources. It separates files that the migrate-cn generator can rewrite from files that still need manual work. This lets one healthcheck report both safe repair work and code that must not be changed without review.
References: libs/…/generator.ts• L42-117 libs/…/cn.ts• L8-43
Class-merging migration
The migrate-cn generator moves generated Helm code from clsx and tailwind-merge to the shared cn package. It replaces known unmodified hlm.ts files with the current shared template and rewrites supported imports in generated Helm sources. It leaves application code outside the configured components path alone.
The migration keeps legacy packages when any source in the workspace still needs them. It also preserves unsupported tailwind-merge imports and reports them for manual work. When the shared hlm.ts template is installed, the generator aligns the Brain dependency with the running CLI version because both provide the shared class behavior.
The migration path is:
flowchart LR
S[Generated Helm sources] --> D{Known template or supported import}
D -->|yes| R[Replace template or rewrite imports]
D -->|no| M[Report manual migration]
R --> P[Recheck workspace package use]
M --> P
P --> U[Update cn, Brain, and legacy package dependencies]
References: libs/…/generator.ts• L24-41 libs/…/generator.ts• L65-92 libs/…/generator.ts• L94-140 libs/…/generator.ts• L143-154 libs/…/generator.ts• L197-238 libs/…/generator.ts• L241-274 libs/…/legacy-imports.ts• L1-14 libs/…/source-fingerprint.ts• L11-50
Helm library migration
The migrate-helm-libraries generator refreshes Helm primitives that are already installed in a workspace. It detects installed libraries through TypeScript import paths, lets the contributor select a subset or all detected libraries, removes the old library, and regenerates it from the current supported-library catalog. Interactive use warns that custom changes will be overwritten; programmatic use can provide the selection directly.
The removal path follows the workspace mode. Nx library projects use the Nx removal flow, while Angular CLI or non-library layouts remove the library files and its TypeScript path. Regeneration uses the workspace's current import alias and library mode, so the refreshed result remains usable by the same project.
References: libs/…/generator.ts• L45-109 libs/…/generator.ts• L113-135 libs/…/generator.ts• L137-209 libs/…/generator.ts• L212-228 libs/…/supported-ui-libraries.json• L1-25
Repository maintenance
Contributor records
The contributor generator keeps the public contributor list current from repository history. It combines GitHub-style identities found in commit emails and commit trailers with optional GitHub API results and manual usernames. It filters already listed users and known bot or renamed accounts, then appends new users to both README.md and the home page's _contributors list.
The scheduled workflow runs this generator with full Git history. If it changes either target file, the workflow creates a documentation commit and pushes it; if no user is new, it makes no commit.
References: libs/…/generator.ts• L18-81 libs/…/generator.ts• L100-151 libs/…/generator.ts• L156-214 .github/…/update-contributors.yml• L27-62 package.json• L27-29
Release versions
The release-version generator preserves one version across the packages that publish together: Brain, CLI, and MCP. It accepts an explicit newVersion value or reads VERSION; without either source it stops instead of writing an incomplete release state. It changes only the version field in each package manifest.
This generator belongs to the manual release preparation path. The normal release workflow uses semantic-release to compute and publish versions, while the repository's release branches still depend on consistent package metadata and release commits.
References: libs/…/generator.ts• L4-26 libs/…/schema.json• L3-12 package.json• L17-22 .github/…/release.yml• L1-10
Change checklist
When these files or sections are changed, remember to consider these:
- When adding or renaming a Brain or Helm entry point, keep the package entry-point shape, the matching public import path, and any generated consumer CLI wrapper aligned.
- When changing Helm entry-point naming, check the derived names used by exports, story imports, documentation routes, and snippet-data lookup keys.
- When changing preview or example file naming, preserve the
defaultand variant naming contract used by the docs loader and code display. - When changing multi-file examples, keep relative-import paths compatible with the StackBlitz sibling-file artifact.
- When changing class-merging templates, keep the
cnimports, sharedhlmbehavior, Brain version range, and legacy package cleanup rules aligned. - When changing the supported UI library catalog, keep detection aliases, peer dependencies, and regeneration inputs aligned.
- When changing the publishable package set, update the release-version generator and the release workflow's build and publish scope together.
- When changing contributor-list formats, update the generator's matching rules and the scheduled workflow's changed-file set together.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A Helm component or directive file is created without entry-point registration | Consumers cannot import the new public surface through the entry point | Use the dedicated Helm generator or update the entry-point exports and import collection together |
| A docs page name differs from its generated snippet key | The page loads no example code even though the source exists | Keep the component name, route data name, and per-component JSON slug aligned |
| A preview imports a sibling file that is not found or collides by basename | StackBlitz examples lose support code or use the wrong sibling content | Keep sibling files below the example directory with unique basenames and valid relative imports |
| A generated Helm source uses an unsupported class-merging import | The migration leaves the old import and the old package may remain required | Review the warning and migrate that source manually |
| A customized hlm.ts matches no known generated fingerprint | The migration changes imports but does not replace the custom class implementation | Review the warning before adopting the shared hlm implementation |
| A selected Helm library is refreshed without a backup of local changes | The old library and its customizations are removed before regeneration | Treat library migration as an overwrite and select only libraries ready for replacement |
| A supported-library alias or peer dependency is missing from the catalog | Detection or regenerated projects use the wrong path or lack a required package | Update the catalog with every supported import alias and runtime dependency |
| The contributor list shape changes without matching the parser | Scheduled updates stop at the section or fail to find an insertion point | Preserve the numbered GitHub-link section and _contributors array shape |
| Release version input is absent | Publishable package manifests remain unchanged and release preparation stops | Pass --newVersion or set VERSION before running the generator |
| The publishable package list changes in only one release path | Packages can publish with different versions | Treat the generator list and release build or publish scope as one contract |
Key files
| File | Why to read it |
|---|---|
| libs/…/generators.json | Registry of the workspace generators and their public names |
| libs/…/generator.ts | Main Helm feature-scaffolding flow and its optional surfaces |
| libs/…/generator.ts | Helm component creation and public export registration |
| libs/…/generator.ts | Storybook story connection for a Helm entry point |
| libs/…/generator.ts | Documentation route scaffold for a Helm feature |
| libs/…/generator.ts | Source-to-data flow for docs examples and StackBlitz helpers |
| libs/…/generator.ts | Ordered workspace checks and optional repair execution |
| libs/…/generator.ts | Class-merging migration and dependency transition rules |
| libs/…/generator.ts | Detection, replacement, and regeneration of installed Helm libraries |
| libs/…/supported-ui-libraries.json | Supported primitive catalog and peer dependency contract |
libs/cli/src/generators/ui/libs/utils/files/lib/hlm.ts.template | Shared generated class-merging surface used by Helm primitives |
| libs/…/generator.ts | Contributor discovery, filtering, and file updates |
| libs/…/generator.ts | Lockstep version update for publishable packages |
| apps/…/project.json | Build and serve dependency on generated docs and snippets |
| .github/…/update-contributors.yml | Scheduled contributor maintenance and push behavior |
| .github/…/release.yml | Automated release gates and package publication context |