locate-path
Learn how to find files matching a pattern.
This action finds files matching a glob pattern and stores the paths in a variable.
It is useful for discovering configuration files, checking whether a path exists before creating it, or finding source files to patch.
Example
The following template locates the project's layout file and prints its path:
{ "$schema": "https://schema.croct.com/json/v1/template.json", "title": "Layout finder", "description": "Finds the root layout file.", "actions": [ { "name": "locate-path", "path": "src/**/layout.{tsx,jsx}", "depth": 3, "limit": 1, "result": "layoutFiles" }, { "name": "print", "semantics": "info", "message": "Layout file: ${this.layoutFiles[0]}" } ]}To apply this template, run:
npx croct@latest use template.json5Properties
These are the supported properties:
- namestring
The action identifier. Always locate-path for this action.
- pathstring
The glob pattern to match against file paths.
For example, **/*.ts matches all TypeScript files and src/components/*.tsx matches TSX files in a specific directory.
- resultstring
The variable name to store the list of matching file paths.
The result is a list of strings, where each entry is a relative path to a matched file.
- limit(optional)number
The maximum number of results to return.
Must be a positive integer.
- depth(optional)number
The maximum directory depth to search.
A depth of 0 matches only files in the current directory.
- matcher(optional)object
A content matcher to filter files by their content.
The following examples show a pattern matcher that matches files containing a default function export, and a combination matcher that requires both a React import and a default export in the same file:
{ "pattern": "export default function", "caseSensitive": true}- patternstring
The regular expression to match against the file content.
For pattern matchers, specify this with caseSensitive.
- caseSensitive(optional)boolean
Whether the pattern matching is case-sensitive.
For pattern matchers, use this with pattern.
Default:false- typestring
The logical operator to apply.
Use and to require all nested matchers to match within the same file, or or to match files that satisfy at least one. For combination matchers, specify this with matchers.
- matchersArray<object>
The list of nested matchers to combine.
Each entry can be a pattern matcher or another combination matcher, allowing nested conditions. For combination matchers, specify this with type.
- pattern