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

pinkprint

v1.2.2

Published

command-line tool for generating files

Downloads

2,470

Readme

pink pinkprint

Auto-generate project files.

An easy way to quickly generate project files. Inspired by rails generate.

Install

Install yarn. Then run:

> yarn add pinkprint

Now run pink init. This will create an empty config file in your project root.

Getting Started

Create a new pinkprint

> pink new hello

This will create a new template file in your project root ./pinkprints/hello.js.

Pinkprint templates are written in JavaScript and export a default object in the following shape:

// ./pinkprints/hello.js
exports.default = {
  name: (name, h) => 'hello',           // function to generate file name
  extension: '.js',                     // file extension
  generate: (args, h, argv, ctx) => ``, // function returning string
  pre: (args, h, argv, ctx) => {},      // function that runs before `generate`
  post: (args, h, argv, ctx) => {},     // function that runs after `generate`
}

Create a new command

Commands are the main interface to pinkprint. To create a new command, add one to your config file.

// pinkprint.config.js

exports.default = {
  commands: {
    greet: (ctx, argv) => ctx.print('hello', { basePath: 'src/greetings' }),
  },
};

Now you can run the command with pink g greet World. This will create a new file ./src/greetings/World.js

Run a command

> pink generate component foobar

This will run the component command in your pinkprint.config.js.

More examples:

> pink component foobar               # shorthand for pink generate component
> pink g component common.MyComponent # output to src/common

Generate Alias

It is also recommended to add the following to your package.json:

{
  "scripts": {
    "g": "bin/pink g"
  }
}

Now you can use yarn g <command> as an alias for pink generate.

Config

The pinkprint config file lives in your project root and is named pinkprint.config.js.

It supports the following options:

exports.default = {
  output: {
    // path where files are written to
    path: './src',
  },

  commands: {
    // all commands live here
    file: (ctx, argv) => ctx.print('file', { basePath: 'files' }),
  },
};

See an example config file here.

API

Context

Every command has access to the context and the argv object (from yargs). The pinkprint context contains the following:

{
  projectRoot: '/Users/nick/dev/pinkprint',
  templateDir: '/Users/nick/dev/pinkprint/pinkprints',
  configFile: '/Users/nick/dev/pinkprint/pinkprint.config.js',
  config: {}, // loaded config file

  path: '',
  name: 'world',

  getPackageJson: [Function: getPackageJson],
  getAuthor: [Function: getAuthor],
  getGitUser: [Function],
  getTemplate: [Function: getTemplate],

  print: [Function: print],
  string: [Function: string],

  assert: [Function],
  require: [Function],
  helpers: {}, // template helpers

  fs: {
    mount: '/Users/nick/dev/pinkprint/src',
    defaultExtension: '',
    relativePath: '/Users/nick/dev/pinkprint',
    noWrite: true,
    setDefaultExtension: [Function: setDefaultExtension],
    withExtension: [Function: withExtension],
    resolvePath: [Function: resolvePath],
    write: [Function: write],
    writeFile: [Function: writeFile],
    mkdirp: [Function: mkdirp],
    readFileSync: [Function: readFileSync],
    readDirSync: [Function: readDirSync]
  }
}

Helpers

There are several built-in template helpers.

You can access them via ctx.helpers.