basuicn 0.1.4 → 0.1.6

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/ui-cli.js DELETED
@@ -1,124 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // scripts/ui-cli.ts
4
- import fs from "fs";
5
- import path from "path";
6
- import { execSync } from "child_process";
7
- var REGISTRY_LOCAL = "./registry.json";
8
- var REGISTRY_REMOTE = "https://raw.githubusercontent.com/huy14032003/ui-component/main/registry.json";
9
- var log = (msg) => console.log(`[BASE-CUS-UI] ${msg}`);
10
- var error = (msg) => console.error(`[BASE-CUS-UI] ERROR: ${msg}`);
11
- var getTargetProjectDir = () => process.cwd();
12
- var getRegistry = async (isLocal) => {
13
- if (isLocal && fs.existsSync(REGISTRY_LOCAL)) {
14
- log("S\u1EED d\u1EE5ng Registry n\u1ED9i b\u1ED9...");
15
- return JSON.parse(fs.readFileSync(REGISTRY_LOCAL, "utf-8"));
16
- }
17
- log("\u0110ang t\u1EA3i Registry t\u1EEB m\xE1y ch\u1EE7 t\u1EEB xa...");
18
- try {
19
- const response = await fetch(REGISTRY_REMOTE);
20
- if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
21
- return await response.json();
22
- } catch (err) {
23
- if (isLocal) {
24
- error(`Kh\xF4ng t\xECm th\u1EA5y registry.json n\u1ED9i b\u1ED9 v\xE0 kh\xF4ng th\u1EC3 t\u1EA3i t\u1EEB xa: ${err.message}`);
25
- } else {
26
- error(`Kh\xF4ng th\u1EC3 t\u1EA3i Registry t\u1EEB GitHub: ${err.message}. H\xE3y ki\u1EC3m tra k\u1EBFt n\u1ED1i m\u1EA1ng.`);
27
- }
28
- process.exit(1);
29
- }
30
- };
31
- var installNpmPackages = (packages, cwd) => {
32
- if (packages.length === 0) return;
33
- const pkgJsonPath = path.join(cwd, "package.json");
34
- let toInstall = packages;
35
- if (fs.existsSync(pkgJsonPath)) {
36
- const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
37
- const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
38
- toInstall = packages.filter((p) => !allDeps[p]);
39
- }
40
- if (toInstall.length === 0) return;
41
- log(`\u0110ang c\xE0i \u0111\u1EB7t c\xE1c g\xF3i npm: ${toInstall.join(", ")}...`);
42
- try {
43
- execSync(`npm install ${toInstall.join(" ")} --save`, { stdio: "inherit", cwd });
44
- } catch (err) {
45
- error("L\u1ED7i khi c\xE0i \u0111\u1EB7t c\xE1c g\xF3i npm.");
46
- }
47
- };
48
- var ensureCore = (registry, cwd) => {
49
- const core = registry.core;
50
- if (!core) return;
51
- installNpmPackages(core.dependencies, cwd);
52
- core.files.forEach((file) => {
53
- const targetPath = path.join(cwd, file.path);
54
- const targetDir = path.dirname(targetPath);
55
- if (!fs.existsSync(targetDir)) {
56
- fs.mkdirSync(targetDir, { recursive: true });
57
- }
58
- if (!fs.existsSync(targetPath)) {
59
- fs.writeFileSync(targetPath, file.content);
60
- log(`\u0110\xE3 kh\u1EDFi t\u1EA1o file h\u1EC7 th\u1ED1ng: ${file.path}`);
61
- }
62
- });
63
- };
64
- var addComponent = (name, registry, cwd, added = /* @__PURE__ */ new Set()) => {
65
- if (added.has(name)) return;
66
- added.add(name);
67
- const component = registry.components[name];
68
- if (!component) {
69
- error(`Component "${name}" kh\xF4ng t\u1ED3n t\u1EA1i trong danh s\xE1ch.`);
70
- return;
71
- }
72
- log(`\u0110ang th\xEAm component: ${name}...`);
73
- ensureCore(registry, cwd);
74
- installNpmPackages(component.dependencies, cwd);
75
- if (component.internalDependencies) {
76
- component.internalDependencies.forEach((dep) => {
77
- if (registry.components[dep]) {
78
- addComponent(dep, registry, cwd, added);
79
- }
80
- });
81
- }
82
- component.files.forEach((file) => {
83
- const targetPath = path.join(cwd, file.path);
84
- const targetDir = path.dirname(targetPath);
85
- if (!fs.existsSync(targetDir)) {
86
- fs.mkdirSync(targetDir, { recursive: true });
87
- }
88
- if (fs.existsSync(targetPath)) {
89
- return;
90
- }
91
- fs.writeFileSync(targetPath, file.content);
92
- log(`\u0110\xE3 t\u1EA1o: ${file.path}`);
93
- });
94
- };
95
- var main = async () => {
96
- const args = process.argv.slice(2);
97
- const isLocal = args.includes("--local");
98
- const command = args.find((a) => !a.startsWith("--"));
99
- const componentNames = args.filter((a) => a !== command && !a.startsWith("--"));
100
- const cwd = getTargetProjectDir();
101
- const registry = await getRegistry(isLocal);
102
- if (command === "add") {
103
- if (componentNames.length === 0) {
104
- error("S\u1EED d\u1EE5ng: npx base-cus-ui add <t\xEAn-component>");
105
- return;
106
- }
107
- for (const name of componentNames) {
108
- addComponent(name, registry, cwd);
109
- }
110
- log("T\u1EA5t c\u1EA3 component \u0111\xE3 \u0111\u01B0\u1EE3c th\xEAm th\xE0nh c\xF4ng!");
111
- } else if (command === "list") {
112
- log("Danh s\xE1ch component c\xF3 s\u1EB5n:");
113
- Object.keys(registry.components).forEach((k) => console.log(` - ${k}`));
114
- } else if (command === "init") {
115
- ensureCore(registry, cwd);
116
- log("Kh\u1EDFi t\u1EA1o ho\xE0n t\u1EA5t.");
117
- } else if (command === "tailwind") {
118
- console.log("\n--- SAO CH\xC9P V\xC0O tailwind.config.ts / tailwind.config.js ---\n");
119
- console.log("// Xem trong README_CLI.md \u0111\u1EC3 bi\u1EBFt chi ti\u1EBFt c\u1EA5u h\xECnh");
120
- } else {
121
- log("Ch\xE0o m\u1EEBng \u0111\u1EBFn v\u1EDBi BASE-CUS-UI. C\xE1c l\u1EC7nh h\u1ED7 tr\u1EE3: init, add, list, tailwind.");
122
- }
123
- };
124
- main();