Skip to main content

Interface: ScaffoldConfig

The config object for defining a scaffolding group.

See

Properties

name

name: string

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

Defined in

types.ts:19


templates

templates: string[]

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

Defined in

types.ts:32


output

output: FileResponse<string>

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

Defined in

types.ts:42


subdir

Optional subdir: boolean

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

Defined in

types.ts:52


data

Optional data: Record<string, any>

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.

Defined in

types.ts:59


overwrite

Optional overwrite: FileResponse<boolean>

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

Default

false

Defined in

types.ts:74


logLevel

Optional logLevel: LogLevel

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)

Defined in

types.ts:86


dryRun

Optional dryRun: boolean

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

Defined in

types.ts:94


helpers

Optional helpers: Record<string, HelperDelegate>

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

Defined in

types.ts:136


subdirHelper

Optional subdirHelper: string

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

Defined in

types.ts:147

Methods

beforeWrite

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

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

NameTypeDescription
contentBufferThe original template after token replacement
rawContentBufferThe original template before token replacement
outputPathstringThe final output path of the processed file

Returns

undefined | string | Buffer | Promise<undefined | string | Buffer>

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

Defined in

types.ts:163