Generate
Generate common files, folders, and workspaces from your own standard templates. Since every organization has its own needs and standards, providing a one-size-fits-all solution for scaffolding workspaces and other common files is out of scope for oneRepo. However, the generate
core command provides a helpful way for creating your own template generators.
Configuration
Section titled ConfigurationFirst, set the location for oneRepo to look for your templates. This can be anywhere within your repository, but must be a relative path from the root configuration file.
In your templateDir
directory, create folders for different template types. Most use-cases will include separate templates for app
and module
. Ensure each template directory includes a .onegen.js
or .onegen.cjs
file:
Directoryrepo
- onerepo.config.js
- package.json
Directorytemplates
Directoryapp
- .onegen.js // This is a oneRepo generation config file
- package.json.ejs // Render files with EJS
Directorymodule
- .onegen.js
- package.json.ejs
The .onegen.cjs
file is a configuration file for each template directory that tells oneRepo how to handle and format the output of your workspace:
The above will result in a set of prompts that may look like the following:
All other files in the template directory and any sub-directories will be included in the resulting generated output. Any file that uses the extension .ejs
will be read and parsed using Embedded JavaScript templating and the generated files will have that extension stripped, leaving the rendered file with the correct extension in place.
By default, templates will be rendered with the variables name
and fullName
. These are determined by the nameFormat
function provided in your configuration. If not provided, the values of these will be identical.
Filenames will be rendered using EJS as well. If a file includes something like <%- name %>.ts.ejs
, the resulting output file will have the name variable replaced inline.
Template variables
Section titled Template variablesYou will likely use inquirer prompts provided by each .onegen.cjs
configuration to add input variables to your templates.
The above will result in a set of prompts that may look like the following:
Please see the inquirer documentation for more options and usage instructions.
Commands
Section titled Commandsone generate
Section titled one generateAliases: one gen
Generate files, folders, and Workspaces from templates.
To create new templates add a new folder to config/templates and create a .onegen.cjs
configuration file. Follow the instructions online for more: https://onerepo.tools/core/generate/
Option | Type | Description |
---|---|---|
--type, -t | string | Template type to generate. If not provided, a list will be provided to choose from. |
Advanced options
Option | Type | Description | Required |
---|---|---|---|
--show-advanced | boolean | Pair with --help to show advanced options. | |
--template-dir, --templates-dir | string , default: "config/templates" | Path to the templates | ✅ |