DKCutter provides several built-in variables that you can leverage within your project templates, hooks, and even the dkcutter.json
configuration file. These variables offer dynamic information and functionalities to enhance your project generation process.
There are two primary ways to access global variables in DKCutter:
dkcutter.<variable>
: Use this syntax to access specific DKCutter variables within your project templates and hooks (JavaScript or TypeScript).colors
: This special variable provides color functionality for styling prompts in your dkcutter.json
configuration.DKCutter offers the following built-in variables:
dkcutter.pkgManager
: Returns the package manager used to execute DKCutter (possible values: npm
, yarn
, pnpm
, or bun
).
dkcutter.now
: Provides the current date and time as a JavaScript Date
object. You can use the standard date object methods to manipulate this value (refer to the JavaScript Date constructor documentation for details).
Example: Using dkcutter.now
in dkcutter.json
In this example, the promptMessage
dynamically incorporates the current date using the toLocaleDateString()
method.
dkcutter.update
: This function allows you to modify existing context values during project generation. It takes three arguments:
templates in context
documentation for details), or another variable.true
if you want the function to return the updated value.Example: Updating a Context Variable in a Hook
This code snippet demonstrates how to update the domainName
context variable by removing leading and trailing whitespace using the trim
filter.
dkcutter.add
: This function adds new key-value pairs to the context during project generation. It takes three arguments:
true
if you want the function to return the added value.Example: Adding a Context Variable in a Hook
This code snippet adds a new context variable named authorName
with the value "Your Name"
.
The colors
variable provides access to color functionality for styling prompts within your dkcutter.json
configuration file. It utilizes the colorette
library.
In this example, the promptMessage
uses the colors.blue('license')
expression to style the word "license" in blue, enhancing the readability and user experience of the prompt.
By effectively utilizing these global variables, you can streamline your DKCutter project