# ScaffoldConfig | Simple Scaffold
Defined in14

Skip to main content

# `ScaffoldConfig`

Defined in: types.ts:14

The config object for defining a scaffolding group.

## See​

- Node.js usage
- CLI usage
- DefaultHelpers
- CaseHelpers
- DateHelpers

## Properties​

### name​

> name: `string`

Defined in: types.ts:19

Name to be passed to the generated files. `{{name}}` and `{{Name}}` inside contents and file names will be replaced accordingly.

### templates​

> templates: `string`[]

Defined in: types.ts:32

Template files to use as input. You may provide multiple files, each of which can be a relative or absolute path, or a glob pattern for multiple file matching easily.

You may omit files from output by prepending a `!` to their glob pattern.

For example, `["components/**", "!components/README.md"]` will include everything in the directory `components` except the `README.md` file inside.

#### Default​

    Current working directory

### output​

> output: `FileResponse`<`string`>

Defined in: types.ts:42

Path to output to. If `subdir` is `true`, the subdir will be created inside this path.

May also be a FileResponseHandler which returns a new output path to override the default one.

#### See​

- FileResponse
- FileResponseHandler

### subdir?​

> `optional` subdir?: `boolean`

Defined in: types.ts:52

Whether to create subdir with the input name.

When `true`, you may also use subdirHelper to determine a pre-process helper on the directory name.

#### Default​

`false`

### data?​

> `optional` data?: `Record`<`string`, `unknown`>

Defined in: types.ts:59

Add custom data to the templates. By default, only your app name is included as `{{name}}` and `{{Name}}`.

This can be any object that will be usable by Handlebars.

### overwrite?​

> `optional` overwrite?: `FileResponse`<`boolean`>

Defined in: types.ts:74

Enable to override output files, even if they already exist.

You may supply a function to this option, which can take the arguments `(fullPath, baseDir, baseName)` and returns a boolean for each file.

May also be a FileResponseHandler which returns a boolean value per file.

#### See​

- FileResponse
- FileResponseHandler

#### Default​

`false`

### logLevel?​

> `optional` logLevel?: `LogLevel`

Defined in: types.ts:86

Determine amount of logs to display.

The values are: `0 (none) | 1 (debug) | 2 (info) | 3 (warn) | 4 (error)`. The provided level will display messages of the same level or higher.

#### See​

LogLevel

#### Default​

`2 (info)`

### dryRun?​

> `optional` dryRun?: `boolean`

Defined in: types.ts:94

Don't emit files. This is good for testing your scaffolds and making sure they don't fail, without having to write actual file contents or create directories.

#### Default​

`false`

### helpers?​

> `optional` helpers?: `Record`<`string`, `HelperDelegate`>

Defined in: types.ts:136

Additional helpers to add to the template parser. Provide an object whose keys are the name of the function to add, and the value is the helper function itself. The signature of helpers is as follows:

    (text: string, ...args: any[]) => string

A full example might be:

    Scaffold({
      //...
      helpers: {
        upperKebabCase: (text) => kebabCase(text).toUpperCase()
      }
    })

Which will allow:

    {{ upperKebabCase "my value" }}

To transform to:

    MY-VALUE

See DefaultHelpers for a list of all the built-in available helpers.

Simple Scaffold uses Handlebars.js, so all the syntax from there is supported. See their docs for more information.

#### See​

- DefaultHelpers
- CaseHelpers
- DateHelpers
- Templates

### subdirHelper?​

> `optional` subdirHelper?: `string`

Defined in: types.ts:147

Default transformer to apply to subdir name when using `subdir: true`. Can be one of the default capitalization helpers, or a custom one you provide to `helpers`. Defaults to `undefined`, which means no transformation is done.

#### See​

- subdir
- CaseHelpers
- DefaultHelpers

### inputs?​

> `optional` inputs?: `Record`<`string`, `ScaffoldInput`>

Defined in: types.ts:190

Defines interactive inputs for the template. Each input becomes a template data variable.

When running interactively, required inputs that are not already provided via `data` or CLI args will be prompted for. Optional inputs without a value will use their `default` if defined.

#### Example​

    Scaffold({
      // ...
      inputs: {
        author: { message: "Author name", required: true },
        license: { message: "License", default: "MIT" },
      },
    })

In templates: `{{ author }}`, `{{ license }}`

#### See​

ScaffoldInput

### afterScaffold?​

> `optional` afterScaffold?: `AfterScaffoldHook`

Defined in: types.ts:213

A callback or shell command that runs after all files have been written.

When provided as a function (Node.js API), it receives a context object with the scaffold config and the list of files that were written:

    Scaffold({
      // ...
      afterScaffold: async ({ config, files }) => {
        console.log(`Created ${files.length} files`)
        execSync("npm install", { cwd: config.output })
      },
    })

When provided as a string (CLI `--after` flag), it is executed as a shell command in the output directory after scaffolding completes.

#### See​

AfterScaffoldContext

## Methods​

### beforeWrite()?​

> `optional` beforeWrite(`content`, `rawContent`, `outputPath`): `string` | `Buffer`<`ArrayBufferLike`> | `Promise`<`string` | `Buffer`<`ArrayBufferLike`> | `undefined`> | `undefined`

Defined in: types.ts:163

This callback runs right before content is being written to the disk. If you supply this function, you may return a string that represents the final content of your file, you may process the content as you see fit. For example, you may run formatters on a file, fix output in edge-cases not supported by helpers or data, etc.

If the return value of this function is `undefined`, the original content will be used.

#### Parameters​

##### content​

`Buffer`

The original template after token replacement

##### rawContent​

`Buffer`

The original template before token replacement

##### outputPath​

`string`

The final output path of the processed file

#### Returns​

`string` | `Buffer`<`ArrayBufferLike`> | `Promise`<`string` | `Buffer`<`ArrayBufferLike`> | `undefined`> | `undefined`

The final output of the file contents-only, after further modifications - or `undefined` to use the original content (i.e. `content.toString()`)