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:

  1. config.js
  2. config.cjs
  3. config.mjs
  4. 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 %>
Edit this page on GitHub

Last edited on

Copyright © 2022 wadackel

Released under the MIT License

Built with Next.js

Source Code