myoperator-ui 0.0.28 → 0.0.29

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 +27 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -588,18 +588,33 @@ async function init() {
588
588
  };
589
589
  await fs2.writeJson(configPath, config, { spaces: 2 });
590
590
  const utilsPath = path2.join(cwd, response.utilsPath);
591
+ const cnUtilsContent = `import { type ClassValue, clsx } from "clsx"
592
+ import { twMerge } from "tailwind-merge"
593
+
594
+ export function cn(...inputs: ClassValue[]) {
595
+ return twMerge(clsx(inputs))
596
+ }
597
+ `;
598
+ let utilsCreated = false;
599
+ let utilsUpdated = false;
591
600
  if (!await fs2.pathExists(utilsPath)) {
592
601
  await fs2.ensureDir(path2.dirname(utilsPath));
593
- await fs2.writeFile(
594
- utilsPath,
595
- `import { type ClassValue, clsx } from "clsx"
602
+ await fs2.writeFile(utilsPath, cnUtilsContent);
603
+ utilsCreated = true;
604
+ } else {
605
+ const existingUtils = await fs2.readFile(utilsPath, "utf-8");
606
+ if (!existingUtils.includes("export function cn") && !existingUtils.includes("export const cn")) {
607
+ const cnFunctionOnly = `
608
+ import { type ClassValue, clsx } from "clsx"
596
609
  import { twMerge } from "tailwind-merge"
597
610
 
598
611
  export function cn(...inputs: ClassValue[]) {
599
612
  return twMerge(clsx(inputs))
600
613
  }
601
- `
602
- );
614
+ `;
615
+ await fs2.appendFile(utilsPath, cnFunctionOnly);
616
+ utilsUpdated = true;
617
+ }
603
618
  }
604
619
  const componentsPath = path2.join(cwd, response.componentsPath);
605
620
  await fs2.ensureDir(componentsPath);
@@ -686,7 +701,13 @@ export function cn(...inputs: ClassValue[]) {
686
701
  }
687
702
  spinner.succeed("Project initialized successfully!");
688
703
  console.log(chalk2.green("\n \u2713 Created components.json"));
689
- console.log(chalk2.green(` \u2713 Created ${response.utilsPath}`));
704
+ if (utilsCreated) {
705
+ console.log(chalk2.green(` \u2713 Created ${response.utilsPath}`));
706
+ } else if (utilsUpdated) {
707
+ console.log(chalk2.green(` \u2713 Added cn() function to ${response.utilsPath}`));
708
+ } else {
709
+ console.log(chalk2.green(` \u2713 ${response.utilsPath} already has cn() function`));
710
+ }
690
711
  console.log(chalk2.green(` \u2713 Created ${response.componentsPath}`));
691
712
  if (cssUpdated) {
692
713
  console.log(chalk2.green(` \u2713 Updated ${response.globalCss} with CSS variables`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "myoperator-ui",
3
- "version": "0.0.28",
3
+ "version": "0.0.29",
4
4
  "description": "CLI for adding myOperator UI components to your project",
5
5
  "type": "module",
6
6
  "exports": "./dist/index.js",