@quarklab/rad-ui 0.3.8 → 0.3.9

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 +28 -12
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -84,8 +84,19 @@ async function detectSrcDir(cwd) {
84
84
  if (await fs.pathExists(configPath)) {
85
85
  try {
86
86
  const raw = await fs.readFile(configPath, "utf-8");
87
- const cleaned = raw.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
88
- const config = JSON.parse(cleaned);
87
+ let config;
88
+ try {
89
+ config = JSON.parse(raw);
90
+ } catch {
91
+ const cleaned = raw.replace(
92
+ /("(?:[^"\\]|\\.)*")|\/\/.*$/gm,
93
+ (_, str) => str || ""
94
+ ).replace(
95
+ /("(?:[^"\\]|\\.)*")|\/\*[\s\S]*?\*\//g,
96
+ (_, str) => str || ""
97
+ ).replace(/,\s*([\]}])/g, "$1");
98
+ config = JSON.parse(cleaned);
99
+ }
89
100
  const paths = config?.compilerOptions?.paths;
90
101
  if (paths) {
91
102
  const aliasKey = Object.keys(paths).find(
@@ -94,7 +105,7 @@ async function detectSrcDir(cwd) {
94
105
  if (aliasKey) {
95
106
  const aliasTargets = paths[aliasKey];
96
107
  if (Array.isArray(aliasTargets) && aliasTargets.length > 0) {
97
- const target = aliasTargets[0].replace(/^\.\//, "").replace(/\/\*$/, "");
108
+ const target = aliasTargets[0].replace(/^\.\//, "").replace(/\/?\*$/, "");
98
109
  return target === "" ? "." : target;
99
110
  }
100
111
  }
@@ -111,7 +122,7 @@ function getDefaultCssPath(projectType, srcDir) {
111
122
  const prefix = srcDir === "." ? "" : srcDir ? `${srcDir}/` : "src/";
112
123
  switch (projectType) {
113
124
  case "nextjs":
114
- return `${prefix}/globals.css`;
125
+ return `${prefix}app/globals.css`;
115
126
  case "vite":
116
127
  return `${prefix}index.css`;
117
128
  case "cra":
@@ -488,7 +499,12 @@ async function initCommand(opts) {
488
499
  p.log.info(`Tailwind CSS: ${chalk2.cyan(tailwindVersion)}`);
489
500
  const srcDirDisplay = detectedSrcDir === "." ? "project root" : detectedSrcDir + "/";
490
501
  p.log.info(`Source directory: ${chalk2.cyan(srcDirDisplay)}`);
491
- const examplePrefix = detectedSrcDir === "." ? "" : detectedSrcDir + "/";
502
+ const isRootNextJs = projectType === "nextjs" && detectedSrcDir === ".";
503
+ const aliasBase = isRootNextJs ? "@/app" : "@";
504
+ const defaultComponents = `${aliasBase}/components/ui`;
505
+ const defaultUtils = `${aliasBase}/lib/utils`;
506
+ const defaultHooks = `${aliasBase}/hooks`;
507
+ const examplePrefix = isRootNextJs ? "app/" : detectedSrcDir === "." ? "" : detectedSrcDir + "/";
492
508
  const responses = await p.group(
493
509
  {
494
510
  theme: () => p.select({
@@ -506,18 +522,18 @@ async function initCommand(opts) {
506
522
  }),
507
523
  componentsPath: () => p.text({
508
524
  message: `Where to add UI components (e.g. ${examplePrefix}components/ui):`,
509
- placeholder: "@/components/ui",
510
- defaultValue: "@/components/ui"
525
+ placeholder: defaultComponents,
526
+ defaultValue: defaultComponents
511
527
  }),
512
528
  utilsPath: () => p.text({
513
529
  message: `Where to create the cn() helper (e.g. ${examplePrefix}lib/utils.ts):`,
514
- placeholder: "@/lib/utils",
515
- defaultValue: "@/lib/utils"
530
+ placeholder: defaultUtils,
531
+ defaultValue: defaultUtils
516
532
  }),
517
533
  hooksPath: () => p.text({
518
534
  message: `Where to add hooks (e.g. ${examplePrefix}hooks):`,
519
- placeholder: "@/hooks",
520
- defaultValue: "@/hooks"
535
+ placeholder: defaultHooks,
536
+ defaultValue: defaultHooks
521
537
  }),
522
538
  cssPath: () => p.text({
523
539
  message: `Path to your global CSS file:`,
@@ -1045,7 +1061,7 @@ function transformImports(source, config) {
1045
1061
  );
1046
1062
  result = result.replace(
1047
1063
  /from\s+["']\.\/lib\/utils["']/g,
1048
- `from "@${utilsAlias}"`
1064
+ `from "${utilsAlias}"`
1049
1065
  );
1050
1066
  return result;
1051
1067
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quarklab/rad-ui",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "description": "A CLI for adding Rad UI components to your project. Beautiful Persian-themed React components built on Radix UI and Tailwind CSS.",
5
5
  "license": "MIT",
6
6
  "type": "module",