@hemia/lume 0.0.4 → 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 +96 -31
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -477,37 +477,102 @@ ${result}`;
477
477
  }
478
478
  return result;
479
479
  }
480
+ function extractColors(templateConfig) {
481
+ const colors = /* @__PURE__ */ new Map();
482
+ const colorsMatch = templateConfig.match(/colors:\s*\{([\s\S]*?)\n\s*\}/);
483
+ if (!colorsMatch) return colors;
484
+ const colorsBlock = colorsMatch[1];
485
+ const colorRegex = /([a-zA-Z0-9-]+):\s*\{([^}]+)\}/g;
486
+ let match;
487
+ while ((match = colorRegex.exec(colorsBlock)) !== null) {
488
+ const colorName = match[1];
489
+ const colorValue = match[2].trim();
490
+ colors.set(colorName, colorValue);
491
+ }
492
+ return colors;
493
+ }
494
+ function extractBorderRadius(templateConfig) {
495
+ const radius = /* @__PURE__ */ new Map();
496
+ const radiusMatch = templateConfig.match(/borderRadius:\s*\{([\s\S]*?)\n\s*\}/);
497
+ if (!radiusMatch) return radius;
498
+ const radiusBlock = radiusMatch[1];
499
+ const radiusRegex = /([a-zA-Z0-9-]+):\s*['"`]([^'"`]+)['"`]/g;
500
+ let match;
501
+ while ((match = radiusRegex.exec(radiusBlock)) !== null) {
502
+ radius.set(match[1], match[2]);
503
+ }
504
+ return radius;
505
+ }
480
506
  function mergeTailwindConfig(existingConfig, templateConfig) {
481
- const colorMatches = templateConfig.match(/colors:\s*\{([\s\S]*?)\}/);
482
- const radiusMatches = templateConfig.match(/borderRadius:\s*\{([\s\S]*?)\}/);
507
+ const templateColors = extractColors(templateConfig);
508
+ const templateRadius = extractBorderRadius(templateConfig);
483
509
  let result = existingConfig;
484
510
  if (!result.includes("theme:")) {
485
511
  return templateConfig;
486
512
  }
487
- if (colorMatches) {
488
- const colorsBlock = colorMatches[0];
489
- if (!result.includes("colors:")) {
490
- result = result.replace(
491
- /theme:\s*\{/,
492
- `theme: {
513
+ if (templateColors.size > 0) {
514
+ for (const [colorName, colorValue] of templateColors) {
515
+ if (!result.includes(`${colorName}:`)) {
516
+ const themeMatch = result.match(/theme:\s*\{/);
517
+ if (themeMatch) {
518
+ if (result.includes("extend:")) {
519
+ result = result.replace(
520
+ /extend:\s*\{/,
521
+ `extend: {
522
+ colors: {
523
+ ${colorName}: ${colorValue},
524
+ },`
525
+ );
526
+ } else {
527
+ result = result.replace(
528
+ /theme:\s*\{/,
529
+ `theme: {
493
530
  extend: {
494
- colors: {${colorsBlock.replace("colors:", "")}`
495
- );
531
+ colors: {
532
+ ${colorName}: ${colorValue},
533
+ },`
534
+ );
535
+ }
536
+ }
537
+ }
496
538
  }
497
539
  }
498
- if (radiusMatches) {
499
- const radiusBlock = radiusMatches[0];
500
- if (!result.includes("borderRadius:")) {
501
- result = result.replace(
502
- /theme:\s*\{/,
503
- `theme: {
540
+ if (templateRadius.size > 0) {
541
+ for (const [radiusName, radiusValue] of templateRadius) {
542
+ if (!result.includes(`${radiusName}:`)) {
543
+ const themeMatch = result.match(/theme:\s*\{/);
544
+ if (themeMatch) {
545
+ if (result.includes("extend:")) {
546
+ result = result.replace(
547
+ /extend:\s*\{/,
548
+ `extend: {
549
+ borderRadius: {
550
+ ${radiusName}: '${radiusValue}',
551
+ },`
552
+ );
553
+ } else {
554
+ result = result.replace(
555
+ /theme:\s*\{/,
556
+ `theme: {
504
557
  extend: {
505
- borderRadius: {${radiusBlock.replace("borderRadius:", "")}`
506
- );
558
+ borderRadius: {
559
+ ${radiusName}: '${radiusValue}',
560
+ },`
561
+ );
562
+ }
563
+ }
564
+ }
507
565
  }
508
566
  }
509
- if (!result.includes("colors:") && colorMatches) {
510
- return templateConfig;
567
+ if (!result.includes("darkMode:") && templateConfig.includes("darkMode:")) {
568
+ const darkModeMatch = templateConfig.match(/darkMode:\s*\[[^\]]+\]/);
569
+ if (darkModeMatch) {
570
+ result = result.replace(
571
+ /export default \{/,
572
+ `export default {
573
+ ${darkModeMatch[0]},`
574
+ );
575
+ }
511
576
  }
512
577
  return result;
513
578
  }
@@ -530,6 +595,15 @@ function detectFramework(cwd) {
530
595
  return "vue";
531
596
  }
532
597
  }
598
+ function detectTailwindConfigExtension(cwd) {
599
+ const extensions = ["js", "ts", "mjs", "cjs"];
600
+ for (const ext of extensions) {
601
+ if (fs4.existsSync(path4.resolve(cwd, `tailwind.config.${ext}`))) {
602
+ return ext;
603
+ }
604
+ }
605
+ return "js";
606
+ }
533
607
  async function addStyles(_args = [], options = {}) {
534
608
  if (options.silent === void 0 && process.argv.includes("--help") || process.argv.includes("-h")) {
535
609
  console.log(`
@@ -548,15 +622,8 @@ Options:
548
622
  return;
549
623
  }
550
624
  const cwd = options.cwd ? path4.resolve(options.cwd) : process.cwd();
551
- function detectTailwindConfigExtension(cwd2) {
552
- const extensions = ["js", "ts", "mjs", "cjs"];
553
- for (const ext of extensions) {
554
- if (fs4.existsSync(path4.resolve(cwd2, `tailwind.config.${ext}`))) {
555
- return ext;
556
- }
557
- }
558
- return "js";
559
- }
625
+ const tailwindExt = detectTailwindConfigExtension(cwd);
626
+ const tailwindTemplate = tailwindExt === "js" ? TAILWIND_CONFIG_TEMPLATE_JS : TAILWIND_CONFIG_TEMPLATE;
560
627
  const configPath = path4.resolve(cwd, "lume.config.json");
561
628
  if (!await fs4.pathExists(configPath)) {
562
629
  const cssPath2 = path4.resolve(cwd, "src/assets/globals.css");
@@ -578,8 +645,6 @@ Options:
578
645
  }
579
646
  const framework = detectFramework(cwd);
580
647
  const templateConfig = getTemplateConfig(framework);
581
- const tailwindExt = detectTailwindConfigExtension(cwd);
582
- const tailwindTemplate = tailwindExt === "js" ? TAILWIND_CONFIG_TEMPLATE_JS : tailwindTemplate;
583
648
  const cssPath = path4.resolve(cwd, configPaths.globalsCssPath);
584
649
  const tailwindPath = path4.resolve(cwd, configPaths.tailwindConfigPath);
585
650
  const cssExists = await fs4.pathExists(cssPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hemia/lume",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "files": ["dist"],
6
6
  "bin": {