hcp
hcp - handlebars-copy
Like cp, but with Handlebars template
Install
npm install hcp
Usage
$ hcp <files...> [options]
Options:
--help Show this help output
--version Show package version
--debug Show extended debug output
Examples:
$ hcp package.json package.copy.json
$ hcp index.html package.json app/ --name foobar
$ hcp_name="foobar" hcp text/examples/* ~/dev/myapp/app
Description
hcp is a CLI tool similar to the cp
command.
File copy is done using Streams, with lodash.template
parsing files if they
have template placeholders {{ ... }}
.
Handlebars template are executed in the context of the following object:
Object // where `env` and `opts` have the following structure env: PATH: '...' ... opts: debug: true name: 'Foobar'
The templates context is a merged version of various sources, with the following order of precedence:
- opts - Command line flags as parsed by minimist
- env -
process.env
variables begining withhcp_
- prompts - Generated prompts, see below
Prompts
Handlebars templates can have any number of placeholders. Variables are either available in the context object, or automatically prompted for the user to enter a value.
Skipping a prompt is then available with --name Value
.
To enable it, inquirer must be installed and available in node_modules
.
npm i inquirer -D
If not installed, prompts are not generated.
JSON
JSON files are merged together with destination, if it already exists.
Tests / API
hcp
cli
Copy files
hcp test/examples/package.json test/output.json.
;
Merges files with existing JSON destination
hcp test/examples/package.json test/existing.json.
;
Transfrom Handlebars / Mustache like placeholders with lodash.template
hcp test/examples/* test/output/ --name blah --description desc --foo bar.
;