|
| 1 | +--- |
| 2 | +title: Config File |
| 3 | +description: Overview and example usages of the generate license file CLI config file |
| 4 | +toc_max_heading_level: 4 |
| 5 | +--- |
| 6 | + |
| 7 | +import Tabs from "@theme/Tabs"; |
| 8 | +import TabItem from "@theme/TabItem"; |
| 9 | + |
| 10 | +The generate-license-file CLI can be configured using a config file so that you don't need to re-enter the same |
| 11 | +config options every time. The config file also allows you to specify additional more complex options that are not |
| 12 | +available as CLI flags. |
| 13 | + |
| 14 | +## File Formats |
| 15 | + |
| 16 | +Config files can be called either `.glf` or `.generatelicensefile` and can be customised using the following options: |
| 17 | + |
| 18 | +- File name can optionally end with `rc` |
| 19 | +- Can be in a `./.config` directory (no longer needs the `.` prefix on the file name) |
| 20 | +- Have the following file extensions: `.json`, `jsonc`, `.json5`, `.yaml`, `.yml`, `.js`, `.cjs` |
| 21 | + |
| 22 | +E.g. `.glf.json`, `.glfrc.yml`, `.generatelicensefile.jsonc`, `.config/glf.js`, and more. |
| 23 | + |
| 24 | +## Config Options |
| 25 | + |
| 26 | +The file can contain all of the options that are [available as CLI flags](./). |
| 27 | + |
| 28 | +<Tabs groupId="file-formats"> |
| 29 | +<TabItem value="json" label="JSON" default> |
| 30 | + |
| 31 | +```json |
| 32 | +{ |
| 33 | + "inputs": ["./package.json"], |
| 34 | + "output": "./THIRD-PARTY-LICENSES.txt", |
| 35 | + "overwrite": true, |
| 36 | + "eol": "lf", |
| 37 | + "ci": true, |
| 38 | + "no-spinner": true |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +</TabItem> |
| 43 | + |
| 44 | +<TabItem value="yaml" label="YAML"> |
| 45 | + |
| 46 | +```yaml |
| 47 | +inputs: |
| 48 | + - ./package.json |
| 49 | +output: ./THIRD-PARTY-LICENSES.txt |
| 50 | +overwrite: true |
| 51 | +eol: lf |
| 52 | +ci: true |
| 53 | +no-spinner: true |
| 54 | +``` |
| 55 | +
|
| 56 | +</TabItem> |
| 57 | +
|
| 58 | +<TabItem value="js" label="JavaScript"> |
| 59 | +
|
| 60 | +```js |
| 61 | +module.exports = { |
| 62 | + inputs: ["./package.json"], |
| 63 | + output: "./THIRD-PARTY-LICENSES.txt", |
| 64 | + overwrite: true, |
| 65 | + eol: "lf", |
| 66 | + ci: true, |
| 67 | + noSpinner: true, |
| 68 | +}; |
| 69 | +``` |
| 70 | + |
| 71 | +</TabItem> |
| 72 | +</Tabs> |
| 73 | + |
| 74 | +:::tip |
| 75 | +JavaScript allows for more dynamic usages |
| 76 | + |
| 77 | +```js |
| 78 | +module.exports = { |
| 79 | + ci: process.env.CI === "true", |
| 80 | +}; |
| 81 | +``` |
| 82 | + |
| 83 | +::: |
| 84 | + |
| 85 | +### Advanced Options |
| 86 | + |
| 87 | +The config file also allows for more complex configurations that are not available as CLI flags. |
| 88 | + |
| 89 | +#### Append |
| 90 | + |
| 91 | +The append option allows you to append files to the end of the generated output file. This is useful if your project |
| 92 | +contains other types of licensed material other than node_modules dependencies that you want to include like fonts or images. |
| 93 | + |
| 94 | +<Tabs groupId="file-formats"> |
| 95 | +<TabItem value="json" label="JSON" default> |
| 96 | + |
| 97 | +```json |
| 98 | +{ |
| 99 | + "append": ["./extra-licenses.txt"] |
| 100 | +} |
| 101 | +``` |
| 102 | + |
| 103 | +</TabItem> |
| 104 | + |
| 105 | +<TabItem value="yaml" label="YAML"> |
| 106 | + |
| 107 | +```yaml |
| 108 | +append: |
| 109 | + - ./extra-licenses.txt |
| 110 | +``` |
| 111 | +
|
| 112 | +</TabItem> |
| 113 | +
|
| 114 | +<TabItem value="js" label="JavaScript"> |
| 115 | +
|
| 116 | +```js |
| 117 | +module.exports = { |
| 118 | + append: ["./extra-licenses.txt"], |
| 119 | +}; |
| 120 | +``` |
| 121 | + |
| 122 | +</TabItem> |
| 123 | +</Tabs> |
| 124 | + |
| 125 | +#### Replace |
| 126 | + |
| 127 | +The replace option allows you to replace the license content for a specific dependency. This is useful in situations like: |
| 128 | + |
| 129 | +- A dependency does not have its license file included in the published package |
| 130 | +- The license file is not in a standard format |
| 131 | +- The published package contains multiple license files and you want to pick a specific one |
| 132 | + |
| 133 | +Packages can be specified using the format `package@version` or `package`, where the latter will match all versions of a given package. If both are specified, then the configuration with a matching version will take precedence. |
| 134 | + |
| 135 | +:::info |
| 136 | + |
| 137 | +While it might be more convenient to use the package name without the version, it is recommended to use the version where possible to guarantee you always know exactly which package you are replacing the license for. |
| 138 | + |
| 139 | +::: |
| 140 | + |
| 141 | +The replacement value can be: |
| 142 | + |
| 143 | +- A relative or absolute file path to a location on disk |
| 144 | +- A URL to a remote file on the internet |
| 145 | + |
| 146 | +:::tip |
| 147 | + |
| 148 | +An advantage to using a file path over a URL is that the generated output will always be the same for any given commit. |
| 149 | + |
| 150 | +::: |
| 151 | + |
| 152 | +<Tabs groupId="file-formats"> |
| 153 | +<TabItem value="json" label="JSON" default> |
| 154 | + |
| 155 | +```json |
| 156 | +{ |
| 157 | + "replace": { |
| 158 | + "[email protected]": "./licenses/lodash.txt", |
| 159 | + "[email protected]": "./node_modules/react/LICENSE", |
| 160 | + "axios": "./node_modules/axios/LICENSE", |
| 161 | + "express": "https://spdx.org/licenses/MIT.txt" |
| 162 | + } |
| 163 | +} |
| 164 | +``` |
| 165 | + |
| 166 | +</TabItem> |
| 167 | + |
| 168 | +<TabItem value="yaml" label="YAML"> |
| 169 | + |
| 170 | +```yaml |
| 171 | +replace: |
| 172 | + [email protected]: ./licenses/lodash.txt |
| 173 | + [email protected]: ./node_modules/react/LICENSE |
| 174 | + axios: ./node_modules/axios/LICENSE |
| 175 | + express: https://spdx.org/licenses/MIT.txt |
| 176 | +``` |
| 177 | +
|
| 178 | +</TabItem> |
| 179 | +
|
| 180 | +<TabItem value="js" label="JavaScript"> |
| 181 | +
|
| 182 | +```js |
| 183 | +module.exports = { |
| 184 | + replace: { |
| 185 | + "[email protected]": "./licenses/lodash.txt", |
| 186 | + "[email protected]": "./node_modules/react/LICENSE", |
| 187 | + axios: "./node_modules/axios/LICENSE", |
| 188 | + express: "https://spdx.org/licenses/MIT.txt", |
| 189 | + }, |
| 190 | +}; |
| 191 | +``` |
| 192 | + |
| 193 | +</TabItem> |
| 194 | +</Tabs> |
| 195 | + |
| 196 | +<details> |
| 197 | +<summary>When using pnpm, the way to reference a file in a node_module can look a little different</summary> |
| 198 | +<div> |
| 199 | + |
| 200 | +```json |
| 201 | +{ |
| 202 | + "replace": { |
| 203 | + "[email protected]": "node_modules/.pnpm/[email protected]/node_modules/react/LICENSE" |
| 204 | + } |
| 205 | +} |
| 206 | +``` |
| 207 | + |
| 208 | +</div> |
| 209 | +</details> |
| 210 | + |
| 211 | +#### Exclude |
| 212 | + |
| 213 | +The exclude option allows you to exclude dependencies from the generated output file. This is useful for cases like when a dependency |
| 214 | +accidentally lists one of it's own dev-dependencies as a normal dependency and you want to exclude that dev-dependency. |
| 215 | + |
| 216 | +Values can be specified using the format `package@version` or `package`, where the latter will match all versions of a given package. You can also use regular expressions by wrapping the expression in forward slashes `/.../` and adding any relevant flags after the closing slash. |
| 217 | + |
| 218 | +<Tabs groupId="file-formats"> |
| 219 | +<TabItem value="json" label="JSON" default> |
| 220 | + |
| 221 | +```json |
| 222 | +{ |
| 223 | + "exclude": [ "lodash", "[email protected]", "/lodash-.*/i"] |
| 224 | +} |
| 225 | +``` |
| 226 | + |
| 227 | +</TabItem> |
| 228 | + |
| 229 | +<TabItem value="yaml" label="YAML"> |
| 230 | + |
| 231 | +```yaml |
| 232 | +exclude: |
| 233 | + - lodash |
| 234 | + |
| 235 | + - /lodash-.*/i |
| 236 | +``` |
| 237 | +
|
| 238 | +</TabItem> |
| 239 | +
|
| 240 | +<TabItem value="js" label="JavaScript"> |
| 241 | +
|
| 242 | +```js |
| 243 | +module.exports = { |
| 244 | + exclude: ["lodash", "[email protected]", "/lodash-.*/i"], |
| 245 | +}; |
| 246 | +``` |
| 247 | + |
| 248 | +</TabItem> |
| 249 | +</Tabs> |
| 250 | + |
| 251 | +## File Location |
| 252 | + |
| 253 | +If you want to keep your config file in a different location to the current working directory (or a `./.config` directory) |
| 254 | +then you can specify the location of the config file using the `--config` CLI flag. |
| 255 | + |
| 256 | +```bash |
| 257 | +generate-license-file --config ./path/to/config.json |
| 258 | +``` |
0 commit comments