rafters 0.0.3 → 0.0.5

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 +87 -30
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import { Command } from "commander";
9
9
 
10
10
  // src/commands/add.ts
11
11
  import { existsSync } from "fs";
12
- import { access, mkdir, writeFile } from "fs/promises";
12
+ import { access, mkdir, readFile, writeFile } from "fs/promises";
13
13
  import { dirname, join as join2 } from "path";
14
14
 
15
15
  // ../../node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/external.js
@@ -12927,39 +12927,72 @@ async function isInitialized(cwd) {
12927
12927
  return false;
12928
12928
  }
12929
12929
  }
12930
+ async function loadConfig(cwd) {
12931
+ const paths = getRaftersPaths(cwd);
12932
+ try {
12933
+ const content = await readFile(paths.config, "utf-8");
12934
+ return JSON.parse(content);
12935
+ } catch {
12936
+ return null;
12937
+ }
12938
+ }
12939
+ function transformPath(registryPath, config3) {
12940
+ if (!config3) return registryPath;
12941
+ if (registryPath.startsWith("components/ui/")) {
12942
+ return registryPath.replace("components/ui/", `${config3.componentsPath}/`);
12943
+ }
12944
+ if (registryPath.startsWith("lib/primitives/")) {
12945
+ return registryPath.replace("lib/primitives/", `${config3.primitivesPath}/`);
12946
+ }
12947
+ return registryPath;
12948
+ }
12930
12949
  function fileExists(cwd, relativePath) {
12931
12950
  return existsSync(join2(cwd, relativePath));
12932
12951
  }
12933
- function transformFileContent(content) {
12952
+ function transformFileContent(content, config3) {
12934
12953
  let transformed = content;
12954
+ const componentsPath = config3?.componentsPath ?? "components/ui";
12955
+ const primitivesPath = config3?.primitivesPath ?? "lib/primitives";
12935
12956
  transformed = transformed.replace(
12936
12957
  /from\s+['"]\.\.\/\.\.\/primitives\/([^'"]+)['"]/g,
12937
- "from '@/lib/primitives/$1'"
12958
+ `from '@/${primitivesPath}/$1'`
12938
12959
  );
12939
12960
  transformed = transformed.replace(
12940
12961
  /from\s+['"]\.\.\/primitives\/([^'"]+)['"]/g,
12941
- "from '@/lib/primitives/$1'"
12962
+ `from '@/${primitivesPath}/$1'`
12963
+ );
12964
+ transformed = transformed.replace(
12965
+ /from\s+['"]\.\/([^'"]+)['"]/g,
12966
+ `from '@/${componentsPath}/$1'`
12967
+ );
12968
+ const libPath = primitivesPath.replace(/\/primitives$/, "");
12969
+ transformed = transformed.replace(
12970
+ /from\s+['"]\.\.\/lib\/([^'"]+)['"]/g,
12971
+ `from '@/${libPath}/$1'`
12972
+ );
12973
+ const hooksPath = componentsPath.replace(/components\/ui$/, "hooks");
12974
+ transformed = transformed.replace(
12975
+ /from\s+['"]\.\.\/hooks\/([^'"]+)['"]/g,
12976
+ `from '@/${hooksPath}/$1'`
12942
12977
  );
12943
- transformed = transformed.replace(/from\s+['"]\.\/([^'"]+)['"]/g, "from '@/components/ui/$1'");
12944
- transformed = transformed.replace(/from\s+['"]\.\.\/lib\/([^'"]+)['"]/g, "from '@/lib/$1'");
12945
- transformed = transformed.replace(/from\s+['"]\.\.\/hooks\/([^'"]+)['"]/g, "from '@/hooks/$1'");
12946
12978
  transformed = transformed.replace(
12947
12979
  /from\s+['"]\.\.\/(?!lib\/|hooks\/)([^'"]+)['"]/g,
12948
- "from '@/components/ui/$1'"
12980
+ `from '@/${componentsPath}/$1'`
12949
12981
  );
12950
12982
  return transformed;
12951
12983
  }
12952
- async function installItem(cwd, item, options) {
12984
+ async function installItem(cwd, item, options, config3) {
12953
12985
  const installedFiles = [];
12954
12986
  let skipped = false;
12955
12987
  for (const file2 of item.files) {
12956
- const targetPath = join2(cwd, file2.path);
12957
- if (fileExists(cwd, file2.path)) {
12988
+ const projectPath = transformPath(file2.path, config3);
12989
+ const targetPath = join2(cwd, projectPath);
12990
+ if (fileExists(cwd, projectPath)) {
12958
12991
  if (!options.overwrite) {
12959
12992
  log({
12960
12993
  event: "add:skip",
12961
12994
  component: item.name,
12962
- file: file2.path,
12995
+ file: projectPath,
12963
12996
  reason: "exists"
12964
12997
  });
12965
12998
  skipped = true;
@@ -12967,9 +13000,9 @@ async function installItem(cwd, item, options) {
12967
13000
  }
12968
13001
  }
12969
13002
  await mkdir(dirname(targetPath), { recursive: true });
12970
- const transformedContent = transformFileContent(file2.content);
13003
+ const transformedContent = transformFileContent(file2.content, config3);
12971
13004
  await writeFile(targetPath, transformedContent, "utf-8");
12972
- installedFiles.push(file2.path);
13005
+ installedFiles.push(projectPath);
12973
13006
  }
12974
13007
  return {
12975
13008
  installed: installedFiles.length > 0,
@@ -13001,6 +13034,7 @@ async function add(components, options) {
13001
13034
  process.exitCode = 1;
13002
13035
  return;
13003
13036
  }
13037
+ const config3 = await loadConfig(cwd);
13004
13038
  if (components.length === 0) {
13005
13039
  error46("No components specified. Usage: rafters add <component...>");
13006
13040
  process.exitCode = 1;
@@ -13033,7 +13067,7 @@ async function add(components, options) {
13033
13067
  const skipped = [];
13034
13068
  for (const item of allItems) {
13035
13069
  try {
13036
- const result = await installItem(cwd, item, options);
13070
+ const result = await installItem(cwd, item, options, config3);
13037
13071
  if (result.installed) {
13038
13072
  installed.push(item.name);
13039
13073
  log({
@@ -13090,7 +13124,7 @@ async function add(components, options) {
13090
13124
 
13091
13125
  // src/commands/init.ts
13092
13126
  import { existsSync as existsSync2 } from "fs";
13093
- import { copyFile, mkdir as mkdir3, readFile as readFile3, writeFile as writeFile3 } from "fs/promises";
13127
+ import { copyFile, mkdir as mkdir3, readFile as readFile4, writeFile as writeFile3 } from "fs/promises";
13094
13128
  import { join as join8, relative } from "path";
13095
13129
 
13096
13130
  // ../design-tokens/src/generation-rules.ts
@@ -48960,7 +48994,7 @@ function buildColorSystem(options = {}) {
48960
48994
  }
48961
48995
 
48962
48996
  // ../design-tokens/src/persistence/node-adapter.ts
48963
- import { access as access2, mkdir as mkdir2, readdir as readdir2, readFile, writeFile as writeFile2 } from "fs/promises";
48997
+ import { access as access2, mkdir as mkdir2, readdir as readdir2, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
48964
48998
  import { join as join5 } from "path";
48965
48999
 
48966
49000
  // ../../node_modules/.pnpm/comment-parser@1.4.1/node_modules/comment-parser/es6/primitives.js
@@ -49925,7 +49959,7 @@ var NodePersistenceAdapter = class {
49925
49959
  }
49926
49960
  async loadNamespace(namespace) {
49927
49961
  const filePath = this.getFilePath(namespace);
49928
- const content = await readFile(filePath, "utf-8");
49962
+ const content = await readFile2(filePath, "utf-8");
49929
49963
  const json3 = JSON.parse(content);
49930
49964
  const data = NamespaceFileSchema.parse(json3);
49931
49965
  return data.tokens;
@@ -49985,16 +50019,19 @@ var RuleContextSchema = external_exports.object({
49985
50019
  });
49986
50020
 
49987
50021
  // src/utils/detect.ts
49988
- import { readFile as readFile2 } from "fs/promises";
50022
+ import { readFile as readFile3 } from "fs/promises";
49989
50023
  import { join as join7 } from "path";
49990
50024
  async function detectFramework(cwd) {
49991
50025
  try {
49992
- const content = await readFile2(join7(cwd, "package.json"), "utf-8");
50026
+ const content = await readFile3(join7(cwd, "package.json"), "utf-8");
49993
50027
  const pkg = JSON.parse(content);
49994
50028
  const deps = { ...pkg.dependencies, ...pkg.devDependencies };
49995
50029
  if (deps.next) {
49996
50030
  return "next";
49997
50031
  }
50032
+ if (deps["react-router"]) {
50033
+ return "react-router";
50034
+ }
49998
50035
  const hasRemix = Object.keys(deps).some((dep) => dep.startsWith("@remix-run/"));
49999
50036
  if (hasRemix) {
50000
50037
  return "remix";
@@ -50012,7 +50049,7 @@ async function detectFramework(cwd) {
50012
50049
  }
50013
50050
  async function detectTailwindVersion(cwd) {
50014
50051
  try {
50015
- const content = await readFile2(join7(cwd, "package.json"), "utf-8");
50052
+ const content = await readFile3(join7(cwd, "package.json"), "utf-8");
50016
50053
  const pkg = JSON.parse(content);
50017
50054
  const deps = { ...pkg.dependencies, ...pkg.devDependencies };
50018
50055
  const tailwindVersion = deps.tailwindcss;
@@ -50033,7 +50070,7 @@ function isTailwindV3(version2) {
50033
50070
  }
50034
50071
  async function detectShadcn(cwd) {
50035
50072
  try {
50036
- const content = await readFile2(join7(cwd, "components.json"), "utf-8");
50073
+ const content = await readFile3(join7(cwd, "components.json"), "utf-8");
50037
50074
  return JSON.parse(content);
50038
50075
  } catch {
50039
50076
  return null;
@@ -50106,8 +50143,17 @@ var CSS_LOCATIONS = {
50106
50143
  next: ["src/app/globals.css", "app/globals.css", "styles/globals.css"],
50107
50144
  vite: ["src/index.css", "src/main.css", "src/styles.css", "src/app.css"],
50108
50145
  remix: ["app/styles/global.css", "app/globals.css", "app/root.css"],
50146
+ "react-router": ["app/app.css", "app/root.css", "app/styles.css", "app/globals.css"],
50109
50147
  unknown: ["src/styles/global.css", "src/index.css", "styles/globals.css"]
50110
50148
  };
50149
+ var COMPONENT_PATHS = {
50150
+ astro: { components: "src/components/ui", primitives: "src/lib/primitives" },
50151
+ next: { components: "components/ui", primitives: "lib/primitives" },
50152
+ vite: { components: "src/components/ui", primitives: "src/lib/primitives" },
50153
+ remix: { components: "app/components/ui", primitives: "app/lib/primitives" },
50154
+ "react-router": { components: "app/components/ui", primitives: "app/lib/primitives" },
50155
+ unknown: { components: "components/ui", primitives: "lib/primitives" }
50156
+ };
50111
50157
  async function findMainCssFile(cwd, framework) {
50112
50158
  const locations = CSS_LOCATIONS[framework] || CSS_LOCATIONS.unknown;
50113
50159
  for (const location of locations) {
@@ -50120,7 +50166,7 @@ async function findMainCssFile(cwd, framework) {
50120
50166
  }
50121
50167
  async function updateMainCss(cwd, cssPath, themePath) {
50122
50168
  const fullCssPath = join8(cwd, cssPath);
50123
- const cssContent = await readFile3(fullCssPath, "utf-8");
50169
+ const cssContent = await readFile4(fullCssPath, "utf-8");
50124
50170
  const cssDir = join8(cwd, cssPath, "..");
50125
50171
  const themeFullPath = join8(cwd, themePath);
50126
50172
  const relativeThemePath = relative(cssDir, themeFullPath);
@@ -50206,7 +50252,7 @@ async function init(options) {
50206
50252
  if (shadcn?.tailwind?.css) {
50207
50253
  const cssPath = join8(cwd, shadcn.tailwind.css);
50208
50254
  try {
50209
- const cssContent = await readFile3(cssPath, "utf-8");
50255
+ const cssContent = await readFile4(cssPath, "utf-8");
50210
50256
  existingColors = parseCssVariables(cssContent);
50211
50257
  const backupPath = await backupCss(cssPath);
50212
50258
  log({
@@ -50291,10 +50337,11 @@ async function init(options) {
50291
50337
  await writeFile3(join8(paths.output, "theme.css"), tailwindCss);
50292
50338
  await writeFile3(join8(paths.output, "tokens.ts"), typescriptSrc);
50293
50339
  await writeFile3(join8(paths.output, "tokens.json"), JSON.stringify(dtcgJson, null, 2));
50340
+ let detectedCssPath = null;
50294
50341
  if (!shadcn) {
50295
- const mainCssPath = await findMainCssFile(cwd, framework);
50296
- if (mainCssPath) {
50297
- await updateMainCss(cwd, mainCssPath, ".rafters/output/theme.css");
50342
+ detectedCssPath = await findMainCssFile(cwd, framework);
50343
+ if (detectedCssPath) {
50344
+ await updateMainCss(cwd, detectedCssPath, ".rafters/output/theme.css");
50298
50345
  } else {
50299
50346
  log({
50300
50347
  event: "init:css_not_found",
@@ -50302,10 +50349,20 @@ async function init(options) {
50302
50349
  searchedLocations: CSS_LOCATIONS[framework] || CSS_LOCATIONS.unknown
50303
50350
  });
50304
50351
  }
50352
+ } else if (shadcn?.tailwind?.css) {
50353
+ detectedCssPath = shadcn.tailwind.css;
50305
50354
  }
50355
+ const frameworkPaths = COMPONENT_PATHS[framework] || COMPONENT_PATHS.unknown;
50356
+ const config3 = {
50357
+ framework,
50358
+ componentsPath: frameworkPaths.components,
50359
+ primitivesPath: frameworkPaths.primitives,
50360
+ cssPath: detectedCssPath
50361
+ };
50362
+ await writeFile3(paths.config, JSON.stringify(config3, null, 2));
50306
50363
  log({
50307
50364
  event: "init:complete",
50308
- outputs: ["theme.css", "tokens.ts", "tokens.json"],
50365
+ outputs: ["theme.css", "tokens.ts", "tokens.json", "config.rafters.json"],
50309
50366
  path: paths.output
50310
50367
  });
50311
50368
  }
@@ -50316,7 +50373,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
50316
50373
  import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
50317
50374
 
50318
50375
  // src/mcp/tools.ts
50319
- import { readdir as readdir3, readFile as readFile4 } from "fs/promises";
50376
+ import { readdir as readdir3, readFile as readFile5 } from "fs/promises";
50320
50377
  import { basename, join as join9 } from "path";
50321
50378
  var DESIGN_PATTERNS = {
50322
50379
  "destructive-action": {
@@ -50877,7 +50934,7 @@ var RaftersToolHandler = class {
50877
50934
  const componentsPath = this.getComponentsPath();
50878
50935
  const filePath = join9(componentsPath, `${name2}.tsx`);
50879
50936
  try {
50880
- const source = await readFile4(filePath, "utf-8");
50937
+ const source = await readFile5(filePath, "utf-8");
50881
50938
  const intelligence = parseJSDocIntelligence(source);
50882
50939
  const description = parseDescription(source);
50883
50940
  const metadata = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rafters",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "CLI for Rafters design system - scaffold tokens and add components",
5
5
  "type": "module",
6
6
  "bin": {