UNPKG

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