@hyperfrontend/workspace/generators/librarylibrary
Creates a TypeScript library of the workspace: its package.json and project.json (with the typecheck, test and build targets), its TypeScript, lint and test configurations, an alias in tsconfig.base.json, a README and an entry module. With --publishable, the generator named make-publishable runs on it next.
npx hf generate library my-utils \
--directory=libs --description="Shared helpers" --tags=type:util
npx hf generate library my-utils --publishable --formats=esm,cjs
| Option | What it sets |
|---|---|
--name | The library's name, which names its directory and, with the scope, its package (also the first positional argument) |
--directory | The directory it is created under; defaults to libs |
--scope | The npm scope; defaults to the scope of the root manifest's name, or none |
--projectName | The project name tasks address; defaults to the library's name |
--packageName | The package name; defaults to the name under the scope |
--description | The description written to both manifests |
--tags | The tags the module boundaries read, comma-separated |
--publishable | Runs make-publishable on the new library |
--keywords | npm keywords, used with --publishable |
--formats | The bundle formats, used with --publishable |
--skipFormat | Leave the written files unformatted |
The licence and the repository come from the root manifest, with the project's directory recorded, so a package published from the library carries them.
API Reference§
ƒ Functions
Creates a library: its manifests, the files of its templates, and its alias in
tsconfig.base.json; then, for a publishable one, runs the generator named make-publishable on it, the workspace's own where it provides one.Parameters
| Name | Type | Description |
|---|---|---|
§tree | Tree | The tree, rooted at the workspace |
§options | LibraryGeneratorOptions | What to create |
Returns
Promise< void>Resolves when the library is written
Examples
An internal library
npx hf generate library my-lib --tags=type:utilA publishable library under a chosen directory
npx hf generate library my-utils --directory=libs/utils --publishable --formats=esm,cjs,iife,umdFrom a workspace's own generator, formatting once at the end
import libraryGenerator from '@hyperfrontend/workspace/generators/library'
import { formatFiles } from '@hyperfrontend/workspace/generators'
await libraryGenerator(tree, { name: 'data-utils', tags: ['type:util'], skipFormat: true })
tree.write('libs/data-utils/src/index.ts', 'export * from "./data"\n')
await formatFiles(tree)Settles the options: the names, the directory and the defaults the root manifest gives.
Parameters
| Name | Type | Description |
|---|---|---|
§tree | Tree | The tree, whose root manifest gives the default scope |
§options | LibraryGeneratorOptions | The options as given |
Returns
LibraryPlanThe names, the root and the description the generator writes from
Example
The names a spelling and the root manifest's scope settle to
planLibrary(tree, { name: 'DataUtils', directory: 'libs/utils' })
// => {
// name: 'data-utils',
// projectName: 'data-utils',
// packageName: '@acme/data-utils',
// projectRoot: 'libs/utils/data-utils',
// description: 'DataUtils library.',
// tags: [],
// offsetFromRoot: '../../../',
// } when the root package.json is named @acme/workspace◈ Interfaces
What the
library generator takes.Properties
§
scope?:stringThe npm scope of the package, with or without its @; the scope of the root manifest's name when unsetThe options settled.