@hemia/lume 0.0.2 → 0.0.3
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 +269 -65
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -210,7 +210,7 @@ async function add(components = [], options = {}) {
|
|
|
210
210
|
\u2705 Added ${copiedCount} component(s) to ${targetBase}/`), options);
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
// src/commands/
|
|
213
|
+
// src/commands/add-styles.ts
|
|
214
214
|
import fs4 from "fs-extra";
|
|
215
215
|
import path4 from "path";
|
|
216
216
|
import pc3 from "picocolors";
|
|
@@ -369,12 +369,215 @@ function getTemplateConfig(framework, template) {
|
|
|
369
369
|
};
|
|
370
370
|
}
|
|
371
371
|
|
|
372
|
+
// src/commands/add-styles.ts
|
|
373
|
+
function log2(message, options) {
|
|
374
|
+
if (!options.silent) {
|
|
375
|
+
console.log(message);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
function info(message, options) {
|
|
379
|
+
if (!options.silent) {
|
|
380
|
+
console.log(pc3.cyan(message));
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
function extractCssVariables(cssContent) {
|
|
384
|
+
const vars = /* @__PURE__ */ new Map();
|
|
385
|
+
const varRegex = /--([a-zA-Z0-9-]+):\s*([^;]+);/g;
|
|
386
|
+
let match;
|
|
387
|
+
while ((match = varRegex.exec(cssContent)) !== null) {
|
|
388
|
+
vars.set(match[1], match[2]);
|
|
389
|
+
}
|
|
390
|
+
return vars;
|
|
391
|
+
}
|
|
392
|
+
function mergeCssVariables(existingCss, templateCss) {
|
|
393
|
+
const existingVars = extractCssVariables(existingCss);
|
|
394
|
+
const templateVars = extractCssVariables(templateCss);
|
|
395
|
+
for (const [key, value] of templateVars) {
|
|
396
|
+
existingVars.set(key, value);
|
|
397
|
+
}
|
|
398
|
+
let result = existingCss;
|
|
399
|
+
const rootMatch = result.match(/@layer base\s*\{[\s\S]*?:root\s*\{([\s\S]*?)\}/);
|
|
400
|
+
if (rootMatch) {
|
|
401
|
+
const newRootVars = Array.from(existingVars.entries()).map(([key, value]) => ` --${key}: ${value};`).join("\n");
|
|
402
|
+
result = result.replace(
|
|
403
|
+
/@layer base\s*\{[\s\S]*?:root\s*\{[\s\S]*?\}/,
|
|
404
|
+
`@layer base {
|
|
405
|
+
:root {
|
|
406
|
+
${newRootVars}
|
|
407
|
+
}`
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
return result;
|
|
411
|
+
}
|
|
412
|
+
function mergeTailwindConfig(existingConfig, templateConfig) {
|
|
413
|
+
const colorMatches = templateConfig.match(/colors:\s*\{([\s\S]*?)\}/);
|
|
414
|
+
const radiusMatches = templateConfig.match(/borderRadius:\s*\{([\s\S]*?)\}/);
|
|
415
|
+
let result = existingConfig;
|
|
416
|
+
if (!result.includes("theme:")) {
|
|
417
|
+
return templateConfig;
|
|
418
|
+
}
|
|
419
|
+
if (colorMatches) {
|
|
420
|
+
const colorsBlock = colorMatches[0];
|
|
421
|
+
if (!result.includes("colors:")) {
|
|
422
|
+
result = result.replace(
|
|
423
|
+
/theme:\s*\{/,
|
|
424
|
+
`theme: {
|
|
425
|
+
extend: {
|
|
426
|
+
colors: {${colorsBlock.replace("colors:", "")}`
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (radiusMatches) {
|
|
431
|
+
const radiusBlock = radiusMatches[0];
|
|
432
|
+
if (!result.includes("borderRadius:")) {
|
|
433
|
+
result = result.replace(
|
|
434
|
+
/theme:\s*\{/,
|
|
435
|
+
`theme: {
|
|
436
|
+
extend: {
|
|
437
|
+
borderRadius: {${radiusBlock.replace("borderRadius:", "")}`
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
if (!result.includes("colors:") && colorMatches) {
|
|
442
|
+
return templateConfig;
|
|
443
|
+
}
|
|
444
|
+
return result;
|
|
445
|
+
}
|
|
446
|
+
function getConfigPaths(cwd) {
|
|
447
|
+
try {
|
|
448
|
+
const config = fs4.readJsonSync(path4.resolve(cwd, "lume.config.json"));
|
|
449
|
+
return {
|
|
450
|
+
tailwindConfigPath: config.tailwind?.config ?? "tailwind.config.ts",
|
|
451
|
+
globalsCssPath: config.tailwind?.css ?? "src/assets/globals.css"
|
|
452
|
+
};
|
|
453
|
+
} catch {
|
|
454
|
+
return null;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
function detectFramework(cwd) {
|
|
458
|
+
try {
|
|
459
|
+
const config = fs4.readJsonSync(path4.resolve(cwd, "lume.config.json"));
|
|
460
|
+
return config.framework ?? "vue";
|
|
461
|
+
} catch {
|
|
462
|
+
return "vue";
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
async function addStyles(_args = [], options = {}) {
|
|
466
|
+
if (options.silent === void 0 && process.argv.includes("--help") || process.argv.includes("-h")) {
|
|
467
|
+
console.log(`
|
|
468
|
+
lume add-styles
|
|
469
|
+
|
|
470
|
+
Add globals.css and tailwind.config.ts with merge support
|
|
471
|
+
|
|
472
|
+
Options:
|
|
473
|
+
-y, --yes Skip confirmation prompt
|
|
474
|
+
-o, --overwrite Overwrite existing files (don't merge)
|
|
475
|
+
-f, --force Force overwrite without asking
|
|
476
|
+
-c, --cwd Working directory
|
|
477
|
+
-s, --silent Mute output
|
|
478
|
+
-h, --help Show this help
|
|
479
|
+
`);
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
const cwd = options.cwd ? path4.resolve(options.cwd) : process.cwd();
|
|
483
|
+
const configPath = path4.resolve(cwd, "lume.config.json");
|
|
484
|
+
if (!await fs4.pathExists(configPath)) {
|
|
485
|
+
const cssPath2 = path4.resolve(cwd, "src/assets/globals.css");
|
|
486
|
+
const tailwindPath2 = path4.resolve(cwd, "tailwind.config.ts");
|
|
487
|
+
log2(pc3.cyan("\n\u{1F4E6} Adding styles to your project\n"), options);
|
|
488
|
+
info("No lume.config.json found. Using default paths...", options);
|
|
489
|
+
await fs4.ensureDir(path4.dirname(cssPath2));
|
|
490
|
+
await fs4.writeFile(cssPath2, GLOBALS_CSS_TEMPLATE);
|
|
491
|
+
log2(pc3.green(`\u2705 Created src/assets/globals.css`), options);
|
|
492
|
+
await fs4.writeFile(tailwindPath2, TAILWIND_CONFIG_TEMPLATE);
|
|
493
|
+
log2(pc3.green(`\u2705 Created tailwind.config.ts`), options);
|
|
494
|
+
log2(pc3.green("\n\u2705 Styles added successfully!"), options);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
const configPaths = getConfigPaths(cwd);
|
|
498
|
+
if (!configPaths) {
|
|
499
|
+
log2(pc3.red("\u274C Could not read lume.config.json"), options);
|
|
500
|
+
process.exit(1);
|
|
501
|
+
}
|
|
502
|
+
const framework = detectFramework(cwd);
|
|
503
|
+
const templateConfig = getTemplateConfig(framework);
|
|
504
|
+
const cssPath = path4.resolve(cwd, configPaths.globalsCssPath);
|
|
505
|
+
const tailwindPath = path4.resolve(cwd, configPaths.tailwindConfigPath);
|
|
506
|
+
const cssExists = await fs4.pathExists(cssPath);
|
|
507
|
+
const tailwindExists = await fs4.pathExists(tailwindPath);
|
|
508
|
+
log2(pc3.cyan("\n\u{1F4E6} Adding styles to your project\n"), options);
|
|
509
|
+
if (!cssExists && !tailwindExists) {
|
|
510
|
+
info("No existing CSS or config found. Writing new files...", options);
|
|
511
|
+
await fs4.ensureDir(path4.dirname(cssPath));
|
|
512
|
+
await fs4.writeFile(cssPath, GLOBALS_CSS_TEMPLATE);
|
|
513
|
+
log2(pc3.green(`\u2705 Created ${configPaths.globalsCssPath}`), options);
|
|
514
|
+
await fs4.writeFile(tailwindPath, TAILWIND_CONFIG_TEMPLATE);
|
|
515
|
+
log2(pc3.green(`\u2705 Created ${configPaths.tailwindConfigPath}`), options);
|
|
516
|
+
log2(pc3.green("\n\u2705 Styles added successfully!"), options);
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
let shouldMerge = options.yes;
|
|
520
|
+
let shouldOverwrite = options.overwrite || options.force;
|
|
521
|
+
if ((cssExists || tailwindExists) && !options.yes) {
|
|
522
|
+
const { action } = await prompts2({
|
|
523
|
+
type: "select",
|
|
524
|
+
name: "action",
|
|
525
|
+
message: "Styles already exist. What would you like to do?",
|
|
526
|
+
choices: [
|
|
527
|
+
{ title: "Merge (recommended)", description: "Keep your variables, add missing ones from template", value: "merge" },
|
|
528
|
+
{ title: "Overwrite", description: "Replace with template (your custom styles will be lost)", value: "overwrite" },
|
|
529
|
+
{ title: "Skip", description: "Don't add styles", value: "skip" }
|
|
530
|
+
]
|
|
531
|
+
});
|
|
532
|
+
if (action === "skip") {
|
|
533
|
+
log2(pc3.dim("Cancelled."), options);
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
shouldMerge = action === "merge";
|
|
537
|
+
shouldOverwrite = action === "overwrite";
|
|
538
|
+
}
|
|
539
|
+
if (cssExists) {
|
|
540
|
+
if (shouldOverwrite && !shouldMerge) {
|
|
541
|
+
await fs4.writeFile(cssPath, GLOBALS_CSS_TEMPLATE);
|
|
542
|
+
log2(pc3.green(`\u2705 Overwrote ${configPaths.globalsCssPath}`), options);
|
|
543
|
+
} else if (shouldMerge) {
|
|
544
|
+
const existingCss = await fs4.readFile(cssPath, "utf-8");
|
|
545
|
+
const mergedCss = mergeCssVariables(existingCss, GLOBALS_CSS_TEMPLATE);
|
|
546
|
+
await fs4.writeFile(cssPath, mergedCss);
|
|
547
|
+
log2(pc3.green(`\u2705 Merged CSS variables in ${configPaths.globalsCssPath}`), options);
|
|
548
|
+
}
|
|
549
|
+
} else {
|
|
550
|
+
await fs4.ensureDir(path4.dirname(cssPath));
|
|
551
|
+
await fs4.writeFile(cssPath, GLOBALS_CSS_TEMPLATE);
|
|
552
|
+
log2(pc3.green(`\u2705 Created ${configPaths.globalsCssPath}`), options);
|
|
553
|
+
}
|
|
554
|
+
if (tailwindExists) {
|
|
555
|
+
if (shouldOverwrite && !shouldMerge) {
|
|
556
|
+
await fs4.writeFile(tailwindPath, TAILWIND_CONFIG_TEMPLATE);
|
|
557
|
+
log2(pc3.green(`\u2705 Overwrote ${configPaths.tailwindConfigPath}`), options);
|
|
558
|
+
} else if (shouldMerge) {
|
|
559
|
+
const existingConfig = await fs4.readFile(tailwindPath, "utf-8");
|
|
560
|
+
const mergedConfig = mergeTailwindConfig(existingConfig, TAILWIND_CONFIG_TEMPLATE);
|
|
561
|
+
await fs4.writeFile(tailwindPath, mergedConfig);
|
|
562
|
+
log2(pc3.green(`\u2705 Merged Tailwind config in ${configPaths.tailwindConfigPath}`), options);
|
|
563
|
+
}
|
|
564
|
+
} else {
|
|
565
|
+
await fs4.writeFile(tailwindPath, TAILWIND_CONFIG_TEMPLATE);
|
|
566
|
+
log2(pc3.green(`\u2705 Created ${configPaths.tailwindConfigPath}`), options);
|
|
567
|
+
}
|
|
568
|
+
log2(pc3.green("\n\u2705 Styles added successfully!"), options);
|
|
569
|
+
}
|
|
570
|
+
|
|
372
571
|
// src/commands/init.ts
|
|
572
|
+
import fs5 from "fs-extra";
|
|
573
|
+
import path5 from "path";
|
|
574
|
+
import pc4 from "picocolors";
|
|
575
|
+
import prompts3 from "prompts";
|
|
373
576
|
var SUPPORTED_FRAMEWORKS = ["vue", "react", "svelte", "astro"];
|
|
374
577
|
var SUPPORTED_PACKAGE_MANAGERS = ["npm", "bun", "pnpm", "yarn"];
|
|
375
|
-
function
|
|
578
|
+
function detectFramework2() {
|
|
376
579
|
try {
|
|
377
|
-
const pkg =
|
|
580
|
+
const pkg = fs5.readJsonSync(path5.resolve(process.cwd(), "package.json"));
|
|
378
581
|
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
379
582
|
if (deps["vue"]) return "vue";
|
|
380
583
|
if (deps["react"]) return "react";
|
|
@@ -385,19 +588,19 @@ function detectFramework() {
|
|
|
385
588
|
return null;
|
|
386
589
|
}
|
|
387
590
|
}
|
|
388
|
-
function
|
|
591
|
+
function log3(message, options) {
|
|
389
592
|
if (!options.silent) {
|
|
390
593
|
console.log(message);
|
|
391
594
|
}
|
|
392
595
|
}
|
|
393
596
|
function warn2(message, options) {
|
|
394
597
|
if (!options.silent) {
|
|
395
|
-
console.log(
|
|
598
|
+
console.log(pc4.yellow(`\u26A0\uFE0F ${message}`));
|
|
396
599
|
}
|
|
397
600
|
}
|
|
398
|
-
function
|
|
601
|
+
function info2(message, options) {
|
|
399
602
|
if (!options.silent) {
|
|
400
|
-
console.log(
|
|
603
|
+
console.log(pc4.cyan(message));
|
|
401
604
|
}
|
|
402
605
|
}
|
|
403
606
|
async function init(options = {}) {
|
|
@@ -417,36 +620,36 @@ async function init(options = {}) {
|
|
|
417
620
|
}
|
|
418
621
|
if (options.reinstall === false) {
|
|
419
622
|
}
|
|
420
|
-
const cwd = options.cwd ?
|
|
623
|
+
const cwd = options.cwd ? path5.resolve(options.cwd) : process.cwd();
|
|
421
624
|
const validTemplates = ["next", "vite", "start", "react-router", "laravel", "astro"];
|
|
422
625
|
let template = options.template?.toLowerCase();
|
|
423
626
|
if (template && !validTemplates.includes(template)) {
|
|
424
627
|
warn2(`Invalid template "${template}". Using default.`, options);
|
|
425
628
|
template = void 0;
|
|
426
629
|
}
|
|
427
|
-
const configPath =
|
|
428
|
-
const configExists = await
|
|
630
|
+
const configPath = path5.resolve(cwd, "lume.config.json");
|
|
631
|
+
const configExists = await fs5.pathExists(configPath);
|
|
429
632
|
if (configExists && !options.force) {
|
|
430
633
|
if (!options.yes) {
|
|
431
|
-
const { overwrite } = await
|
|
634
|
+
const { overwrite } = await prompts3({
|
|
432
635
|
type: "confirm",
|
|
433
636
|
name: "overwrite",
|
|
434
637
|
message: "lume.config.json already exists. Overwrite?",
|
|
435
638
|
initial: false
|
|
436
639
|
});
|
|
437
640
|
if (!overwrite) {
|
|
438
|
-
|
|
641
|
+
log3("Cancelled.", options);
|
|
439
642
|
return;
|
|
440
643
|
}
|
|
441
644
|
}
|
|
442
645
|
}
|
|
443
|
-
const detected =
|
|
646
|
+
const detected = detectFramework2();
|
|
444
647
|
let framework;
|
|
445
648
|
if (detected) {
|
|
446
649
|
framework = detected;
|
|
447
|
-
|
|
650
|
+
info2(`Detected framework: ${detected}`, options);
|
|
448
651
|
} else if (!options.yes) {
|
|
449
|
-
const { framework: selectedFramework } = await
|
|
652
|
+
const { framework: selectedFramework } = await prompts3({
|
|
450
653
|
type: "select",
|
|
451
654
|
name: "framework",
|
|
452
655
|
message: "Which framework are you using?",
|
|
@@ -457,16 +660,16 @@ async function init(options = {}) {
|
|
|
457
660
|
framework = "vue";
|
|
458
661
|
}
|
|
459
662
|
if (!framework) {
|
|
460
|
-
|
|
663
|
+
log3(pc4.red("\u274C Framework selection required"), options);
|
|
461
664
|
process.exit(1);
|
|
462
665
|
}
|
|
463
666
|
const detectedPm = detectPackageManager(cwd);
|
|
464
667
|
let packageManager;
|
|
465
668
|
if (detectedPm) {
|
|
466
669
|
packageManager = detectedPm;
|
|
467
|
-
|
|
670
|
+
info2(`Detected package manager: ${detectedPm}`, options);
|
|
468
671
|
} else if (!options.yes) {
|
|
469
|
-
const { pm } = await
|
|
672
|
+
const { pm } = await prompts3({
|
|
470
673
|
type: "select",
|
|
471
674
|
name: "pm",
|
|
472
675
|
message: "Which package manager are you using?",
|
|
@@ -477,7 +680,7 @@ async function init(options = {}) {
|
|
|
477
680
|
packageManager = "npm";
|
|
478
681
|
}
|
|
479
682
|
if (!packageManager) {
|
|
480
|
-
|
|
683
|
+
log3(pc4.red("\u274C Package manager selection required"), options);
|
|
481
684
|
process.exit(1);
|
|
482
685
|
}
|
|
483
686
|
const installCmd = getInstallCommand(packageManager);
|
|
@@ -498,11 +701,11 @@ async function init(options = {}) {
|
|
|
498
701
|
utils: `@/${templateConfig.utilsPath}`
|
|
499
702
|
}
|
|
500
703
|
};
|
|
501
|
-
await
|
|
502
|
-
|
|
704
|
+
await fs5.writeJson(configPath, config, { spaces: 2 });
|
|
705
|
+
log3(pc4.green(`\u2705 Created lume.config.json`), options);
|
|
503
706
|
let writeFiles = options.yes;
|
|
504
707
|
if (!options.yes) {
|
|
505
|
-
const { confirm } = await
|
|
708
|
+
const { confirm } = await prompts3({
|
|
506
709
|
type: "confirm",
|
|
507
710
|
name: "confirm",
|
|
508
711
|
message: "Write globals.css and tailwind.config.ts?",
|
|
@@ -511,47 +714,47 @@ async function init(options = {}) {
|
|
|
511
714
|
writeFiles = confirm;
|
|
512
715
|
}
|
|
513
716
|
if (writeFiles) {
|
|
514
|
-
const cssPath =
|
|
515
|
-
await
|
|
516
|
-
if (await
|
|
717
|
+
const cssPath = path5.resolve(cwd, templateConfig.globalsCssPath);
|
|
718
|
+
await fs5.ensureDir(path5.dirname(cssPath));
|
|
719
|
+
if (await fs5.pathExists(cssPath)) {
|
|
517
720
|
if (options.force || !options.yes) {
|
|
518
|
-
const { overwrite } = await
|
|
721
|
+
const { overwrite } = await prompts3({
|
|
519
722
|
type: "confirm",
|
|
520
723
|
name: "overwrite",
|
|
521
724
|
message: `${templateConfig.globalsCssPath} already exists. Overwrite?`,
|
|
522
725
|
initial: false
|
|
523
726
|
});
|
|
524
727
|
if (overwrite) {
|
|
525
|
-
await
|
|
526
|
-
|
|
728
|
+
await fs5.writeFile(cssPath, GLOBALS_CSS_TEMPLATE);
|
|
729
|
+
log3(pc4.green(`\u2705 Updated ${templateConfig.globalsCssPath}`), options);
|
|
527
730
|
}
|
|
528
731
|
}
|
|
529
732
|
} else {
|
|
530
|
-
await
|
|
531
|
-
|
|
733
|
+
await fs5.writeFile(cssPath, GLOBALS_CSS_TEMPLATE);
|
|
734
|
+
log3(pc4.green(`\u2705 Created ${templateConfig.globalsCssPath}`), options);
|
|
532
735
|
}
|
|
533
|
-
const tailwindPath =
|
|
534
|
-
if (await
|
|
736
|
+
const tailwindPath = path5.resolve(cwd, templateConfig.tailwindConfigPath);
|
|
737
|
+
if (await fs5.pathExists(tailwindPath)) {
|
|
535
738
|
if (options.force || !options.yes) {
|
|
536
|
-
const { overwrite } = await
|
|
739
|
+
const { overwrite } = await prompts3({
|
|
537
740
|
type: "confirm",
|
|
538
741
|
name: "overwrite",
|
|
539
742
|
message: `${templateConfig.tailwindConfigPath} already exists. Overwrite?`,
|
|
540
743
|
initial: false
|
|
541
744
|
});
|
|
542
745
|
if (overwrite) {
|
|
543
|
-
await
|
|
544
|
-
|
|
746
|
+
await fs5.writeFile(tailwindPath, TAILWIND_CONFIG_TEMPLATE);
|
|
747
|
+
log3(pc4.green(`\u2705 Updated ${templateConfig.tailwindConfigPath}`), options);
|
|
545
748
|
}
|
|
546
749
|
}
|
|
547
750
|
} else {
|
|
548
|
-
await
|
|
549
|
-
|
|
751
|
+
await fs5.writeFile(tailwindPath, TAILWIND_CONFIG_TEMPLATE);
|
|
752
|
+
log3(pc4.green(`\u2705 Created ${templateConfig.tailwindConfigPath}`), options);
|
|
550
753
|
}
|
|
551
754
|
}
|
|
552
755
|
let installDeps = options.yes;
|
|
553
756
|
if (!options.yes) {
|
|
554
|
-
const { confirm } = await
|
|
757
|
+
const { confirm } = await prompts3({
|
|
555
758
|
type: "confirm",
|
|
556
759
|
name: "confirm",
|
|
557
760
|
message: "Install base dependencies (tailwindcss, autoprefixer, postcss)?",
|
|
@@ -560,30 +763,30 @@ async function init(options = {}) {
|
|
|
560
763
|
installDeps = confirm;
|
|
561
764
|
}
|
|
562
765
|
if (installDeps) {
|
|
563
|
-
|
|
766
|
+
log3("", options);
|
|
564
767
|
const baseDeps = ["tailwindcss", "autoprefixer", "postcss"];
|
|
565
768
|
installDependencies(baseDeps, { dev: true });
|
|
566
|
-
|
|
769
|
+
log3("", options);
|
|
567
770
|
const frameworkPkg = framework === "vue" ? "@hemia/lume-vue" : `@hemia/lume-${framework}`;
|
|
568
|
-
|
|
569
|
-
|
|
771
|
+
info2(`\u{1F4E6} Installing ${frameworkPkg}...`, options);
|
|
772
|
+
log3(pc4.dim(` When published, run: ${installCmd} ${frameworkPkg}`), options);
|
|
570
773
|
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
774
|
+
log3("", options);
|
|
775
|
+
log3(pc4.green("\u{1F389} All done! Run the following to add components:"), options);
|
|
776
|
+
info2(` lume add button`, options);
|
|
777
|
+
log3("", options);
|
|
575
778
|
}
|
|
576
779
|
|
|
577
780
|
// src/commands/list.ts
|
|
578
|
-
import
|
|
579
|
-
import
|
|
580
|
-
import
|
|
781
|
+
import fs6 from "fs-extra";
|
|
782
|
+
import path6 from "path";
|
|
783
|
+
import pc5 from "picocolors";
|
|
581
784
|
import { createRequire as createRequire2 } from "module";
|
|
582
785
|
var require3 = createRequire2(import.meta.url);
|
|
583
786
|
function getFrameworkFromConfig2() {
|
|
584
787
|
try {
|
|
585
|
-
const config =
|
|
586
|
-
|
|
788
|
+
const config = fs6.readJsonSync(
|
|
789
|
+
path6.resolve(process.cwd(), "hemia.config.json")
|
|
587
790
|
);
|
|
588
791
|
return config.framework ?? "vue";
|
|
589
792
|
} catch {
|
|
@@ -591,43 +794,43 @@ function getFrameworkFromConfig2() {
|
|
|
591
794
|
}
|
|
592
795
|
}
|
|
593
796
|
function resolveRegistryPath2(framework) {
|
|
594
|
-
const registryRoot =
|
|
797
|
+
const registryRoot = path6.dirname(
|
|
595
798
|
require3.resolve("@hemia/lume-registry/package.json")
|
|
596
799
|
);
|
|
597
|
-
return
|
|
800
|
+
return path6.join(registryRoot, "registry", framework);
|
|
598
801
|
}
|
|
599
802
|
async function list(options = {}) {
|
|
600
803
|
const framework = options.framework ?? getFrameworkFromConfig2();
|
|
601
804
|
const frameworkRegistry = resolveRegistryPath2(framework);
|
|
602
|
-
if (!await
|
|
603
|
-
console.log(
|
|
805
|
+
if (!await fs6.pathExists(frameworkRegistry)) {
|
|
806
|
+
console.log(pc5.red(`\u274C No components found for framework "${framework}"`));
|
|
604
807
|
process.exit(1);
|
|
605
808
|
}
|
|
606
|
-
const entries = await
|
|
809
|
+
const entries = await fs6.readdir(frameworkRegistry, { withFileTypes: true });
|
|
607
810
|
const components = entries.filter((entry) => entry.isDirectory());
|
|
608
811
|
if (components.length === 0) {
|
|
609
|
-
console.log(
|
|
812
|
+
console.log(pc5.yellow(`\u26A0\uFE0F No components available for ${framework}`));
|
|
610
813
|
return;
|
|
611
814
|
}
|
|
612
|
-
console.log(
|
|
815
|
+
console.log(pc5.cyan(`
|
|
613
816
|
\u{1F4E6} Available components for ${framework}:
|
|
614
817
|
`));
|
|
615
818
|
for (const component of components) {
|
|
616
819
|
const meta = await readComponentMeta(
|
|
617
|
-
|
|
820
|
+
path6.join(frameworkRegistry, component.name)
|
|
618
821
|
);
|
|
619
822
|
if (meta) {
|
|
620
|
-
const deps = meta.registryDependencies?.length ?
|
|
621
|
-
console.log(` ${
|
|
823
|
+
const deps = meta.registryDependencies?.length ? pc5.dim(` (requires: ${meta.registryDependencies.join(", ")})`) : "";
|
|
824
|
+
console.log(` ${pc5.green("\u25CF")} ${component.name}${deps}`);
|
|
622
825
|
} else {
|
|
623
|
-
console.log(` ${
|
|
826
|
+
console.log(` ${pc5.green("\u25CF")} ${component.name}`);
|
|
624
827
|
}
|
|
625
828
|
}
|
|
626
829
|
console.log();
|
|
627
|
-
console.log(
|
|
830
|
+
console.log(pc5.dim(`Total: ${components.length} component(s)`));
|
|
628
831
|
console.log();
|
|
629
|
-
console.log(
|
|
630
|
-
console.log(
|
|
832
|
+
console.log(pc5.cyan("Usage:"));
|
|
833
|
+
console.log(pc5.dim(` hemia add <component-name>`));
|
|
631
834
|
console.log();
|
|
632
835
|
}
|
|
633
836
|
|
|
@@ -636,5 +839,6 @@ var program = new Command();
|
|
|
636
839
|
program.name("lume").description("lume CLI \u2014 multi-framework component generator inspired by shadcn/ui").version("0.0.1");
|
|
637
840
|
program.command("init").description("Initialize your project and install dependencies").allowUnknownOption(true).argument("[components...]", "name, url or local path to component").option("-t, --template <template>", "the template to use. (next, vite, start, react-router, laravel, astro)").option("-p, --preset [name]", "use a preset configuration. (name, URL, or preset code)").option("-d, --defaults", "use default configuration. (default: false)").option("-y, --yes", "skip confirmation prompt. (default: true)").option("-f, --force", "force overwrite of existing configuration. (default: false)").option("-c, --cwd <cwd>", "the working directory. defaults to the current directory.").option("-s, --silent", "mute output. (default: false)").option("--monorepo", "scaffold a monorepo project.").option("--no-monorepo", "skip the monorepo prompt.").option("--reinstall", "re-install existing UI components.").option("--no-reinstall", "do not re-install existing UI components.").option("--css-variables", "use css variables for theming. (default: true)").option("--no-css-variables", "do not use css variables for theming.").option("-h, --help", "display help for command").action(init);
|
|
638
841
|
program.command("add").description("add a component to your project").allowUnknownOption(true).argument("[components...]", "name, url or local path to component").option("-y, --yes", "skip confirmation prompt. (default: false)").option("-o, --overwrite", "overwrite existing files. (default: false)").option("-c, --cwd <cwd>", "the working directory. defaults to the current directory.").option("-a, --all", "add all available components (default: false)").option("-p, --path <path>", "the path to add the component to.").option("-s, --silent", "mute output. (default: false)").option("--dry-run", "preview changes without writing files. (default: false)").option("--diff [path]", "show diff for a file.").option("--view [path]", "show file contents.").option("-h, --help", "display help for command").option("-f, --framework <framework>", "Target framework (vue, react, svelte, astro)").action(add);
|
|
842
|
+
program.command("add-styles").description("add globals.css and tailwind.config.ts with merge support").option("-y, --yes", "skip confirmation prompt. (default: false)").option("-o, --overwrite", "overwrite existing files. (default: false)").option("-f, --force", "force overwrite without asking. (default: false)").option("-c, --cwd <cwd>", "the working directory. defaults to the current directory.").option("-s, --silent", "mute output. (default: false)").option("-h, --help", "display help for command").action(addStyles);
|
|
639
843
|
program.command("list").description("List all available components").option("-f, --framework <framework>", "Target framework (vue, react, svelte, astro)").action(list);
|
|
640
844
|
program.parse();
|