# makit

> Make in JavaScript done right!

Latest version **1.17.1** (published 2021-02-26) · MIT license · 0 weekly downloads

## Install

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

Provides the command `makit`.

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.17.1 |
| Published | 2021-02-26 |
| First published | 2019-11-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 704.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | harttle |
| Maintainers | harttle, jleemt |
| Keywords | Make, JavaScript, Done-Right |

## Links

- npm: https://www.npmjs.com/package/makit
- Repository: https://github.com/searchfe/makit
- Homepage: https://github.com/searchfe/makit#readme
- Issues: https://github.com/searchfe/makit/issues
- npm.io page: https://npm.io/package/makit

## Dependencies (8)

- [chalk](https://npm.io/package/chalk.md) ^4.0.0
- [yargs](https://npm.io/package/yargs.md) ^14.2.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [extglob](https://npm.io/package/extglob.md) ^3.0.0
- [is-glob](https://npm.io/package/is-glob.md) ^4.0.1
- [treeify](https://npm.io/package/treeify.md) ^1.1.0
- [memory-fs](https://npm.io/package/memory-fs.md) ^0.5.0
- [typescript](https://npm.io/package/typescript.md) ^4.1.5

## Recent versions

- 1.17.1 (latest) — 2021-02-26
- 1.17.0 — 2021-02-26
- 1.16.1 — 2020-08-10
- 1.16.0 — 2020-08-06
- 1.15.4 — 2020-05-09
- 1.15.3 — 2020-05-08
- 1.15.2 — 2020-05-08
- 1.15.1 — 2020-01-03
- 1.15.0 — 2019-12-12
- 1.14.0 — 2019-12-12
- 1.13.2 — 2019-12-04
- 1.13.1 — 2019-12-04
- 1.13.0 — 2019-12-03
- 1.12.3 — 2019-12-02
- 1.12.2 — 2019-12-02
- … 21 more at https://npm.io/package/makit/versions

## README

# makit
[![npm version](https://img.shields.io/npm/v/makit.svg)](https://www.npmjs.org/package/makit)
[![downloads](https://img.shields.io/npm/dm/makit.svg)](https://www.npmjs.org/package/makit)
[![Build Status](https://travis-ci.com/searchfe/makit.svg?branch=master)](https://travis-ci.com/searchfe/makit)
[![Coveralls](https://img.shields.io/coveralls/searchfe/makit.svg)](https://coveralls.io/github/searchfe/makit?branch=master)
[![dependencies](https://img.shields.io/david/searchfe/makit.svg)](https://david-dm.org/searchfe/makit)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/searchfe/makit)
[![GitHub issues](https://img.shields.io/github/issues-closed/searchfe/makit.svg)](https://github.com/searchfe/makit/issues)
[![David](https://img.shields.io/david/searchfe/makit.svg)](https://david-dm.org/searchfe/makit)
[![David Dev](https://img.shields.io/david/dev/searchfe/makit.svg)](https://david-dm.org/searchfe/makit?type=dev)
[![DUB license](https://img.shields.io/dub/l/vibe-d.svg)](https://github.com/searchfe/makit/blob/master/LICENSE)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#commits)

Purposes and Principles:

* Minimal Concepts. It's intended to be a general purpose build automation tool just like GNU Make. Do not introduce unnecessary concept to keep it simple and stupid.
* Less Restrictions. It should be as open as GNU Make, makit doesn't expect recipes return anything, doesn't even requrie a recipe for its rule definition, and doesn't care about the actual output of recipes.
* JavaScript Style. Recipes can be written as callback style, Promise style or just synchronous style. Automatic variables are replaced by camelCased equivalents. Wildcard in static patterns are replaced by JavaScript RegExp and globs.

API Spec: <https://searchfe.github.io/makit/modules/_index_.html>

## Get Started

Basically, the syntax is as simple as Makefiles but with a `.js` extension. A Makefile.js contains a set of rules, each of which consists of 3 parts:

* **target**: either a filepath string, a glob string, or a RegExp object.
* **prerequisites**: list of filepath strings, functions that return a list of strings, or list of strings and functions. functions here can be either sync or async.
* **recipe**: an optional function, can be either sync or async.

Suppose we have a makefile.js containing the following contents:

```javascript
const { rule } = require('makit')

rule('all', ['a1.min.js'])  // default rule

rule('a1.min.js', ['a.js'], function () {
    const src = readFileSync(this.dependencies[0], 'utf8')
    const dst = UglifyJS.minify(src).code
    writeFileSync(this.target, dst)
})
```

When we run `makit`(which is equivelant to `make all` cause `all` is the first rule), makit tries to make the target `all` which requires `a1.min.js` so the second rule will be applied firstly and its recipe is called to generate the target `a1.min.js`. The prerequisites for `all` has been fully resolved now and makit then tries to call its recipe, which is not defined for the above case so makit will just skip call the recipe and assume the target `all` is made successfully.

See [/demo](https://github.com/searchfe/makit/tree/master/demo) directory for a working demo.
For more details see the typedoc for [.rule()](https://searchfe.github.io/makit/modules/_index_.html#rule.)

## Config

The `makit` CLI supports `--help` to print usage info:

```
makit.js [OPTION] <TARGET>...

Options:
  --version       Show version number                             [boolean]
  --makefile, -m  makefile path                                    [string]
  --database, -d  database file, will be used for cache invalidation
                                                   [default: "./.makit.db"]
  --require, -r   require a module before loading makefile.js or
                  makefile.ts                         [array] [default: []]
  --verbose, -v   set loglevel to verbose                         [boolean]
  --debug, -v     set loglevel to debug                           [boolean]
  --loglevel, -l  error, warning, info, verbose, debug
                                                   [choices: 0, 1, 2, 3, 4]
  --graph, -g     output dependency graph        [boolean] [default: false]
  --help          Show help                                       [boolean]
```

Or specify in `package.json`:

```json
{
  "name": "your package name",
  "dependencies": {},
  "makit": {
    "loglevel": 2,
    "makefile": "makefile.ts",
    "require": ["ts-node/register"]
  }
}
```

## Async (Promise & Callbacks)

When the recipe returns a Promise, that promise will be awaited.

```javascript
rule('a1.min.js', ['a.js'], async function () {
    const src = await readFile(this.dependencies[0], 'utf8')
    const dst = UglifyJS.minify(src).code
    await writeFile(this.target, dst)
})
// equivelent to
rule('a1.min.js', ['a.js'], async ctx => {
    const src = await readFile(ctx.dependencies[0], 'utf8')
    const dst = UglifyJS.minify(src).code
    await writeFile(ctx.target, dst)
})
```

Callback style functions also work:

```javascript
rule('clean', [], (ctx, done) => rimraf('{*.md5,*.min.js}', done))
```

## Dynamic Dependencies

```javascript
// `makit a.js.md5` will make a.js.md5 from a.js
rule('*.js.md5', ctx => ctx.target.replace('.md5', ''), async function () {
    const src = await this.readDependency(0)
    await this.writeTarget(md5(src))
})
```

Similarly, async prerequisites functions, i.e. functions of return type `Promise<string>` or `Promise<string[]>`, are also supported.


## Matching Groups and Reference

Makit uses [extglob](https://www.npmjs.com/package/extglob) to match target names.
Furthermore it's extended to support match groups which can be referenced in prerequisites.

```javascript
// `makit output/app/app.js` will make app.js.md5 from a.ts
rule('(output/**)/(*).js', '$1/$2.ts', async function () {
    return this.writeTarget(tsc(await this.readDependency()))
})
make('output/app/app.js')
```

## Dynamic Prerequisites

It's sometimes handy to call `make()` within the recipe, but global `make()` is not valid in recipes.
For example the following rule is **NOT** valid:

```javascript
const { rule, make } = require('makit')

rule('bundle.js', 'a.js', async (ctx) => {
    await make('b.js')
    const js = (await ctx.readFile('a.js')) + (await ctx.readFile('b.js'))
    ctx.writeTarget(js)
})
```

We introduce `rude()` to facilitate this situation, a `ctx.make` API is available inside the recipe of `rude`:

```javascript
const { rude } = require('makit')

rude(
    'bundle.js', [], async ctx => {
        await ctx.make('a.js')
        await ctx.make('b.js')
        const js = (await ctx.readFile('a.js')) + (await ctx.readFile('b.js'))
        return ctx.writeTarget(js)
    }
)
```

A pseudo rule with `bundle.js.rude.dep` as target, the contents of which is the actual dependencies,
will be generated for each `rude()`.

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