@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.
- package/bin/brxndxndiaz-ui.js +92 -44
- package/package.json +5 -2
package/bin/brxndxndiaz-ui.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
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
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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(
|
|
277
|
+
await addComponent(
|
|
278
|
+
dependency,
|
|
279
|
+
componentsRoot,
|
|
280
|
+
seen,
|
|
281
|
+
dependencies,
|
|
282
|
+
devDependencies
|
|
283
|
+
);
|
|
251
284
|
}
|
|
252
285
|
}
|
|
253
|
-
if (
|
|
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
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
+
}
|