@marv3l/canopy-ui 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +59 -30
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -13,28 +13,33 @@ import pc from "picocolors";
13
13
 
14
14
  // src/registry.ts
15
15
  var REGISTRY = {
16
- // Toast component registration
17
16
  toast: {
18
- name: "Custom Toast Notification System",
19
- // Packages to automatically install in consumer project
20
- dependencies: ["lucide-react", "clsx", "tailwind-merge"],
17
+ name: "Toast",
18
+ packageName: "@canopy-ui/toast",
19
+ // Your published npm package name
20
+ dependencies: ["lucide-react"],
21
21
  files: [
22
22
  {
23
- templatePath: "toast/toast.tsx",
24
- targetName: "toast.tsx"
25
- },
26
- {
27
- templatePath: "toast/use-toast.ts",
28
- targetName: "use-toast.ts"
23
+ targetName: "toast.tsx",
24
+ content: `"use client";
25
+
26
+ export * from "@canopy-ui/toast";`
29
27
  }
30
28
  ]
31
29
  }
32
- // Future components (dialog, sheet, dropdown) are added here
33
30
  };
34
31
 
35
32
  // src/commands/add.ts
36
33
  var __filename = fileURLToPath(import.meta.url);
37
34
  var __dirname = path.dirname(__filename);
35
+ async function detectPackageManager(projectRoot) {
36
+ if (await fs.pathExists(path.join(projectRoot, "pnpm-lock.yaml"))) return "pnpm";
37
+ if (await fs.pathExists(path.join(projectRoot, "yarn.lock"))) return "yarn";
38
+ if (await fs.pathExists(path.join(projectRoot, "bun.lockb")) || await fs.pathExists(path.join(projectRoot, "bun.lock"))) {
39
+ return "bun";
40
+ }
41
+ return "npm";
42
+ }
38
43
  async function add(componentKeys) {
39
44
  p.intro(pc.bgCyan(pc.black(" Canopy UI ")));
40
45
  let selected = componentKeys;
@@ -55,6 +60,7 @@ async function add(componentKeys) {
55
60
  selected = response;
56
61
  }
57
62
  const projectRoot = process.cwd();
63
+ const pkgManager = await detectPackageManager(projectRoot);
58
64
  const hasSrc = await fs.pathExists(path.join(projectRoot, "src"));
59
65
  const targetDir = hasSrc ? path.join(projectRoot, "src", "components", "ui") : path.join(projectRoot, "components", "ui");
60
66
  await fs.ensureDir(targetDir);
@@ -65,35 +71,58 @@ async function add(componentKeys) {
65
71
  p.log.error(`Component "${key}" was not found in registry.`);
66
72
  continue;
67
73
  }
68
- spinner2.start(`Copying ${meta.name} source files...`);
74
+ spinner2.start(`Setting up ${meta.name}...`);
75
+ const allDependencies = [
76
+ ...meta.packageName ? [meta.packageName] : [],
77
+ ...meta.dependencies || []
78
+ ];
79
+ if (allDependencies.length > 0) {
80
+ spinner2.message(
81
+ `Installing packages (${pc.cyan(pkgManager)}): ${pc.dim(allDependencies.join(", "))}...`
82
+ );
83
+ const installArgs = {
84
+ npm: ["install", ...allDependencies],
85
+ pnpm: ["add", ...allDependencies],
86
+ yarn: ["add", ...allDependencies],
87
+ bun: ["add", ...allDependencies]
88
+ }[pkgManager];
89
+ try {
90
+ await execa(pkgManager, installArgs, {
91
+ cwd: projectRoot,
92
+ stdio: "pipe"
93
+ });
94
+ } catch (err) {
95
+ spinner2.stop(pc.red(`Failed to install dependencies for ${meta.name}`));
96
+ p.log.error(String(err));
97
+ continue;
98
+ }
99
+ }
100
+ spinner2.message(`Creating component stub for ${meta.name}...`);
69
101
  for (const file of meta.files) {
70
- const srcPath = path.resolve(__dirname, "../templates", file.templatePath);
71
102
  const destPath = path.join(targetDir, file.targetName);
72
- if (await fs.pathExists(srcPath)) {
73
- await fs.copy(srcPath, destPath, { overwrite: true });
74
- } else {
75
- spinner2.stop(pc.red(`Template file missing: ${file.templatePath}`));
76
- p.log.warn(pc.dim(`Looked at path: ${srcPath}`));
77
- return;
103
+ if (file.templatePath) {
104
+ const srcPath = path.resolve(__dirname, "../templates", file.templatePath);
105
+ if (await fs.pathExists(srcPath)) {
106
+ await fs.copy(srcPath, destPath, { overwrite: true });
107
+ } else {
108
+ spinner2.stop(pc.red(`Template file missing: ${file.templatePath}`));
109
+ p.log.warn(pc.dim(`Looked at path: ${srcPath}`));
110
+ return;
111
+ }
112
+ } else if (file.content) {
113
+ await fs.writeFile(destPath, file.content.trim() + "\n", "utf-8");
78
114
  }
79
115
  }
80
- if (meta.dependencies && meta.dependencies.length > 0) {
81
- spinner2.message(
82
- `Installing required npm packages: ${meta.dependencies.join(", ")}...`
83
- );
84
- await execa("npm", ["install", ...meta.dependencies], {
85
- cwd: projectRoot
86
- });
87
- }
88
- spinner2.stop(pc.green(`\u2714 Added ${meta.name} into ${hasSrc ? "src/" : ""}components/ui/`));
116
+ const relativePath = `${hasSrc ? "src/" : ""}components/ui/`;
117
+ spinner2.stop(pc.green(`\u2714 Added ${meta.name} into ${relativePath}`));
89
118
  }
90
119
  p.outro(pc.green("All components successfully installed!"));
91
120
  }
92
121
 
93
122
  // src/index.ts
94
123
  var program = new Command();
95
- program.name("Canopy UI").description("Install custom modular UI components directly to your project").version("1.0.0");
96
- program.command("add").description("Add a component to your project").argument("[components...]", "Component identifiers (e.g., toast").action(async (components) => {
124
+ program.name("canopy-ui").description("Install custom modular UI components directly to your project").version("1.0.0");
125
+ program.command("add").description("Add a component to your project").argument("[components...]", "Component identifiers (e.g., toast)").action(async (components) => {
97
126
  await add(components);
98
127
  });
99
128
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marv3l/canopy-ui",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "An accessible, themable React UI component library built for fast-moving web applications.",
5
5
  "main": "./dist/index.js",
6
6
  "bin": {