Skip to content

Commit

Permalink
cli: use new shadcn CLI (#1182)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Nov 19, 2024
1 parent f69a62d commit 4a55849
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 217 deletions.
7 changes: 2 additions & 5 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
"dependencies": {
"chalk": "^5.3.0",
"commander": "^12.1.0",
"cosmiconfig": "^9.0.0",
"cross-spawn": "^7.0.5",
"shadcn-ui": "0.8.0",
"tsconfig-paths": "^4.2.0",
"zod": "^3.23.8"
"cross-spawn": "^7.0.5"
},
"devDependencies": {
"@assistant-ui/tsconfig": "workspace:*",
"@types/cross-spawn": "^6.0.6",
"@types/node": "^22.9.0",
"eslint-config-next": "15.0.3",
"tsup": "8.3.5"
},
"files": [
Expand Down
84 changes: 0 additions & 84 deletions packages/cli/src/commands/add.ts

This file was deleted.

42 changes: 42 additions & 0 deletions packages/cli/src/commands/shadcn/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Command } from "commander";
import { spawn } from "cross-spawn";

export const shadcnAdd = new Command()
.name("add")
.description("add a component to your project")
.argument("<components...>", "the components to add")
.option("-y, --yes", "skip confirmation prompt.", true)
.option("-o, --overwrite", "overwrite existing files.", false)
.option(
"-c, --cwd <cwd>",
"the working directory. defaults to the current directory.",
process.cwd(),
)
.option("-p, --path <path>", "the path to add the component to.")
.action(async (components: string[], opts) => {
const componentsToAdd = components.map(
(c) => `"https://r.assistant-ui.com/shadcn/${c}"`,
);

const args = [`shadcn@latest`, "add", ...componentsToAdd];

if (opts.yes) args.push("--yes");
if (opts.overwrite) args.push("--overwrite");
if (opts.cwd) args.push("--cwd", opts.cwd);
if (opts.path) args.push("--path", opts.path);

const child = spawn("npx", args, {
stdio: "inherit",
shell: true,
});

child.on("error", (error) => {
console.error(`Error: ${error.message}`);
});

child.on("close", (code) => {
if (code !== 0) {
console.log(`other-package-script process exited with code ${code}`);
}
});
});
4 changes: 2 additions & 2 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env node

import { add } from "@/src/commands/add";
import { Command } from "commander";

import packageJson from "../package.json";
import { create } from "./commands/create";
import { shadcnAdd } from "./commands/shadcn/add";

process.on("SIGINT", () => process.exit(0));
process.on("SIGTERM", () => process.exit(0));
Expand All @@ -19,7 +19,7 @@ async function main() {
"display the version number",
);

program.addCommand(add);
program.addCommand(shadcnAdd);
program.addCommand(create);

program.parse();
Expand Down
18 changes: 0 additions & 18 deletions packages/cli/src/utils/get-component-target-path.ts

This file was deleted.

92 changes: 0 additions & 92 deletions packages/cli/src/utils/get-config.ts

This file was deleted.

16 changes: 0 additions & 16 deletions packages/cli/src/utils/resolve-import.ts

This file was deleted.

28 changes: 28 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4a55849

Please sign in to comment.