@hemia/lume 0.0.3 → 0.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/dist/index.js +89 -10
- 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
|
|
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(
|
|
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
|
|
400
|
-
if (
|
|
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,6 +454,26 @@ 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,6 +548,15 @@ Options:
|
|
|
480
548
|
return;
|
|
481
549
|
}
|
|
482
550
|
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
|
+
}
|
|
483
560
|
const configPath = path4.resolve(cwd, "lume.config.json");
|
|
484
561
|
if (!await fs4.pathExists(configPath)) {
|
|
485
562
|
const cssPath2 = path4.resolve(cwd, "src/assets/globals.css");
|
|
@@ -489,7 +566,7 @@ Options:
|
|
|
489
566
|
await fs4.ensureDir(path4.dirname(cssPath2));
|
|
490
567
|
await fs4.writeFile(cssPath2, GLOBALS_CSS_TEMPLATE);
|
|
491
568
|
log2(pc3.green(`\u2705 Created src/assets/globals.css`), options);
|
|
492
|
-
await fs4.writeFile(tailwindPath2,
|
|
569
|
+
await fs4.writeFile(tailwindPath2, tailwindTemplate);
|
|
493
570
|
log2(pc3.green(`\u2705 Created tailwind.config.ts`), options);
|
|
494
571
|
log2(pc3.green("\n\u2705 Styles added successfully!"), options);
|
|
495
572
|
return;
|
|
@@ -501,6 +578,8 @@ Options:
|
|
|
501
578
|
}
|
|
502
579
|
const framework = detectFramework(cwd);
|
|
503
580
|
const templateConfig = getTemplateConfig(framework);
|
|
581
|
+
const tailwindExt = detectTailwindConfigExtension(cwd);
|
|
582
|
+
const tailwindTemplate = tailwindExt === "js" ? TAILWIND_CONFIG_TEMPLATE_JS : tailwindTemplate;
|
|
504
583
|
const cssPath = path4.resolve(cwd, configPaths.globalsCssPath);
|
|
505
584
|
const tailwindPath = path4.resolve(cwd, configPaths.tailwindConfigPath);
|
|
506
585
|
const cssExists = await fs4.pathExists(cssPath);
|
|
@@ -511,7 +590,7 @@ Options:
|
|
|
511
590
|
await fs4.ensureDir(path4.dirname(cssPath));
|
|
512
591
|
await fs4.writeFile(cssPath, GLOBALS_CSS_TEMPLATE);
|
|
513
592
|
log2(pc3.green(`\u2705 Created ${configPaths.globalsCssPath}`), options);
|
|
514
|
-
await fs4.writeFile(tailwindPath,
|
|
593
|
+
await fs4.writeFile(tailwindPath, tailwindTemplate);
|
|
515
594
|
log2(pc3.green(`\u2705 Created ${configPaths.tailwindConfigPath}`), options);
|
|
516
595
|
log2(pc3.green("\n\u2705 Styles added successfully!"), options);
|
|
517
596
|
return;
|
|
@@ -553,16 +632,16 @@ Options:
|
|
|
553
632
|
}
|
|
554
633
|
if (tailwindExists) {
|
|
555
634
|
if (shouldOverwrite && !shouldMerge) {
|
|
556
|
-
await fs4.writeFile(tailwindPath,
|
|
635
|
+
await fs4.writeFile(tailwindPath, tailwindTemplate);
|
|
557
636
|
log2(pc3.green(`\u2705 Overwrote ${configPaths.tailwindConfigPath}`), options);
|
|
558
637
|
} else if (shouldMerge) {
|
|
559
638
|
const existingConfig = await fs4.readFile(tailwindPath, "utf-8");
|
|
560
|
-
const mergedConfig = mergeTailwindConfig(existingConfig,
|
|
639
|
+
const mergedConfig = mergeTailwindConfig(existingConfig, tailwindTemplate);
|
|
561
640
|
await fs4.writeFile(tailwindPath, mergedConfig);
|
|
562
641
|
log2(pc3.green(`\u2705 Merged Tailwind config in ${configPaths.tailwindConfigPath}`), options);
|
|
563
642
|
}
|
|
564
643
|
} else {
|
|
565
|
-
await fs4.writeFile(tailwindPath,
|
|
644
|
+
await fs4.writeFile(tailwindPath, tailwindTemplate);
|
|
566
645
|
log2(pc3.green(`\u2705 Created ${configPaths.tailwindConfigPath}`), options);
|
|
567
646
|
}
|
|
568
647
|
log2(pc3.green("\n\u2705 Styles added successfully!"), options);
|