paperback
v0.5.0
Published
Easily generate files from templates
Downloads
21
Maintainers
Readme
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
2. Create a pages
directory mirroring the file structure of the actual project. The pages
directory holds the templates.
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.log('Hello <%= place %>')
The contents of proj/pages/components/__name__/style.css
.<%= name %> {
color: #000;
}
3. Create a prompts.js
file.
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
module.exports = [
{
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-world
What is the place? Taco Bell
paperback will log:
Created /Users/dustin/proj/components/hello-world/hello-world.js
Created /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.log('Hello Taco Bell')
proj/components/hello-world/style.css
.hello-world {
color: #000;
}
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
module.exports = [
{
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