Configuration
Running the Migration mode in an existing repository will re-run create
on that repository.
You can store persistent customizations to the repository’s template in a configuration file named create.config.js
.
It should export default
a call to a createConfig()
function that takes in a template and which preset to use.
For example, keeping a repository up-to-date with create-typescript-app
’s everything preset:
import { createConfig } from "create";import { template } from "create-typescript-app";
export default createConfig(template, { preset: "everything" });
Running npx create
in a repository with that create.config.js
would be the equivalent of running npx create typescript-app@beta --preset everything
.
createConfig
The exported createConfig
function takes in up to two arguments:
- (required) A preset imported from a package
- (optional) An object containing any customizations to be applied to the preset
addons
Any Addons to be passed to the Blocks that come with the Preset. These will be merged in with Addons provided by other Blocks.
For example, this configuration file adds the word "arethetypeswrong"
to a CSpell Block’s Addons:
import { createConfig } from "create";import { blockCSpell, template } from "create-typescript-app";
export default createConfig(template, { addons: [ blockCSpell({ words: ["arethetypeswrong"], }), ], preset: "everything",});
Running npx create
in a repository with that configuration file would merge in that words
to the Addons provided to its CSpell Block.
blocks
Any customizations to the Blocks provided as part of the Preset.
add
Any Blocks to add to what the Preset provides.
For example, this configuration file adds in an “arethetypeswrong” Block alongside existing Blocks provided by create-typescript-app
:
import { createConfig } from "create";import { blockAreTheTypesWrong, template } from "create-typescript-app";
export default createConfig(template, { blocks: { add: [blockAreTheTypesWrong], }, preset: "everything",});
Running npx create
in a repository with that configuration file would add in the created outputs from blockAreTheTypesWrong
.
exclude
Any Blocks to exclude from what the Preset provides.
For example, this configuration file omits the default “This package was templated with…” notice that comes with create-typescript-app
:
import { createConfig } from "create";import { blockTemplatedBy, template } from "create-typescript-app";
export default createConfig(template, { blocks: { exclude: [blockTemplatedBy], }, preset: "everything",});
Running npx create
in a repository with that configuration file would not include that Block, and so its generated README.md would not include the notice.
Custom Blocks
Configurations can use Blocks beyond those included in Template Presets.
Some Templates provide Blocks that can be opted into using blocks
> add
.
Templates that export their Base also allow configurations to create and include their own, custom Blocks. See Templating Engine for documentation on creating Blocks.
For example, this custom Block adds a Wallaby configuration file:
import { base, blockPackageJson } from "create-typescript-app";
export const blockWallabyConfig = base.createBlock({ about: { name: "Wallaby Config", }, produce() { return { files: { "wallaby.js": `module.exports = function () { return { reportConsoleErrorAsError: true, };};`, }, }; },});
import { createConfig } from "create";import { template } from "create-typescript-app";
import { blockWallabyConfig } from "./blockWallabyConfig.js";
export default createConfig(template, { blocks: { add: [blockWallabyConfig], }, preset: "everything",});
Custom Blocks and Addons
Custom Blocks can provide Addons to any other Blocks, including those provided by the package. This allows your repositories to blend in seamlessly with the features provided by your Template.
For example, to add an @arethetypeswrong/cli
lint task to the package.json
file, a repository using the create-typescript-app
Template could create and use a custom Block:
import { base, blockPackageJson } from "create-typescript-app";
export const blockLintAreTheTypesWrong = base.createBlock({ about: { name: "Lint Are The Types Wrong", }, produce() { return { addons: [ blockPackageJson({ properties: { devDependencies: { "@arethetypeswrong/cli": "0.17.3", }, scripts: { "lint:arethetypeswrong": "attw --pack .", }, }, }), ], }; },});
import { createConfig } from "create";import { template } from "create-typescript-app";
import { blockLintAreTheTypesWrong } from "./blockLintAreTheTypesWrong.js";
export default createConfig(template, { blocks: { add: [blockLintAreTheTypesWrong], }, preset: "everything",});
See the documentation of your Template for what Blocks are available and with what Addons.