weloop-kosign 1.0.3 → 1.0.4

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.
package/README.md CHANGED
@@ -4,23 +4,18 @@ A modular component library built with Next.js, similar to shadcn/ui. Install on
4
4
 
5
5
  ## Installation
6
6
 
7
- First, make sure you have the base dependencies installed:
8
-
9
- ```bash
10
- npm install clsx tailwind-merge
11
- ```
12
-
13
- Then install components using the CLI:
7
+ Install components directly - the CLI handles everything automatically:
14
8
 
15
9
  ```bash
16
10
  npx weloop-kosign@latest add button
17
11
  ```
18
12
 
19
- To install the base CSS styles:
13
+ This will automatically:
20
14
 
21
- ```bash
22
- npx weloop-kosign@latest css
23
- ```
15
+ - Install base dependencies (`clsx`, `tailwind-merge`, `tw-animate-css`)
16
+ - Create `components.json` configuration file
17
+ - Install CSS styles with animations
18
+ - Install the component and its dependencies
24
19
 
25
20
  ## Usage
26
21
 
@@ -34,7 +29,7 @@ export function MyComponent() {
34
29
  }
35
30
  ```
36
31
 
37
- The CLI will automatically install any required dependencies for each component. If something's missing, it'll let you know.
32
+ The CLI automatically handles all dependencies, configuration, and CSS setup. No manual setup required.
38
33
 
39
34
  ## Available Commands
40
35
 
@@ -50,7 +45,7 @@ See all available components:
50
45
  npx weloop-kosign@latest list
51
46
  ```
52
47
 
53
- Install or update CSS styles:
48
+ Install or update CSS styles (optional - CSS is auto-installed with components):
54
49
 
55
50
  ```bash
56
51
  npx weloop-kosign@latest css
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weloop-kosign",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "CLI tool for installing Weloop UI components",
5
5
  "keywords": [
6
6
  "weloop",
@@ -405,6 +405,28 @@ function hasWeloopStyles(content) {
405
405
  content.includes('--system-200');
406
406
  }
407
407
 
408
+ function removeDuplicateTwAnimateImports(cssContent) {
409
+ const twAnimatePattern = /@import\s+["']tw-animate-css["'];?\s*\n?/g;
410
+ const matches = cssContent.match(twAnimatePattern);
411
+
412
+ if (matches && matches.length > 1) {
413
+ // Remove all occurrences
414
+ let cleaned = cssContent.replace(twAnimatePattern, '');
415
+ // Add it back once after tailwindcss import
416
+ if (cleaned.includes('@import "tailwindcss"') || cleaned.includes("@import 'tailwindcss'")) {
417
+ cleaned = cleaned.replace(
418
+ /(@import\s+["']tailwindcss["'];?\s*\n?)/,
419
+ '$1@import "tw-animate-css";\n'
420
+ );
421
+ } else {
422
+ cleaned = '@import "tw-animate-css";\n' + cleaned;
423
+ }
424
+ return cleaned;
425
+ }
426
+
427
+ return cssContent;
428
+ }
429
+
408
430
  function processTwAnimateImport(cssContent, hasTwAnimate, forceUpdate = false) {
409
431
  const twAnimatePattern = /@import\s+["']tw-animate-css["'];?\s*\n?/g;
410
432
  let processed = cssContent;
@@ -423,7 +445,10 @@ function processTwAnimateImport(cssContent, hasTwAnimate, forceUpdate = false) {
423
445
  }
424
446
  }
425
447
  } else {
426
- // Ensure import exists if package is installed
448
+ // Remove any duplicates first
449
+ processed = removeDuplicateTwAnimateImports(processed);
450
+
451
+ // Ensure import exists if package is installed (only if not already present)
427
452
  if (!processed.match(/@import\s+["']tw-animate-css["'];?\s*\n?/)) {
428
453
  if (processed.includes('@import "tailwindcss"') || processed.includes("@import 'tailwindcss'")) {
429
454
  processed = processed.replace(
@@ -444,10 +469,27 @@ function removeTailwindImport(cssContent) {
444
469
  }
445
470
 
446
471
  function ensureTwAnimateImport(cssContent, hasTwAnimate) {
447
- if (!hasTwAnimate || cssContent.includes('@import "tw-animate-css"')) {
472
+ if (!hasTwAnimate) {
448
473
  return cssContent;
449
474
  }
450
- return '@import "tw-animate-css";\n' + cssContent;
475
+
476
+ // Remove duplicates first
477
+ let cleaned = removeDuplicateTwAnimateImports(cssContent);
478
+
479
+ // Check if import already exists
480
+ if (cleaned.match(/@import\s+["']tw-animate-css["'];?\s*\n?/)) {
481
+ return cleaned;
482
+ }
483
+
484
+ // Add import after tailwindcss if it exists
485
+ if (cleaned.includes('@import "tailwindcss"') || cleaned.includes("@import 'tailwindcss'")) {
486
+ return cleaned.replace(
487
+ /(@import\s+["']tailwindcss["'];?\s*\n?)/,
488
+ '$1@import "tw-animate-css";\n'
489
+ );
490
+ }
491
+
492
+ return '@import "tw-animate-css";\n' + cleaned;
451
493
  }
452
494
 
453
495
  function mergeCSSWithTailwind(existing, weloopStyles, hasTwAnimate) {
@@ -459,8 +501,12 @@ function mergeCSSWithTailwind(existing, weloopStyles, hasTwAnimate) {
459
501
  const beforeTailwind = existing.substring(0, existing.indexOf(tailwindMatch[0]));
460
502
  const afterTailwind = existing.substring(existing.indexOf(tailwindMatch[0]) + tailwindMatch[0].length);
461
503
 
504
+ // Check if tw-animate-css import already exists in existing or weloopStyles
505
+ const hasTwAnimateInExisting = existing.match(/@import\s+["']tw-animate-css["'];?\s*\n?/);
506
+ const hasTwAnimateInWeloop = weloopStyles.match(/@import\s+["']tw-animate-css["'];?\s*\n?/);
507
+
462
508
  let importsToAdd = '';
463
- if (hasTwAnimate && !existing.includes('@import "tw-animate-css"')) {
509
+ if (hasTwAnimate && !hasTwAnimateInExisting && !hasTwAnimateInWeloop) {
464
510
  importsToAdd = '@import "tw-animate-css";\n';
465
511
  }
466
512
 
@@ -562,8 +608,11 @@ async function installCSSStyles(config, registryUrl, forceUpdate = false) {
562
608
  info(` Your existing styles are preserved`);
563
609
  } else {
564
610
  // No Tailwind imports, prepend everything
565
- let finalCssContent = processedCssContent;
566
- if (hasTwAnimate && !finalCssContent.includes('@import "tw-animate-css"')) {
611
+ // Remove duplicates from processedCssContent first
612
+ let finalCssContent = removeDuplicateTwAnimateImports(processedCssContent);
613
+
614
+ // Only add if not already present
615
+ if (hasTwAnimate && !finalCssContent.match(/@import\s+["']tw-animate-css["'];?\s*\n?/)) {
567
616
  if (finalCssContent.includes('@import "tailwindcss"')) {
568
617
  finalCssContent = finalCssContent.replace(
569
618
  /(@import\s+["']tailwindcss["'];?\s*\n?)/,
@@ -615,16 +664,25 @@ export function cn(...inputs: ClassValue[]) {
615
664
  `;
616
665
  fs.writeFileSync(utilsPath, utilsContent);
617
666
  success(`Created ${path.relative(process.cwd(), utilsPath)}`);
618
-
619
- // Check if required packages are installed
620
- if (!checkPackageInstalled('clsx') || !checkPackageInstalled('tailwind-merge')) {
621
- warn('utils.ts requires: clsx and tailwind-merge');
622
- info(' Install with: npm install clsx tailwind-merge');
623
- }
624
667
  }
625
668
 
626
669
  async function installComponent(componentName, options = {}) {
627
670
  const { overwrite = false, registryUrl = DEFAULT_REGISTRY_URL } = options;
671
+
672
+ // Install base dependencies first (required for utils.ts)
673
+ const baseDeps = [];
674
+ if (!checkPackageInstalled('clsx')) {
675
+ baseDeps.push('clsx');
676
+ }
677
+ if (!checkPackageInstalled('tailwind-merge')) {
678
+ baseDeps.push('tailwind-merge');
679
+ }
680
+ if (baseDeps.length > 0) {
681
+ info(`Installing base dependencies: ${baseDeps.join(', ')}...`);
682
+ await installPackages(baseDeps);
683
+ }
684
+
685
+ // Load or create components.json (after base deps are installed)
628
686
  const config = loadComponentsConfig();
629
687
 
630
688
  // Install tw-animate-css automatically (required for animations)