Generates package from template for a Lerna Monorepo Project
You can get lerna-templater
via npm.
npm i -D lerna-templater
import { TemplaterOptions, templater } from 'lerna-template';
/**
* @param {string} cwd The current working directory.
* @param {TemplaterOptions} options The options for templater.
*/
templater(cwd, options);
npx lerna-templater -n "Name of the new package" -d "Description of the new package"
or
"scripts": {
"create": "lerna-templater"
}
npm run create -- -n "Name of the new package" -d "Description of the new package"
templater(cwd, optioins)
Generates a new package from cwd
/options.template
directory into cwd
/options.packages
/options.name
directory. The cwd
argument is the current working directory.
TemplaterOptions
name
string, requireddescription
string, optionalscope
string, optionalpackages
string, optionaltemplate
string, optionalThe lerna-templater uses Mustache.js for templating. If the template directory contains files which ends with .mustache, the templater will render them with Mustache.js. After the rendering, the .mustache extension will be removed from the filename. For example: package.json.mustache
will be saved as package.json
.
{{{name}}}
- The name of the new package.{{{descriptio}}}
- The description of the new package.{{{scope}}}
- The scope of the new package.{{{packages}}}
- The relative path of the packages (output) directory.{{{template}}}
- The relative path of the template (input) directory.{{{version}}}
- The version of the new package.{{{repoDir}}}
- The relative path of the new package in the repository..
├── __template__/
| ├── package.json.mustache
| └── README.md.mustache
├── packages/
├── lerna.json
└── package.json
{
"name": "{{{scope}}}{{{name}}}",
"description": "{{{description}}}",
"version": "{{{version}}}",
"repository": {
"directory": "{{{repoDir}}}"
}
}
# {{{name}}}
{{{description}}}
{
"packages": [
"packages/*"
],
"version": "0.0.0"
}
{
"name": "@examplescope/example-monorepo"
}
Running the npx lerna-templater -n "example-newpackage" -d "Description for the new example package"
command will result this output:
{
"name": "@examplescope/example-newpackage",
"description": "Description for the new example package",
"version": "0.0.0",
"repository": {
"directory": "packages/example-newpackage"
}
}
# example-newpackage
Description of the new example package
Generated using TypeDoc