-
-
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.
feat: add spec for shadcn-ui (#2019)
- Loading branch information
Showing
1 changed file
with
106 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,106 @@ | ||
interface RegistryItem { | ||
name: string; | ||
dependencies: string[]; | ||
files: string[]; | ||
type: string; | ||
} | ||
|
||
const componentGenerator: Fig.Generator = { | ||
custom: async (_tokens, executeShellCommand) => { | ||
const json = await executeShellCommand( | ||
`curl -sL 'https://raw.githubusercontent.com/shadcn/ui/main/apps/www/public/registry/index.json'` | ||
); | ||
const components = JSON.parse(json) as RegistryItem[]; | ||
return components.map((component) => ({ | ||
name: component.name, | ||
description: component.type, | ||
priority: 50, | ||
icon: "fig://icon?type=box", | ||
})); | ||
}, | ||
}; | ||
|
||
const completionSpec: Fig.Spec = { | ||
name: "shadcn-ui", | ||
description: "Shadcn UI CLI", | ||
subcommands: [ | ||
{ | ||
name: "add", | ||
description: "Add a component to your project", | ||
args: { | ||
name: "components", | ||
description: "The components to add", | ||
isVariadic: true, | ||
generators: componentGenerator, | ||
}, | ||
options: [ | ||
{ | ||
name: ["-y", "--yes"], | ||
description: "Skip confirmation prompt", | ||
}, | ||
{ | ||
name: ["-o", "--overwrite"], | ||
description: "Overwrite existing files", | ||
}, | ||
{ | ||
name: ["-c", "--cwd"], | ||
description: | ||
"The working directory. defaults to the current directory", | ||
args: { | ||
name: "cwd", | ||
}, | ||
}, | ||
{ | ||
name: ["-p", "--path"], | ||
description: "The path to add the component to", | ||
args: { | ||
name: "path", | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
name: "diff", | ||
description: "Check for updates against the registry", | ||
args: { | ||
name: "component", | ||
description: "The component name", | ||
generators: componentGenerator, | ||
}, | ||
options: [ | ||
{ | ||
name: ["-y", "--yes"], | ||
description: "Skip confirmation prompt", | ||
}, | ||
{ | ||
name: ["-c", "--cwd"], | ||
description: | ||
"The working directory. defaults to the current directory", | ||
args: { | ||
name: "cwd", | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
name: "init", | ||
description: "Initialize your project and install dependencies", | ||
options: [ | ||
{ | ||
name: ["-y", "--yes"], | ||
description: "Skip confirmation prompt", | ||
}, | ||
{ | ||
name: ["-c", "--cwd"], | ||
description: | ||
"The working directory. defaults to the current directory", | ||
args: { | ||
name: "cwd", | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
export default completionSpec; |