@glass-ui-kit/cli 0.1.0 → 0.1.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 +68 -26
  2. package/package.json +7 -4
package/dist/index.js CHANGED
@@ -9,30 +9,30 @@ import { Command } from "commander";
9
9
  import path2 from "path";
10
10
 
11
11
  // src/utils/filesystem.ts
12
+ import fs from "fs";
12
13
  import path from "path";
13
- import { existsSync, mkdirSync } from "fs";
14
14
  async function writeFile(filePath, content) {
15
15
  const absolutePath = path.resolve(process.cwd(), filePath);
16
16
  const dir = path.dirname(absolutePath);
17
- if (!existsSync(dir)) {
18
- mkdirSync(dir, { recursive: true });
17
+ if (!fs.existsSync(dir)) {
18
+ await fs.promises.mkdir(dir, { recursive: true });
19
19
  }
20
- await Bun.write(absolutePath, content);
20
+ await fs.promises.writeFile(absolutePath, content, "utf-8");
21
21
  return absolutePath;
22
22
  }
23
23
  async function readFile(filePath) {
24
24
  const absolutePath = path.resolve(process.cwd(), filePath);
25
- const file = Bun.file(absolutePath);
26
- if (!await file.exists()) {
25
+ if (!fs.existsSync(absolutePath)) {
27
26
  throw new Error(`File not found: ${filePath}`);
28
27
  }
29
- return await file.text();
28
+ return await fs.promises.readFile(absolutePath, "utf-8");
30
29
  }
31
30
  function exists(filePath) {
32
- return existsSync(path.resolve(process.cwd(), filePath));
31
+ return fs.existsSync(path.resolve(process.cwd(), filePath));
33
32
  }
34
33
 
35
34
  // src/utils/get-project-info.ts
35
+ import { spawn } from "child_process";
36
36
  async function getPackageManager() {
37
37
  if (exists("bun.lockb")) return "bun";
38
38
  if (exists("pnpm-lock.yaml")) return "pnpm";
@@ -41,11 +41,16 @@ async function getPackageManager() {
41
41
  }
42
42
  async function getFramework() {
43
43
  if (!exists("package.json")) return "unknown";
44
- const pkg = await Bun.file("package.json").json();
45
- const deps = { ...pkg.dependencies, ...pkg.devDependencies };
46
- if (deps["next"]) return "next";
47
- if (deps["astro"]) return "astro";
48
- if (deps["vite"]) return "vite";
44
+ try {
45
+ const content = await readFile("package.json");
46
+ const pkg = JSON.parse(content);
47
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies };
48
+ if (deps["next"]) return "next";
49
+ if (deps["astro"]) return "astro";
50
+ if (deps["vite"]) return "vite";
51
+ } catch (error) {
52
+ return "unknown";
53
+ }
49
54
  return "unknown";
50
55
  }
51
56
  function getCssPath(framework) {
@@ -62,12 +67,22 @@ function getCssPath(framework) {
62
67
  }
63
68
  async function installDependencies(deps, pm) {
64
69
  const installCmd = pm === "npm" ? "install" : "add";
65
- const args = [installCmd, ...deps];
66
- const proc = Bun.spawn([pm, ...args], {
67
- stdout: "inherit",
68
- stderr: "inherit"
70
+ console.log(`Running ${pm} ${installCmd}...`);
71
+ return new Promise((resolve, reject) => {
72
+ const child = spawn(pm, [installCmd, ...deps], {
73
+ stdio: "inherit",
74
+ // Para ver los colores y logs del instalador
75
+ shell: true
76
+ // CRÍTICO para Windows (ejecuta npm.cmd/pnpm.cmd correctamente)
77
+ });
78
+ child.on("close", (code) => {
79
+ if (code !== 0) {
80
+ reject(new Error(`Failed to install dependencies. Code: ${code}`));
81
+ return;
82
+ }
83
+ resolve();
84
+ });
69
85
  });
70
- await proc.exited;
71
86
  }
72
87
 
73
88
  // src/utils/templates.ts
@@ -184,10 +199,37 @@ import path4 from "path";
184
199
  // src/utils/registry.ts
185
200
  import path3 from "path";
186
201
  import os from "os";
187
- import fs from "fs/promises";
188
- import {
189
- registryIndexSchema
190
- } from "@glass-ui-kit/schema";
202
+ import fs2 from "fs/promises";
203
+
204
+ // ../schema/dist/registry.js
205
+ import { z } from "zod";
206
+ var registryTypeSchema = z.enum([
207
+ "registry:ui",
208
+ "registry:lib",
209
+ "registry:hook",
210
+ "registry:theme"
211
+ ]);
212
+ var registryItemSchema = z.object({
213
+ name: z.string(),
214
+ type: registryTypeSchema,
215
+ dependencies: z.array(z.string()).optional(),
216
+ devDependencies: z.array(z.string()).optional(),
217
+ registryDependencies: z.array(z.string()).optional(),
218
+ files: z.array(z.object({
219
+ path: z.string(),
220
+ content: z.string().optional(),
221
+ // Se rellena en build-time
222
+ type: z.enum(["client", "server"]).default("client")
223
+ // Future-proofing para RSC
224
+ })),
225
+ meta: z.object({
226
+ // Metadatos específicos para Glass UI (ej. si requiere backdrop-filter específico)
227
+ requiresBlur: z.boolean().default(true)
228
+ }).optional()
229
+ });
230
+ var registryIndexSchema = z.array(registryItemSchema);
231
+
232
+ // src/utils/registry.ts
191
233
  var DEFAULT_REGISTRY_URL = "https://ui-glass.vercel.app/registry.json";
192
234
  var CACHE_DIR = path3.join(os.homedir(), ".glass-ui");
193
235
  var CACHE_FILE = path3.join(CACHE_DIR, "registry.json");
@@ -197,9 +239,9 @@ function getRegistryUrl() {
197
239
  }
198
240
  async function readCache() {
199
241
  try {
200
- const fileExists = await fs.stat(CACHE_FILE).then(() => true).catch(() => false);
242
+ const fileExists = await fs2.stat(CACHE_FILE).then(() => true).catch(() => false);
201
243
  if (!fileExists) return null;
202
- const raw = await fs.readFile(CACHE_FILE, "utf-8");
244
+ const raw = await fs2.readFile(CACHE_FILE, "utf-8");
203
245
  const cache = JSON.parse(raw);
204
246
  const now = Date.now();
205
247
  if (now - cache.lastUpdated > CACHE_TTL) {
@@ -212,12 +254,12 @@ async function readCache() {
212
254
  }
213
255
  async function writeCache(data) {
214
256
  try {
215
- await fs.mkdir(CACHE_DIR, { recursive: true });
257
+ await fs2.mkdir(CACHE_DIR, { recursive: true });
216
258
  const cache = {
217
259
  lastUpdated: Date.now(),
218
260
  data
219
261
  };
220
- await fs.writeFile(CACHE_FILE, JSON.stringify(cache), "utf-8");
262
+ await fs2.writeFile(CACHE_FILE, JSON.stringify(cache), "utf-8");
221
263
  } catch {
222
264
  }
223
265
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glass-ui-kit/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "The official CLI for Glass UI. Add glassmorphism components to your React projects in seconds.",
5
5
  "keywords": [
6
6
  "glassmorphism",
@@ -29,19 +29,22 @@
29
29
  "dist",
30
30
  "README.md"
31
31
  ],
32
+ "engines": {
33
+ "node": ">=18.0.0"
34
+ },
32
35
  "dependencies": {
33
36
  "chalk": "^5.3.0",
34
37
  "commander": "^11.1.0",
35
38
  "node-fetch": "^3.3.2",
36
- "zod": "^3.22.4",
37
- "@glass-ui-kit/schema": "0.0.1"
39
+ "zod": "^3.22.4"
38
40
  },
39
41
  "devDependencies": {
40
42
  "@types/node": "^20.11.0",
41
43
  "bun-types": "latest",
42
44
  "tsup": "^8.0.1",
43
45
  "typescript": "^5.3.3",
44
- "@glass-ui-kit/tsconfig": "0.0.1"
46
+ "@glass-ui-kit/tsconfig": "0.0.1",
47
+ "@glass-ui-kit/schema": "0.0.1"
45
48
  },
46
49
  "publishConfig": {
47
50
  "access": "public"