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.

Default

Current working directory

Defined in

types.ts:27


output

output: FileResponse<string>

Path to output to. If subdir is true, the subfolder 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:37


subdir

Optional subdir: boolean

Whether to create subfolder 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:47


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:54


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:69


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:81


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:89


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:131


subdirHelper

Optional subdirHelper: string

Default transformer to apply to subfolder 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:142

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:158