Skip to content

Commit

Permalink
feat: add spec for shadcn-ui (#2019)
Browse files Browse the repository at this point in the history
  • Loading branch information
neo773 authored Jul 25, 2023
1 parent 9177aa5 commit ee7fb19
Showing 1 changed file with 106 additions and 0 deletions.
106 changes: 106 additions & 0 deletions src/shadcn-ui.ts
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;

0 comments on commit ee7fb19

Please sign in to comment.