-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: implement shadcn-ui autocomplete
- Loading branch information
1 parent
f308f78
commit 2e04ad4
Showing
1 changed file
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
const completionSpec: Fig.Spec = { | ||
name: "shadcn-ui", | ||
description: "Add shadcn-ui components to your project", | ||
subcommands: [ | ||
{ | ||
name: "init", | ||
description: "Configure your Next.js project", | ||
options: [ | ||
{ | ||
name: ["--yes", "-y"], | ||
description: "Skip confirmation prompt", | ||
}, | ||
{ | ||
name: ["--help", "-h"], | ||
description: "Display help for command", | ||
}, | ||
], | ||
}, | ||
{ | ||
name: "add", | ||
description: "Add components to your project", | ||
args: { | ||
name: "component", | ||
description: "Names of components", | ||
isVariadic: true, | ||
generators: { | ||
script: "curl -s https://ui.shadcn.com/api/components", | ||
postProcess(out) { | ||
const registry = JSON.parse(out); | ||
if (!registry) { | ||
return []; | ||
} | ||
|
||
if (!Array.isArray(registry)) { | ||
return []; | ||
} | ||
|
||
if ( | ||
registry.some((component) => typeof component.name !== "string") | ||
) { | ||
return []; | ||
} | ||
|
||
return registry.map((component: { name: string }) => { | ||
const suggestion: Fig.Suggestion = { | ||
name: component.name, | ||
}; | ||
|
||
return suggestion; | ||
}); | ||
}, | ||
}, | ||
}, | ||
options: [ | ||
{ | ||
name: ["--yes", "-y"], | ||
description: "Skip confirmation prompt", | ||
}, | ||
{ | ||
name: ["--overwrite", "-o"], | ||
description: "Overwrite existing files", | ||
}, | ||
{ | ||
name: ["--cwd", "-c"], | ||
description: | ||
"The working directory. defaults to the current directory", | ||
}, | ||
{ | ||
name: ["--path", "-p"], | ||
description: "The path to add the component to", | ||
}, | ||
{ | ||
name: ["--help", "-h"], | ||
description: "Display help for command", | ||
}, | ||
], | ||
}, | ||
{ | ||
name: "help", | ||
description: "Display help for command", | ||
subcommands: [ | ||
{ | ||
name: "my_nested_subcommand", | ||
description: | ||
"Nested subcommand, example usage: 'shadcn-ui my_subcommand my_nested_subcommand'", | ||
}, | ||
], | ||
}, | ||
], | ||
options: [ | ||
{ | ||
name: ["--version", "-v"], | ||
description: "Display the version number", | ||
}, | ||
{ | ||
name: ["--help", "-h"], | ||
description: "Display help for command", | ||
}, | ||
], | ||
// Only uncomment if shadcn-ui takes an argument | ||
// args: {} | ||
}; | ||
|
||
export default completionSpec; |