@hemia/lume 0.0.3 → 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 +174 -30
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -336,6 +336,53 @@ export default {
336
336
  plugins: [],
337
337
  } satisfies Config
338
338
  `;
339
+ var TAILWIND_CONFIG_TEMPLATE_JS = `/** @type {import('tailwindcss').Config} */
340
+ export default {
341
+ darkMode: ['class'],
342
+ content: [
343
+ './index.html',
344
+ './src/**/*.{vue,js,ts,jsx,tsx}',
345
+ ],
346
+ theme: {
347
+ extend: {
348
+ colors: {
349
+ border: 'hsl(var(--border))',
350
+ input: 'hsl(var(--input))',
351
+ ring: 'hsl(var(--ring))',
352
+ background: 'hsl(var(--background))',
353
+ foreground: 'hsl(var(--foreground))',
354
+ primary: {
355
+ DEFAULT: 'hsl(var(--primary))',
356
+ foreground: 'hsl(var(--primary-foreground))',
357
+ },
358
+ secondary: {
359
+ DEFAULT: 'hsl(var(--secondary))',
360
+ foreground: 'hsl(var(--secondary-foreground))',
361
+ },
362
+ destructive: {
363
+ DEFAULT: 'hsl(var(--destructive))',
364
+ foreground: 'hsl(var(--destructive-foreground))',
365
+ },
366
+ muted: {
367
+ DEFAULT: 'hsl(var(--muted))',
368
+ foreground: 'hsl(var(--muted-foreground))',
369
+ },
370
+ accent: {
371
+ DEFAULT: 'hsl(var(--accent))',
372
+ foreground: 'hsl(var(--accent-foreground))',
373
+ },
374
+ },
375
+ borderRadius: {
376
+ sm: 'var(--radius-sm)',
377
+ md: 'var(--radius-md)',
378
+ lg: 'var(--radius-lg)',
379
+ DEFAULT: 'var(--radius)',
380
+ },
381
+ },
382
+ },
383
+ plugins: [],
384
+ }
385
+ `;
339
386
  function getTemplateConfig(framework, template) {
340
387
  const configs = {
341
388
  "vite-vue": {
@@ -382,10 +429,11 @@ function info(message, options) {
382
429
  }
383
430
  function extractCssVariables(cssContent) {
384
431
  const vars = /* @__PURE__ */ new Map();
385
- const varRegex = /--([a-zA-Z0-9-]+):\s*([^;]+);/g;
432
+ const cleanContent = cssContent.replace(/\/\*[\s\S]*?\*\//g, "");
433
+ const varRegex = /--([a-zA-Z0-9-]+)\s*:\s*([^;]+);/g;
386
434
  let match;
387
- while ((match = varRegex.exec(cssContent)) !== null) {
388
- vars.set(match[1], match[2]);
435
+ while ((match = varRegex.exec(cleanContent)) !== null) {
436
+ vars.set(match[1].trim(), match[2].trim());
389
437
  }
390
438
  return vars;
391
439
  }
@@ -396,8 +444,8 @@ function mergeCssVariables(existingCss, templateCss) {
396
444
  existingVars.set(key, value);
397
445
  }
398
446
  let result = existingCss;
399
- const rootMatch = result.match(/@layer base\s*\{[\s\S]*?:root\s*\{([\s\S]*?)\}/);
400
- if (rootMatch) {
447
+ const rootLayerMatch = result.match(/@layer base\s*\{[\s\S]*?:root\s*\{([\s\S]*?)\}/);
448
+ if (rootLayerMatch) {
401
449
  const newRootVars = Array.from(existingVars.entries()).map(([key, value]) => ` --${key}: ${value};`).join("\n");
402
450
  result = result.replace(
403
451
  /@layer base\s*\{[\s\S]*?:root\s*\{[\s\S]*?\}/,
@@ -406,40 +454,125 @@ function mergeCssVariables(existingCss, templateCss) {
406
454
  ${newRootVars}
407
455
  }`
408
456
  );
457
+ } else {
458
+ const rootMatch = result.match(/:root\s*\{([\s\S]*?)\}/);
459
+ if (rootMatch) {
460
+ const newRootVars = Array.from(existingVars.entries()).map(([key, value]) => ` --${key}: ${value};`).join("\n");
461
+ result = result.replace(
462
+ /:root\s*\{[\s\S]*?\}/,
463
+ `:root {
464
+ ${newRootVars}
465
+ }`
466
+ );
467
+ } else {
468
+ const newRootVars = Array.from(existingVars.entries()).map(([key, value]) => ` --${key}: ${value};`).join("\n");
469
+ result = `@layer base {
470
+ :root {
471
+ ${newRootVars}
472
+ }
473
+ }
474
+
475
+ ${result}`;
476
+ }
409
477
  }
410
478
  return result;
411
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
+ }
412
506
  function mergeTailwindConfig(existingConfig, templateConfig) {
413
- const colorMatches = templateConfig.match(/colors:\s*\{([\s\S]*?)\}/);
414
- const radiusMatches = templateConfig.match(/borderRadius:\s*\{([\s\S]*?)\}/);
507
+ const templateColors = extractColors(templateConfig);
508
+ const templateRadius = extractBorderRadius(templateConfig);
415
509
  let result = existingConfig;
416
510
  if (!result.includes("theme:")) {
417
511
  return templateConfig;
418
512
  }
419
- if (colorMatches) {
420
- const colorsBlock = colorMatches[0];
421
- if (!result.includes("colors:")) {
422
- result = result.replace(
423
- /theme:\s*\{/,
424
- `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: {
425
530
  extend: {
426
- colors: {${colorsBlock.replace("colors:", "")}`
427
- );
531
+ colors: {
532
+ ${colorName}: ${colorValue},
533
+ },`
534
+ );
535
+ }
536
+ }
537
+ }
428
538
  }
429
539
  }
430
- if (radiusMatches) {
431
- const radiusBlock = radiusMatches[0];
432
- if (!result.includes("borderRadius:")) {
433
- result = result.replace(
434
- /theme:\s*\{/,
435
- `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: {
436
557
  extend: {
437
- borderRadius: {${radiusBlock.replace("borderRadius:", "")}`
438
- );
558
+ borderRadius: {
559
+ ${radiusName}: '${radiusValue}',
560
+ },`
561
+ );
562
+ }
563
+ }
564
+ }
439
565
  }
440
566
  }
441
- if (!result.includes("colors:") && colorMatches) {
442
- 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
+ }
443
576
  }
444
577
  return result;
445
578
  }
@@ -462,6 +595,15 @@ function detectFramework(cwd) {
462
595
  return "vue";
463
596
  }
464
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
+ }
465
607
  async function addStyles(_args = [], options = {}) {
466
608
  if (options.silent === void 0 && process.argv.includes("--help") || process.argv.includes("-h")) {
467
609
  console.log(`
@@ -480,6 +622,8 @@ Options:
480
622
  return;
481
623
  }
482
624
  const cwd = options.cwd ? path4.resolve(options.cwd) : process.cwd();
625
+ const tailwindExt = detectTailwindConfigExtension(cwd);
626
+ const tailwindTemplate = tailwindExt === "js" ? TAILWIND_CONFIG_TEMPLATE_JS : TAILWIND_CONFIG_TEMPLATE;
483
627
  const configPath = path4.resolve(cwd, "lume.config.json");
484
628
  if (!await fs4.pathExists(configPath)) {
485
629
  const cssPath2 = path4.resolve(cwd, "src/assets/globals.css");
@@ -489,7 +633,7 @@ Options:
489
633
  await fs4.ensureDir(path4.dirname(cssPath2));
490
634
  await fs4.writeFile(cssPath2, GLOBALS_CSS_TEMPLATE);
491
635
  log2(pc3.green(`\u2705 Created src/assets/globals.css`), options);
492
- await fs4.writeFile(tailwindPath2, TAILWIND_CONFIG_TEMPLATE);
636
+ await fs4.writeFile(tailwindPath2, tailwindTemplate);
493
637
  log2(pc3.green(`\u2705 Created tailwind.config.ts`), options);
494
638
  log2(pc3.green("\n\u2705 Styles added successfully!"), options);
495
639
  return;
@@ -511,7 +655,7 @@ Options:
511
655
  await fs4.ensureDir(path4.dirname(cssPath));
512
656
  await fs4.writeFile(cssPath, GLOBALS_CSS_TEMPLATE);
513
657
  log2(pc3.green(`\u2705 Created ${configPaths.globalsCssPath}`), options);
514
- await fs4.writeFile(tailwindPath, TAILWIND_CONFIG_TEMPLATE);
658
+ await fs4.writeFile(tailwindPath, tailwindTemplate);
515
659
  log2(pc3.green(`\u2705 Created ${configPaths.tailwindConfigPath}`), options);
516
660
  log2(pc3.green("\n\u2705 Styles added successfully!"), options);
517
661
  return;
@@ -553,16 +697,16 @@ Options:
553
697
  }
554
698
  if (tailwindExists) {
555
699
  if (shouldOverwrite && !shouldMerge) {
556
- await fs4.writeFile(tailwindPath, TAILWIND_CONFIG_TEMPLATE);
700
+ await fs4.writeFile(tailwindPath, tailwindTemplate);
557
701
  log2(pc3.green(`\u2705 Overwrote ${configPaths.tailwindConfigPath}`), options);
558
702
  } else if (shouldMerge) {
559
703
  const existingConfig = await fs4.readFile(tailwindPath, "utf-8");
560
- const mergedConfig = mergeTailwindConfig(existingConfig, TAILWIND_CONFIG_TEMPLATE);
704
+ const mergedConfig = mergeTailwindConfig(existingConfig, tailwindTemplate);
561
705
  await fs4.writeFile(tailwindPath, mergedConfig);
562
706
  log2(pc3.green(`\u2705 Merged Tailwind config in ${configPaths.tailwindConfigPath}`), options);
563
707
  }
564
708
  } else {
565
- await fs4.writeFile(tailwindPath, TAILWIND_CONFIG_TEMPLATE);
709
+ await fs4.writeFile(tailwindPath, tailwindTemplate);
566
710
  log2(pc3.green(`\u2705 Created ${configPaths.tailwindConfigPath}`), options);
567
711
  }
568
712
  log2(pc3.green("\n\u2705 Styles added successfully!"), options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hemia/lume",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "files": ["dist"],
6
6
  "bin": {