DKCutter provides powerful templating capabilities within the values (not the keys) of your dkcutter.json
configuration file. This allows you to dynamically generate values based on user input, creating more intelligent and user-friendly project setups. By leveraging Nunjucks templating, you can derive context values from previously answered prompts, significantly reducing repetitive user input and providing more sensible defaults.
When DKCutter processes your dkcutter.json
file, it treats the values as Nunjucks templates. As the user responds to prompts, those answers are immediately added to the template context. This means subsequent values can reference and transform earlier responses.
Consider this dkcutter.json
snippet:
Here's how this works in practice:
User Accepts Default Project Name: If the user accepts the default projectName
("My New Project") or uses the -y
or --default
flag to skip prompts, DKCutter will evaluate the projectSlug
template as follows:
{{ projectName }}
resolves to "My New Project".|lower
converts the string to lowercase: "my new project".|replace(' ', '-')
replaces spaces with hyphens: "my-new-project".|trim
removes any leading or trailing whitespace (which isn't present in this example).The final value of projectSlug
becomes my-new-project
.
User Provides a Custom Project Name: If the user enters a different project name, such as "Yet Another New Project", the same templating process occurs:
{{ projectName }}
resolves to "Yet Another New Project".|lower
converts the string to lowercase: "yet another new project".|replace(' ', '-')
replaces spaces with hyphens: "yet-another-new-project".|trim
removes any leading or trailing whitespace.The resulting projectSlug
is yet-another-new-project
.
This simple example demonstrates how you can automatically generate a URL-friendly project slug based on the project name, saving the user from having to manually enter it. This approach can be extended to more complex scenarios, further enhancing the user experience and streamlining project setup.