# pinkprint

> command-line tool for generating files

Latest version **1.2.2** (published 2020-04-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install pinkprint
pnpm add pinkprint
yarn add pinkprint
bun add pinkprint
```

Provides the command `pink`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2020-04-01 |
| First published | 2017-09-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 28.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Nick Aversano |
| Maintainers | nickav |

## Links

- npm: https://www.npmjs.com/package/pinkprint
- Repository: https://github.com/nickav/pinkprint
- npm.io page: https://npm.io/package/pinkprint

## Dependencies (5)

- [chalk](https://npm.io/package/chalk.md) ^3.0.0
- [humps](https://npm.io/package/humps.md) ^2.0.0
- [yargs](https://npm.io/package/yargs.md) ^15.0.2
- [pluralize](https://npm.io/package/pluralize.md) ^8.0.0
- [helper-date](https://npm.io/package/helper-date.md) ^1.0.1

## Recent versions

- 1.2.2 (latest) — 2020-04-01
- 1.2.1 — 2020-03-29
- 1.2.0 — 2020-01-10
- 1.1.1 — 2020-01-09
- 1.1.0 — 2019-12-27
- 1.0.3 — 2019-12-27
- 1.0.2 — 2019-12-27
- 1.0.1 — 2019-12-27
- 1.0.0 — 2019-12-27
- 0.1.2 — 2018-02-07
- 0.1.1 — 2017-09-18
- 0.1.0 — 2017-09-18
- 0.0.3 — 2017-09-15
- 0.0.1 — 2017-09-12

## README

# ![pink](/pink.png) pinkprint

#### _Auto-generate project files._

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

## Install

Install [yarn][yarn-install]. Then run:

```bash
> yarn add pinkprint
```

Now run `pink init`. This will create an empty [config file](#config) in your project root.

## Getting Started

### Create a new pinkprint

```bash
> 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:

```javascript
// ./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](#config).

```javascript
// 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

```bash
> pink generate component foobar
```

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

More examples:

```bash
> 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`:

```javascript
{
  "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:

```javascript
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](./pinkprint.config.js).

## API

### Context

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

```javascript
{
  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](./src/template-helpers.js).

You can access them via `ctx.helpers`.

[prettier]: https://github.com/prettier/prettier
[yarn-install]: https://yarnpkg.com/lang/en/docs/install/
[yargs]: https://github.com/yargs/yargs

---
_Source: https://npm.io/package/pinkprint · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
