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