@hyperfrontend/workspace/generators/application

application

Creates an application of the workspace, a project that is run and never imported: its project.json (stating the application kind, with the typecheck and test targets), a private ES module package.json, its TypeScript, lint and test configurations, and an entry module, src/main.ts, with a spec that passes on it. The new project's type check, lint and tests succeed as written.

npx hf generate application web --description="The public site" --tags=type:app
npx hf generate application admin \
  --directory=apps/internal --projectName=app-admin
OptionWhat it sets
--nameThe application's name, which names its directory and, with the scope of the root manifest, its package (also the first positional argument)
--directoryThe directory it is created under; defaults to apps
--projectNameThe project name tasks address; defaults to the application's name
--descriptionThe description written to both manifests
--tagsThe tags the module boundaries read, comma-separated
--skipFormatLeave the written files unformatted

The kind is written into project.json whatever the directory, so an application created outside apps is still read as one. No alias is added to tsconfig.base.json: the module boundaries refuse an import of an application, so nothing needs a name to import it by.

It refuses to run where the application's directory already exists or another project already holds its project name, so nothing is written over; pass --directory or --projectName to place it beside what is there. It also refuses a project name that holds a quote, a backslash, a control character or the two characters that end a comment, since the entry module and its spec write the name between quotes and in comments. Any description is accepted: in the comment that heads the entry module, the two characters that would end the comment are written apart, and a word that opens a line with @, which the comment would read as a tag, is wrapped in backticks.

API Reference§

ƒ Functions

§function

applicationGenerator(tree: Tree, options: ApplicationGeneratorOptions): Promise<void>

Creates an application: a project.json that states projectType: 'application' with the typecheck and test targets, a private ES module package.json, the TypeScript, lint and test configurations, and src/main.ts with a spec that passes on it, so the new project's type check, lint and tests succeed as written. No alias is added to tsconfig.base.json, since no project may import an application.
Parameters
NameTypeDescription
§tree
TreeThe tree, rooted at the workspace
§options
ApplicationGeneratorOptionsWhat to create
Returns
Promise<void>
Resolves when the application is written
Examples

An application under the default directory

npx hf generate application web --tags=type:app
npx hf run web:test

Under a chosen directory, with the name tasks address it by

npx hf generate application admin --directory=apps/internal --projectName=app-admin

From a workspace's own generator, formatting once at the end

import applicationGenerator from '@hyperfrontend/workspace/generators/application'
import { formatFiles } from '@hyperfrontend/workspace/generators'

await applicationGenerator(tree, { name: 'web', tags: ['type:app'], skipFormat: true })
tree.write('apps/web/src/routes.ts', 'export const routes = ["/"]\n')
await formatFiles(tree)

◈ Interfaces

§interface

ApplicationGeneratorOptions

What the application generator takes.
Properties
§name:stringThe name of the application, which names its directory and, with the scope of the root manifest, its package
§directory?:stringThe directory the application is created under; apps when unset
§projectName?:stringThe project's name, as tasks address it; the application's name when unset
§description?:stringA description of the application
§tags?:string[]The tags the module boundaries read
§skipFormat?:booleanSkip formatting the generated files