rafters 0.0.36 → 0.0.37

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 +50 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -12829,6 +12829,7 @@ function frameworkToTarget(framework) {
12829
12829
  if (framework === "astro") return "astro";
12830
12830
  return "react";
12831
12831
  }
12832
+ var COMPONENT_EXTENSIONS = [".tsx", ".astro", ".vue", ".svelte"];
12832
12833
  function targetToExtension(target) {
12833
12834
  const map2 = {
12834
12835
  react: ".tsx",
@@ -12838,6 +12839,11 @@ function targetToExtension(target) {
12838
12839
  };
12839
12840
  return map2[target];
12840
12841
  }
12842
+ function resolveComponentTarget(config3) {
12843
+ if (config3?.componentTarget) return config3.componentTarget;
12844
+ if (config3?.framework) return frameworkToTarget(config3.framework);
12845
+ return "react";
12846
+ }
12841
12847
  async function hasAstroReact(cwd) {
12842
12848
  try {
12843
12849
  const content = await readFile(join(cwd, "package.json"), "utf-8");
@@ -13350,9 +13356,7 @@ function getInstalledNames(config3) {
13350
13356
  return [...names2].sort();
13351
13357
  }
13352
13358
  function getComponentTarget(config3) {
13353
- if (config3?.componentTarget) return config3.componentTarget;
13354
- if (config3?.framework) return frameworkToTarget(config3.framework);
13355
- return "react";
13359
+ return resolveComponentTarget(config3);
13356
13360
  }
13357
13361
  var SHARED_EXTENSIONS = /* @__PURE__ */ new Set([".classes.ts", ".types.ts", ".constants.ts"]);
13358
13362
  function isSharedFile(path2) {
@@ -60601,12 +60605,32 @@ var RaftersToolHandler = class _RaftersToolHandler {
60601
60605
  return join10(this.projectRoot, "packages/ui/src/components/ui");
60602
60606
  }
60603
60607
  /**
60604
- * Load component metadata from source file
60608
+ * Find the actual component file on disk for a given name.
60609
+ * Checks the config's componentTarget extension first, then falls back
60610
+ * to all known extensions so Astro projects with React islands also work.
60611
+ */
60612
+ async resolveComponentFile(componentsPath, name2) {
60613
+ const config3 = await this.loadConfig();
60614
+ const preferredExt = targetToExtension(resolveComponentTarget(config3));
60615
+ const preferred = join10(componentsPath, `${name2}${preferredExt}`);
60616
+ if (existsSync4(preferred)) return preferred;
60617
+ for (const ext2 of COMPONENT_EXTENSIONS) {
60618
+ if (ext2 === preferredExt) continue;
60619
+ const candidate = join10(componentsPath, `${name2}${ext2}`);
60620
+ if (existsSync4(candidate)) return candidate;
60621
+ }
60622
+ return null;
60623
+ }
60624
+ /**
60625
+ * Load component metadata from source file.
60626
+ * Resolves the actual file extension from the config's componentTarget
60627
+ * and merges variant/size data from .classes.ts companions when present.
60605
60628
  */
60606
60629
  async loadComponentMetadata(name2) {
60607
60630
  const componentsPath = await this.getComponentsPath();
60608
60631
  if (!componentsPath) return null;
60609
- const filePath = join10(componentsPath, `${name2}.tsx`);
60632
+ const filePath = await this.resolveComponentFile(componentsPath, name2);
60633
+ if (!filePath) return null;
60610
60634
  try {
60611
60635
  const source = await readFile6(filePath, "utf-8");
60612
60636
  const intelligence = parseJSDocIntelligence(source);
@@ -60616,16 +60640,28 @@ var RaftersToolHandler = class _RaftersToolHandler {
60616
60640
  jsDocDeps = extractJSDocDependencies(source);
60617
60641
  } catch {
60618
60642
  }
60643
+ let variants = extractVariants(source);
60644
+ let sizes = extractSizes(source);
60645
+ try {
60646
+ const classesSource = await readFile6(join10(componentsPath, `${name2}.classes.ts`), "utf-8");
60647
+ if (!variants || variants.length === 0) {
60648
+ variants = extractVariants(classesSource);
60649
+ }
60650
+ if (!sizes || sizes.length === 0) {
60651
+ sizes = extractSizes(classesSource);
60652
+ }
60653
+ } catch {
60654
+ }
60619
60655
  const metadata = {
60620
60656
  name: name2,
60621
60657
  displayName: toDisplayName(name2),
60622
60658
  category: this.inferCategory(name2),
60623
- variants: extractVariants(source),
60624
- sizes: extractSizes(source),
60659
+ variants,
60660
+ sizes,
60625
60661
  dependencies: extractDependencies(source),
60626
60662
  primitives: extractPrimitiveDependencies(source),
60627
60663
  // projectRoot is guaranteed non-null here: handleToolCall guards it
60628
- filePath: relative2(this.projectRoot, join10(componentsPath, `${name2}.tsx`))
60664
+ filePath: relative2(this.projectRoot, filePath)
60629
60665
  };
60630
60666
  if (hasAnyDeps(jsDocDeps)) {
60631
60667
  metadata.jsDocDependencies = jsDocDeps;
@@ -60722,7 +60758,12 @@ var RaftersToolHandler = class _RaftersToolHandler {
60722
60758
  if (componentsPath) {
60723
60759
  try {
60724
60760
  const files = await readdir3(componentsPath);
60725
- available = files.filter((f) => f.endsWith(".tsx")).map((f) => basename(f, ".tsx")).filter((n2) => n2.includes(name2) || name2.includes(n2)).slice(0, 5);
60761
+ available = files.filter(
60762
+ (f) => COMPONENT_EXTENSIONS.some((ext2) => f.endsWith(ext2)) && !f.includes(".classes.")
60763
+ ).map((f) => {
60764
+ const ext2 = COMPONENT_EXTENSIONS.find((e) => f.endsWith(e));
60765
+ return ext2 ? basename(f, ext2) : basename(f);
60766
+ }).filter((n2) => n2.includes(name2) || name2.includes(n2)).slice(0, 5);
60726
60767
  } catch {
60727
60768
  }
60728
60769
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rafters",
3
- "version": "0.0.36",
3
+ "version": "0.0.37",
4
4
  "description": "CLI for Rafters design system - scaffold tokens and add components",
5
5
  "license": "MIT",
6
6
  "type": "module",