execute-package
Learn how to run a package command.
This action runs a package command using the project's package manager, such as npx for npm, pnpx for pnpm, or the equivalent for other managers.
Example
The following template scaffolds a new project using a package command:
{ "$schema": "https://schema.croct.com/json/v1/template.json", "title": "Project scaffold", "description": "Creates a new project using giget.", "options": { "name": { "type": "string", "description": "The project name.", "default": "my-project" } }, "actions": [ { "name": "execute-package", "command": "giget@latest", "arguments": [ "gh:user/starter", "${options.name}" ] } ]}You can pass the project name using the --name flag:
npx croct@latest use template.json5 --name my-appInteractive commands
Some commands display interactive prompts that require user input. Use interactions to automate responses so the template can run without manual intervention:
{ "$schema": "https://schema.croct.com/json/v1/template.json", "title": "Add components", "description": "Adds UI components using shadcn.", "actions": [ { "name": "execute-package", "command": "shadcn@latest", "arguments": [ "add", "button", "card" ], "interactions": [ { "when": "Would you like to overwrite?", "then": ["y"], "always": true }, { "when": "(Created|Skipped) \\d+ files?", "pattern": true, "final": true } ] } ]}The first rule answers "y" every time the overwrite prompt appears. The second rule uses a regular expression to detect when the command finishes and signals the end of interaction.
Project scripts
Set script to true to run a project script instead of a package binary:
{ "$schema": "https://schema.croct.com/json/v1/template.json", "title": "Seed database", "description": "Runs the database seed script.", "actions": [ { "name": "install" }, { "name": "execute-package", "command": "seed", "script": true, "arguments": ["--force"] } ]}Properties
These are the supported properties:
- namestring
The action identifier. Always execute-package for this action.
- commandstring
The package or script name to run.
For packages, this supports version specifiers like giget@latest. For scripts, this is the name defined in the project's package.json.
- arguments(optional)Array<string>
The arguments to pass to the command.
- script(optional)boolean
Whether to treat the command as a project script.
Default:false- runner(optional)string
The package manager to use for running the command.
Defaults to the package manager detected from the project. Supported values are npm, yarn, pnpm, and bun.
- interactions(optional)Array<object>|boolean
Automated responses to interactive prompts.
Set to true to pass through all I/O directly to the terminal, or provide a list of interaction rules.
Rules are evaluated in order against the command output. At least one rule must have final set to true.
- whenstring
The text to match against the command output.
When pattern is true, this is interpreted as a regular expression.
- then(optional)Array<string>
The responses to send when the prompt matches.
Each value is sent as literal text, except for the following special keystrokes:
Keystroke Description [enter] Enter [space] Space [up] Arrow up [down] Arrow down [left] Arrow left [right] Arrow right [backspace] Backspace Either then or final must be specified.
- pattern(optional)boolean
Whether when is a regular expression.
Default:false- always(optional)boolean
Whether to respond every time the prompt appears.
By default, each rule matches only once. Cannot be combined with final.
Default:false- final(optional)boolean
Whether to stop accepting input after this match.
At least one rule in the list must be final. Either then or final must be specified.
Default:false
- when
- output(optional)string
The variable name to store the command output.
Cannot be used when interactions is true.