@dinachi/cli 0.6.0 → 0.6.1

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 +78 -16
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -668,6 +668,45 @@ ${withTrailingComma}
668
668
  `;
669
669
  return next;
670
670
  }
671
+ function detectTailwindMajorVersion(projectRoot) {
672
+ const packageJsonPath = path3.join(projectRoot, "package.json");
673
+ if (!fs3.existsSync(packageJsonPath)) return 4;
674
+ try {
675
+ const raw = fs3.readFileSync(packageJsonPath, "utf-8");
676
+ const packageJson = JSON.parse(raw);
677
+ const deps = { ...packageJson.dependencies ?? {}, ...packageJson.devDependencies ?? {} };
678
+ const twVersion = deps.tailwindcss;
679
+ if (!twVersion) return 4;
680
+ const match = twVersion.match(/(\d+)/);
681
+ return match ? parseInt(match[1], 10) : 4;
682
+ } catch {
683
+ return 4;
684
+ }
685
+ }
686
+ async function ensureTW4Plugin(deps, cssFilePath) {
687
+ if (!deps.includes("tailwindcss-animate")) {
688
+ return null;
689
+ }
690
+ if (!fs3.existsSync(cssFilePath)) {
691
+ return { skipped: true, path: cssFilePath };
692
+ }
693
+ const content = await fs3.readFile(cssFilePath, "utf-8");
694
+ if (content.includes("tailwindcss-animate")) {
695
+ return { exists: true, path: cssFilePath };
696
+ }
697
+ const pluginLine = '@plugin "tailwindcss-animate";';
698
+ const importMatch = content.match(/^@import\s+["']tailwindcss["'];?\s*$/m);
699
+ let updated;
700
+ if (importMatch) {
701
+ updated = content.replace(importMatch[0], `${importMatch[0].trimEnd()}
702
+ ${pluginLine}`);
703
+ } else {
704
+ updated = `${pluginLine}
705
+ ${content}`;
706
+ }
707
+ await fs3.writeFile(cssFilePath, updated);
708
+ return { updated: true, path: cssFilePath };
709
+ }
671
710
  async function ensureTailwindConfig(deps, projectRoot, configuredFileName) {
672
711
  if (!deps.includes("tailwindcss-animate")) {
673
712
  return null;
@@ -761,8 +800,8 @@ ${linesToAppend.join("\n")}
761
800
  await fs3.writeFile(targetPath, updatedContent);
762
801
  allFilesAdded.push({ name: "index.ts", path: path3.join(targetDir, "index.ts") });
763
802
  }
764
- var addCommand = new Command("add").description("Add a component to your project").argument("[component]", "Name of the component (optional when using --all)").option("-y, --yes", "Skip confirmation prompts").option("-o, --overwrite", "Overwrite existing files").option("-a, --all", "Install all available components").option("--skip-install", "Skip package installation").action(
765
- async (componentName, options) => {
803
+ var addCommand = new Command("add").description("Add a component to your project").argument("[components...]", "Names of the components to add (optional when using --all)").option("-y, --yes", "Skip confirmation prompts").option("-o, --overwrite", "Overwrite existing files").option("-a, --all", "Install all available components").option("--skip-install", "Skip package installation").action(
804
+ async (componentNames, options) => {
766
805
  const spinner = ora("Adding component...").start();
767
806
  try {
768
807
  const config = await getConfig();
@@ -785,7 +824,7 @@ var addCommand = new Command("add").description("Add a component to your project
785
824
  }
786
825
  componentsToInstall = Array.from(allComponentsWithDeps);
787
826
  } else {
788
- if (!componentName) {
827
+ if (componentNames.length === 0) {
789
828
  spinner.fail("\u274C Component name is required when not using --all flag.");
790
829
  console.log("Available components:");
791
830
  Object.keys(registry).forEach((name) => {
@@ -793,16 +832,23 @@ var addCommand = new Command("add").description("Add a component to your project
793
832
  });
794
833
  process.exit(1);
795
834
  }
796
- const component = registry[componentName];
797
- if (!component) {
798
- spinner.fail(`\u274C Component "${componentName}" not found.`);
799
- console.log("Available components:");
800
- Object.keys(registry).forEach((name) => {
801
- console.log(` ${chalk.cyan(name)}`);
802
- });
803
- process.exit(1);
835
+ for (const name of componentNames) {
836
+ if (!registry[name]) {
837
+ spinner.fail(`\u274C Component "${name}" not found.`);
838
+ console.log("Available components:");
839
+ Object.keys(registry).forEach((n) => {
840
+ console.log(` ${chalk.cyan(n)}`);
841
+ });
842
+ process.exit(1);
843
+ }
844
+ }
845
+ const allWithDeps = /* @__PURE__ */ new Set();
846
+ for (const name of componentNames) {
847
+ allWithDeps.add(name);
848
+ const deps = getComponentDependencies(name);
849
+ deps.forEach((dep) => allWithDeps.add(dep));
804
850
  }
805
- componentsToInstall = [componentName, ...getComponentDependencies(componentName)];
851
+ componentsToInstall = Array.from(allWithDeps);
806
852
  }
807
853
  if (!options.all) {
808
854
  spinner.text = `Installing ${componentsToInstall.join(", ")}...`;
@@ -868,7 +914,11 @@ var addCommand = new Command("add").description("Add a component to your project
868
914
  }
869
915
  }
870
916
  spinner.text = "Updating Tailwind configuration...";
871
- const tailwindConfigInfo = await ensureTailwindConfig(
917
+ const tailwindMajor = detectTailwindMajorVersion(projectRoot);
918
+ const tailwindConfigInfo = tailwindMajor >= 4 ? await ensureTW4Plugin(
919
+ allDepsInstalled,
920
+ path3.resolve(projectRoot, config.tailwind?.css || "src/index.css")
921
+ ) : await ensureTailwindConfig(
872
922
  allDepsInstalled,
873
923
  projectRoot,
874
924
  config.tailwind?.config || "tailwind.config.js"
@@ -967,7 +1017,7 @@ export function cn(...inputs: ClassValue[]) {
967
1017
  }
968
1018
  `;
969
1019
  }
970
- function detectTailwindMajorVersion(projectRoot) {
1020
+ function detectTailwindMajorVersion2(projectRoot) {
971
1021
  const packageJsonPath = path4.join(projectRoot, "package.json");
972
1022
  if (!fs4.existsSync(packageJsonPath)) return 4;
973
1023
  try {
@@ -1081,6 +1131,16 @@ function getThemeCSS(tailwindMajor, mode) {
1081
1131
  }
1082
1132
  return parts.join("\n\n") + "\n";
1083
1133
  }
1134
+ function stripConflictingCSS(css) {
1135
+ let result = css;
1136
+ result = result.replace(/@media\s*\(\s*prefers-color-scheme\s*:\s*dark\s*\)\s*\{[\s\S]*?\n\}/g, "");
1137
+ result = result.replace(/:root\s*\{[^}]*\}/g, "");
1138
+ result = result.replace(/\.dark\s*\{[^}]*\}/g, "");
1139
+ result = result.replace(/@theme\s+inline\s*\{[^}]*\}/g, "");
1140
+ result = result.replace(/(?:^|\n)body\s*\{[^}]*\}/g, "");
1141
+ result = result.replace(/\n{3,}/g, "\n\n");
1142
+ return result.trim();
1143
+ }
1084
1144
  async function injectThemeCSS(cssFilePath, tailwindMajor) {
1085
1145
  await fs4.ensureDir(path4.dirname(cssFilePath));
1086
1146
  if (fs4.existsSync(cssFilePath)) {
@@ -1088,8 +1148,10 @@ async function injectThemeCSS(cssFilePath, tailwindMajor) {
1088
1148
  if (existing.includes("--primary:")) {
1089
1149
  return { path: cssFilePath, skipped: true };
1090
1150
  }
1151
+ const cleaned = stripConflictingCSS(existing);
1091
1152
  const theme2 = getThemeCSS(tailwindMajor, "append");
1092
- await fs4.writeFile(cssFilePath, existing.trimEnd() + "\n\n" + theme2);
1153
+ const result = cleaned.length > 0 ? cleaned + "\n\n" + theme2 : getThemeCSS(tailwindMajor, "full");
1154
+ await fs4.writeFile(cssFilePath, result);
1093
1155
  return { path: cssFilePath, updated: true };
1094
1156
  }
1095
1157
  const theme = getThemeCSS(tailwindMajor, "full");
@@ -1332,7 +1394,7 @@ var initCommand = new Command2("init").description("Initialize Dinachi UI in you
1332
1394
  const utilsContent = createUtilsFileContent();
1333
1395
  await fs4.writeFile(utilsFilePath, utilsContent);
1334
1396
  spinner.text = "Setting up color theme...";
1335
- const tailwindMajor = detectTailwindMajorVersion(projectRoot);
1397
+ const tailwindMajor = detectTailwindMajorVersion2(projectRoot);
1336
1398
  const cssFilePath = path4.resolve(projectRoot, projectConfig.cssPath);
1337
1399
  const themeCSSResult = await injectThemeCSS(cssFilePath, tailwindMajor);
1338
1400
  let twColorConfigResult = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dinachi/cli",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "CLI for adding Dinachi UI components to your project",
5
5
  "type": "module",
6
6
  "keywords": [