Skip to content

Commit

Permalink
feature: implement shadcn-ui autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobparis committed Jul 2, 2023
1 parent f308f78 commit 2e04ad4
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions src/shadcn-ui.ts
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;

0 comments on commit 2e04ad4

Please sign in to comment.