paperback
Easily generate files from templates
Install
npm install --global paperback
Purpose
Create your own templates. Answer questions about the templates via inquirer. Generate those templates with the power of lodash.
Usage
1. Starting with a project such as:
proj/
components/
app-bar/
app-bar.js
style.css
jumping-button/
jumping-button.js
style.css
pages
directory mirroring the file structure of the actual project. The pages
directory holds the templates.
2. Create a proj/ components/ app-bar/ app-bar.js style.css jumping-button/ jumping-button.js style.css+ pages/+ components/+ __name__/+ __name__.js+ style.css
The __word__
notation is treated specially in paperback. Paperback will later replace these values with answers from questions about how to generate the files.
The contents of proj/pages/components/__name__/__name__.js
are a lodash template. Paperback will later perform lodash's template function to provide unique data.
console
The contents of proj/pages/components/__name__/style.css
prompts.js
file.
3. Create a proj/ components/ app-bar/ app-bar.js style.css jumping-button/ jumping-button.js style.css pages/ components/ __name__/ __name__.js+ prompts.js style.css
proj/pages/components/__name__/prompts.js
moduleexports = name: "name" message: "What is the component name?" name: "place" message: "What is the place?"
There must be a prompt with a "name" for each lodash template variable used.
These prompts are provided to inquirer to retrieve the required values for the template. Inquirer offers tons of features including input validation and different question types.
Later on after answering inquirer questions, paperback will know what to provide for the name
and place
template values in the file paths and file contents.
4. Run paperback
paperback components/__name__
Note: paperback
may be ran without passing a page to generate. paperback will then ask the user to select which page to load.
inquirer asks questions...
What is the component name? hello-worldWhat is the place? Taco Bell
paperback will log:
Created /Users/dustin/proj/components/hello-world/hello-world.jsCreated /Users/dustin/proj/components/hello-world/style.css
paperback generates the templated files.
proj/ components/ app-bar/ app-bar.js style.css+ hello-world/+ hello-world.js+ style.css jumping-button/ jumping-button.js style.css pages/ components/ __name__/ __name__.js prompts.js style.css
proj/components/hello-world/hello-world.js
console
proj/components/hello-world/style.css
Misc. Usage
Custom Template Directory
If the pages
directory name conflicts with the project structure, paperback may be told where to look for templates via:
paperback components/__name__ --template-path=templates/go/here
Providing Prompt Answers via CLI
Prompt answers may be passed via paperback
command. For example, given a prompts.js
of
moduleexports = name: "name" message: "What is the name?" name: "greeting" message: "What is the greeting?"
and paperback
is invoked like paperback components/__name__ --name Dustin
then paperback
will not ask the name question, but will still ask the greeting question. The value provided with the name flag will be the assumed answer.
LICENSE
MIT © Dustin Specker