boardui 0.1.0
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/README.md +64 -0
- package/dist/index.js +487 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# boardui
|
|
2
|
+
|
|
3
|
+
CLI for adding [BoardUI](https://www.boardui.com) components to your project.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
# set up an existing Next.js project (Tailwind v4, theme tokens, utils)
|
|
7
|
+
npx boardui@latest init
|
|
8
|
+
|
|
9
|
+
# add components
|
|
10
|
+
npx boardui@latest add button select date-picker
|
|
11
|
+
|
|
12
|
+
# browse what's available
|
|
13
|
+
npx boardui@latest list
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Commands
|
|
17
|
+
|
|
18
|
+
### `init`
|
|
19
|
+
|
|
20
|
+
Prepares an existing Next.js project: installs runtime dependencies
|
|
21
|
+
(`react-aria-components`, `tailwind-merge`, `@remixicon/react`, Tailwind v4),
|
|
22
|
+
writes `styles/theme.css`, `styles/typography.css`, `styles/globals.css`,
|
|
23
|
+
`utils/cx.ts`, and prints wiring instructions.
|
|
24
|
+
|
|
25
|
+
| Option | Description |
|
|
26
|
+
| --- | --- |
|
|
27
|
+
| `-y, --yes` | Skip confirmation prompts |
|
|
28
|
+
| `-o, --overwrite` | Overwrite existing files |
|
|
29
|
+
| `-d, --dir <dir>` | Target directory (defaults to the project source root) |
|
|
30
|
+
|
|
31
|
+
### `add [components...]`
|
|
32
|
+
|
|
33
|
+
Fetches components from the registry, resolves their internal dependencies
|
|
34
|
+
transitively (utils, icons, other components), writes the source files into
|
|
35
|
+
your project, and installs any missing npm packages. Run without arguments for
|
|
36
|
+
an interactive picker.
|
|
37
|
+
|
|
38
|
+
| Option | Description |
|
|
39
|
+
| --- | --- |
|
|
40
|
+
| `-a, --all` | Add every component in the registry |
|
|
41
|
+
| `-p, --path <path>` | Custom directory to write files into |
|
|
42
|
+
| `-d, --dir <dir>` | Target directory (defaults to the project source root) |
|
|
43
|
+
| `-o, --overwrite` | Overwrite existing files |
|
|
44
|
+
| `-y, --yes` | Skip prompts (skips existing files, installs deps) |
|
|
45
|
+
|
|
46
|
+
### `list`
|
|
47
|
+
|
|
48
|
+
Prints all available components grouped by type.
|
|
49
|
+
|
|
50
|
+
## Environment
|
|
51
|
+
|
|
52
|
+
| Variable | Description |
|
|
53
|
+
| --- | --- |
|
|
54
|
+
| `BOARDUI_REGISTRY_URL` | Override the registry base URL (default `https://www.boardui.com/r`). Useful for testing against `http://localhost:3000/r`. |
|
|
55
|
+
|
|
56
|
+
## Releasing
|
|
57
|
+
|
|
58
|
+
1. Bump `version` in `cli/package.json` (and the `.version()` string in `src/index.ts`).
|
|
59
|
+
2. `cd cli && npm install && npm run build`
|
|
60
|
+
3. Smoke test: `node dist/index.js list`
|
|
61
|
+
4. `npm publish`
|
|
62
|
+
|
|
63
|
+
The registry itself is generated by `npm run build:registry` in the repo root
|
|
64
|
+
and deployed with the site (served from `/r/*.json`).
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import pc4 from "picocolors";
|
|
6
|
+
|
|
7
|
+
// src/commands/add.ts
|
|
8
|
+
import { existsSync as existsSync2, mkdirSync, writeFileSync } from "fs";
|
|
9
|
+
import path2 from "path";
|
|
10
|
+
import ora from "ora";
|
|
11
|
+
import pc from "picocolors";
|
|
12
|
+
import prompts from "prompts";
|
|
13
|
+
|
|
14
|
+
// src/lib/install.ts
|
|
15
|
+
import { spawn } from "child_process";
|
|
16
|
+
|
|
17
|
+
// src/lib/project.ts
|
|
18
|
+
import { existsSync, readFileSync } from "fs";
|
|
19
|
+
import path from "path";
|
|
20
|
+
function detectPackageManager(cwd) {
|
|
21
|
+
if (existsSync(path.join(cwd, "pnpm-lock.yaml"))) return "pnpm";
|
|
22
|
+
if (existsSync(path.join(cwd, "yarn.lock"))) return "yarn";
|
|
23
|
+
if (existsSync(path.join(cwd, "bun.lock")) || existsSync(path.join(cwd, "bun.lockb"))) {
|
|
24
|
+
return "bun";
|
|
25
|
+
}
|
|
26
|
+
return "npm";
|
|
27
|
+
}
|
|
28
|
+
function installCommand(pm, packages) {
|
|
29
|
+
switch (pm) {
|
|
30
|
+
case "pnpm":
|
|
31
|
+
return ["pnpm", "add", ...packages];
|
|
32
|
+
case "yarn":
|
|
33
|
+
return ["yarn", "add", ...packages];
|
|
34
|
+
case "bun":
|
|
35
|
+
return ["bun", "add", ...packages];
|
|
36
|
+
default:
|
|
37
|
+
return ["npm", "install", ...packages];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function parseJsonc(raw) {
|
|
41
|
+
let out = "";
|
|
42
|
+
let i = 0;
|
|
43
|
+
let inString = false;
|
|
44
|
+
while (i < raw.length) {
|
|
45
|
+
const ch = raw[i];
|
|
46
|
+
if (inString) {
|
|
47
|
+
out += ch;
|
|
48
|
+
if (ch === "\\") {
|
|
49
|
+
out += raw[i + 1] ?? "";
|
|
50
|
+
i += 2;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (ch === '"') inString = false;
|
|
54
|
+
i++;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (ch === '"') {
|
|
58
|
+
inString = true;
|
|
59
|
+
out += ch;
|
|
60
|
+
i++;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (ch === "/" && raw[i + 1] === "/") {
|
|
64
|
+
while (i < raw.length && raw[i] !== "\n") i++;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (ch === "/" && raw[i + 1] === "*") {
|
|
68
|
+
i += 2;
|
|
69
|
+
while (i < raw.length && !(raw[i] === "*" && raw[i + 1] === "/")) i++;
|
|
70
|
+
i += 2;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
out += ch;
|
|
74
|
+
i++;
|
|
75
|
+
}
|
|
76
|
+
return JSON.parse(out.replace(/,\s*([}\]])/g, "$1"));
|
|
77
|
+
}
|
|
78
|
+
function readProject(cwd) {
|
|
79
|
+
const pkgPath = path.join(cwd, "package.json");
|
|
80
|
+
if (!existsSync(pkgPath)) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
"No package.json found in the current directory. Run this command from your project root."
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
86
|
+
const installedDependencies = /* @__PURE__ */ new Set([
|
|
87
|
+
...Object.keys(pkg.dependencies ?? {}),
|
|
88
|
+
...Object.keys(pkg.devDependencies ?? {})
|
|
89
|
+
]);
|
|
90
|
+
let hasAtAlias = false;
|
|
91
|
+
let aliasBase = ".";
|
|
92
|
+
for (const configName of ["tsconfig.json", "jsconfig.json"]) {
|
|
93
|
+
const configPath = path.join(cwd, configName);
|
|
94
|
+
if (!existsSync(configPath)) continue;
|
|
95
|
+
try {
|
|
96
|
+
const config = parseJsonc(readFileSync(configPath, "utf8"));
|
|
97
|
+
const atPaths = config.compilerOptions?.paths?.["@/*"];
|
|
98
|
+
if (atPaths && atPaths.length > 0) {
|
|
99
|
+
hasAtAlias = true;
|
|
100
|
+
aliasBase = atPaths[0].replace(/\/?\*$/, "") || ".";
|
|
101
|
+
}
|
|
102
|
+
} catch {
|
|
103
|
+
}
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
const usesSrcDir = existsSync(path.join(cwd, "src")) && (aliasBase.includes("src") || existsSync(path.join(cwd, "src", "app")) || existsSync(path.join(cwd, "src", "pages")));
|
|
107
|
+
return {
|
|
108
|
+
cwd,
|
|
109
|
+
packageManager: detectPackageManager(cwd),
|
|
110
|
+
isNextJs: installedDependencies.has("next"),
|
|
111
|
+
hasAtAlias,
|
|
112
|
+
usesSrcDir,
|
|
113
|
+
installedDependencies
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function sourceRoot(project) {
|
|
117
|
+
return project.usesSrcDir ? path.join(project.cwd, "src") : project.cwd;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/lib/install.ts
|
|
121
|
+
async function installPackages(pm, packages, cwd) {
|
|
122
|
+
if (packages.length === 0) return;
|
|
123
|
+
const [command, ...args] = installCommand(pm, packages);
|
|
124
|
+
await new Promise((resolve, reject) => {
|
|
125
|
+
const child = spawn(command, args, { cwd, stdio: "ignore", shell: process.platform === "win32" });
|
|
126
|
+
child.on("error", reject);
|
|
127
|
+
child.on("close", (code) => {
|
|
128
|
+
if (code === 0) resolve();
|
|
129
|
+
else reject(new Error(`${command} ${args.join(" ")} exited with code ${code}`));
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/lib/registry.ts
|
|
135
|
+
var DEFAULT_REGISTRY_URL = "https://www.boardui.com/r";
|
|
136
|
+
function registryBaseUrl() {
|
|
137
|
+
return (process.env.BOARDUI_REGISTRY_URL ?? DEFAULT_REGISTRY_URL).replace(/\/$/, "");
|
|
138
|
+
}
|
|
139
|
+
async function fetchJson(url) {
|
|
140
|
+
let response;
|
|
141
|
+
try {
|
|
142
|
+
response = await fetch(url);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
throw new Error(
|
|
145
|
+
`Could not reach the BoardUI registry at ${url}. Check your network connection.`,
|
|
146
|
+
{ cause: error }
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
if (!response.ok) {
|
|
150
|
+
if (response.status === 404) {
|
|
151
|
+
throw new Error(`Not found in the registry: ${url}`);
|
|
152
|
+
}
|
|
153
|
+
throw new Error(`Registry request failed (${response.status}): ${url}`);
|
|
154
|
+
}
|
|
155
|
+
return await response.json();
|
|
156
|
+
}
|
|
157
|
+
async function fetchRegistryIndex() {
|
|
158
|
+
return fetchJson(`${registryBaseUrl()}/registry.json`);
|
|
159
|
+
}
|
|
160
|
+
async function fetchRegistryItem(name) {
|
|
161
|
+
return fetchJson(`${registryBaseUrl()}/${name}.json`);
|
|
162
|
+
}
|
|
163
|
+
async function resolveItems(names) {
|
|
164
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
165
|
+
async function visit(name) {
|
|
166
|
+
if (resolved.has(name)) return;
|
|
167
|
+
const item = await fetchRegistryItem(name);
|
|
168
|
+
resolved.set(name, item);
|
|
169
|
+
for (const dep of item.registryDependencies ?? []) {
|
|
170
|
+
await visit(dep);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
for (const name of names) {
|
|
174
|
+
await visit(name);
|
|
175
|
+
}
|
|
176
|
+
const ordered = [];
|
|
177
|
+
const emitted = /* @__PURE__ */ new Set();
|
|
178
|
+
function emit(item) {
|
|
179
|
+
if (emitted.has(item.name)) return;
|
|
180
|
+
emitted.add(item.name);
|
|
181
|
+
for (const dep of item.registryDependencies ?? []) {
|
|
182
|
+
const depItem = resolved.get(dep);
|
|
183
|
+
if (depItem) emit(depItem);
|
|
184
|
+
}
|
|
185
|
+
ordered.push(item);
|
|
186
|
+
}
|
|
187
|
+
for (const item of resolved.values()) emit(item);
|
|
188
|
+
return ordered;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// src/commands/add.ts
|
|
192
|
+
var TYPE_LABEL = {
|
|
193
|
+
base: "Base components",
|
|
194
|
+
application: "Application blocks",
|
|
195
|
+
foundations: "Foundations"
|
|
196
|
+
};
|
|
197
|
+
async function pickComponents() {
|
|
198
|
+
const index = await fetchRegistryIndex();
|
|
199
|
+
const { type } = await prompts({
|
|
200
|
+
type: "select",
|
|
201
|
+
name: "type",
|
|
202
|
+
message: "What would you like to add?",
|
|
203
|
+
choices: ["base", "application", "foundations"].map((t) => ({
|
|
204
|
+
title: TYPE_LABEL[t],
|
|
205
|
+
value: t
|
|
206
|
+
}))
|
|
207
|
+
});
|
|
208
|
+
if (!type) return [];
|
|
209
|
+
const { names } = await prompts({
|
|
210
|
+
type: "multiselect",
|
|
211
|
+
name: "names",
|
|
212
|
+
message: "Select components (space to toggle, enter to confirm)",
|
|
213
|
+
choices: index.items.filter((item) => item.boarduiType === type).map((item) => ({
|
|
214
|
+
title: item.title,
|
|
215
|
+
value: item.name,
|
|
216
|
+
description: item.description
|
|
217
|
+
})),
|
|
218
|
+
min: 1
|
|
219
|
+
});
|
|
220
|
+
return names ?? [];
|
|
221
|
+
}
|
|
222
|
+
async function add(components, options) {
|
|
223
|
+
const project = readProject(process.cwd());
|
|
224
|
+
if (!project.hasAtAlias) {
|
|
225
|
+
console.log(
|
|
226
|
+
pc.yellow(
|
|
227
|
+
`warning: no "@/*" path alias found in tsconfig.json \u2014 BoardUI components import via "@/". Add:
|
|
228
|
+
"compilerOptions": { "paths": { "@/*": ["./*"] } }`
|
|
229
|
+
)
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
let names = components;
|
|
233
|
+
if (options.all) {
|
|
234
|
+
const index = await fetchRegistryIndex();
|
|
235
|
+
names = index.items.map((item) => item.name);
|
|
236
|
+
} else if (names.length === 0) {
|
|
237
|
+
names = await pickComponents();
|
|
238
|
+
}
|
|
239
|
+
if (names.length === 0) {
|
|
240
|
+
console.log("Nothing to add.");
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const spinner = ora("Resolving components...").start();
|
|
244
|
+
let items;
|
|
245
|
+
try {
|
|
246
|
+
items = await resolveItems(names);
|
|
247
|
+
} catch (error) {
|
|
248
|
+
spinner.fail(error.message);
|
|
249
|
+
process.exitCode = 1;
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
spinner.succeed(
|
|
253
|
+
`Resolved ${items.length} item${items.length === 1 ? "" : "s"}: ${items.map((i) => i.name).join(", ")}`
|
|
254
|
+
);
|
|
255
|
+
const targetRoot = options.path ? path2.resolve(process.cwd(), options.path) : options.dir ? path2.resolve(process.cwd(), options.dir) : sourceRoot(project);
|
|
256
|
+
const writes = [];
|
|
257
|
+
for (const item of items) {
|
|
258
|
+
for (const file of item.files) {
|
|
259
|
+
const relPath = file.target ?? file.path;
|
|
260
|
+
const absPath = path2.join(targetRoot, relPath);
|
|
261
|
+
writes.push({ absPath, relPath, content: file.content, exists: existsSync2(absPath) });
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const conflicts = writes.filter((w) => w.exists);
|
|
265
|
+
let skipExisting = false;
|
|
266
|
+
if (conflicts.length > 0 && !options.overwrite) {
|
|
267
|
+
if (options.yes) {
|
|
268
|
+
skipExisting = true;
|
|
269
|
+
} else {
|
|
270
|
+
console.log(pc.yellow(`
|
|
271
|
+
The following files already exist:`));
|
|
272
|
+
for (const c of conflicts) console.log(` ${c.relPath}`);
|
|
273
|
+
const { action } = await prompts({
|
|
274
|
+
type: "select",
|
|
275
|
+
name: "action",
|
|
276
|
+
message: "How should existing files be handled?",
|
|
277
|
+
choices: [
|
|
278
|
+
{ title: "Skip existing files", value: "skip" },
|
|
279
|
+
{ title: "Overwrite existing files", value: "overwrite" },
|
|
280
|
+
{ title: "Cancel", value: "cancel" }
|
|
281
|
+
]
|
|
282
|
+
});
|
|
283
|
+
if (!action || action === "cancel") {
|
|
284
|
+
console.log("Cancelled.");
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
skipExisting = action === "skip";
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
let written = 0;
|
|
291
|
+
let skipped = 0;
|
|
292
|
+
for (const write of writes) {
|
|
293
|
+
if (write.exists && skipExisting) {
|
|
294
|
+
skipped++;
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
mkdirSync(path2.dirname(write.absPath), { recursive: true });
|
|
298
|
+
writeFileSync(write.absPath, write.content);
|
|
299
|
+
written++;
|
|
300
|
+
console.log(` ${pc.green(write.exists ? "overwrote" : "created")} ${write.relPath}`);
|
|
301
|
+
}
|
|
302
|
+
if (skipped > 0) console.log(pc.dim(` skipped ${skipped} existing file${skipped === 1 ? "" : "s"}`));
|
|
303
|
+
const wanted = /* @__PURE__ */ new Map();
|
|
304
|
+
for (const item of items) {
|
|
305
|
+
for (const spec of item.dependencies ?? []) {
|
|
306
|
+
const at = spec.lastIndexOf("@");
|
|
307
|
+
const pkg = at > 0 ? spec.slice(0, at) : spec;
|
|
308
|
+
if (!project.installedDependencies.has(pkg)) wanted.set(pkg, spec);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (wanted.size > 0) {
|
|
312
|
+
const packages = [...wanted.values()];
|
|
313
|
+
let install = true;
|
|
314
|
+
if (!options.yes) {
|
|
315
|
+
const { confirmed } = await prompts({
|
|
316
|
+
type: "confirm",
|
|
317
|
+
name: "confirmed",
|
|
318
|
+
message: `Install ${packages.length} npm dependenc${packages.length === 1 ? "y" : "ies"} with ${project.packageManager}? (${[...wanted.keys()].join(", ")})`,
|
|
319
|
+
initial: true
|
|
320
|
+
});
|
|
321
|
+
install = Boolean(confirmed);
|
|
322
|
+
}
|
|
323
|
+
if (install) {
|
|
324
|
+
const depSpinner = ora(`Installing dependencies with ${project.packageManager}...`).start();
|
|
325
|
+
try {
|
|
326
|
+
await installPackages(project.packageManager, packages, project.cwd);
|
|
327
|
+
depSpinner.succeed("Dependencies installed.");
|
|
328
|
+
} catch (error) {
|
|
329
|
+
depSpinner.fail(`Failed to install dependencies: ${error.message}`);
|
|
330
|
+
console.log(pc.dim(`Install manually: ${project.packageManager} add ${packages.join(" ")}`));
|
|
331
|
+
}
|
|
332
|
+
} else {
|
|
333
|
+
console.log(pc.dim(`Skipped. Install manually: ${project.packageManager} add ${packages.join(" ")}`));
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
const installedGlobals = items.some((item) => item.name === "globals");
|
|
337
|
+
if (installedGlobals) {
|
|
338
|
+
console.log(
|
|
339
|
+
`
|
|
340
|
+
${pc.bold("Note:")} import the BoardUI styles in your root layout or global css:
|
|
341
|
+
${pc.cyan(`@import "../styles/globals.css";`)} ${pc.dim("(adjust the relative path)")}`
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
console.log(pc.green(`
|
|
345
|
+
Done. ${written} file${written === 1 ? "" : "s"} written.`));
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// src/commands/init.ts
|
|
349
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
350
|
+
import path3 from "path";
|
|
351
|
+
import ora2 from "ora";
|
|
352
|
+
import pc2 from "picocolors";
|
|
353
|
+
import prompts2 from "prompts";
|
|
354
|
+
var RUNTIME_DEPS = ["react-aria-components", "tailwind-merge", "@remixicon/react"];
|
|
355
|
+
var DEV_DEPS = ["tailwindcss", "@tailwindcss/postcss"];
|
|
356
|
+
var INIT_ITEMS = ["globals", "cx", "use-dismiss-on-outside-press"];
|
|
357
|
+
async function init(options) {
|
|
358
|
+
const project = readProject(process.cwd());
|
|
359
|
+
console.log(pc2.bold("\nBoardUI init\n"));
|
|
360
|
+
if (!project.isNextJs) {
|
|
361
|
+
console.log(
|
|
362
|
+
pc2.yellow(
|
|
363
|
+
"warning: this doesn't look like a Next.js project (no `next` dependency). BoardUI is tested with Next.js + Tailwind v4; continuing anyway."
|
|
364
|
+
)
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
if (!project.hasAtAlias) {
|
|
368
|
+
console.log(
|
|
369
|
+
pc2.yellow(
|
|
370
|
+
`warning: no "@/*" path alias found in tsconfig.json \u2014 BoardUI components import via "@/". Add:
|
|
371
|
+
"compilerOptions": { "paths": { "@/*": ["./*"] } }`
|
|
372
|
+
)
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
if (!options.yes) {
|
|
376
|
+
const { confirmed } = await prompts2({
|
|
377
|
+
type: "confirm",
|
|
378
|
+
name: "confirmed",
|
|
379
|
+
message: `Set up BoardUI in ${path3.basename(project.cwd)}? (installs Tailwind v4 + runtime deps, writes styles/ and utils/)`,
|
|
380
|
+
initial: true
|
|
381
|
+
});
|
|
382
|
+
if (!confirmed) {
|
|
383
|
+
console.log("Cancelled.");
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
const missingRuntime = RUNTIME_DEPS.filter((pkg) => !project.installedDependencies.has(pkg));
|
|
388
|
+
const missingDev = DEV_DEPS.filter((pkg) => !project.installedDependencies.has(pkg));
|
|
389
|
+
const missing = [...missingRuntime, ...missingDev];
|
|
390
|
+
if (missing.length > 0) {
|
|
391
|
+
const spinner2 = ora2(`Installing ${missing.join(", ")} with ${project.packageManager}...`).start();
|
|
392
|
+
try {
|
|
393
|
+
await installPackages(project.packageManager, missing, project.cwd);
|
|
394
|
+
spinner2.succeed("Dependencies installed.");
|
|
395
|
+
} catch (error) {
|
|
396
|
+
spinner2.fail(`Failed to install dependencies: ${error.message}`);
|
|
397
|
+
console.log(pc2.dim(`Install manually: ${project.packageManager} add ${missing.join(" ")}`));
|
|
398
|
+
}
|
|
399
|
+
} else {
|
|
400
|
+
console.log(pc2.dim("All required dependencies already installed."));
|
|
401
|
+
}
|
|
402
|
+
const spinner = ora2("Fetching BoardUI foundations...").start();
|
|
403
|
+
let items;
|
|
404
|
+
try {
|
|
405
|
+
items = await resolveItems(INIT_ITEMS);
|
|
406
|
+
} catch (error) {
|
|
407
|
+
spinner.fail(error.message);
|
|
408
|
+
process.exitCode = 1;
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
spinner.succeed("Foundations fetched.");
|
|
412
|
+
const targetRoot = options.dir ? path3.resolve(process.cwd(), options.dir) : sourceRoot(project);
|
|
413
|
+
for (const item of items) {
|
|
414
|
+
for (const file of item.files) {
|
|
415
|
+
const relPath = file.target ?? file.path;
|
|
416
|
+
const absPath = path3.join(targetRoot, relPath);
|
|
417
|
+
if (existsSync3(absPath) && !options.overwrite) {
|
|
418
|
+
console.log(` ${pc2.dim("skipped (exists)")} ${relPath}`);
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
mkdirSync2(path3.dirname(absPath), { recursive: true });
|
|
422
|
+
writeFileSync2(absPath, file.content);
|
|
423
|
+
console.log(` ${pc2.green("created")} ${relPath}`);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
const globalsPath = project.usesSrcDir ? "src/styles/globals.css" : "styles/globals.css";
|
|
427
|
+
console.log(`
|
|
428
|
+
${pc2.bold("Almost done \u2014 wire up the styles:")}
|
|
429
|
+
|
|
430
|
+
1. Import the BoardUI stylesheet in your root layout (app/layout.tsx):
|
|
431
|
+
|
|
432
|
+
${pc2.cyan(`import "@/styles/globals.css";`)}
|
|
433
|
+
|
|
434
|
+
${pc2.dim(`(replaces the default create-next-app "./globals.css" import \u2014 or add`)}
|
|
435
|
+
${pc2.dim(`@import "${globalsPath.startsWith("src/") ? "../styles/globals.css" : "../styles/globals.css"}"; to your existing global css instead)`)}
|
|
436
|
+
|
|
437
|
+
2. Make sure PostCSS uses Tailwind v4 (postcss.config.mjs):
|
|
438
|
+
|
|
439
|
+
${pc2.cyan(`export default { plugins: { "@tailwindcss/postcss": {} } };`)}
|
|
440
|
+
|
|
441
|
+
3. Add components:
|
|
442
|
+
|
|
443
|
+
${pc2.cyan("npx boardui add button select date-picker")}
|
|
444
|
+
`);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// src/commands/list.ts
|
|
448
|
+
import pc3 from "picocolors";
|
|
449
|
+
var TYPE_LABEL2 = {
|
|
450
|
+
base: "Base components",
|
|
451
|
+
application: "Application blocks",
|
|
452
|
+
foundations: "Foundations"
|
|
453
|
+
};
|
|
454
|
+
async function list() {
|
|
455
|
+
const index = await fetchRegistryIndex();
|
|
456
|
+
for (const type of ["base", "application", "foundations"]) {
|
|
457
|
+
const items = index.items.filter((item) => item.boarduiType === type);
|
|
458
|
+
if (items.length === 0) continue;
|
|
459
|
+
console.log(`
|
|
460
|
+
${pc3.bold(TYPE_LABEL2[type])}`);
|
|
461
|
+
const width = Math.max(...items.map((item) => item.name.length));
|
|
462
|
+
for (const item of items) {
|
|
463
|
+
console.log(` ${pc3.cyan(item.name.padEnd(width))} ${pc3.dim(item.description)}`);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
console.log(`
|
|
467
|
+
Add a component with ${pc3.cyan("npx boardui add <name>")}
|
|
468
|
+
`);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// src/index.ts
|
|
472
|
+
var program = new Command();
|
|
473
|
+
program.name("boardui").description("Add BoardUI components to your project.").version("0.1.0", "-v, --version");
|
|
474
|
+
program.command("init").description("Set up BoardUI in an existing Next.js project (deps, theme, utils).").option("-y, --yes", "skip confirmation prompts").option("-o, --overwrite", "overwrite existing files").option("-d, --dir <dir>", "target directory (defaults to the project source root)").action(async (options) => {
|
|
475
|
+
await init(options);
|
|
476
|
+
});
|
|
477
|
+
program.command("add").description("Add components to your project.").argument("[components...]", "component names (run `boardui list` to see them)").option("-a, --all", "add every component in the registry").option("-p, --path <path>", "custom directory to write component files into").option("-d, --dir <dir>", "target directory (defaults to the project source root)").option("-o, --overwrite", "overwrite existing files").option("-y, --yes", "skip prompts (skips existing files, installs deps)").action(async (components, options) => {
|
|
478
|
+
await add(components, options);
|
|
479
|
+
});
|
|
480
|
+
program.command("list").description("List all available components.").action(async () => {
|
|
481
|
+
await list();
|
|
482
|
+
});
|
|
483
|
+
program.parseAsync().catch((error) => {
|
|
484
|
+
console.error(pc4.red(`
|
|
485
|
+
${error.message}`));
|
|
486
|
+
process.exit(1);
|
|
487
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "boardui",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Add BoardUI components to your project.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"boardui": "dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsup",
|
|
15
|
+
"dev": "tsup --watch",
|
|
16
|
+
"prepublishOnly": "npm run build"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"boardui",
|
|
20
|
+
"components",
|
|
21
|
+
"react",
|
|
22
|
+
"tailwindcss",
|
|
23
|
+
"cli"
|
|
24
|
+
],
|
|
25
|
+
"homepage": "https://www.boardui.com/docs/cli",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/mertcanesmergul/boardui.git",
|
|
29
|
+
"directory": "cli"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=18"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"commander": "^12.1.0",
|
|
36
|
+
"ora": "^8.1.1",
|
|
37
|
+
"picocolors": "^1.1.1",
|
|
38
|
+
"prompts": "^2.4.2"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^20",
|
|
42
|
+
"@types/prompts": "^2.4.9",
|
|
43
|
+
"tsup": "^8.3.5",
|
|
44
|
+
"typescript": "^5"
|
|
45
|
+
}
|
|
46
|
+
}
|