Config
scaffdog uses the object exported in .scaffdog/config.js
as the configuration.
Configuration File Formats#
scaffdog supports CommonJS, ESM and TypeScript configuration file formats.
The names of configuration files are searched in the following order:
config.js
config.cjs
config.mjs
config.ts
An example of a configuration file definition is as follows:
CommonJS:
module.exports = {/* ... */};
ESM/TypeScript:
export default {/* ... */};
Simple Configuration#
In the files
field, specify the path pattern of the document used by scaffdog. The files
field is required.
export default {files: ['*'],};
Global Variables#
You can define the global variables available in the template in the variables
field.
export default {files: ['*'],variables: {key: 'value',},};
Custom Helpers#
You can define the custom helpers available in the template in the helpers
field.
export default {files: ['*'],helpers: [// Using Key-Value{trim: (context, value) => value.trim(),},// Using Helper Registry(registry) => {registry.set('padstart', (context, value, size, str) =>value.padStart(size, str || ' '),);registry.set('padend', (context, value, size, str) =>value.padEnd(size, str || ' '),);},],};
The context
passed to the first argument of the helper function has the following structure.
type Variable =| undefined| null| string| number| boolean| { [key in string]: Variable }| Variable[];type VariableMap = Map<string, Variable>;type Helper<T extends any[] = any[]> = (context: Context,...args: T) => string | Helper | Variable;type HelperMap = Map<string, Helper>;type TagPair = Readonly<[open: string, close: string]>;type Context = {cwd: string;variables: VariableMap;helpers: HelperMap;tags: TagPair;};
Custom Tags#
The default tag delimiter available in templates is {{
and }}
.
You can change it with tags
.
export default {files: ['*'],tags: ['<%', '%>'],};
By setting the above config, <%
and %>
will be the tag delimiters in the template.
<% inputs.name %>
Last edited on