@hemia/lume 0.0.5 → 0.0.6
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/dist/index.js +107 -87
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -477,102 +477,123 @@ ${result}`;
|
|
|
477
477
|
}
|
|
478
478
|
return result;
|
|
479
479
|
}
|
|
480
|
-
function
|
|
480
|
+
function parseTailwindTheme(config) {
|
|
481
481
|
const colors = /* @__PURE__ */ new Map();
|
|
482
|
-
const
|
|
483
|
-
|
|
484
|
-
const
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
482
|
+
const borderRadius = /* @__PURE__ */ new Map();
|
|
483
|
+
let darkMode = null;
|
|
484
|
+
const darkModeMatch = config.match(/darkMode:\s*([^\n,]+)/);
|
|
485
|
+
if (darkModeMatch) {
|
|
486
|
+
darkMode = darkModeMatch[1].trim();
|
|
487
|
+
}
|
|
488
|
+
const colorsMatch = config.match(/colors:\s*\{([^}]+(?:\{[^}]+\})?[^}]*)\}/);
|
|
489
|
+
if (colorsMatch) {
|
|
490
|
+
const colorsBlock = colorsMatch[1];
|
|
491
|
+
const simpleColorRegex = /([a-zA-Z0-9-]+):\s*["']([^"']+)["']/g;
|
|
492
|
+
let match;
|
|
493
|
+
while ((match = simpleColorRegex.exec(colorsBlock)) !== null) {
|
|
494
|
+
colors.set(match[1], `"${match[2]}"`);
|
|
495
|
+
}
|
|
496
|
+
const nestedColorRegex = /([a-zA-Z0-9-]+):\s*\{[^}]*DEFAULT:\s*["']([^"']+)["']/g;
|
|
497
|
+
while ((match = nestedColorRegex.exec(colorsBlock)) !== null) {
|
|
498
|
+
colors.set(match[1], `{ DEFAULT: "${match[2]}" }`);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
const radiusMatch = config.match(/borderRadius:\s*\{([^}]+)\}/);
|
|
502
|
+
if (radiusMatch) {
|
|
503
|
+
const radiusBlock = radiusMatch[1];
|
|
504
|
+
const radiusRegex = /([a-zA-Z0-9-]+):\s*["']([^"']+)["']/g;
|
|
505
|
+
let match;
|
|
506
|
+
while ((match = radiusRegex.exec(radiusBlock)) !== null) {
|
|
507
|
+
borderRadius.set(match[1], `"${match[2]}"`);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
return { colors, borderRadius, darkMode };
|
|
511
|
+
}
|
|
512
|
+
function rebuildThemeExtend(existingConfig, mergedColors, mergedRadius) {
|
|
513
|
+
let result = existingConfig;
|
|
514
|
+
const colorsEntries = Array.from(mergedColors.entries()).map(([name, value]) => {
|
|
515
|
+
const needsQuotes = name.includes("-");
|
|
516
|
+
return needsQuotes ? ` "${name}": ${value},` : ` ${name}: ${value},`;
|
|
517
|
+
}).join("\n");
|
|
518
|
+
const radiusEntries = Array.from(mergedRadius.entries()).map(([name, value]) => ` ${name}: ${value},`).join("\n");
|
|
519
|
+
const hasColors = result.includes("colors:");
|
|
520
|
+
const hasRadius = result.includes("borderRadius:");
|
|
521
|
+
const hasExtend = result.includes("extend:");
|
|
522
|
+
if (!hasExtend) {
|
|
523
|
+
const extendBlock = `theme: {
|
|
524
|
+
extend: {
|
|
525
|
+
colors: {
|
|
526
|
+
${colorsEntries}
|
|
527
|
+
},
|
|
528
|
+
borderRadius: {
|
|
529
|
+
${radiusEntries}
|
|
530
|
+
},
|
|
531
|
+
},
|
|
532
|
+
}`;
|
|
533
|
+
return result.replace(/theme:\s*\{/, extendBlock);
|
|
534
|
+
}
|
|
535
|
+
if (hasColors) {
|
|
536
|
+
result = result.replace(
|
|
537
|
+
/colors:\s*\{[\s\S]*?\n\s{4}\}/,
|
|
538
|
+
`colors: {
|
|
539
|
+
${colorsEntries}
|
|
540
|
+
}`
|
|
541
|
+
);
|
|
542
|
+
} else {
|
|
543
|
+
result = result.replace(
|
|
544
|
+
/extend:\s*\{/,
|
|
545
|
+
`extend: {
|
|
546
|
+
colors: {
|
|
547
|
+
${colorsEntries}
|
|
548
|
+
},`
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
if (hasRadius) {
|
|
552
|
+
result = result.replace(
|
|
553
|
+
/borderRadius:\s*\{[\s\S]*?\n\s{4}\}/,
|
|
554
|
+
`borderRadius: {
|
|
555
|
+
${radiusEntries}
|
|
556
|
+
}`
|
|
557
|
+
);
|
|
558
|
+
} else {
|
|
559
|
+
result = result.replace(
|
|
560
|
+
/extend:\s*\{/,
|
|
561
|
+
`extend: {
|
|
562
|
+
borderRadius: {
|
|
563
|
+
${radiusEntries}
|
|
564
|
+
},`
|
|
565
|
+
);
|
|
503
566
|
}
|
|
504
|
-
return
|
|
567
|
+
return result;
|
|
505
568
|
}
|
|
506
569
|
function mergeTailwindConfig(existingConfig, templateConfig) {
|
|
507
|
-
const
|
|
508
|
-
const
|
|
570
|
+
const existing = parseTailwindTheme(existingConfig);
|
|
571
|
+
const template = parseTailwindTheme(templateConfig);
|
|
509
572
|
let result = existingConfig;
|
|
510
573
|
if (!result.includes("theme:")) {
|
|
511
574
|
return templateConfig;
|
|
512
575
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
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: {
|
|
530
|
-
extend: {
|
|
531
|
-
colors: {
|
|
532
|
-
${colorName}: ${colorValue},
|
|
533
|
-
},`
|
|
534
|
-
);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
}
|
|
576
|
+
const mergedColors = /* @__PURE__ */ new Map();
|
|
577
|
+
for (const [name, value] of existing.colors) {
|
|
578
|
+
mergedColors.set(name, value);
|
|
539
579
|
}
|
|
540
|
-
|
|
541
|
-
|
|
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: {
|
|
557
|
-
extend: {
|
|
558
|
-
borderRadius: {
|
|
559
|
-
${radiusName}: '${radiusValue}',
|
|
560
|
-
},`
|
|
561
|
-
);
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
}
|
|
580
|
+
for (const [name, value] of template.colors) {
|
|
581
|
+
mergedColors.set(name, value);
|
|
566
582
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
583
|
+
const mergedRadius = /* @__PURE__ */ new Map();
|
|
584
|
+
for (const [name, value] of existing.borderRadius) {
|
|
585
|
+
mergedRadius.set(name, value);
|
|
586
|
+
}
|
|
587
|
+
for (const [name, value] of template.borderRadius) {
|
|
588
|
+
mergedRadius.set(name, value);
|
|
589
|
+
}
|
|
590
|
+
result = rebuildThemeExtend(result, mergedColors, mergedRadius);
|
|
591
|
+
if (!result.includes("darkMode:") && template.darkMode) {
|
|
592
|
+
result = result.replace(
|
|
593
|
+
/export default \{/,
|
|
594
|
+
`export default {
|
|
595
|
+
darkMode: ${template.darkMode},`
|
|
596
|
+
);
|
|
576
597
|
}
|
|
577
598
|
return result;
|
|
578
599
|
}
|
|
@@ -644,7 +665,6 @@ Options:
|
|
|
644
665
|
process.exit(1);
|
|
645
666
|
}
|
|
646
667
|
const framework = detectFramework(cwd);
|
|
647
|
-
const templateConfig = getTemplateConfig(framework);
|
|
648
668
|
const cssPath = path4.resolve(cwd, configPaths.globalsCssPath);
|
|
649
669
|
const tailwindPath = path4.resolve(cwd, configPaths.tailwindConfigPath);
|
|
650
670
|
const cssExists = await fs4.pathExists(cssPath);
|