boardui 0.5.1 → 0.5.3

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 +158 -40
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -86,6 +86,10 @@ function readProject(cwd) {
86
86
  );
87
87
  }
88
88
  const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
89
+ const dependencyVersions = {
90
+ ...pkg.devDependencies ?? {},
91
+ ...pkg.dependencies ?? {}
92
+ };
89
93
  const installedDependencies = /* @__PURE__ */ new Set([
90
94
  ...Object.keys(pkg.dependencies ?? {}),
91
95
  ...Object.keys(pkg.devDependencies ?? {})
@@ -113,7 +117,8 @@ function readProject(cwd) {
113
117
  isNextJs: installedDependencies.has("next"),
114
118
  hasAtAlias,
115
119
  usesSrcDir,
116
- installedDependencies
120
+ installedDependencies,
121
+ dependencyVersions
117
122
  };
118
123
  }
119
124
  function sourceRoot(project) {
@@ -273,11 +278,16 @@ async function fetchJson(url) {
273
278
  let response;
274
279
  try {
275
280
  response = await fetch(url);
276
- } catch (error) {
277
- throw new Error(
278
- `Could not reach the BoardUI registry at ${url}. Check your network connection.`,
279
- { cause: error }
280
- );
281
+ } catch {
282
+ await new Promise((resolve) => setTimeout(resolve, 500));
283
+ try {
284
+ response = await fetch(url);
285
+ } catch (error) {
286
+ throw new Error(
287
+ `Could not reach the BoardUI registry at ${url}. Check your network connection.`,
288
+ { cause: error }
289
+ );
290
+ }
281
291
  }
282
292
  if (!response.ok) {
283
293
  if (response.status === 404) {
@@ -294,7 +304,7 @@ async function fetchProRegistryItem(name) {
294
304
  const license = getLicense();
295
305
  if (!license) {
296
306
  throw new Error(
297
- `"${name}" is not in the public registry. If it's a BoardUI Pro component, run \`boardui login <license-key>\` first (the key is in your Lemon Squeezy receipt).`
307
+ `"${name}" is a BoardUI Pro component. Run \`boardui login <license-key>\` first (the key is in your Lemon Squeezy receipt).`
298
308
  );
299
309
  }
300
310
  let response;
@@ -325,10 +335,18 @@ async function fetchRegistryItem(name) {
325
335
  try {
326
336
  return await fetchJson(`${registryBaseUrl()}/${name}.json`);
327
337
  } catch (error) {
328
- if (error instanceof Error && error.message.startsWith("Not found in the registry")) {
329
- return fetchProRegistryItem(name);
338
+ if (!(error instanceof Error && error.message.startsWith("Not found in the registry"))) {
339
+ throw error;
330
340
  }
331
- throw error;
341
+ let listedAsPro = true;
342
+ try {
343
+ listedAsPro = (await fetchProIndex()).items.some((item) => item.name === name);
344
+ } catch {
345
+ }
346
+ if (!listedAsPro) {
347
+ throw new Error(`"${name}" is not in the BoardUI registry. Check the name with \`boardui list\`.`);
348
+ }
349
+ return fetchProRegistryItem(name);
332
350
  }
333
351
  }
334
352
  async function resolveItems(names) {
@@ -402,12 +420,15 @@ ${block}
402
420
  `);
403
421
  return "appended";
404
422
  }
423
+ function isRootAnchored(relPath) {
424
+ return relPath.startsWith(".") || relPath.startsWith("public/");
425
+ }
405
426
  function collectWrites(items, targetRoot, rootAnchor = targetRoot) {
406
427
  const writesByPath = /* @__PURE__ */ new Map();
407
428
  for (const item of items) {
408
429
  for (const file of item.files) {
409
430
  const relPath = file.target ?? file.path;
410
- const absPath = path3.join(relPath.startsWith(".") ? rootAnchor : targetRoot, relPath);
431
+ const absPath = path3.join(isRootAnchored(relPath) ? rootAnchor : targetRoot, relPath);
411
432
  const pending = writesByPath.get(absPath);
412
433
  if (pending) {
413
434
  if (pending.content !== file.content) {
@@ -438,10 +459,10 @@ function writeFiles(writes, overwrite) {
438
459
  }
439
460
  return report;
440
461
  }
441
- async function downloadAssets(items, targetRoot, overwrite) {
462
+ async function downloadAssets(items, targetRoot, overwrite, rootAnchor = targetRoot) {
442
463
  const report = { fetched: [], skipped: [], failed: [] };
443
464
  for (const asset of items.flatMap((item) => item.assets ?? [])) {
444
- const absPath = path3.join(targetRoot, asset.target);
465
+ const absPath = path3.join(isRootAnchored(asset.target) ? rootAnchor : targetRoot, asset.target);
445
466
  if (existsSync3(absPath) && !overwrite) {
446
467
  report.skipped.push(asset.target);
447
468
  continue;
@@ -464,11 +485,23 @@ function missingDependencies(items, project) {
464
485
  for (const spec of item.dependencies ?? []) {
465
486
  const at = spec.lastIndexOf("@");
466
487
  const pkg = at > 0 ? spec.slice(0, at) : spec;
467
- if (!project.installedDependencies.has(pkg)) wanted.set(pkg, spec);
488
+ const range = at > 0 ? spec.slice(at + 1) : "";
489
+ if (!project.installedDependencies.has(pkg)) {
490
+ wanted.set(pkg, spec);
491
+ continue;
492
+ }
493
+ const have = majorOf(project.dependencyVersions?.[pkg]);
494
+ const need = majorOf(range);
495
+ if (have !== void 0 && need !== void 0 && have !== need) wanted.set(pkg, spec);
468
496
  }
469
497
  }
470
498
  return wanted;
471
499
  }
500
+ function majorOf(range) {
501
+ if (!range) return void 0;
502
+ const match = /^[\^~>=v\s]*(\d+)/.exec(range.trim());
503
+ return match ? Number(match[1]) : void 0;
504
+ }
472
505
  async function installMissingDependencies(project, wanted) {
473
506
  const packages = [...wanted.values()];
474
507
  if (packages.length === 0) return { installed: [] };
@@ -681,7 +714,7 @@ The following files already exist:`));
681
714
  const assetSpinner = ora(
682
715
  `Downloading ${assetCount} template asset${assetCount === 1 ? "" : "s"}...`
683
716
  ).start();
684
- const assets = await downloadAssets(items, targetRoot, Boolean(options.overwrite));
717
+ const assets = await downloadAssets(items, targetRoot, Boolean(options.overwrite), project.cwd);
685
718
  if (assets.failed.length > 0) {
686
719
  assetSpinner.warn(
687
720
  `Downloaded ${assets.fetched.length} asset${assets.fetched.length === 1 ? "" : "s"}; failed: ${assets.failed.join(", ")} \u2014 re-run with --overwrite to retry.`
@@ -693,6 +726,8 @@ The following files already exist:`));
693
726
  }
694
727
  }
695
728
  const wanted = missingDependencies(items, project);
729
+ const missingDev = DEV_DEPS.filter((pkg) => !project.installedDependencies.has(pkg));
730
+ for (const pkg of missingDev) wanted.set(pkg, pkg);
696
731
  if (wanted.size > 0) {
697
732
  const packages = [...wanted.values()];
698
733
  let install = true;
@@ -718,6 +753,22 @@ The following files already exist:`));
718
753
  console.log(pc.dim(`Skipped. Install manually: ${project.packageManager} add ${packages.join(" ")}`));
719
754
  }
720
755
  }
756
+ const shipsAppRoute = items.some(
757
+ (item) => item.files.some((file) => (file.target ?? file.path).startsWith("app/"))
758
+ );
759
+ if (shipsAppRoute && !project.isNextJs) {
760
+ console.log(
761
+ pc.yellow(
762
+ "\nWarning: this component ships an app/ route handler, which only runs in Next.js. It was written, but this project does not depend on next."
763
+ )
764
+ );
765
+ }
766
+ if (missingDev.length > 0) {
767
+ console.log(
768
+ `
769
+ ${pc.bold("Note:")} Tailwind was installed. Make sure a ${pc.cyan("postcss.config.mjs")} loads ${pc.cyan("@tailwindcss/postcss")}, or run ${pc.cyan("npx boardui init")} to set the project up.`
770
+ );
771
+ }
721
772
  const installedGlobals = items.some((item) => item.name === "globals");
722
773
  if (installedGlobals) {
723
774
  console.log(
@@ -805,7 +856,7 @@ async function init(options) {
805
856
  for (const item of items) {
806
857
  for (const file of item.files) {
807
858
  const relPath = file.target ?? file.path;
808
- const absPath = path6.join(relPath.startsWith(".") ? project.cwd : targetRoot, relPath);
859
+ const absPath = path6.join(isRootAnchored(relPath) ? project.cwd : targetRoot, relPath);
809
860
  if (existsSync5(absPath) && !options.overwrite) {
810
861
  console.log(` ${pc2.dim("skipped (exists)")} ${relPath}`);
811
862
  continue;
@@ -957,6 +1008,79 @@ function proIndex() {
957
1008
  });
958
1009
  return proIndexPromise;
959
1010
  }
1011
+ function normalizeName(raw) {
1012
+ return raw.trim().toLowerCase().replace(/\.tsx?$/, "").replace(/[\s_]+/g, "-").replace(/^@?boardui\//, "");
1013
+ }
1014
+ function editDistance(a, b) {
1015
+ const rows = a.length + 1;
1016
+ const cols = b.length + 1;
1017
+ const d = Array.from({ length: rows }, (_, i) => {
1018
+ const row = new Array(cols).fill(0);
1019
+ row[0] = i;
1020
+ return row;
1021
+ });
1022
+ for (let j = 0; j < cols; j++) d[0][j] = j;
1023
+ for (let i = 1; i < rows; i++) {
1024
+ for (let j = 1; j < cols; j++) {
1025
+ d[i][j] = Math.min(
1026
+ d[i - 1][j] + 1,
1027
+ d[i][j - 1] + 1,
1028
+ d[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1)
1029
+ );
1030
+ }
1031
+ }
1032
+ return d[rows - 1][cols - 1];
1033
+ }
1034
+ var UNRELEASED = {
1035
+ "agent-orb": '"agent-orb" is not available yet. It is still in progress and not open to public use.',
1036
+ orb: "The BoardUI orb component is not available yet. It is still in progress and not open to public use."
1037
+ };
1038
+ var CURATED_SUGGESTIONS = {
1039
+ textarea: ["input"],
1040
+ "text-area": ["input"],
1041
+ form: ["input", "select", "checkbox"],
1042
+ modal: ["settings-modal", "auth-card"],
1043
+ dialog: ["settings-modal"],
1044
+ card: ["stat-cards", "area-chart-card", "auth-card"],
1045
+ toast: ["notification"],
1046
+ chart: ["area-chart-card", "line-chart-card", "bar-list-card"]
1047
+ };
1048
+ async function nameUniverse() {
1049
+ const [free, pro] = await Promise.all([freeIndex(), proIndex()]);
1050
+ const all = /* @__PURE__ */ new Set([
1051
+ ...free.items.map((item) => item.name),
1052
+ ...pro.items.map((item) => item.name)
1053
+ ]);
1054
+ const aliases = /* @__PURE__ */ new Map();
1055
+ for (const item of pro.items) {
1056
+ const slug = item.docsUrl?.split("/").pop();
1057
+ if (slug && slug !== item.name && !all.has(slug)) aliases.set(slug, item.name);
1058
+ }
1059
+ return { all, aliases };
1060
+ }
1061
+ function resolveName(raw, universe) {
1062
+ const n = normalizeName(raw);
1063
+ if (universe.all.has(n)) return { name: n };
1064
+ const alias = universe.aliases.get(n);
1065
+ if (alias) return { name: alias };
1066
+ const unreleased = UNRELEASED[n];
1067
+ if (unreleased) return { error: unreleased };
1068
+ const suggestions = new Set(CURATED_SUGGESTIONS[n] ?? []);
1069
+ const scored = [];
1070
+ for (const name of universe.all) {
1071
+ if (name.includes(n) || n.includes(name)) scored.push({ name, score: 0 });
1072
+ else {
1073
+ const dist = editDistance(n, name);
1074
+ if (dist <= 2) scored.push({ name, score: dist });
1075
+ }
1076
+ }
1077
+ scored.sort((a, b) => a.score - b.score || a.name.localeCompare(b.name));
1078
+ for (const entry of scored) suggestions.add(entry.name);
1079
+ const hint = suggestions.size ? ` Closest matches: ${[...suggestions].slice(0, 4).join(", ")}.` : "";
1080
+ return {
1081
+ error: `Unknown component "${raw}".${hint} Call list_components for the exact names.`
1082
+ };
1083
+ }
960
1084
  function text(value) {
961
1085
  return { content: [{ type: "text", text: value }] };
962
1086
  }
@@ -981,7 +1105,7 @@ function loadProject(projectDir) {
981
1105
  return readProject(cwd);
982
1106
  } catch {
983
1107
  throw new Error(
984
- `No package.json found in ${cwd}. Pass projectDir with the absolute path of the user's project root (the directory containing package.json).`
1108
+ `No package.json found in ${cwd}. Pass projectDir with the absolute path of the user's project root (the directory containing package.json). If the directory is a fresh or empty one, scaffold an app there first (e.g. \`npx create-next-app@latest .\`), then call init_boardui again.`
985
1109
  );
986
1110
  }
987
1111
  }
@@ -1148,8 +1272,11 @@ ${templates.map((item) => `- ${item.name}: ${item.description}`).join("\n")}`
1148
1272
  },
1149
1273
  annotations: { readOnlyHint: true }
1150
1274
  },
1151
- safe(async ({ name }) => {
1152
- const [free, pro] = await Promise.all([freeIndex(), proIndex()]);
1275
+ safe(async ({ name: rawName }) => {
1276
+ const resolved = resolveName(rawName, await nameUniverse());
1277
+ if (resolved.error !== void 0) return errorText(resolved.error);
1278
+ const name = resolved.name;
1279
+ const pro = await proIndex();
1153
1280
  const proItem = pro.items.find((item2) => item2.name === name);
1154
1281
  if (proItem && !getLicense()) {
1155
1282
  const example = proItem.example ? `
@@ -1160,11 +1287,6 @@ ${proItem.example}
1160
1287
  \`\`\`` : "";
1161
1288
  return text(proPitch([proItem]) + example);
1162
1289
  }
1163
- if (!proItem && !free.items.some((item2) => item2.name === name)) {
1164
- return errorText(
1165
- `Unknown component "${name}". Call list_components for the exact names.`
1166
- );
1167
- }
1168
1290
  const item = await fetchRegistryItem(name);
1169
1291
  return text(formatItemDetail(item, proItem ? "pro" : "free"));
1170
1292
  })
@@ -1179,8 +1301,11 @@ ${proItem.example}
1179
1301
  },
1180
1302
  annotations: { readOnlyHint: true }
1181
1303
  },
1182
- safe(async ({ name }) => {
1183
- const [free, pro] = await Promise.all([freeIndex(), proIndex()]);
1304
+ safe(async ({ name: rawName }) => {
1305
+ const resolved = resolveName(rawName, await nameUniverse());
1306
+ if (resolved.error !== void 0) return errorText(resolved.error);
1307
+ const name = resolved.name;
1308
+ const pro = await proIndex();
1184
1309
  const proItem = pro.items.find((item2) => item2.name === name);
1185
1310
  if (proItem) {
1186
1311
  const lines2 = [
@@ -1196,11 +1321,6 @@ ${proItem.example}
1196
1321
  }
1197
1322
  return text(lines2.join("\n"));
1198
1323
  }
1199
- if (!free.items.some((item2) => item2.name === name)) {
1200
- return errorText(
1201
- `Unknown component "${name}". Call list_components for the exact names.`
1202
- );
1203
- }
1204
1324
  const item = await fetchRegistryItem(name);
1205
1325
  const lines = [
1206
1326
  `# ${item.title} (${item.name})`,
@@ -1241,16 +1361,14 @@ ${proItem.example}
1241
1361
  projectDir
1242
1362
  }) => {
1243
1363
  const project = loadProject(projectDir);
1244
- const [free, pro] = await Promise.all([freeIndex(), proIndex()]);
1245
- const requested = [...new Set(names)];
1246
- const unknown = requested.filter(
1247
- (name) => !free.items.some((item) => item.name === name) && !pro.items.some((item) => item.name === name)
1248
- );
1364
+ const universe = await nameUniverse();
1365
+ const pro = await proIndex();
1366
+ const resolutions = [...new Set(names)].map((raw) => resolveName(raw, universe));
1367
+ const unknown = resolutions.flatMap((r) => r.error ? [r.error] : []);
1249
1368
  if (unknown.length > 0) {
1250
- return errorText(
1251
- `Unknown component${unknown.length === 1 ? "" : "s"}: ${unknown.join(", ")}. Call list_components for the exact names.`
1252
- );
1369
+ return errorText(unknown.join("\n"));
1253
1370
  }
1371
+ const requested = [...new Set(resolutions.flatMap((r) => r.name ? [r.name] : []))];
1254
1372
  const licensed = getLicense() !== null;
1255
1373
  const lockedPro = licensed ? [] : pro.items.filter((item) => requested.includes(item.name));
1256
1374
  const lockedNames = new Set(lockedPro.map((item) => item.name));
@@ -1277,7 +1395,7 @@ ${proItem.example}
1277
1395
  }
1278
1396
  const targetRoot = sourceRoot(project);
1279
1397
  const report = writeFiles(collectWrites(items, targetRoot, project.cwd), overwrite);
1280
- const assets = await downloadAssets(items, targetRoot, overwrite);
1398
+ const assets = await downloadAssets(items, targetRoot, overwrite, project.cwd);
1281
1399
  const wanted = missingDependencies(items, project);
1282
1400
  const deps = installDependencies ? await installMissingDependencies(project, wanted) : null;
1283
1401
  const written = report.created.length + report.overwritten.length;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "boardui",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "Add BoardUI components to your project.",
5
5
  "license": "MIT",
6
6
  "type": "module",