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