@brxndxndiaz/ui 0.1.2 → 0.1.4

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.
@@ -4,7 +4,7 @@
4
4
  const fs = require("fs");
5
5
  const path = require("path");
6
6
  const { spawnSync } = require("child_process");
7
- const readline = require("readline");
7
+ const inquirer = require("inquirer");
8
8
 
9
9
  const REGISTRY_BASE = "https://ui.brndndiaz.dev/r";
10
10
  const SOURCE_BASE = process.env.BRXN_SOURCE_BASE;
@@ -63,16 +63,13 @@ function readJson(filePath) {
63
63
  }
64
64
 
65
65
  function prompt(question) {
66
- const rl = readline.createInterface({
67
- input: process.stdin,
68
- output: process.stdout,
69
- });
70
- return new Promise((resolve) => {
71
- rl.question(question, (answer) => {
72
- rl.close();
73
- resolve(answer.trim());
74
- });
75
- });
66
+ return inquirer.prompt([
67
+ {
68
+ type: "input",
69
+ name: "answer",
70
+ message: question,
71
+ },
72
+ ]).then((answers) => answers.answer);
76
73
  }
77
74
 
78
75
  function parseSelection(input, max) {
@@ -116,23 +113,49 @@ function detectPackageManager(projectRoot) {
116
113
  return "npm";
117
114
  }
118
115
 
119
- function installDependencies(dependencies) {
120
- if (!dependencies || dependencies.length === 0) return;
116
+ function installDependencies(dependencies, devDependencies) {
117
+ const deps = dependencies || [];
118
+ const devDeps = devDependencies || [];
119
+ if (deps.length === 0 && devDeps.length === 0) return;
121
120
  const projectRoot = process.cwd();
122
121
  if (!fileExists(path.join(projectRoot, "package.json"))) {
123
122
  console.warn("Skipping dependency install: package.json not found.");
124
123
  return;
125
124
  }
126
125
  const pkgManager = detectPackageManager(projectRoot);
127
- const args =
128
- pkgManager === "yarn"
129
- ? ["add", ...dependencies]
130
- : pkgManager === "pnpm" || pkgManager === "bun"
131
- ? ["add", ...dependencies]
132
- : ["install", ...dependencies];
133
- const result = spawnSync(pkgManager, args, { stdio: "inherit" });
134
- if (result.status !== 0) {
135
- throw new Error(`Failed to install dependencies with ${pkgManager}.`);
126
+ const installArgs = (items, isDev) => {
127
+ if (items.length === 0) return null;
128
+ if (pkgManager === "npm") {
129
+ return isDev ? ["install", "--save-dev", ...items] : ["install", ...items];
130
+ }
131
+ if (pkgManager === "yarn") {
132
+ return isDev ? ["add", "-D", ...items] : ["add", ...items];
133
+ }
134
+ if (pkgManager === "pnpm") {
135
+ return isDev ? ["add", "-D", ...items] : ["add", ...items];
136
+ }
137
+ if (pkgManager === "bun") {
138
+ return isDev ? ["add", "-d", ...items] : ["add", ...items];
139
+ }
140
+ return null;
141
+ };
142
+
143
+ if (deps.length > 0) {
144
+ console.log(`Installing dependencies with ${pkgManager}: ${deps.join(", ")}`);
145
+ const args = installArgs(deps, false);
146
+ const result = spawnSync(pkgManager, args, { stdio: "inherit" });
147
+ if (result.status !== 0) {
148
+ throw new Error(`Failed to install dependencies with ${pkgManager}.`);
149
+ }
150
+ }
151
+
152
+ if (devDeps.length > 0) {
153
+ console.log(`Installing dev dependencies with ${pkgManager}: ${devDeps.join(", ")}`);
154
+ const args = installArgs(devDeps, true);
155
+ const result = spawnSync(pkgManager, args, { stdio: "inherit" });
156
+ if (result.status !== 0) {
157
+ throw new Error(`Failed to install dev dependencies with ${pkgManager}.`);
158
+ }
136
159
  }
137
160
  }
138
161
 
@@ -181,14 +204,17 @@ async function promptForComponentsRoot(projectRoot) {
181
204
  const defaults = ["components", "src/components", "app/components", "src/app/components"];
182
205
  const options = detection && Array.isArray(detection) ? detection : defaults;
183
206
 
184
- console.log("\nSelect a components directory:");
185
- options.forEach((option, index) => {
186
- console.log(` ${index + 1}) ${option}`);
187
- });
188
- const answer = await prompt("Enter a number (default 1): ");
189
- const selection = parseSelection(answer || "1", options.length)[0] || 1;
190
- const chosen = options[selection - 1] || options[0];
191
- return chosen;
207
+ const answers = await inquirer.prompt([
208
+ {
209
+ type: "list",
210
+ name: "root",
211
+ message: "Select a components directory:",
212
+ choices: options,
213
+ default: options[0],
214
+ },
215
+ ]);
216
+
217
+ return answers.root;
192
218
  }
193
219
 
194
220
  function resolveComponentTarget(targetPath, componentsRoot) {
@@ -219,7 +245,8 @@ async function addComponent(
219
245
  name,
220
246
  componentsRoot,
221
247
  seen = new Set(),
222
- dependencies = new Set()
248
+ dependencies = new Set(),
249
+ devDependencies = new Set()
223
250
  ) {
224
251
  if (seen.has(name)) return;
225
252
  seen.add(name);
@@ -247,12 +274,24 @@ async function addComponent(
247
274
 
248
275
  if (item.registryDependencies && item.registryDependencies.length > 0) {
249
276
  for (const dependency of item.registryDependencies) {
250
- await addComponent(dependency, componentsRoot, seen, dependencies);
277
+ await addComponent(
278
+ dependency,
279
+ componentsRoot,
280
+ seen,
281
+ dependencies,
282
+ devDependencies
283
+ );
251
284
  }
252
285
  }
253
- if (item.dependencies && item.dependencies.length > 0) {
286
+ if (Array.isArray(item.dependencies)) {
254
287
  item.dependencies.forEach((dep) => dependencies.add(dep));
255
288
  }
289
+ if (Array.isArray(item.devDependencies)) {
290
+ item.devDependencies.forEach((dep) => devDependencies.add(dep));
291
+ }
292
+ if (Array.isArray(item.peerDependencies)) {
293
+ item.peerDependencies.forEach((dep) => dependencies.add(dep));
294
+ }
256
295
 
257
296
  for (const file of item.files) {
258
297
  const targetPath = file.target || file.path;
@@ -285,18 +324,26 @@ async function promptForRegistryComponents(componentsRoot) {
285
324
  process.exit(0);
286
325
  }
287
326
 
288
- console.log("\nWhich components would you like to add?");
289
- available.forEach((item, index) => {
290
- console.log(` ${index + 1}) ${item.name}`);
291
- });
292
- console.log("Enter numbers separated by commas (or 'all'):");
293
- const answer = await prompt("> ");
294
- const selections = parseSelection(answer, available.length);
295
- if (!selections.length) {
327
+ const answers = await inquirer.prompt([
328
+ {
329
+ type: "checkbox",
330
+ name: "components",
331
+ message: "Which components would you like to add?",
332
+ choices: available.map((item) => ({
333
+ name: item.name,
334
+ value: item.name,
335
+ checked: false,
336
+ })),
337
+ pageSize: 10,
338
+ },
339
+ ]);
340
+
341
+ if (!answers.components.length) {
296
342
  console.log("No components selected. Exiting.");
297
343
  process.exit(1);
298
344
  }
299
- return selections.map((index) => available[index - 1].name);
345
+
346
+ return answers.components;
300
347
  }
301
348
 
302
349
  function resolveTailwindCssPath(projectRoot) {
@@ -398,10 +445,11 @@ async function main() {
398
445
 
399
446
  const seen = new Set();
400
447
  const dependencies = new Set();
448
+ const devDependencies = new Set();
401
449
  for (const component of components) {
402
- await addComponent(component, componentsRoot, seen, dependencies);
450
+ await addComponent(component, componentsRoot, seen, dependencies, devDependencies);
403
451
  }
404
- installDependencies(Array.from(dependencies));
452
+ installDependencies(Array.from(dependencies), Array.from(devDependencies));
405
453
  }
406
454
 
407
455
  main().catch((error) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brxndxndiaz/ui",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "private": false,
5
5
  "description": "CLI for the brxndxndiaz UI registry.",
6
6
  "scripts": {
@@ -9,7 +9,10 @@
9
9
  "bin": {
10
10
  "brxndxndiaz-ui": "bin/brxndxndiaz-ui.js"
11
11
  },
12
+ "dependencies": {
13
+ "inquirer": "^8.2.5"
14
+ },
12
15
  "engines": {
13
16
  "node": ">=18"
14
17
  }
15
- }
18
+ }