Skip to main content

simple-scaffold

Interfaces

Main

Scaffold

Scaffold(config): Promise<void>

Create a scaffold using given options.

Create files

To create a file structure to output, use any directory and file structure you would like. Inside folder names, file names or file contents, you may place {{ var }} where var is either name which is the scaffold name you provided or one of the keys you provided in the data option.

The contents and names will be replaced with the transformed values so you can use your original structure as a boilerplate for other projects, components, modules, or even single files.

The files will maintain their structure, starting from the directory containing the template (or the template itself if it is already a directory), and will output from that directory into the directory defined by config.output.

Helpers

Helpers are functions you can use to transform your {{ var }} contents into other values without having to pre-define the data and use a duplicated key.

Any functions you provide in helpers option will also be available to you to make custom formatting as you see fit (for example, formatting a date)

For available default values, see DefaultHelpers.

Parameters

NameTypeDescription
configScaffoldConfigThe main configuration object

Returns

Promise<void>

A promise that resolves when the scaffold is complete

See

Defined in

scaffold.ts:58

Config

FileResponseHandler

Ƭ FileResponseHandler<T>: (fullPath: string, basedir: string, basename: string) => T

A function that takes path information about file, and returns a value of type T

Type parameters

NameDescription
TThe return type for the function

Type declaration

▸ (fullPath, basedir, basename): T

Parameters
NameTypeDescription
fullPathstringThe full path of the current file
basedirstringThe directory containing the current file
basenamestringThe name of the file
Returns

T

Defined in

types.ts:322


FileResponse

Ƭ FileResponse<T>: T | FileResponseHandler<T>

Represents a response for file path information. Can either be:

  1. T - static value
  2. A function with the following signature which returns T:
    (fullPath: string, basedir: string, basename: string) => T

See

FileResponseHandler

Type parameters

Name
T

Defined in

types.ts:338


ScaffoldConfigMap

Ƭ ScaffoldConfigMap: Record<string, ScaffoldConfig>

A mapping of scaffold template keys to their configurations.

Each configuration is a ScaffoldConfig object.

The key is the name of the template, and the value is the configuration for that template.

When no template key is provided to the scaffold command, the "default" template is used.

See

ScaffoldConfig

Defined in

types.ts:400


ScaffoldConfigFile

Ƭ ScaffoldConfigFile: AsyncResolver<ScaffoldCmdConfig, ScaffoldConfigMap>

The scaffold config file is either:

Defined in

types.ts:411

Helpers

CaseHelpers

Ƭ CaseHelpers: "camelCase" | "hyphenCase" | "kebabCase" | "lowerCase" | "pascalCase" | "snakeCase" | "startCase" | "upperCase"

The names of the available helper functions that relate to text capitalization.

These are available for subdirHelper.

Helper nameExample codeExample output
[None]{{ name }}my name
camelCase{{ camelCase name }}myName
snakeCase{{ snakeCase name }}my_name
startCase{{ startCase name }}My Name
kebabCase{{ kebabCase name }}my-name
hyphenCase{{ hyphenCase name }}my-name
pascalCase{{ pascalCase name }}MyName
upperCase{{ upperCase name }}MY NAME
lowerCase{{ lowerCase name }}my name

See

Defined in

types.ts:197


DateHelpers

Ƭ DateHelpers: "date" | "now"

The names of the available helper functions that relate to dates.

Helper nameDescriptionExample codeExample output
nowCurrent date with format{{ now "yyyy-MM-dd HH:mm" }}2042-01-01 15:00
now (with offset)Current date with format, and with offset{{ now "yyyy-MM-dd HH:mm" -1 "hours" }}2042-01-01 14:00
dateCustom date with format{{ date "2042-01-01T15:00:00Z" "yyyy-MM-dd HH:mm" }}2042-01-01 15:00
date (with offset)Custom date with format, and with offset{{ date "2042-01-01T15:00:00Z" "yyyy-MM-dd HH:mm" -1 "days" }}2041-31-12 15:00
date (with date from --data)Custom date with format, with data from the data config option{{ date myCustomDate "yyyy-MM-dd HH:mm" }}2042-01-01 12:00

Further details:

  • We use date-fns for parsing/manipulating the dates. If you want more information on the date tokens to use, refer to their format documentation.

  • The date helper format takes the following arguments:

    (
    date: string,
    format: string,
    offsetAmount?: number,
    offsetType?: "years" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds"
    )
  • The now helper (for current time) takes the same arguments, minus the first one (date) as it is implicitly the current date.

See

Defined in

types.ts:244


DefaultHelpers

Ƭ DefaultHelpers: CaseHelpers | DateHelpers

The names of all the available helper functions in templates. Simple-Scaffold provides some built-in text transformation filters usable by Handlebars.js.

For example, you may use {{ snakeCase name }} inside a template file or filename, and it will replace My Name with my_name when producing the final value.

See

Defined in

types.ts:259


Helper

Ƭ Helper: HelperDelegate

Helper function, see https://handlebarsjs.com/guide/#custom-helpers

Defined in

types.ts:266

Logging (const)

LogLevel

Const LogLevel: Object

The amount of information to log when generating scaffold. When not none, the selected level will be the lowest level included.

For example, level info will include info, warning and error, but not debug; and warning will only show warning and error, but not info or debug.

Default

info

Type declaration

NameTypeDescription
none"none"Silent output
debug"debug"Debugging information. Very verbose and only recommended for troubleshooting.
info"info"The regular level of logging. Major actions are logged to show the scaffold progress. Default ts
warning"warning"Warnings such as when file fails to replace token values properly in template.
error"error"Errors, such as missing files, bad replacement token syntax, or un-writable directories.

Defined in

types.ts:280

types.ts:308

Logging (type)

LogLevel

Ƭ LogLevel: typeof LogLevel[keyof typeof LogLevel]

The amount of information to log when generating scaffold. When not none, the selected level will be the lowest level included.

For example, level info will include info, warning and error, but not debug; and warning will only show warning and error, but not info or debug.

Default

info

Defined in

types.ts:280

types.ts:308

Other

ScaffoldCmdConfig

Ƭ ScaffoldCmdConfig: Object

The Scaffold config for CLI Contains less and more specific options than ScaffoldConfig.

For more information about each option, see ScaffoldConfig.

Type declaration

NameTypeDescription
namestringThe name of the scaffold template to use.
templatesstring[]The templates to use for generation
outputstringThe output path to write to
subdirbooleanWhether to create subdir with the input name
subdirHelper?stringDefault transformer to apply to subdir name when using subdir: true
data?Record<string, string>Add custom data to the templates
appendData?Record<string, string>Add custom data to the template in a CLI-friendly syntax (and not JSON)
overwritebooleanEnable to override output files, even if they already exist
quietbooleanSilence logs, same as logLevel: "none"
logLevelLogLevelDetermine amount of logs to display. See LogLevel
dryRunbooleanDon'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.
config?stringConfig file path to use
key?stringThe key of the template to use
git?stringThe git repository to use to fetch the config file
versionbooleanDisplay version
beforeWrite?stringRun a script before writing the files. This can be a command or a path to a file. The file contents will be passed to the given command.

Defined in

types.ts:346


ListCommandCliOptions

Ƭ ListCommandCliOptions: Pick<ScaffoldCmdConfig, "config" | "git" | "logLevel" | "quiet">

Defined in

types.ts:431


default

Renames and re-exports Scaffold