Git Product home page Git Product logo

lerna-templater's Introduction

lerna-templater

Generates package from template for a Lerna Monorepo Project

Release coverage


Installing

You can get lerna-templater via npm.

npm i -D lerna-templater

Usage

As an import

import { TemplaterOptions, templater } from 'lerna-template';

/**
 * @param {string} cwd The current working directory.
 * @param {TemplaterOptions} options The options for templater.
 */
templater(cwd, options);

As a commandline tool

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"

API

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, required
    The name of the new package
  • description string, optional
    The description of the new package.
  • scope string, optional
    The scope of the new package. Default value is the scope of the main package.json.
  • packages string, optional
    The relative path of the packages directory. Default value is the first element of the lerna.json's packages array.
  • template string, optional
    The relative path of the template directory. Default values is __template__.

Mustache templating

The 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.

Available tags:

  • {{{name}}} - The name of the new package.
  • {{{description}}} - 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.

Example

Directory structure

.
├── __template__/
|   ├── package.json.mustache
|   └── README.md.mustache
├── packages/
├── lerna.json
└── package.json

Content of the files

  • __template__/package.json.mustache:
    {
      "name": "{{{scope}}}{{{name}}}",
      "description": "{{{description}}}",
      "version": "{{{version}}}",
      "repository": {
        "directory": "{{{repoDir}}}"
      }
    }
  • __template__/README.md.mustache:
    # {{{name}}}
    {{{description}}}
  • lerna.json:
    {
      "packages": [
        "packages/*"
      ],
      "version": "0.0.0"
    }
  • package.json:
    {
      "name": "@examplescope/example-monorepo"
    }

Output

Running the npx lerna-templater -n "example-newpackage" -d "Description for the new example package" command will result this output:

  • packages/example-newpackage directory
  • package.json and README.md in the packages/example-newpackage directory
  • package.json:
    {
      "name": "@examplescope/example-newpackage",
      "description": "Description for the new example package",
      "version": "0.0.0",
      "repository": {
        "directory": "packages/example-newpackage"
      }
    }
  • README.md:
    # example-newpackage
    Description of the new example package

Resources
  • Add resources here

lerna-templater's People

Contributors

dependabot[bot] avatar megancooper avatar rdarida avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.