npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

paperback

v0.5.0

Published

Easily generate files from templates

Downloads

21

Readme

paperback

NPM version Build Status Coverage Status

Code Climate Dependencies DevDependencies

PRs Welcome Commitizen friendly semantic-release

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