# haki

> Small generator with will powers

Latest version **0.12.0** (published 2020-09-04) · MIT license · 0 weekly downloads

## Install

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

Provides the command `haki`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.12.0 |
| Published | 2020-09-04 |
| First published | 2016-02-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 14 |
| Unpacked size | 52.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Alvaro Cabrera |
| Maintainers | pateketrueke |
| Keywords | scaffolding, templates, codegen, prompt, cli |

## Links

- npm: https://www.npmjs.com/package/haki
- npm.io page: https://npm.io/package/haki

## Dependencies (14)

- [glob](https://npm.io/package/glob.md) ^7.1.2
- [chalk](https://npm.io/package/chalk.md) ^4.1.0
- [wargs](https://npm.io/package/wargs.md) ^0.9.2
- [rimraf](https://npm.io/package/rimraf.md) ^3.0.2
- [prompts](https://npm.io/package/prompts.md) ^2.3.2
- [fs-extra](https://npm.io/package/fs-extra.md) ^9.0.1
- [log-pose](https://npm.io/package/log-pose.md) ^0.3.7
- [mustache](https://npm.io/package/mustache.md) ^4.0.1
- [pluralize](https://npm.io/package/pluralize.md) ^8.0.0
- [pretty-ms](https://npm.io/package/pretty-ms.md) ^7.0.0
- [change-case](https://npm.io/package/change-case.md) ^4.1.1
- [clean-stack](https://npm.io/package/clean-stack.md) ^3.0.0
- [text-extensions](https://npm.io/package/text-extensions.md) ^2.1.0
- [download-github-repo](https://npm.io/package/download-github-repo.md) ^0.1.4

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 0.12.0 (latest) — 2020-09-04
- 0.11.0 — 2020-09-04
- 0.10.4 — 2019-04-03
- 0.10.3 — 2019-02-17
- 0.10.2 — 2018-12-05
- 0.10.1 — 2018-12-04
- 0.10.0 — 2017-11-21
- 0.9.0 — 2017-11-08
- 0.8.0 — 2017-10-26
- 0.7.1 — 2017-10-26
- 0.7.0 — 2017-10-24
- 0.6.5 — 2017-10-13
- 0.6.4 — 2017-07-30
- 0.6.3 — 2017-06-29
- 0.6.2 — 2017-06-24
- … 20 more at https://npm.io/package/haki/versions

## README

# Haki

![Ryou Haki](https://cdn.lanetaneta.com/wp-content/uploads/2020/08/1597113488_One-Piece-revela-un-nuevo-nombre-para-Haki-780x470.webp)

[![NPM version](https://badge.fury.io/js/haki.png)](http://badge.fury.io/js/haki)
[![travis-ci](https://api.travis-ci.org/pateketrueke/haki.svg)](https://travis-ci.org/pateketrueke/haki)
[![codecov](https://codecov.io/gh/pateketrueke/haki/branch/master/graph/badge.svg)](https://codecov.io/gh/pateketrueke/haki)

Small generator with will powers.

```bash
$ npx haki [-e FILE] [COMMAND] [...]
# or `npm i -g haki`
# or `yarn global add haki`
```

> Run `haki` without arguments to get usage hints.

## Example

Create a file named `Hakifile.js` in your project with this:

```js
module.exports = haki => {
  haki.setGenerator('the:truth', {
    description: "Display if it's true, or not",
    arguments: ['verb', 'value'],
    abortOnFail: true,
    actions(input) {
      const { verb, value } = input;

      if (verb === 'is' && parseInt(value, 10) === 42) {
        console.log('Gotcha!');
        return;
      }

      throw new Error('Is not true');
    },
  });
}
```

Now you can execute this task through the CLI:

- `haki the:truth`
- `haki the:truth is 42`

## API

Available methods:

- `load(filepath: String)` &mdash; Load a Hakifile from given filepath
- `prompt(options: Object)` &mdash; Generic prompting helper, see options below
- `getPrompts()` &mdash; Returns [Prompts](https://github.com/terkelg/prompts) instance
- `getLogger()` &mdash; Returns [LogPose](https://github.com/pateketrueke/log-pose) instance
- `getPath(destName: String)` &mdash; Returns a filepath for output
- `addHelper(name: String, callback: Function)` &mdash; Register a [Mustache](https://github.com/janl/mustache.js/) helper for calling on templates
- `getHelperList()` &mdash; Retrieve all registered helpers
- `renderString(value: String, data: Object)` &mdash; Render template values
- `setGenerator(name: String[, options: Object])` &mdash; Register a generator definition, see options below
- `getGenerator(name: String)` &mdash; Retrieve a registered generator
- `runGenerator(name: String|Object[, defaults: Object])` &mdash; Execute any given generator; given `name` can be an object, see options below
- `hasGenerator(name: String)` &mdash; Returns `true` if given generator is defined
- `getGeneratorList([hints: Boolean])` &mdash; Retrieve all registered generators, if `hints` is given then descriptions are prefixed with their names
- `chooseGeneratorList([defaults: Object])` &mdash; Prompt to execute from registered generators, `defaults` are given as for `runGenerator()`

### Generators

Those can be registered or executed directly.

Valid options are:

- `description: String` &mdash; Displayed on `--help`
- `validate: Object|Function` &mdash; To validate input
- `arguments: Array` &mdash; Map extra `argv` as input
- `actions: Array|Function` &mdash; [See below](#actions)
- `prompts: Array|Function` &mdash; [See below](#prompts)
- `defaults: Object` &mdash; Initial values
- `quiet: Boolean` &mdash; Hide output from logs
- `basePath: String` &mdash; Resolve sources from here
- `abortOnFail: Boolean` &mdash; Abort whole process on failure

> Both `prompts` and `arrays` can be functions, once executed they should return an array to be used or nothing.

#### Actions

Enumerated actions can perform several tasks based on its definition.

Definitions can contain:

- `src: String` &mdash; Relative to generator's `basePath`
- `type: String` &mdash; Action type: add, copy, clean, etc.
- `dest: String` &mdash; Relative to `process.cwd()` for output
- `template: String` &mdash; Used when creating files
- `templateFile: String` &mdash; Source file used when creating files
- `defaultContent: String` &mdash; On `modify`, used if file does not exists yet
- `deleteContent: Boolean` &mdash; On `modify`, remove matched code instead of replacing it
- `after: String|RegExp` &mdash; As below, used to replace before the match
- `before: String|RegExp` &mdash; As below, used to replace after the match (alias of `pattern`)
- `pattern: String|RegExp` &mdash; On `modify`, used to match-and-replace
- `unless: String|RegExp` &mdash; On `modify`, used to skip matching code
- `content: String` &mdash; Like `template` but without Mustache support
- `gitUrl: String` &mdash; Used on `clone` actions, relative to github
- `callback: Function` &mdash; Used on `extend` actions to merge input
- `command: String` &mdash; Used on `exec` actions, as shell command
- `quiet: Boolean` &mdash; Override generator's `quiet` value
- `abortOnFail: Boolean` &mdash; Override generator's `abortOnFail` value

#### Prompts

User input is being done by **Prompts**, so any syntax supported is valid, e.g.

- `type: String` &mdash; Generator type <sup>1</sup>
- `name: String` &mdash; Input name
- `message: String` &mdash; Optional label

> <sup>1</sup> Check which [types](https://github.com/terkelg/prompts#-types) are supported by default.

## Global usage

By design `haki` will scan for immediately available Hakifiles from the current working and other special directories.

Say, we are at `$HOME/path/to/project/name` so paths below are used:

- `/etc/.config/haki`
- `/etc/.hakirc`
- `/etc/Hakifile.js`
- `$HOME/.config/haki`
- `$HOME/.hakirc`
- `$HOME/Hakifile.js`
- `$HOME/path/to/project/name/.config/haki`
- `$HOME/path/to/project/name/.hakirc`
- `$HOME/path/to/project/name/Hakifile.js`
- `$HOME/path/to/project/.config/haki`
- `$HOME/path/to/project/.hakirc`
- `$HOME/path/to/project/Hakifile.js`
- `$HOME/path/to/.config/haki`
- `$HOME/path/to/.hakirc`
- `$HOME/path/to/Hakifile.js`
- etc. &mdash; scanning stops when `/` or `$HOME` path is reached.

## Gist usage

You can download and run remote gists too:

```bash
$ haki -g [SHA1]
```

List available gists with `haki -g` only.

## GitHub usage

Download github repositories with:

```bash
$ haki <USER/REPO> <DEST>
```

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