|
| 1 | +# Configuration Files |
| 2 | + |
| 3 | +`create-typescript-app` supports a `create-typescript-app.config.js` configuration file per [Bingo > Configuration](https://www.create.bingo/configuration). |
| 4 | +Bingo configuration files are generally used for describing complex options that can't be inferred from existing repositories. |
| 5 | +`create-typescript-app` is built on the [Stratum engine](https:://create.bingo/engines/stratum/about), so its configuration files adhere to [Bingo > Stratum > Details > Configurations](https://www.create.bingo/engines/stratum/details/configurations): |
| 6 | + |
| 7 | +- [`options`](#options): any type-safe options the template has declared |
| 8 | +- [`refinements`](#refinements): any customizations specified by the template |
| 9 | + |
| 10 | +> [!TIP] |
| 11 | +> `create-typescript-app` defaults `options` to their values in an existing repository. |
| 12 | +> You most likely only need to use `refinements` to specify changes that can't be inferred. |
| 13 | +
|
| 14 | +## `options` |
| 15 | + |
| 16 | +Any type-safe options the template has declared. |
| 17 | +This includes the options described in [CLI](./CLI.md). |
| 18 | + |
| 19 | +Some of create-typescript-app's options are rich objects, typically very long strings, or otherwise not reasonable on the CLI. |
| 20 | +These options are generally only programmatically used internally, but can still be specified in a configuration file: |
| 21 | + |
| 22 | +| Option | Description | Default (If Available) | |
| 23 | +| ---------------- | ------------------------------------------------------------------------ | --------------------------------------------------------- | |
| 24 | +| `contributors` | AllContributors contributors to store in `.all-contributorsrc` | Existing contributors in the file, or just your username | |
| 25 | +| `documentation` | any additional docs to add to `.github/DEVELOPMENT.md` | Extra content in `.github/DEVELOPMENT.md` | |
| 26 | +| `existingLabels` | existing labels to switch to the standard template labels | Existing labels on the repository from the GitHub API | |
| 27 | +| `explainer` | additional `README.md` sentence(s) describing the package | Extra content in `README.md` after badges and description | |
| 28 | +| `guide` | link to a contribution guide to place at the top of development docs | Block quote on top of `.github/DEVELOPMENT.md` | |
| 29 | +| `logo` | local image file and alt text to display near the top of the `README.md` | First non-badge image's `alt` and `src` in `README.md` | |
| 30 | +| `node` | Node.js engine version(s) to pin and require a minimum of | Values from `.nvmrc` and `package.json`'s `"engines"` | |
| 31 | +| `packageData` | additional properties to include in `package.json` | Existing values in `package.json` | |
| 32 | +| `rulesetId` | GitHub branch ruleset ID for main branch protections | Existing ruleset on the `main` branch from the GitHub API | |
| 33 | +| `usage` | Markdown docs to put in `README.md` under the `## Usage` heading | Existing usage lines in `README.md` | |
| 34 | + |
| 35 | +For example, changing `node` versions to values different from what would be inferred: |
| 36 | + |
| 37 | +```ts |
| 38 | +// create-typescript-app.config.js |
| 39 | +import { createConfig } from "create-typescript-app"; |
| 40 | + |
| 41 | +export default createConfig({ |
| 42 | + options: { |
| 43 | + node: { |
| 44 | + minimum: ">=20.19.0", |
| 45 | + pinned: "22.14.0", |
| 46 | + }, |
| 47 | + }, |
| 48 | +}); |
| 49 | +``` |
| 50 | + |
| 51 | +> [!TIP] |
| 52 | +> Running `npx create-typescript-app` will apply any new `options` values to the repository. |
| 53 | +> You can generally remove `options` from your configuration file after running `npx create-typescript-app`. |
| 54 | +
|
| 55 | +## `refinements` |
| 56 | + |
| 57 | +[Refinements](https://www.create.bingo/engines/stratum/details/configurations#refinements) can be used to modify the "Blocks" of tooling provided by create-typescript-app. |
| 58 | + |
| 59 | +See [Blocks.md](./Blocks.md) for the list of blocks, which presets contain them, and their corresponding `--exclude-*` flags. |
| 60 | + |
| 61 | +### `addons` |
| 62 | + |
| 63 | +Any additional [Addons](https://www.create.bingo/engines/stratum/concepts/blocks#addons) provided to Blocks provided by the selected Preset. |
| 64 | + |
| 65 | +For example, this configuration file adds the word `"joshuakgoldberg"` to the CSpell Block's Addons: |
| 66 | + |
| 67 | +```ts |
| 68 | +// create-typescript-app.config.js |
| 69 | +import { blockCSpell, createConfig } from "create-typescript-app"; |
| 70 | + |
| 71 | +export default createConfig({ |
| 72 | + refinements: { |
| 73 | + addons: [ |
| 74 | + blockCSpell({ |
| 75 | + words: ["joshuakgoldberg"], |
| 76 | + }), |
| 77 | + ], |
| 78 | + }, |
| 79 | +}); |
| 80 | +``` |
| 81 | + |
| 82 | +Running `npx create-typescript-app` in a repository with that configuration file would add `"joshuakgoldberg"` to the `words` in `cspell.json`. |
| 83 | + |
| 84 | +### `blocks` |
| 85 | + |
| 86 | +Any customizations to the Blocks provided by the selected Preset. |
| 87 | + |
| 88 | +#### `add` |
| 89 | + |
| 90 | +Any Blocks to add to what the Preset provides. |
| 91 | + |
| 92 | +For example, this configuration file adds in `create-typescript-app`'s provided "arethetypeswrong" Block: |
| 93 | + |
| 94 | +```ts |
| 95 | +// create-typescript-app.config.js |
| 96 | +import { blockAreTheTypesWrong, createConfig } from "create-typescript-app"; |
| 97 | + |
| 98 | +export default createConfig({ |
| 99 | + refinements: { |
| 100 | + blocks: { |
| 101 | + add: [blockAreTheTypesWrong], |
| 102 | + }, |
| 103 | + }, |
| 104 | +}); |
| 105 | +``` |
| 106 | + |
| 107 | +Running `npx create-typescript-app` in a repository with that configuration file would add in the created outputs from `blockAreTheTypesWrong`. |
| 108 | + |
| 109 | +#### `exclude` |
| 110 | + |
| 111 | +Any Blocks to exclude from what the Preset provides. |
| 112 | + |
| 113 | +For example, this configuration file omits the default _"This package was templated with..."_ notice that comes with `create-typescript-app`: |
| 114 | + |
| 115 | +```ts |
| 116 | +// create-typescript-app.config.js |
| 117 | +import { blockTemplatedBy, createConfig } from "create-typescript-app"; |
| 118 | + |
| 119 | +export default createConfig({ |
| 120 | + refinements: { |
| 121 | + blocks: { |
| 122 | + exclude: [blockTemplatedBy], |
| 123 | + }, |
| 124 | + }, |
| 125 | +}); |
| 126 | +``` |
| 127 | + |
| 128 | +Running `npx create-typescript-app` in a repository with that configuration file would not include that Block, and so its generated README.md would not include the notice. |
| 129 | + |
| 130 | +#### Custom Blocks and Addons |
| 131 | + |
| 132 | +Custom Blocks can provide Addons to any other Blocks, including those provided by the package. |
| 133 | +This allows your repositories to blend in seamlessly with the features provided by your Template. |
| 134 | + |
| 135 | +For example, to add an [`@arethetypeswrong/cli`](https://www.npmjs.com/package/@arethetypeswrong/cli) lint task to the `package.json` file, a repository using the `create-typescript-app` Template could create and use a custom Block: |
| 136 | + |
| 137 | +```ts |
| 138 | +// blockLintAreTheTypesWrong.js |
| 139 | +import { base, blockPackageJson } from "create-typescript-app"; |
| 140 | + |
| 141 | +export const blockLintAreTheTypesWrong = base.createBlock({ |
| 142 | + about: { |
| 143 | + name: "Lint Are The Types Wrong", |
| 144 | + }, |
| 145 | + produce() { |
| 146 | + return { |
| 147 | + addons: [ |
| 148 | + blockPackageJson({ |
| 149 | + properties: { |
| 150 | + devDependencies: { |
| 151 | + "@arethetypeswrong/cli": "0.17.3", |
| 152 | + }, |
| 153 | + scripts: { |
| 154 | + "lint:arethetypeswrong": "attw --pack .", |
| 155 | + }, |
| 156 | + }, |
| 157 | + }), |
| 158 | + ], |
| 159 | + }; |
| 160 | + }, |
| 161 | +}); |
| 162 | +``` |
| 163 | + |
| 164 | +```ts |
| 165 | +// create-typescript-app.config.js |
| 166 | +import { createConfig } from "create-typescript-app"; |
| 167 | + |
| 168 | +import { blockLintAreTheTypesWrong } from "./blockLintAreTheTypesWrong.js"; |
| 169 | + |
| 170 | +export default createConfig({ |
| 171 | + refinements: { |
| 172 | + blocks: { |
| 173 | + add: [blockLintAreTheTypesWrong], |
| 174 | + }, |
| 175 | + }, |
| 176 | +}); |
| 177 | +``` |
0 commit comments