UNPKG

3.68 kBMarkdownView Raw
1# hereby
2
3[![npm](https://img.shields.io/npm/v/hereby.svg)](https://npmjs.com/package/hereby)
4[![node](https://img.shields.io/node/v/hereby.svg)](https://nodejs.org)
5[![install size](https://packagephobia.com/badge?p=hereby)](https://packagephobia.com/result?p=hereby)
6[![ci](https://github.com/jakebailey/hereby/actions/workflows/ci.yml/badge.svg)](https://github.com/jakebailey/hereby/actions/workflows/ci.yml)
7[![codecov](https://codecov.io/gh/jakebailey/hereby/branch/main/graph/badge.svg?token=YL2Z1uk5dh)](https://codecov.io/gh/jakebailey/hereby)
8
9> _I hereby declare thee built._
10
11`hereby` is a simple task runner.
12
13```
14$ npm i -D hereby
15$ yarn add -D hereby
16```
17
18## Herebyfile.mjs
19
20Tasks are defined in `Herebyfile.mjs`. Exported tasks are available to run at
21the CLI, with support for `export default`.
22
23For example:
24
25```js
26import { execa } from "execa";
27import { task } from "hereby";
28
29export const build = task({
30 name: "build",
31 run: async () => {
32 await execa("tsc", ["-b", "./src"]);
33 },
34});
35
36export const test = task({
37 name: "test",
38 dependencies: [build],
39 run: async () => {
40 await execa("node", ["./out/test.js"]);
41 },
42});
43
44export const lint = task({
45 name: "lint",
46 run: async () => {
47 await runLinter(...);
48 },
49});
50
51export const testAndLint = task({
52 name: "testAndLint",
53 dependencies: [test, lint],
54});
55
56export default testAndLint;
57
58export const bundle = task({
59 name: "bundle",
60 dependencies: [build],
61 run: async () => {
62 await execa("esbuild", [
63 "--bundle",
64 "./out/index.js",
65 "--outfile=./out/bundled.js",
66 ]);
67 },
68});
69```
70
71## Running tasks
72
73Given the above Herebyfile:
74
75```
76$ hereby build # Run the "build" task
77$ hereby test # Run the "test" task, which depends on "build".
78$ hereby # Run the default exported task.
79$ hereby test bundle # Run the "test" and "bundle" tasks in parallel.
80```
81
82## Flags
83
84`hereby` also supports a handful of flags:
85
86```
87-h, --help Display this usage guide.
88--herebyfile path A path to a Herebyfile. Optional.
89-T, --tasks Print a listing of the available tasks.
90```
91
92## ESM
93
94`hereby` is implemented in ES modules. But, don't fret! This does not mean that
95your project must be ESM-only, only that your `Herebyfile` must be ESM module so
96that `hereby`'s `task` function can be imported. It's recommended to use the
97filename `Herebyfile.mjs` to ensure that it is treated as ESM. This will work in
98a CommonJS project; ES modules can import CommonJS modules.
99
100If your package already sets `"type": "module"`, `Herebyfile.js` will work as
101well.
102
103## Caveats
104
105### No serial tasks
106
107`hereby` does not support running tasks in series; specifying multiple tasks at
108the CLI or as dependencies of another task will run them in parallel. This
109matches the behavior of tools like `make`, which like `hereby` intend to encode
110a dedpendency graph of tasks, not act as a script.
111
112In general, if you're trying to emulate a serial task, you will likely be better
113served by writing out explicit dependencies for your tasks.
114
115### Tasks only run once
116
117`hereby` will only run each task once during its execution. This means that
118tasks which consist of other tasks run in order like a script cannot be
119constructed. For example, it's not possible to run "build", then "clean", then
120"build" again within the same invocation of `hereby`, since "build" will only be
121executed once (and the lack of serial tasks prevents such a construction
122anyway).
123
124To run tasks in a specific order and more than once, run `hereby` multiple
125times:
126
127```
128$ hereby build
129$ hereby clean
130$ hereby build
131```