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
Name | Type | Description |
---|---|---|
config | ScaffoldConfig | The main configuration object |
Returns
Promise
<void
>
A promise that resolves when the scaffold is complete
See
Defined in
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
Name | Description |
---|---|
T | The return type for the function |
Type declaration
▸ (fullPath
, basedir
, basename
): T
Parameters
Name | Type | Description |
---|---|---|
fullPath | string | The full path of the current file |
basedir | string | The directory containing the current file |
basename | string | The name of the file |
Returns
T
Defined in
FileResponse
Ƭ FileResponse<T
>: T
| FileResponseHandler
<T
>
Represents a response for file path information. Can either be:
T
- static value- A function with the following signature which returns
T
:(fullPath: string, basedir: string, basename: string) => T
See
Type parameters
Name |
---|
T |
Defined in
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
Defined in
ScaffoldConfigFile
Ƭ ScaffoldConfigFile: AsyncResolver
<ScaffoldCmdConfig
, ScaffoldConfigMap
>
The scaffold config file is either:
- A ScaffoldConfigMap object
- A function that returns a ScaffoldConfigMap object
- A promise that resolves to a ScaffoldConfigMap object
- A function that returns a promise that resolves to a ScaffoldConfigMap object
Defined in
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 name | Example code | Example 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
DateHelpers
Ƭ DateHelpers: "date"
| "now"
The names of the available helper functions that relate to dates.
Helper name | Description | Example code | Example output |
---|---|---|---|
now | Current 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 |
date | Custom 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
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
Helper
Ƭ Helper: HelperDelegate
Helper function, see https://handlebarsjs.com/guide/#custom-helpers
Defined in
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
Name | Type | Description |
---|---|---|
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
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
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
Name | Type | Description |
---|---|---|
name | string | The name of the scaffold template to use. |
templates | string [] | The templates to use for generation |
output | string | The output path to write to |
subdir | boolean | Whether to create subdir with the input name |
subdirHelper? | string | Default 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) |
overwrite | boolean | Enable to override output files, even if they already exist |
quiet | boolean | Silence logs, same as logLevel: "none" |
logLevel | LogLevel | Determine amount of logs to display. See LogLevel |
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. |
config? | string | Config file path to use |
key? | string | The key of the template to use |
git? | string | The git repository to use to fetch the config file |
version | boolean | Display version |
beforeWrite? | string | Run 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
ListCommandCliOptions
Ƭ ListCommandCliOptions: Pick
<ScaffoldCmdConfig
, "config"
| "git"
| "logLevel"
| "quiet"
>
Defined in
default
Renames and re-exports Scaffold