@glass-ui-kit/cli 0.1.1 → 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.
- package/dist/index.js +38 -23
- package/package.json +1 -1
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
|
-
|
|
17
|
+
if (!fs.existsSync(dir)) {
|
|
18
|
+
await fs.promises.mkdir(dir, { recursive: true });
|
|
19
19
|
}
|
|
20
|
-
await
|
|
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
|
-
|
|
26
|
-
if (!await file.exists()) {
|
|
25
|
+
if (!fs.existsSync(absolutePath)) {
|
|
27
26
|
throw new Error(`File not found: ${filePath}`);
|
|
28
27
|
}
|
|
29
|
-
return await
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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,7 +199,7 @@ import path4 from "path";
|
|
|
184
199
|
// src/utils/registry.ts
|
|
185
200
|
import path3 from "path";
|
|
186
201
|
import os from "os";
|
|
187
|
-
import
|
|
202
|
+
import fs2 from "fs/promises";
|
|
188
203
|
|
|
189
204
|
// ../schema/dist/registry.js
|
|
190
205
|
import { z } from "zod";
|
|
@@ -224,9 +239,9 @@ function getRegistryUrl() {
|
|
|
224
239
|
}
|
|
225
240
|
async function readCache() {
|
|
226
241
|
try {
|
|
227
|
-
const fileExists = await
|
|
242
|
+
const fileExists = await fs2.stat(CACHE_FILE).then(() => true).catch(() => false);
|
|
228
243
|
if (!fileExists) return null;
|
|
229
|
-
const raw = await
|
|
244
|
+
const raw = await fs2.readFile(CACHE_FILE, "utf-8");
|
|
230
245
|
const cache = JSON.parse(raw);
|
|
231
246
|
const now = Date.now();
|
|
232
247
|
if (now - cache.lastUpdated > CACHE_TTL) {
|
|
@@ -239,12 +254,12 @@ async function readCache() {
|
|
|
239
254
|
}
|
|
240
255
|
async function writeCache(data) {
|
|
241
256
|
try {
|
|
242
|
-
await
|
|
257
|
+
await fs2.mkdir(CACHE_DIR, { recursive: true });
|
|
243
258
|
const cache = {
|
|
244
259
|
lastUpdated: Date.now(),
|
|
245
260
|
data
|
|
246
261
|
};
|
|
247
|
-
await
|
|
262
|
+
await fs2.writeFile(CACHE_FILE, JSON.stringify(cache), "utf-8");
|
|
248
263
|
} catch {
|
|
249
264
|
}
|
|
250
265
|
}
|