scarfold

0.0.7 • Public • Published

Scarfold

Node CLI Utility for scaffolding source files from custom Handlebars templates

Installation

$ npm install -g scarfold

or

$ yarn global add scarfold

Quickstart

  1. scarfold init
  2. add custom scaffolding commands to scarfold.json
  3. Run generation scarfold <template> --var1 value1 --var2 value2

Command reference


scarfold <template> [...options] [...vars]

Generates rendered template with provided values in vars

--override - Disable checking whether destination file already exists. Beware of accidental data loss.


scarfold init

Creates basic scarfold.json and templates folder.


Template syntax

The templates use standard Handlebars.js syntax which can be found here. Also check out examples.

{{ variable }}                      // render a value
{{{ variable }}}                    // render unescaped
{{#if variable }}...{{/if}}         // condition
{{#unless variable }}...{{/unless}} // negated condition

Also scarfold provides Handlebars helpers for working with different case conventions. This allows usage of one variable for multiple purposes (e.g. class name, file name, variable name ...) These are:

  • camelCase (variableIdentifierInCamelCase)
  • pascalCase (VariableIdentifierInPascalCase)
  • noCase (as is, just remove dashes from provided var)

These helpers requires variable to be provided in-snake-case. Specifiyng parameter '--someVar some-variable-name' and using helper {{camelCase someVar}} will render value someVariableName.

Description

Each scaffolding command has "render" and "vars" properties.

render - defines how templates are projected to rendered files. In the example, template "textfile.txt" will be transformed to file "test/src/{{name}}.txt" (note paths can be also templated using standard Handlebars syntax).

vars - user defined parameters which can be supplied as command line arguments. These values will be passed to template engine.

Vars can also contain options default, if specified, the var will be considered optional and if not provided through CLI default value will be used.

Example configuration

This configuration defines following:

  • templateFolder - folder where users templates are stored (default: "templates")
  • scaffolding - user defined commands which will be used to generate templates.
  • scaffolding.textfile - scaffolding command

In example config "textfile" command is defined. user invokes this scaffolding command by scarfold textfile --name SomeName --status SomeStatus

{
  "templateFolder": "templates",
  "scaffolding": {
    "textfile": {
      "render": [
        {
          "template": "textfile.txt",
          "dest": "test/src/{{name}}.txt"
        },
        {
          "template": "textfile2.txt",
          "dest": "test/src/{{name}}2.txt"
        }
      ],
      "vars": {
        "name": { },
        "status": {
          "default": "simple"
        }
      }
    }
  }
}

Development

Compilation - yarn build

Dev compilation watcher - yarn dev

Run tests - yarn test

Todos

  • CI
  • var type coercion (typed parameter)
  • support arrays
  • support complex types ?
  • ???
  • profit

Package Sidebar

Install

npm i scarfold

Weekly Downloads

0

Version

0.0.7

License

MIT

Unpacked Size

94.9 kB

Total Files

24

Last publish

Collaborators

  • noxcorpus