|
1 | 1 | # CLI |
2 | 2 |
|
3 | | -The `doc-kit` command-line interface. Every option that maps to |
4 | | -configuration can also live in a [configuration file](./configuration.md); |
5 | | -when both are present, CLI flags win (rule of specifity). |
| 3 | +The `doc-kit` command builds your docs with `doc-kit generate` and serves |
| 4 | +them locally with `doc-kit preview`. It comes from the |
| 5 | +[`@doc-kit/cli`](./packages/cli.md) package; install it in your project as |
| 6 | +shown in [Getting started](./getting-started.md), then run it with `npx`: |
6 | 7 |
|
7 | 8 | ```bash |
8 | 9 | npx @doc-kit/cli [command] [options] |
9 | 10 | ``` |
10 | 11 |
|
11 | | -One option applies to every command: |
12 | | - |
13 | | -- `--log-level <level>` {string} `debug`, `info`, `warn`, `error`, or |
14 | | - `fatal`. **Default:** `'info'`. |
| 12 | +`npx @doc-kit/cli --help` lists the commands, and |
| 13 | +`npx @doc-kit/cli generate --help` the options of one. |
15 | 14 |
|
16 | 15 | ## `doc-kit generate` |
17 | 16 |
|
| 17 | +Runs the generators and writes their output. It needs at least one target |
| 18 | +and an input, from flags or a [configuration file](#configuration-files): |
| 19 | + |
| 20 | +```bash |
| 21 | +npx @doc-kit/cli generate -t html -t orama-db -i "docs/**/*.md" -o out |
| 22 | +``` |
| 23 | + |
| 24 | +Quote glob patterns, so they reach doc-kit as written instead of being |
| 25 | +expanded by your shell. Options that take a list accept several values after |
| 26 | +one flag (`-t html orama-db`) or the flag repeated (`-t html -t orama-db`). |
| 27 | +Each option except `--config-file` sets the configuration key named in |
| 28 | +parentheses. |
| 29 | + |
| 30 | +- `-t, --target <name...>` {string[]} Generators to run (`target`): built-in |
| 31 | + names, such as `html` or `orama-db`, or the import specifier or path of a |
| 32 | + [custom generator](./creating-generators.md). The |
| 33 | + [generators overview](./generators.md) lists the built-in ones and the |
| 34 | + package each comes from. |
| 35 | +- `-i, --input <patterns...>` {string[]} Glob patterns of the files to read |
| 36 | + (`global.input`). |
| 37 | +- `--ignore <patterns...>` {string[]} Glob patterns of files to leave out |
| 38 | + (`global.ignore`). |
| 39 | +- `-o, --output <dir>` {string} Directory to write the output to |
| 40 | + (`global.output`). |
| 41 | +- `--config-file <path>` {string} Path of the configuration file to load, |
| 42 | + instead of searching the working directory for one. |
| 43 | +- `-v, --version <semver>` {string} Version of the project being documented |
| 44 | + (`global.version`), coerced to semver, so `22` means `22.0.0`. |
| 45 | + **Default:** the version of Node.js running doc-kit. |
| 46 | +- `-c, --changelog <url>` {string} URL or path of a changelog in the format of |
| 47 | + Node.js's `CHANGELOG.md`, which the version selector is built from |
| 48 | + (`global.changelog`). Without one, the output covers a single version. |
| 49 | +- `--index <url>` {string} URL or path of an `index.md` whose list of links |
| 50 | + (`* [Title](file.md)`) sets the order of the documents in the JSON bundle, |
| 51 | + the legacy HTML sidebar and the legacy JSON bundle (`global.index`). |
| 52 | +- `--git-ref <ref>` {string} Git branch, tag, or commit that links into your |
| 53 | + repository point to, such as edit links and the JSON output's source URLs |
| 54 | + (`global.ref`). The website's source code links follow |
| 55 | + [`jsx-ast.ref`](./generators/jsx-ast.md#configuring) instead, which defaults |
| 56 | + to `'main'` and is set in a configuration file. **Default:** `'HEAD'`. |
| 57 | +- `--type-map <url>` {string} URL or path of a JSON file mapping type names to |
| 58 | + the URLs documenting them, used to link types (`metadata.typeMap`). |
| 59 | +- `--minify` {boolean} Minify the output (`global.minify`). **Default:** |
| 60 | + `false`. |
| 61 | +- `-p, --threads <n>` {number} Worker threads to use, at least 1 (`threads`). |
| 62 | + **Default:** the number of CPUs, up to 4. |
| 63 | +- `--chunk-size <n>` {number} Items each worker processes per task, at least 1 |
| 64 | + (`chunkSize`). **Default:** `10`. |
| 65 | + |
18 | 66 | ```bash |
19 | | -npx @doc-kit/cli generate [options] |
| 67 | +# Build everything the configuration file describes |
| 68 | +npx @doc-kit/cli generate |
| 69 | + |
| 70 | +# Build only the JSON output, minified, into dist/json |
| 71 | +npx @doc-kit/cli generate -t json -o dist/json --minify |
20 | 72 | ``` |
21 | 73 |
|
22 | | -Runs the generators and writes their output. Requires a `target` and an |
23 | | -`input`, from flags or the configuration file. |
24 | | - |
25 | | -- `--config-file <path>` {string} Use a specific configuration file instead |
26 | | - of searching. |
27 | | -- `-i, --input <patterns...>` {string[]} Input file patterns (glob). |
28 | | -- `-t, --target <name...>` {string[]} Generator name(s), or import |
29 | | - specifiers for custom generators. |
30 | | -- `--ignore <patterns...>` {string[]} Input patterns to skip. |
31 | | -- `-o, --output <dir>` {string} The output directory. |
32 | | -- `-v, --version <semver>` {string} The version of the project being |
33 | | - documented. |
34 | | -- `-c, --changelog <url>` {string} Changelog URL or path (release history |
35 | | - for version selectors). |
36 | | -- `--git-ref <ref>` {string} Git ref used in source links. |
37 | | -- `--index <url>` {string} `index.md` URL or path. |
38 | | -- `--minify` {boolean} Minify the output. |
39 | | -- `--type-map <url>` {string} Type map URL or path (custom type-name → URL |
40 | | - links). |
41 | | -- `-p, --threads <n>` {number} Worker threads to use (minimum 1). |
42 | | -- `--chunk-size <n>` {number} Items per worker thread (minimum 1). |
| 74 | +When something fails, doc-kit logs the error and exits with code 1, so a |
| 75 | +broken build also fails your CI job. |
43 | 76 |
|
44 | 77 | ## `doc-kit preview` |
45 | 78 |
|
| 79 | +Serves the output directory over HTTP at <http://localhost:3000>, so you can |
| 80 | +check a build in the browser the way a host would serve it: |
| 81 | + |
46 | 82 | ```bash |
47 | 83 | npx @doc-kit/cli preview [options] |
48 | 84 | ``` |
49 | 85 |
|
50 | | -Serves the generated docs over HTTP for local verification. Every `generate` |
51 | | -option is accepted: when any of them is passed, the docs are built first |
52 | | -(same semantics as `doc-kit generate`); otherwise the existing output |
53 | | -directory is served as-is (`./out` by default). |
| 86 | +What it serves depends on the options you pass: |
| 87 | + |
| 88 | +- **No `generate` options:** it serves `./out` as it is, without reading your |
| 89 | + configuration file, and stops with an error if `./out` doesn't exist. |
| 90 | +- **Any `generate` option:** it builds first, exactly as `doc-kit generate` |
| 91 | + would, then serves the directory that build wrote to. To build from your |
| 92 | + configuration file alone, pass it with `--config-file`. |
| 93 | + |
| 94 | +It builds once and doesn't watch for changes, so run it again after editing. |
| 95 | +Directories serve their `index.html`, and paths that don't exist get the |
| 96 | +output's `404.html`, when it has one. |
| 97 | + |
| 98 | +It takes these options, plus every option of |
| 99 | +[`doc-kit generate`](#doc-kit-generate): |
| 100 | + |
| 101 | +- `--port <n>` {number} Port to serve on; `0` picks a free one. **Default:** |
| 102 | + `3000`. |
| 103 | +- `--host <host>` {string} Host to listen on. **Default:** `'localhost'`. |
| 104 | + |
| 105 | +```bash |
| 106 | +# Build with the configuration file, then serve its output directory |
| 107 | +npx @doc-kit/cli preview --config-file doc-kit.config.mjs |
| 108 | + |
| 109 | +# Build only the site, then serve it on another port |
| 110 | +npx @doc-kit/cli preview -t html --port 8080 |
| 111 | +``` |
| 112 | + |
| 113 | +> [!WARNING] |
| 114 | +> The preview server is meant for local testing only. It is not a secure, |
| 115 | +> production-grade server: don't expose it to other machines, and don't use |
| 116 | +> it to deploy your documentation. To publish, see |
| 117 | +> [Publishing your docs](./publishing.md). |
| 118 | +
|
| 119 | +## Global options |
| 120 | + |
| 121 | +These work with every command, before or after its name: |
| 122 | + |
| 123 | +- `--log-level <level>` {string} Log only messages at this level or above: |
| 124 | + `debug`, `info`, `warn`, `error`, or `fatal`. **Default:** `'info'`. |
| 125 | + |
| 126 | +```bash |
| 127 | +npx @doc-kit/cli generate --log-level debug |
| 128 | +``` |
54 | 129 |
|
55 | | -> **Note:** The preview server is meant for local testing only — it is not |
56 | | -> production grade. Do not use it to deploy your documentation. |
| 130 | +## Configuration files |
57 | 131 |
|
58 | | -- `--port <n>` {number} Port to serve on. **Default:** `3000`. |
59 | | -- `--host <host>` {string} Host to listen on (e.g. `localhost`, `0.0.0.0`). |
60 | | - **Default:** `'localhost'`. |
61 | | -- Every option of [`doc-kit generate`](#doc-kit-generate). |
| 132 | +Everything the `generate` flags set can also live in a |
| 133 | +[configuration file](./configuration.md), along with what they don't cover, |
| 134 | +such as generator options, Markdown plugins, and presets. Flags win over the |
| 135 | +file; see [Precedence](./configuration.md#precedence). |
0 commit comments