chaincss 2.1.29 → 2.1.31
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/README.md +397 -65
- package/dist/browser.js +3398 -0
- package/dist/cli/index.js +312 -375
- package/dist/compiler/btt.d.ts +11 -72
- package/dist/compiler/component-generator.d.ts +10 -0
- package/dist/compiler/index.js +198 -331
- package/dist/compiler/recipe.d.ts +35 -0
- package/dist/compiler/scanner.d.ts +5 -0
- package/dist/compiler/timeline.d.ts +29 -0
- package/dist/index.js +253 -397
- package/dist/plugins/vite.js +110 -186
- package/index.html +41 -0
- package/package.json +8 -7
- package/src/browser.ts +9 -0
- package/src/compiler/btt.ts +126 -901
- package/src/compiler/component-generator.ts +87 -0
- package/src/compiler/recipe.ts +145 -0
- package/src/compiler/scanner.ts +46 -0
- package/src/compiler/timeline.ts +128 -0
package/dist/cli/index.js
CHANGED
|
@@ -451,32 +451,20 @@ var init_commonProps = __esm({
|
|
|
451
451
|
}
|
|
452
452
|
});
|
|
453
453
|
|
|
454
|
-
// src/compiler/
|
|
455
|
-
import fs3 from "fs";
|
|
456
|
-
import https from "https";
|
|
457
|
-
import chalk2 from "chalk";
|
|
454
|
+
// src/compiler/timeline.ts
|
|
458
455
|
function takeSnapshot(selector, styles, source) {
|
|
459
456
|
if (!timelineEnabled) return "";
|
|
460
457
|
const hash = JSON.stringify(styles);
|
|
461
458
|
const existing = styleHistory.find((s) => s.selector === selector && s.hash === hash);
|
|
462
459
|
if (existing) return existing.id;
|
|
463
460
|
const id = `snapshot_${currentSnapshotId++}`;
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
selector,
|
|
468
|
-
styles: { ...styles },
|
|
469
|
-
source,
|
|
470
|
-
hash
|
|
471
|
-
};
|
|
472
|
-
styleHistory.push(snapshot);
|
|
473
|
-
const previousSnapshot = styleHistory.slice(-2)[0];
|
|
474
|
-
if (previousSnapshot && previousSnapshot.selector === selector) {
|
|
461
|
+
styleHistory.push({ id, timestamp: Date.now(), selector, styles: { ...styles }, source, hash });
|
|
462
|
+
const previous = styleHistory[styleHistory.length - 2];
|
|
463
|
+
if (previous && previous.selector === selector) {
|
|
475
464
|
for (const [key, value] of Object.entries(styles)) {
|
|
476
|
-
|
|
477
|
-
if (!(key in previousSnapshot.styles)) {
|
|
465
|
+
if (!(key in previous.styles)) {
|
|
478
466
|
styleChanges.push({
|
|
479
|
-
id: `change_${Date.now()}_${Math.random()}`,
|
|
467
|
+
id: `change_${Date.now()}_${Math.random().toString(36).slice(2)}`,
|
|
480
468
|
timestamp: Date.now(),
|
|
481
469
|
selector,
|
|
482
470
|
property: key,
|
|
@@ -484,26 +472,26 @@ function takeSnapshot(selector, styles, source) {
|
|
|
484
472
|
newValue: value,
|
|
485
473
|
type: "add"
|
|
486
474
|
});
|
|
487
|
-
} else if (JSON.stringify(
|
|
475
|
+
} else if (JSON.stringify(previous.styles[key]) !== JSON.stringify(value)) {
|
|
488
476
|
styleChanges.push({
|
|
489
|
-
id: `change_${Date.now()}_${Math.random()}`,
|
|
477
|
+
id: `change_${Date.now()}_${Math.random().toString(36).slice(2)}`,
|
|
490
478
|
timestamp: Date.now(),
|
|
491
479
|
selector,
|
|
492
480
|
property: key,
|
|
493
|
-
oldValue,
|
|
481
|
+
oldValue: previous.styles[key],
|
|
494
482
|
newValue: value,
|
|
495
483
|
type: "modify"
|
|
496
484
|
});
|
|
497
485
|
}
|
|
498
486
|
}
|
|
499
|
-
for (const [key] of Object.entries(
|
|
487
|
+
for (const [key] of Object.entries(previous.styles)) {
|
|
500
488
|
if (!(key in styles)) {
|
|
501
489
|
styleChanges.push({
|
|
502
|
-
id: `change_${Date.now()}_${Math.random()}`,
|
|
490
|
+
id: `change_${Date.now()}_${Math.random().toString(36).slice(2)}`,
|
|
503
491
|
timestamp: Date.now(),
|
|
504
492
|
selector,
|
|
505
493
|
property: key,
|
|
506
|
-
oldValue:
|
|
494
|
+
oldValue: previous.styles[key],
|
|
507
495
|
newValue: void 0,
|
|
508
496
|
type: "remove"
|
|
509
497
|
});
|
|
@@ -512,19 +500,62 @@ function takeSnapshot(selector, styles, source) {
|
|
|
512
500
|
}
|
|
513
501
|
return id;
|
|
514
502
|
}
|
|
503
|
+
function isTimelineEnabled() {
|
|
504
|
+
return timelineEnabled;
|
|
505
|
+
}
|
|
506
|
+
var styleHistory, styleChanges, timelineEnabled, currentSnapshotId;
|
|
507
|
+
var init_timeline = __esm({
|
|
508
|
+
"src/compiler/timeline.ts"() {
|
|
509
|
+
"use strict";
|
|
510
|
+
styleHistory = [];
|
|
511
|
+
styleChanges = [];
|
|
512
|
+
timelineEnabled = false;
|
|
513
|
+
currentSnapshotId = 0;
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
// src/compiler/scanner.ts
|
|
518
|
+
import fs3 from "fs";
|
|
519
|
+
function scanFileForStyles(filePath, optimizer, source = null) {
|
|
520
|
+
const errors = [];
|
|
521
|
+
let foundCount = 0;
|
|
522
|
+
try {
|
|
523
|
+
const content = source !== null ? source : fs3.readFileSync(filePath, "utf8");
|
|
524
|
+
if (!content || content.trim().length === 0) return { foundCount: 0, errors };
|
|
525
|
+
const styleRegex = /(?:chain|smartChain|\$)\(((?:[^()]|\([^()]*\))*)\)/g;
|
|
526
|
+
let match;
|
|
527
|
+
while ((match = styleRegex.exec(content)) !== null) {
|
|
528
|
+
try {
|
|
529
|
+
const styleBody = match[1].trim();
|
|
530
|
+
const cleanBody = styleBody.replace(/^['"\`]|['"\`]$/g, "");
|
|
531
|
+
if (cleanBody && optimizer && typeof optimizer.trackStyles === "function") {
|
|
532
|
+
optimizer.trackStyles([{ selectors: { "&": cleanBody } }]);
|
|
533
|
+
foundCount++;
|
|
534
|
+
}
|
|
535
|
+
} catch (parseError) {
|
|
536
|
+
errors.push(parseError);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
} catch (err) {
|
|
540
|
+
errors.push(err);
|
|
541
|
+
}
|
|
542
|
+
return { foundCount, errors };
|
|
543
|
+
}
|
|
544
|
+
var init_scanner = __esm({
|
|
545
|
+
"src/compiler/scanner.ts"() {
|
|
546
|
+
"use strict";
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
// src/compiler/btt.ts
|
|
551
|
+
import https from "https";
|
|
515
552
|
function getSourceLocation() {
|
|
516
553
|
if (!enableSourceComments) return null;
|
|
517
554
|
const stack = new Error().stack;
|
|
518
555
|
if (!stack) return null;
|
|
519
|
-
const
|
|
520
|
-
for (let i = 0; i < stackLines.length; i++) {
|
|
521
|
-
const line = stackLines[i];
|
|
556
|
+
for (const line of stack.split("\n")) {
|
|
522
557
|
const match = line.match(/([^/]+\.chain\.js):(\d+):\d+/);
|
|
523
|
-
if (match) {
|
|
524
|
-
const fileName = match[1];
|
|
525
|
-
const lineNumber = match[2];
|
|
526
|
-
return `${fileName}:${lineNumber}`;
|
|
527
|
-
}
|
|
558
|
+
if (match) return `${match[1]}:${match[2]}`;
|
|
528
559
|
}
|
|
529
560
|
return null;
|
|
530
561
|
}
|
|
@@ -546,21 +577,13 @@ function processAtRule(rule, parentSelectors = null) {
|
|
|
546
577
|
output = `@media ${rule.query} {
|
|
547
578
|
`;
|
|
548
579
|
if (rule.styles && typeof rule.styles === "object") {
|
|
549
|
-
let
|
|
550
|
-
for (const prop in rule.styles) {
|
|
551
|
-
const kebabKey = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
552
|
-
ruleBody += ` ${kebabKey}: ${rule.styles[prop]};
|
|
580
|
+
let body = "";
|
|
581
|
+
for (const prop in rule.styles) body += ` ${prop.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${rule.styles[prop]};
|
|
553
582
|
`;
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
if (enableSourceComments && sourceLocation) {
|
|
559
|
-
output += ` /* Generated from: ${sourceLocation} */
|
|
560
|
-
`;
|
|
561
|
-
}
|
|
562
|
-
output += ` ${selector} {
|
|
563
|
-
${ruleBody} }
|
|
583
|
+
if (body.trim()) {
|
|
584
|
+
const sel = parentSelectors?.length ? parentSelectors.join(", ") : ".unknown-selector";
|
|
585
|
+
output += ` ${sel} {
|
|
586
|
+
${body} }
|
|
564
587
|
`;
|
|
565
588
|
}
|
|
566
589
|
}
|
|
@@ -573,11 +596,8 @@ ${ruleBody} }
|
|
|
573
596
|
output += ` ${step} {
|
|
574
597
|
`;
|
|
575
598
|
for (const prop in rule.steps[step]) {
|
|
576
|
-
if (prop !== "selectors") {
|
|
577
|
-
const kebabKey = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
578
|
-
output += ` ${kebabKey}: ${rule.steps[step][prop]};
|
|
599
|
+
if (prop !== "selectors") output += ` ${prop.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${rule.steps[step][prop]};
|
|
579
600
|
`;
|
|
580
|
-
}
|
|
581
601
|
}
|
|
582
602
|
output += " }\n";
|
|
583
603
|
}
|
|
@@ -586,68 +606,22 @@ ${ruleBody} }
|
|
|
586
606
|
case "font-face":
|
|
587
607
|
output = "@font-face {\n";
|
|
588
608
|
for (const prop in rule.properties) {
|
|
589
|
-
if (prop !== "selectors") {
|
|
590
|
-
const kebabKey = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
591
|
-
output += ` ${kebabKey}: ${rule.properties[prop]};
|
|
609
|
+
if (prop !== "selectors") output += ` ${prop.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${rule.properties[prop]};
|
|
592
610
|
`;
|
|
593
|
-
}
|
|
594
611
|
}
|
|
595
612
|
output += "}\n";
|
|
596
613
|
break;
|
|
597
|
-
default:
|
|
598
|
-
output = "";
|
|
599
|
-
break;
|
|
600
614
|
}
|
|
601
615
|
return output;
|
|
602
616
|
}
|
|
603
|
-
|
|
604
|
-
const errors = [];
|
|
605
|
-
let foundCount = 0;
|
|
606
|
-
try {
|
|
607
|
-
const content = source !== null ? source : fs3.readFileSync(filePath, "utf8");
|
|
608
|
-
if (!content || content.trim().length === 0) {
|
|
609
|
-
return { foundCount: 0, errors };
|
|
610
|
-
}
|
|
611
|
-
const styleRegex = /(?:chain|\$)\(((?:[^()]|\([^()]*\))*)\)/g;
|
|
612
|
-
let match;
|
|
613
|
-
while ((match = styleRegex.exec(content)) !== null) {
|
|
614
|
-
try {
|
|
615
|
-
const styleBody = match[1].trim();
|
|
616
|
-
const cleanBody = styleBody.replace(/^['"`]|['"`]$/g, "");
|
|
617
|
-
if (cleanBody) {
|
|
618
|
-
if (optimizer && typeof optimizer.trackStyles === "function") {
|
|
619
|
-
optimizer.trackStyles([{ selectors: { "&": cleanBody } }]);
|
|
620
|
-
}
|
|
621
|
-
foundCount++;
|
|
622
|
-
}
|
|
623
|
-
} catch (parseError) {
|
|
624
|
-
errors.push(parseError);
|
|
625
|
-
if (process.env.DEBUG) {
|
|
626
|
-
console.error(`[Scanner] Parse error in ${filePath}:`, parseError);
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
if (foundCount > 0 && process.env.DEBUG) {
|
|
631
|
-
console.log(chalk2.magenta(`[Scanner] Found ${foundCount} styles in ${filePath}`));
|
|
632
|
-
}
|
|
633
|
-
} catch (err) {
|
|
634
|
-
errors.push(err);
|
|
635
|
-
if (process.env.DEBUG) {
|
|
636
|
-
console.error(`[Scanner] Error processing ${filePath}:`, err);
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
return { foundCount, errors };
|
|
640
|
-
}
|
|
641
|
-
var styleHistory, styleChanges, timelineEnabled, currentSnapshotId, enableSourceComments, fetchWithHttps, loadCSSProperties, chains, atomicOptimizer, compile;
|
|
617
|
+
var enableSourceComments, fetchWithHttps, loadCSSProperties, chains, atomicOptimizer, compile;
|
|
642
618
|
var init_btt = __esm({
|
|
643
619
|
"src/compiler/btt.ts"() {
|
|
644
620
|
"use strict";
|
|
645
621
|
init_commonProps();
|
|
622
|
+
init_timeline();
|
|
646
623
|
init_breakpoints();
|
|
647
|
-
|
|
648
|
-
styleChanges = [];
|
|
649
|
-
timelineEnabled = false;
|
|
650
|
-
currentSnapshotId = 0;
|
|
624
|
+
init_scanner();
|
|
651
625
|
enableSourceComments = true;
|
|
652
626
|
fetchWithHttps = (url) => {
|
|
653
627
|
return new Promise((resolve, reject) => {
|
|
@@ -674,9 +648,7 @@ var init_btt = __esm({
|
|
|
674
648
|
});
|
|
675
649
|
};
|
|
676
650
|
loadCSSProperties = async () => {
|
|
677
|
-
if (chains.cachedValidProperties
|
|
678
|
-
return chains.cachedValidProperties;
|
|
679
|
-
}
|
|
651
|
+
if (chains.cachedValidProperties?.length > 0) return chains.cachedValidProperties;
|
|
680
652
|
try {
|
|
681
653
|
const url = "https://raw.githubusercontent.com/mdn/data/main/css/properties.json";
|
|
682
654
|
let data;
|
|
@@ -690,14 +662,9 @@ var init_btt = __esm({
|
|
|
690
662
|
data = await fetchWithHttps(url);
|
|
691
663
|
}
|
|
692
664
|
const allProperties = Object.keys(data);
|
|
693
|
-
|
|
694
|
-
allProperties.forEach((prop) => {
|
|
695
|
-
const baseProp = prop.replace(/^-(webkit|moz|ms|o)-/, "");
|
|
696
|
-
baseProperties.add(baseProp);
|
|
697
|
-
});
|
|
698
|
-
chains.cachedValidProperties = Array.from(baseProperties).sort();
|
|
665
|
+
chains.cachedValidProperties = allProperties.map((p) => p.replace(/^-(webkit|moz|ms|o)-/, "")).filter((v, i, a) => a.indexOf(v) === i).sort();
|
|
699
666
|
return chains.cachedValidProperties;
|
|
700
|
-
} catch
|
|
667
|
+
} catch {
|
|
701
668
|
chains.cachedValidProperties = COMMON_CSS_PROPERTIES;
|
|
702
669
|
return chains.cachedValidProperties;
|
|
703
670
|
}
|
|
@@ -708,11 +675,8 @@ var init_btt = __esm({
|
|
|
708
675
|
classMap: {},
|
|
709
676
|
atomicStats: null,
|
|
710
677
|
async initializeProperties() {
|
|
711
|
-
if (this.cachedValidProperties
|
|
712
|
-
|
|
713
|
-
}
|
|
714
|
-
const properties = await loadCSSProperties();
|
|
715
|
-
this.cachedValidProperties = properties;
|
|
678
|
+
if (this.cachedValidProperties?.length > 0) return;
|
|
679
|
+
this.cachedValidProperties = await loadCSSProperties();
|
|
716
680
|
},
|
|
717
681
|
getCachedProperties() {
|
|
718
682
|
return this.cachedValidProperties;
|
|
@@ -727,25 +691,20 @@ var init_btt = __esm({
|
|
|
727
691
|
if (!obj.hasOwnProperty(key)) continue;
|
|
728
692
|
const element = obj[key];
|
|
729
693
|
if (element && element.variants && typeof element.compileAll === "function") {
|
|
730
|
-
|
|
731
|
-
const recipeOutput = element.compileAll(cleanKey);
|
|
732
|
-
cssString += recipeOutput + "\n";
|
|
694
|
+
cssString += element.compileAll(key.includes("_") ? key.split("_").pop() : key) + "\n";
|
|
733
695
|
continue;
|
|
734
696
|
}
|
|
735
|
-
if (!element
|
|
697
|
+
if (!element?.selectors?.[0]) continue;
|
|
736
698
|
const selectorKey = element.selectors.join(",");
|
|
737
699
|
if (processedSelectors.has(selectorKey)) continue;
|
|
738
700
|
processedSelectors.add(selectorKey);
|
|
739
701
|
collected.push(element);
|
|
740
702
|
const sourceLocation = getSourceLocation();
|
|
741
|
-
let elementCSS = "";
|
|
742
|
-
|
|
743
|
-
if (timelineEnabled) {
|
|
703
|
+
let elementCSS = "", subRulesCSS = "";
|
|
704
|
+
if (isTimelineEnabled()) {
|
|
744
705
|
const styles = {};
|
|
745
706
|
for (const prop in element) {
|
|
746
|
-
if (!["selectors", "atRules", "hover", "nestedRules", "use", "nest", "themes"].includes(prop))
|
|
747
|
-
styles[prop] = element[prop];
|
|
748
|
-
}
|
|
707
|
+
if (!["selectors", "atRules", "hover", "nestedRules", "use", "nest", "themes"].includes(prop)) styles[prop] = element[prop];
|
|
749
708
|
}
|
|
750
709
|
takeSnapshot(element.selectors[0], styles, sourceLocation || "unknown");
|
|
751
710
|
}
|
|
@@ -755,41 +714,25 @@ var init_btt = __esm({
|
|
|
755
714
|
if (prop.startsWith("_") || !element.hasOwnProperty(prop)) continue;
|
|
756
715
|
const value = element[prop];
|
|
757
716
|
if (value === void 0 || value === null) continue;
|
|
758
|
-
|
|
759
|
-
elementCSS += ` ${kebabKey}: ${value};
|
|
717
|
+
elementCSS += ` ${prop.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${value};
|
|
760
718
|
`;
|
|
761
719
|
}
|
|
762
|
-
if (elementCSS.trim()) {
|
|
763
|
-
let block = `${element.selectors.join(", ")} {
|
|
720
|
+
if (elementCSS.trim()) cssString += addSourceComment(`${element.selectors.join(", ")} {
|
|
764
721
|
${elementCSS}}
|
|
765
|
-
|
|
766
|
-
cssString += addSourceComment(block, sourceLocation);
|
|
767
|
-
}
|
|
722
|
+
`, sourceLocation);
|
|
768
723
|
if (element.hover && typeof element.hover === "object") {
|
|
769
|
-
let
|
|
770
|
-
for (const
|
|
771
|
-
const hKebab = hProp.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
772
|
-
hoverBody += ` ${hKebab}: ${element.hover[hProp]};
|
|
773
|
-
`;
|
|
774
|
-
}
|
|
775
|
-
if (hoverBody) {
|
|
776
|
-
let block = `${element.selectors.join(", ")}:hover {
|
|
777
|
-
${hoverBody}}
|
|
724
|
+
let hb = "";
|
|
725
|
+
for (const hp in element.hover) hb += ` ${hp.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${element.hover[hp]};
|
|
778
726
|
`;
|
|
779
|
-
|
|
780
|
-
|
|
727
|
+
if (hb) cssString += addSourceComment(`${element.selectors.join(", ")}:hover {
|
|
728
|
+
${hb}}
|
|
729
|
+
`, sourceLocation);
|
|
781
730
|
}
|
|
782
731
|
for (const prop in element) {
|
|
783
732
|
if ((prop.startsWith(".") || prop.startsWith("&")) && typeof element[prop] === "object") {
|
|
784
|
-
const
|
|
785
|
-
const
|
|
786
|
-
|
|
787
|
-
cssString += compile({
|
|
788
|
-
[subSelector]: {
|
|
789
|
-
selectors: [subSelector],
|
|
790
|
-
...subElement
|
|
791
|
-
}
|
|
792
|
-
}) + "\n";
|
|
733
|
+
const parentSel = element.selectors[0];
|
|
734
|
+
const subSel = prop.startsWith("&") ? prop.replace("&", parentSel) : `${parentSel} ${prop}`;
|
|
735
|
+
cssString += compile({ [subSel]: { selectors: [subSel], ...element[prop] } }) + "\n";
|
|
793
736
|
}
|
|
794
737
|
}
|
|
795
738
|
if (element.atRules && Array.isArray(element.atRules)) {
|
|
@@ -800,25 +743,21 @@ ${hoverBody}}
|
|
|
800
743
|
if (element.themes && Array.isArray(element.themes)) {
|
|
801
744
|
element.themes.forEach((theme) => {
|
|
802
745
|
if (theme.styles) {
|
|
803
|
-
let
|
|
804
|
-
for (const
|
|
805
|
-
if (
|
|
806
|
-
|
|
807
|
-
themeCSS += ` ${tKebab}: ${theme.styles[tProp]};
|
|
808
|
-
`;
|
|
809
|
-
}
|
|
810
|
-
if (themeCSS) {
|
|
811
|
-
let block = `${theme.styles.selectors?.join(", ") || element.selectors.join(", ")} {
|
|
812
|
-
${themeCSS}}
|
|
746
|
+
let tc = "";
|
|
747
|
+
for (const tp in theme.styles) {
|
|
748
|
+
if (tp === "selectors") continue;
|
|
749
|
+
tc += ` ${tp.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${theme.styles[tp]};
|
|
813
750
|
`;
|
|
814
|
-
subRulesCSS += addSourceComment(block, sourceLocation);
|
|
815
751
|
}
|
|
752
|
+
if (tc) subRulesCSS += addSourceComment(`${theme.styles.selectors?.join(", ") || element.selectors.join(", ")} {
|
|
753
|
+
${tc}}
|
|
754
|
+
`, sourceLocation);
|
|
816
755
|
}
|
|
817
756
|
});
|
|
818
757
|
}
|
|
819
758
|
cssString += subRulesCSS;
|
|
820
759
|
}
|
|
821
|
-
if (atomicOptimizer
|
|
760
|
+
if (atomicOptimizer?.options.enabled) {
|
|
822
761
|
const result = atomicOptimizer.optimize(collected);
|
|
823
762
|
chains.cssOutput = result.css;
|
|
824
763
|
return result.css;
|
|
@@ -827,9 +766,7 @@ ${themeCSS}}
|
|
|
827
766
|
return chains.cssOutput;
|
|
828
767
|
};
|
|
829
768
|
chains.initializeProperties().catch((err) => {
|
|
830
|
-
if (process.env.DEBUG)
|
|
831
|
-
console.error("Failed to load CSS properties:", err.message);
|
|
832
|
-
}
|
|
769
|
+
if (process.env.DEBUG) console.error("Failed to load CSS properties:", err.message);
|
|
833
770
|
});
|
|
834
771
|
}
|
|
835
772
|
});
|
|
@@ -2684,7 +2621,7 @@ __export(compiler_exports, {
|
|
|
2684
2621
|
import fs7 from "fs";
|
|
2685
2622
|
import path6 from "path";
|
|
2686
2623
|
import crypto4 from "crypto";
|
|
2687
|
-
import
|
|
2624
|
+
import chalk2 from "chalk";
|
|
2688
2625
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
2689
2626
|
async function compileChainCSS(inputFile, outputDir, config) {
|
|
2690
2627
|
const compiler = new ChainCSSCompiler(config || {});
|
|
@@ -2814,7 +2751,7 @@ var init_compiler = __esm({
|
|
|
2814
2751
|
if (oldest) {
|
|
2815
2752
|
this.styleCache.delete(oldest);
|
|
2816
2753
|
if (this.config.verbose) {
|
|
2817
|
-
console.log(
|
|
2754
|
+
console.log(chalk2.gray(` \u{1F9F9} Cache evicted: ${oldest.slice(0, 8)}...`));
|
|
2818
2755
|
}
|
|
2819
2756
|
}
|
|
2820
2757
|
}
|
|
@@ -2834,7 +2771,7 @@ var init_compiler = __esm({
|
|
|
2834
2771
|
console.log(` \u2514\u2500 Processed ${processedCount} chain() styles from ${id.split("/").pop()}`);
|
|
2835
2772
|
}
|
|
2836
2773
|
} catch (error) {
|
|
2837
|
-
console.error(
|
|
2774
|
+
console.error(chalk2.red(` \u274C Error compiling source ${id}: ${error}`));
|
|
2838
2775
|
}
|
|
2839
2776
|
}
|
|
2840
2777
|
/**
|
|
@@ -2859,7 +2796,7 @@ var init_compiler = __esm({
|
|
|
2859
2796
|
}
|
|
2860
2797
|
} catch (err) {
|
|
2861
2798
|
if (this.config.verbose) {
|
|
2862
|
-
console.warn(
|
|
2799
|
+
console.warn(chalk2.yellow(` \u26A0\uFE0F Failed to parse style body: ${input.substring(0, 100)}...`));
|
|
2863
2800
|
}
|
|
2864
2801
|
}
|
|
2865
2802
|
return {};
|
|
@@ -3068,7 +3005,7 @@ var init_compiler = __esm({
|
|
|
3068
3005
|
if (this.atomicOptimizer) this.atomicOptimizer.reset();
|
|
3069
3006
|
this.accumulatedCSS = "";
|
|
3070
3007
|
if (!this.config.silent) {
|
|
3071
|
-
console.log(
|
|
3008
|
+
console.log(chalk2.blue("\n\u{1F50D} Phase 1: Scanning & Usage Analysis..."));
|
|
3072
3009
|
}
|
|
3073
3010
|
const BATCH_SIZE = PERFORMANCE.BATCH_SIZE || 10;
|
|
3074
3011
|
const errors = [];
|
|
@@ -3093,7 +3030,7 @@ var init_compiler = __esm({
|
|
|
3093
3030
|
}
|
|
3094
3031
|
} catch (err) {
|
|
3095
3032
|
if (this.config.verbose) {
|
|
3096
|
-
console.warn(
|
|
3033
|
+
console.warn(chalk2.yellow(` \u26A0\uFE0F Scanning fallback for ${path6.basename(file)}`));
|
|
3097
3034
|
}
|
|
3098
3035
|
const result = scanFileForStyles(file, this.atomicOptimizer);
|
|
3099
3036
|
if (result.errors.length > 0) {
|
|
@@ -3104,14 +3041,14 @@ var init_compiler = __esm({
|
|
|
3104
3041
|
});
|
|
3105
3042
|
await Promise.allSettled(batchPromises);
|
|
3106
3043
|
if (this.config.verbose && i % (BATCH_SIZE * 5) === 0) {
|
|
3107
|
-
console.log(
|
|
3044
|
+
console.log(chalk2.gray(` \u{1F4CA} Processed ${Math.min(i + BATCH_SIZE, components.length)}/${components.length} files`));
|
|
3108
3045
|
}
|
|
3109
3046
|
}
|
|
3110
3047
|
if (errors.length > 0 && this.config.verbose) {
|
|
3111
|
-
console.warn(
|
|
3048
|
+
console.warn(chalk2.yellow(` \u26A0\uFE0F ${errors.length} scanning errors occurred`));
|
|
3112
3049
|
}
|
|
3113
3050
|
if (!this.config.silent) {
|
|
3114
|
-
console.log(
|
|
3051
|
+
console.log(chalk2.blue("\n\u{1F3D7}\uFE0F Phase 2: Generating Component Styles..."));
|
|
3115
3052
|
}
|
|
3116
3053
|
const publicDir = path6.resolve(process.cwd(), "public");
|
|
3117
3054
|
const manifestDir = path6.resolve(process.cwd(), ".chaincss", "manifest");
|
|
@@ -3142,7 +3079,7 @@ var init_compiler = __esm({
|
|
|
3142
3079
|
const result = this.compileStyle(name, style);
|
|
3143
3080
|
if (this.config.verbose) {
|
|
3144
3081
|
const className2 = Object.values(result.classMap)[0];
|
|
3145
|
-
console.log(
|
|
3082
|
+
console.log(chalk2.gray(` \u{1F4DD} ${name} \u2192 ${className2 || "(empty)"}`));
|
|
3146
3083
|
}
|
|
3147
3084
|
const className = Object.values(result.classMap)[0];
|
|
3148
3085
|
if (className) {
|
|
@@ -3168,21 +3105,21 @@ var init_compiler = __esm({
|
|
|
3168
3105
|
}
|
|
3169
3106
|
processedComponents++;
|
|
3170
3107
|
if (this.config.verbose) {
|
|
3171
|
-
console.log(
|
|
3108
|
+
console.log(chalk2.green(` \u2728 ${baseName} \u2192 ${path6.relative(process.cwd(), classFilePath)}`));
|
|
3172
3109
|
}
|
|
3173
3110
|
}
|
|
3174
3111
|
} catch (error) {
|
|
3175
|
-
console.error(
|
|
3112
|
+
console.error(chalk2.red(` \u274C Failed to process ${baseName}: ${error.message}`));
|
|
3176
3113
|
}
|
|
3177
3114
|
}
|
|
3178
3115
|
if (!this.config.silent) {
|
|
3179
|
-
console.log(
|
|
3116
|
+
console.log(chalk2.blue("\n\u{1F30D} Phase 3: Finalizing Global Assets..."));
|
|
3180
3117
|
}
|
|
3181
3118
|
const finalAtomicCSS = this.atomicOptimizer ? this.atomicOptimizer.generateAtomicCSS() : "";
|
|
3182
3119
|
const globalCssPath = path6.join(publicDir, "global.css");
|
|
3183
3120
|
fs7.writeFileSync(globalCssPath, formatCSS(finalAtomicCSS, this.config.output.minify));
|
|
3184
3121
|
if (this.config.verbose) {
|
|
3185
|
-
console.log(
|
|
3122
|
+
console.log(chalk2.blue(` \u{1F4E6} Global CSS \u2192 ${path6.relative(process.cwd(), globalCssPath)} (${finalAtomicCSS.length} bytes)`));
|
|
3186
3123
|
}
|
|
3187
3124
|
const manifestData = {
|
|
3188
3125
|
version: VERSION,
|
|
@@ -3194,25 +3131,25 @@ var init_compiler = __esm({
|
|
|
3194
3131
|
const manifestPath = path6.join(manifestDir, "manifest.json");
|
|
3195
3132
|
fs7.writeFileSync(manifestPath, JSON.stringify(manifestData, null, 2));
|
|
3196
3133
|
if (this.config.verbose) {
|
|
3197
|
-
console.log(
|
|
3134
|
+
console.log(chalk2.blue(` \u{1F4E6} Manifest \u2192 ${path6.relative(process.cwd(), manifestPath)}`));
|
|
3198
3135
|
}
|
|
3199
3136
|
if (!this.config.silent) {
|
|
3200
|
-
console.log(
|
|
3137
|
+
console.log(chalk2.green(`
|
|
3201
3138
|
\u2705 Build Complete!`));
|
|
3202
|
-
console.log(
|
|
3203
|
-
console.log(
|
|
3204
|
-
console.log(
|
|
3205
|
-
console.log(
|
|
3139
|
+
console.log(chalk2.gray(` \u{1F4C1} Components processed: ${processedComponents}`));
|
|
3140
|
+
console.log(chalk2.gray(` \u{1F4C1} Class files generated: ${generatedClassFiles.length}`));
|
|
3141
|
+
console.log(chalk2.gray(` \u{1F4C1} Global CSS: ${path6.relative(process.cwd(), globalCssPath)}`));
|
|
3142
|
+
console.log(chalk2.gray(` \u{1F4C1} Manifest: ${path6.relative(process.cwd(), manifestPath)}`));
|
|
3206
3143
|
if (this.atomicOptimizer) {
|
|
3207
3144
|
const atomicCount = Object.keys(this.atomicOptimizer.atomicMap).length;
|
|
3208
3145
|
const stats = this.atomicOptimizer.getStats();
|
|
3209
|
-
console.log(
|
|
3146
|
+
console.log(chalk2.cyan(`
|
|
3210
3147
|
\u{1F4CA} Optimization Stats:`));
|
|
3211
|
-
console.log(
|
|
3212
|
-
console.log(
|
|
3213
|
-
console.log(
|
|
3148
|
+
console.log(chalk2.gray(` Atomic Rules: ${atomicCount}`));
|
|
3149
|
+
console.log(chalk2.gray(` Total Styles: ${stats.totalStyles}`));
|
|
3150
|
+
console.log(chalk2.gray(` Unique Properties: ${stats.uniqueProperties}`));
|
|
3214
3151
|
if (stats.savings) {
|
|
3215
|
-
console.log(
|
|
3152
|
+
console.log(chalk2.green(` CSS Savings: ${stats.savings}`));
|
|
3216
3153
|
}
|
|
3217
3154
|
}
|
|
3218
3155
|
}
|
|
@@ -3287,7 +3224,7 @@ var timeline_exports = {};
|
|
|
3287
3224
|
__export(timeline_exports, {
|
|
3288
3225
|
timelineCommand: () => timelineCommand
|
|
3289
3226
|
});
|
|
3290
|
-
import
|
|
3227
|
+
import chalk3 from "chalk";
|
|
3291
3228
|
import fs8 from "fs";
|
|
3292
3229
|
import path7 from "path";
|
|
3293
3230
|
import { createRequire } from "module";
|
|
@@ -3319,7 +3256,7 @@ function loadTimelineData(timelineFile) {
|
|
|
3319
3256
|
}
|
|
3320
3257
|
return data;
|
|
3321
3258
|
} catch (error) {
|
|
3322
|
-
console.error(
|
|
3259
|
+
console.error(chalk3.red(`Failed to load timeline data: ${error.message}`));
|
|
3323
3260
|
return null;
|
|
3324
3261
|
}
|
|
3325
3262
|
}
|
|
@@ -3327,20 +3264,20 @@ function displaySnapshotDetails(snapshot, index) {
|
|
|
3327
3264
|
const date = new Date(snapshot.timestamp).toLocaleString();
|
|
3328
3265
|
const propCount = Object.keys(snapshot.styles).length;
|
|
3329
3266
|
console.log(`
|
|
3330
|
-
${
|
|
3331
|
-
console.log(` ${
|
|
3332
|
-
console.log(` ${
|
|
3333
|
-
console.log(` ${
|
|
3334
|
-
console.log(` ${
|
|
3335
|
-
console.log(` ${
|
|
3267
|
+
${chalk3.green(`[${index}]`)} ${chalk3.white.bold(snapshot.selector)}`);
|
|
3268
|
+
console.log(` ${chalk3.gray(`ID: ${snapshot.id}`)}`);
|
|
3269
|
+
console.log(` ${chalk3.gray(`Time: ${date}`)}`);
|
|
3270
|
+
console.log(` ${chalk3.gray(`Source: ${snapshot.source}`)}`);
|
|
3271
|
+
console.log(` ${chalk3.gray(`Properties: ${propCount}`)}`);
|
|
3272
|
+
console.log(` ${chalk3.gray(`Hash: ${snapshot.hash.slice(0, 8)}...`)}`);
|
|
3336
3273
|
const previewProps = Object.entries(snapshot.styles).slice(0, 5);
|
|
3337
3274
|
if (previewProps.length > 0) {
|
|
3338
|
-
console.log(` ${
|
|
3275
|
+
console.log(` ${chalk3.dim("Preview:")}`);
|
|
3339
3276
|
for (const [prop, value] of previewProps) {
|
|
3340
|
-
console.log(` ${
|
|
3277
|
+
console.log(` ${chalk3.blue(prop)}: ${chalk3.yellow(value)}`);
|
|
3341
3278
|
}
|
|
3342
3279
|
if (Object.keys(snapshot.styles).length > 5) {
|
|
3343
|
-
console.log(` ${
|
|
3280
|
+
console.log(` ${chalk3.dim(`... and ${Object.keys(snapshot.styles).length - 5} more`)}`);
|
|
3344
3281
|
}
|
|
3345
3282
|
}
|
|
3346
3283
|
}
|
|
@@ -3369,26 +3306,26 @@ function displayDiff(diff, selector1, selector2) {
|
|
|
3369
3306
|
const { added, removed, modified } = diff;
|
|
3370
3307
|
const totalChanges = Object.keys(added).length + Object.keys(removed).length + Object.keys(modified).length;
|
|
3371
3308
|
if (totalChanges === 0) {
|
|
3372
|
-
console.log(
|
|
3309
|
+
console.log(chalk3.gray(" No changes detected"));
|
|
3373
3310
|
return;
|
|
3374
3311
|
}
|
|
3375
3312
|
for (const [prop, value] of Object.entries(removed)) {
|
|
3376
|
-
console.log(`${
|
|
3313
|
+
console.log(`${chalk3.red("\u2212")} ${chalk3.red(prop)}: ${chalk3.red(String(value))}`);
|
|
3377
3314
|
}
|
|
3378
3315
|
for (const [prop, value] of Object.entries(added)) {
|
|
3379
|
-
console.log(`${
|
|
3316
|
+
console.log(`${chalk3.green("+")} ${chalk3.green(prop)}: ${chalk3.green(String(value))}`);
|
|
3380
3317
|
}
|
|
3381
3318
|
for (const [prop, { old, new: newVal }] of Object.entries(modified)) {
|
|
3382
|
-
console.log(`${
|
|
3319
|
+
console.log(`${chalk3.yellow("~")} ${chalk3.yellow(prop)}: ${chalk3.red(String(old))} \u2192 ${chalk3.green(String(newVal))}`);
|
|
3383
3320
|
}
|
|
3384
3321
|
}
|
|
3385
3322
|
async function timelineCommand(action, options) {
|
|
3386
3323
|
const timelineFile = path7.join(process.cwd(), ".chaincss-timeline.json");
|
|
3387
3324
|
const data = loadTimelineData(timelineFile);
|
|
3388
3325
|
if (!data) {
|
|
3389
|
-
console.log(
|
|
3390
|
-
console.log(
|
|
3391
|
-
console.log(
|
|
3326
|
+
console.log(chalk3.yellow("\n\u26A0\uFE0F No timeline data found."));
|
|
3327
|
+
console.log(chalk3.gray(" Run your build with --timeline flag first:"));
|
|
3328
|
+
console.log(chalk3.cyan(" $ chaincss build --timeline\n"));
|
|
3392
3329
|
return;
|
|
3393
3330
|
}
|
|
3394
3331
|
if (!data.stats && data.history.length > 0) {
|
|
@@ -3401,20 +3338,20 @@ async function timelineCommand(action, options) {
|
|
|
3401
3338
|
}
|
|
3402
3339
|
switch (action) {
|
|
3403
3340
|
case "list":
|
|
3404
|
-
console.log(
|
|
3405
|
-
console.log(
|
|
3406
|
-
console.log(
|
|
3341
|
+
console.log(chalk3.cyan.bold("\n\u{1F4CA} Style Timeline History\n"));
|
|
3342
|
+
console.log(chalk3.gray(` Total Snapshots: ${data.stats?.totalSnapshots || data.history.length}`));
|
|
3343
|
+
console.log(chalk3.gray(` Total Changes: ${data.stats?.totalChanges || data.changes?.length || 0}`));
|
|
3407
3344
|
if (data.stats?.firstRecorded && data.stats?.lastRecorded) {
|
|
3408
3345
|
const duration = data.stats.lastRecorded - data.stats.firstRecorded;
|
|
3409
|
-
console.log(
|
|
3346
|
+
console.log(chalk3.gray(` Duration: ${formatDuration(duration)}`));
|
|
3410
3347
|
}
|
|
3411
|
-
console.log(
|
|
3348
|
+
console.log(chalk3.gray("\n Snapshots:\n"));
|
|
3412
3349
|
data.history.forEach((snapshot, index) => {
|
|
3413
3350
|
displaySnapshotDetails(snapshot, index);
|
|
3414
3351
|
});
|
|
3415
3352
|
try {
|
|
3416
3353
|
const stats = fs8.statSync(timelineFile);
|
|
3417
|
-
console.log(
|
|
3354
|
+
console.log(chalk3.gray(`
|
|
3418
3355
|
\u{1F4C1} Timeline file size: ${formatBytes(stats.size)}`));
|
|
3419
3356
|
} catch (e) {
|
|
3420
3357
|
}
|
|
@@ -3423,8 +3360,8 @@ async function timelineCommand(action, options) {
|
|
|
3423
3360
|
const id1 = options.snapshot1;
|
|
3424
3361
|
const id2 = options.snapshot2;
|
|
3425
3362
|
if (!id1 || !id2) {
|
|
3426
|
-
console.log(
|
|
3427
|
-
console.log(
|
|
3363
|
+
console.log(chalk3.red("\n\u274C Both snapshot1 and snapshot2 are required for diff"));
|
|
3364
|
+
console.log(chalk3.gray(" Usage: chaincss timeline diff --snapshot1 <id> --snapshot2 <id>\n"));
|
|
3428
3365
|
return;
|
|
3429
3366
|
}
|
|
3430
3367
|
const snapshot1 = data.history.find(
|
|
@@ -3434,36 +3371,36 @@ async function timelineCommand(action, options) {
|
|
|
3434
3371
|
(s) => s.id === id2 || s.selector === id2
|
|
3435
3372
|
);
|
|
3436
3373
|
if (!snapshot1) {
|
|
3437
|
-
console.log(
|
|
3374
|
+
console.log(chalk3.red(`
|
|
3438
3375
|
\u274C Snapshot not found: ${id1}`));
|
|
3439
|
-
console.log(
|
|
3376
|
+
console.log(chalk3.gray(' Use "chaincss timeline list" to see available snapshots\n'));
|
|
3440
3377
|
return;
|
|
3441
3378
|
}
|
|
3442
3379
|
if (!snapshot2) {
|
|
3443
|
-
console.log(
|
|
3380
|
+
console.log(chalk3.red(`
|
|
3444
3381
|
\u274C Snapshot not found: ${id2}`));
|
|
3445
|
-
console.log(
|
|
3382
|
+
console.log(chalk3.gray(' Use "chaincss timeline list" to see available snapshots\n'));
|
|
3446
3383
|
return;
|
|
3447
3384
|
}
|
|
3448
3385
|
const diff = calculateDiff(snapshot1, snapshot2);
|
|
3449
3386
|
const totalChanges = Object.keys(diff.added).length + Object.keys(diff.removed).length + Object.keys(diff.modified).length;
|
|
3450
|
-
console.log(
|
|
3387
|
+
console.log(chalk3.cyan.bold(`
|
|
3451
3388
|
\u{1F50D} Diff: ${snapshot1.selector} \u2192 ${snapshot2.selector}
|
|
3452
3389
|
`));
|
|
3453
|
-
console.log(
|
|
3454
|
-
console.log(
|
|
3390
|
+
console.log(chalk3.gray(` Changes: ${totalChanges}`));
|
|
3391
|
+
console.log(chalk3.gray(` Time between: ${formatDuration(snapshot2.timestamp - snapshot1.timestamp)}
|
|
3455
3392
|
`));
|
|
3456
3393
|
displayDiff(diff, snapshot1.selector, snapshot2.selector);
|
|
3457
3394
|
if (totalChanges > 0) {
|
|
3458
|
-
console.log(
|
|
3459
|
-
Legend: ${
|
|
3395
|
+
console.log(chalk3.gray(`
|
|
3396
|
+
Legend: ${chalk3.red("\u2212")} removed ${chalk3.green("+")} added ${chalk3.yellow("~")} modified
|
|
3460
3397
|
`));
|
|
3461
3398
|
}
|
|
3462
3399
|
break;
|
|
3463
3400
|
case "changes":
|
|
3464
|
-
console.log(
|
|
3401
|
+
console.log(chalk3.cyan.bold("\n\u{1F4DD} Style Change History\n"));
|
|
3465
3402
|
if (!data.changes || data.changes.length === 0) {
|
|
3466
|
-
console.log(
|
|
3403
|
+
console.log(chalk3.gray(" No changes recorded\n"));
|
|
3467
3404
|
return;
|
|
3468
3405
|
}
|
|
3469
3406
|
const changesBySelector = /* @__PURE__ */ new Map();
|
|
@@ -3474,19 +3411,19 @@ async function timelineCommand(action, options) {
|
|
|
3474
3411
|
changesBySelector.get(change.selector).push(change);
|
|
3475
3412
|
}
|
|
3476
3413
|
for (const [selector, changes] of changesBySelector) {
|
|
3477
|
-
console.log(
|
|
3414
|
+
console.log(chalk3.white.bold(`
|
|
3478
3415
|
${selector}`));
|
|
3479
3416
|
for (const change of changes) {
|
|
3480
3417
|
const date = new Date(change.timestamp).toLocaleTimeString();
|
|
3481
3418
|
switch (change.type) {
|
|
3482
3419
|
case "add":
|
|
3483
|
-
console.log(` ${
|
|
3420
|
+
console.log(` ${chalk3.green(`+ ${change.property}: ${change.newValue}`)} ${chalk3.gray(`[${date}]`)}`);
|
|
3484
3421
|
break;
|
|
3485
3422
|
case "remove":
|
|
3486
|
-
console.log(` ${
|
|
3423
|
+
console.log(` ${chalk3.red(`- ${change.property}: ${change.oldValue}`)} ${chalk3.gray(`[${date}]`)}`);
|
|
3487
3424
|
break;
|
|
3488
3425
|
case "modify":
|
|
3489
|
-
console.log(` ${
|
|
3426
|
+
console.log(` ${chalk3.yellow(`~ ${change.property}: ${change.oldValue} \u2192 ${change.newValue}`)} ${chalk3.gray(`[${date}]`)}`);
|
|
3490
3427
|
break;
|
|
3491
3428
|
}
|
|
3492
3429
|
}
|
|
@@ -3494,41 +3431,41 @@ async function timelineCommand(action, options) {
|
|
|
3494
3431
|
console.log();
|
|
3495
3432
|
break;
|
|
3496
3433
|
case "stats":
|
|
3497
|
-
console.log(
|
|
3498
|
-
console.log(
|
|
3499
|
-
console.log(
|
|
3434
|
+
console.log(chalk3.cyan.bold("\n\u{1F4C8} Timeline Statistics\n"));
|
|
3435
|
+
console.log(chalk3.gray(` Total Snapshots: ${data.history.length}`));
|
|
3436
|
+
console.log(chalk3.gray(` Total Changes: ${data.changes?.length || 0}`));
|
|
3500
3437
|
if (data.history.length > 0) {
|
|
3501
3438
|
const firstSnapshot = data.history[0];
|
|
3502
3439
|
const lastSnapshot = data.history[data.history.length - 1];
|
|
3503
3440
|
const duration = lastSnapshot.timestamp - firstSnapshot.timestamp;
|
|
3504
|
-
console.log(
|
|
3505
|
-
console.log(
|
|
3506
|
-
console.log(
|
|
3441
|
+
console.log(chalk3.gray(` First Recorded: ${new Date(firstSnapshot.timestamp).toLocaleString()}`));
|
|
3442
|
+
console.log(chalk3.gray(` Last Recorded: ${new Date(lastSnapshot.timestamp).toLocaleString()}`));
|
|
3443
|
+
console.log(chalk3.gray(` Duration: ${formatDuration(duration)}`));
|
|
3507
3444
|
const changesByType = { add: 0, remove: 0, modify: 0 };
|
|
3508
3445
|
for (const change of data.changes || []) {
|
|
3509
3446
|
changesByType[change.type]++;
|
|
3510
3447
|
}
|
|
3511
|
-
console.log(
|
|
3448
|
+
console.log(chalk3.gray(`
|
|
3512
3449
|
Changes by Type:`));
|
|
3513
|
-
console.log(
|
|
3514
|
-
console.log(
|
|
3515
|
-
console.log(
|
|
3450
|
+
console.log(chalk3.green(` Added: ${changesByType.add}`));
|
|
3451
|
+
console.log(chalk3.red(` Removed: ${changesByType.remove}`));
|
|
3452
|
+
console.log(chalk3.yellow(` Modified: ${changesByType.modify}`));
|
|
3516
3453
|
const changesBySelector2 = {};
|
|
3517
3454
|
for (const change of data.changes || []) {
|
|
3518
3455
|
changesBySelector2[change.selector] = (changesBySelector2[change.selector] || 0) + 1;
|
|
3519
3456
|
}
|
|
3520
3457
|
const topSelectors = Object.entries(changesBySelector2).sort((a, b) => b[1] - a[1]).slice(0, 5);
|
|
3521
3458
|
if (topSelectors.length > 0) {
|
|
3522
|
-
console.log(
|
|
3459
|
+
console.log(chalk3.gray(`
|
|
3523
3460
|
Most Active Selectors:`));
|
|
3524
3461
|
for (const [selector, count] of topSelectors) {
|
|
3525
|
-
console.log(
|
|
3462
|
+
console.log(chalk3.gray(` ${selector}: ${count} changes`));
|
|
3526
3463
|
}
|
|
3527
3464
|
}
|
|
3528
3465
|
}
|
|
3529
3466
|
try {
|
|
3530
3467
|
const stats = fs8.statSync(timelineFile);
|
|
3531
|
-
console.log(
|
|
3468
|
+
console.log(chalk3.gray(`
|
|
3532
3469
|
File Size: ${formatBytes(stats.size)}`));
|
|
3533
3470
|
} catch (e) {
|
|
3534
3471
|
}
|
|
@@ -3546,11 +3483,11 @@ async function timelineCommand(action, options) {
|
|
|
3546
3483
|
try {
|
|
3547
3484
|
fs8.writeFileSync(fullExportPath, JSON.stringify(exportData, null, 2));
|
|
3548
3485
|
const stats = fs8.statSync(fullExportPath);
|
|
3549
|
-
console.log(
|
|
3486
|
+
console.log(chalk3.green(`
|
|
3550
3487
|
\u2713 Timeline exported to ${fullExportPath}`));
|
|
3551
|
-
console.log(
|
|
3488
|
+
console.log(chalk3.gray(` Size: ${formatBytes(stats.size)}`));
|
|
3552
3489
|
} catch (error) {
|
|
3553
|
-
console.log(
|
|
3490
|
+
console.log(chalk3.red(`
|
|
3554
3491
|
\u274C Failed to export: ${error.message}`));
|
|
3555
3492
|
}
|
|
3556
3493
|
break;
|
|
@@ -3559,17 +3496,17 @@ async function timelineCommand(action, options) {
|
|
|
3559
3496
|
const backupPath = `${timelineFile}.backup-${Date.now()}`;
|
|
3560
3497
|
fs8.copyFileSync(timelineFile, backupPath);
|
|
3561
3498
|
fs8.unlinkSync(timelineFile);
|
|
3562
|
-
console.log(
|
|
3499
|
+
console.log(chalk3.green(`
|
|
3563
3500
|
\u2713 Timeline cleared`));
|
|
3564
|
-
console.log(
|
|
3501
|
+
console.log(chalk3.gray(` Backup saved to ${backupPath}`));
|
|
3565
3502
|
} catch (error) {
|
|
3566
|
-
console.log(
|
|
3503
|
+
console.log(chalk3.red(`
|
|
3567
3504
|
\u274C Failed to clear timeline: ${error.message}`));
|
|
3568
3505
|
}
|
|
3569
3506
|
break;
|
|
3570
3507
|
case "watch":
|
|
3571
|
-
console.log(
|
|
3572
|
-
console.log(
|
|
3508
|
+
console.log(chalk3.cyan.bold("\n\u{1F441}\uFE0F Watching timeline changes...\n"));
|
|
3509
|
+
console.log(chalk3.gray(" Press Ctrl+C to stop\n"));
|
|
3573
3510
|
let lastModified = fs8.statSync(timelineFile).mtimeMs;
|
|
3574
3511
|
const watcher = setInterval(() => {
|
|
3575
3512
|
try {
|
|
@@ -3578,13 +3515,13 @@ async function timelineCommand(action, options) {
|
|
|
3578
3515
|
lastModified = stats.mtimeMs;
|
|
3579
3516
|
const newData = loadTimelineData(timelineFile);
|
|
3580
3517
|
if (newData && newData.history.length !== data.history.length) {
|
|
3581
|
-
console.log(
|
|
3518
|
+
console.log(chalk3.yellow(`
|
|
3582
3519
|
\u{1F4DD} Timeline updated - ${(/* @__PURE__ */ new Date()).toLocaleTimeString()}`));
|
|
3583
|
-
console.log(
|
|
3520
|
+
console.log(chalk3.gray(` New snapshot count: ${newData.history.length}`));
|
|
3584
3521
|
const latest = newData.history[newData.history.length - 1];
|
|
3585
3522
|
if (latest) {
|
|
3586
|
-
console.log(
|
|
3587
|
-
console.log(
|
|
3523
|
+
console.log(chalk3.green(` Latest: ${latest.selector}`));
|
|
3524
|
+
console.log(chalk3.gray(` Properties: ${Object.keys(latest.styles).length}`));
|
|
3588
3525
|
}
|
|
3589
3526
|
}
|
|
3590
3527
|
Object.assign(data, newData);
|
|
@@ -3594,25 +3531,25 @@ async function timelineCommand(action, options) {
|
|
|
3594
3531
|
}, 1e3);
|
|
3595
3532
|
process.on("SIGINT", () => {
|
|
3596
3533
|
clearInterval(watcher);
|
|
3597
|
-
console.log(
|
|
3534
|
+
console.log(chalk3.gray("\n\n\u{1F44B} Stopped watching\n"));
|
|
3598
3535
|
process.exit(0);
|
|
3599
3536
|
});
|
|
3600
3537
|
break;
|
|
3601
3538
|
default:
|
|
3602
|
-
console.log(
|
|
3539
|
+
console.log(chalk3.yellow(`
|
|
3603
3540
|
\u274C Unknown action: ${action}`));
|
|
3604
|
-
console.log(
|
|
3605
|
-
console.log(
|
|
3606
|
-
console.log(
|
|
3607
|
-
console.log(
|
|
3608
|
-
console.log(
|
|
3609
|
-
console.log(
|
|
3610
|
-
console.log(
|
|
3611
|
-
console.log(
|
|
3541
|
+
console.log(chalk3.gray("\nAvailable actions:"));
|
|
3542
|
+
console.log(chalk3.cyan(" list ") + chalk3.gray("- List all timeline snapshots"));
|
|
3543
|
+
console.log(chalk3.cyan(" diff ") + chalk3.gray("- Compare two snapshots"));
|
|
3544
|
+
console.log(chalk3.cyan(" changes ") + chalk3.gray("- Show individual style changes"));
|
|
3545
|
+
console.log(chalk3.cyan(" stats ") + chalk3.gray("- Show timeline statistics"));
|
|
3546
|
+
console.log(chalk3.cyan(" export ") + chalk3.gray("- Export timeline to JSON"));
|
|
3547
|
+
console.log(chalk3.cyan(" clear ") + chalk3.gray("- Clear timeline data"));
|
|
3548
|
+
console.log(chalk3.cyan(" watch ") + chalk3.gray("- Watch for timeline updates\n"));
|
|
3612
3549
|
}
|
|
3613
3550
|
}
|
|
3614
3551
|
var require2;
|
|
3615
|
-
var
|
|
3552
|
+
var init_timeline2 = __esm({
|
|
3616
3553
|
"src/cli/commands/timeline.ts"() {
|
|
3617
3554
|
"use strict";
|
|
3618
3555
|
require2 = createRequire(import.meta.url);
|
|
@@ -3624,7 +3561,7 @@ var cache_exports = {};
|
|
|
3624
3561
|
__export(cache_exports, {
|
|
3625
3562
|
cacheCommand: () => cacheCommand
|
|
3626
3563
|
});
|
|
3627
|
-
import
|
|
3564
|
+
import chalk4 from "chalk";
|
|
3628
3565
|
import fs9 from "fs";
|
|
3629
3566
|
import path8 from "path";
|
|
3630
3567
|
function formatBytes2(bytes) {
|
|
@@ -3647,12 +3584,12 @@ function displayCacheEntry(key, entry, index) {
|
|
|
3647
3584
|
const created = entry.createdAt ? new Date(entry.createdAt).toLocaleString() : "Unknown";
|
|
3648
3585
|
const lastAccessed = entry.lastAccessed ? new Date(entry.lastAccessed).toLocaleString() : "Never";
|
|
3649
3586
|
console.log(`
|
|
3650
|
-
${
|
|
3651
|
-
console.log(` ${
|
|
3652
|
-
console.log(` ${
|
|
3653
|
-
console.log(` ${
|
|
3587
|
+
${chalk4.green(`[${index}]`)} ${chalk4.white.bold(key)}`);
|
|
3588
|
+
console.log(` ${chalk4.gray(`Created: ${created}`)}`);
|
|
3589
|
+
console.log(` ${chalk4.gray(`Last Accessed: ${lastAccessed}`)}`);
|
|
3590
|
+
console.log(` ${chalk4.gray(`Usage Count: ${entry.accessCount || 0}`)}`);
|
|
3654
3591
|
if (entry.size) {
|
|
3655
|
-
console.log(` ${
|
|
3592
|
+
console.log(` ${chalk4.gray(`Size: ${formatBytes2(entry.size)}`)}`);
|
|
3656
3593
|
}
|
|
3657
3594
|
}
|
|
3658
3595
|
async function cacheCommand(action, options) {
|
|
@@ -3667,9 +3604,9 @@ async function cacheCommand(action, options) {
|
|
|
3667
3604
|
});
|
|
3668
3605
|
switch (action) {
|
|
3669
3606
|
case "clear":
|
|
3670
|
-
console.log(
|
|
3607
|
+
console.log(chalk4.yellow("\n\u26A0\uFE0F This will delete all cached data"));
|
|
3671
3608
|
if (!options.force) {
|
|
3672
|
-
console.log(
|
|
3609
|
+
console.log(chalk4.gray(" Use --force to confirm\n"));
|
|
3673
3610
|
return;
|
|
3674
3611
|
}
|
|
3675
3612
|
try {
|
|
@@ -3677,12 +3614,12 @@ async function cacheCommand(action, options) {
|
|
|
3677
3614
|
if (fs9.existsSync(cacheDir)) {
|
|
3678
3615
|
fs9.rmSync(cacheDir, { recursive: true, force: true });
|
|
3679
3616
|
}
|
|
3680
|
-
console.log(
|
|
3681
|
-
console.log(
|
|
3682
|
-
console.log(
|
|
3617
|
+
console.log(chalk4.green("\n\u2713 All cache cleared"));
|
|
3618
|
+
console.log(chalk4.gray(` Removed: ${cacheDir}`));
|
|
3619
|
+
console.log(chalk4.gray(` Removed: ${persistentCacheDir}
|
|
3683
3620
|
`));
|
|
3684
3621
|
} catch (error) {
|
|
3685
|
-
console.log(
|
|
3622
|
+
console.log(chalk4.red(`
|
|
3686
3623
|
\u274C Failed to clear cache: ${error.message}
|
|
3687
3624
|
`));
|
|
3688
3625
|
}
|
|
@@ -3692,28 +3629,28 @@ async function cacheCommand(action, options) {
|
|
|
3692
3629
|
const stats = await persistentCache.getStats();
|
|
3693
3630
|
const regularCacheExists = fs9.existsSync(cacheDir);
|
|
3694
3631
|
const persistentCacheExists = fs9.existsSync(persistentCacheDir);
|
|
3695
|
-
console.log(
|
|
3696
|
-
console.log(
|
|
3697
|
-
console.log(` Status: ${persistentCacheExists ?
|
|
3632
|
+
console.log(chalk4.cyan.bold("\n\u{1F4CA} Cache Statistics\n"));
|
|
3633
|
+
console.log(chalk4.white.bold("Persistent Cache:"));
|
|
3634
|
+
console.log(` Status: ${persistentCacheExists ? chalk4.green("Active") : chalk4.gray("Empty")}`);
|
|
3698
3635
|
if (persistentCacheExists) {
|
|
3699
|
-
console.log(` Entry count: ${
|
|
3700
|
-
console.log(` Total size: ${
|
|
3701
|
-
console.log(` Total size (bytes): ${
|
|
3636
|
+
console.log(` Entry count: ${chalk4.white(stats.entryCount || 0)}`);
|
|
3637
|
+
console.log(` Total size: ${chalk4.white((stats.totalSizeMB || 0).toFixed(2))} MB`);
|
|
3638
|
+
console.log(` Total size (bytes): ${chalk4.white(formatBytes2(stats.totalSizeBytes || 0))}`);
|
|
3702
3639
|
if (stats.oldestEntry) {
|
|
3703
3640
|
const age = Date.now() - new Date(stats.oldestEntry).getTime();
|
|
3704
|
-
console.log(` Oldest entry: ${
|
|
3641
|
+
console.log(` Oldest entry: ${chalk4.white(new Date(stats.oldestEntry).toLocaleDateString())} (${formatDuration2(age)} ago)`);
|
|
3705
3642
|
}
|
|
3706
3643
|
if (stats.newestEntry) {
|
|
3707
3644
|
const age = Date.now() - new Date(stats.newestEntry).getTime();
|
|
3708
|
-
console.log(` Newest entry: ${
|
|
3645
|
+
console.log(` Newest entry: ${chalk4.white(new Date(stats.newestEntry).toLocaleDateString())} (${formatDuration2(age)} ago)`);
|
|
3709
3646
|
}
|
|
3710
3647
|
if (stats.hitRate !== void 0) {
|
|
3711
|
-
const hitRateColor = stats.hitRate > 80 ?
|
|
3648
|
+
const hitRateColor = stats.hitRate > 80 ? chalk4.green : stats.hitRate > 50 ? chalk4.yellow : chalk4.red;
|
|
3712
3649
|
console.log(` Cache hit rate: ${hitRateColor(`${(stats.hitRate * 100).toFixed(1)}%`)}`);
|
|
3713
3650
|
}
|
|
3714
3651
|
}
|
|
3715
|
-
console.log(
|
|
3716
|
-
console.log(` Status: ${regularCacheExists ?
|
|
3652
|
+
console.log(chalk4.white.bold("\nRegular Cache:"));
|
|
3653
|
+
console.log(` Status: ${regularCacheExists ? chalk4.green("Active") : chalk4.gray("Empty")}`);
|
|
3717
3654
|
if (regularCacheExists) {
|
|
3718
3655
|
let totalSize = 0;
|
|
3719
3656
|
let fileCount = 0;
|
|
@@ -3731,16 +3668,16 @@ async function cacheCommand(action, options) {
|
|
|
3731
3668
|
}
|
|
3732
3669
|
};
|
|
3733
3670
|
calculateSize(cacheDir);
|
|
3734
|
-
console.log(` File count: ${
|
|
3735
|
-
console.log(` Total size: ${
|
|
3671
|
+
console.log(` File count: ${chalk4.white(fileCount)}`);
|
|
3672
|
+
console.log(` Total size: ${chalk4.white(formatBytes2(totalSize))}`);
|
|
3736
3673
|
}
|
|
3737
|
-
console.log(
|
|
3738
|
-
console.log(` Max age: ${
|
|
3739
|
-
console.log(` Max size: ${
|
|
3740
|
-
console.log(` Cache directory: ${
|
|
3674
|
+
console.log(chalk4.white.bold("\nSettings:"));
|
|
3675
|
+
console.log(` Max age: ${chalk4.white(options.maxAge || 30)} days`);
|
|
3676
|
+
console.log(` Max size: ${chalk4.white(options.maxSize || 500)} MB`);
|
|
3677
|
+
console.log(` Cache directory: ${chalk4.gray(persistentCacheDir)}`);
|
|
3741
3678
|
console.log();
|
|
3742
3679
|
} catch (error) {
|
|
3743
|
-
console.log(
|
|
3680
|
+
console.log(chalk4.red(`
|
|
3744
3681
|
\u274C Failed to get cache stats: ${error.message}
|
|
3745
3682
|
`));
|
|
3746
3683
|
}
|
|
@@ -3750,9 +3687,9 @@ async function cacheCommand(action, options) {
|
|
|
3750
3687
|
const beforeStats = await persistentCache.getStats();
|
|
3751
3688
|
const beforeCount = beforeStats.entryCount || 0;
|
|
3752
3689
|
const beforeSize = beforeStats.totalSizeMB || 0;
|
|
3753
|
-
console.log(
|
|
3690
|
+
console.log(chalk4.yellow(`
|
|
3754
3691
|
\u{1F9F9} Pruning cache...`));
|
|
3755
|
-
console.log(
|
|
3692
|
+
console.log(chalk4.gray(` Before: ${beforeCount} entries, ${beforeSize.toFixed(2)} MB`));
|
|
3756
3693
|
await persistentCache.prune();
|
|
3757
3694
|
await persistentCache.enforceSizeLimit();
|
|
3758
3695
|
const afterStats = await persistentCache.getStats();
|
|
@@ -3761,15 +3698,15 @@ async function cacheCommand(action, options) {
|
|
|
3761
3698
|
const removedCount = beforeCount - afterCount;
|
|
3762
3699
|
const removedSize = beforeSize - afterSize;
|
|
3763
3700
|
if (removedCount > 0) {
|
|
3764
|
-
console.log(
|
|
3765
|
-
console.log(
|
|
3766
|
-
console.log(
|
|
3701
|
+
console.log(chalk4.green(`\u2713 Cache pruned successfully`));
|
|
3702
|
+
console.log(chalk4.gray(` Removed: ${removedCount} entries, ${removedSize.toFixed(2)} MB`));
|
|
3703
|
+
console.log(chalk4.gray(` Remaining: ${afterCount} entries, ${afterSize.toFixed(2)} MB`));
|
|
3767
3704
|
} else {
|
|
3768
|
-
console.log(
|
|
3705
|
+
console.log(chalk4.gray(` No entries to prune`));
|
|
3769
3706
|
}
|
|
3770
3707
|
console.log();
|
|
3771
3708
|
} catch (error) {
|
|
3772
|
-
console.log(
|
|
3709
|
+
console.log(chalk4.red(`
|
|
3773
3710
|
\u274C Failed to prune cache: ${error.message}
|
|
3774
3711
|
`));
|
|
3775
3712
|
}
|
|
@@ -3778,10 +3715,10 @@ async function cacheCommand(action, options) {
|
|
|
3778
3715
|
try {
|
|
3779
3716
|
const entries = await persistentCache.listEntries();
|
|
3780
3717
|
if (!entries || entries.length === 0) {
|
|
3781
|
-
console.log(
|
|
3718
|
+
console.log(chalk4.yellow("\n\u{1F4ED} No cache entries found\n"));
|
|
3782
3719
|
return;
|
|
3783
3720
|
}
|
|
3784
|
-
console.log(
|
|
3721
|
+
console.log(chalk4.cyan.bold(`
|
|
3785
3722
|
\u{1F4E6} Cache Entries (${entries.length})
|
|
3786
3723
|
`));
|
|
3787
3724
|
entries.forEach((entry, index) => {
|
|
@@ -3789,7 +3726,7 @@ async function cacheCommand(action, options) {
|
|
|
3789
3726
|
});
|
|
3790
3727
|
console.log();
|
|
3791
3728
|
} catch (error) {
|
|
3792
|
-
console.log(
|
|
3729
|
+
console.log(chalk4.red(`
|
|
3793
3730
|
\u274C Failed to list cache entries: ${error.message}
|
|
3794
3731
|
`));
|
|
3795
3732
|
}
|
|
@@ -3797,37 +3734,37 @@ async function cacheCommand(action, options) {
|
|
|
3797
3734
|
case "inspect":
|
|
3798
3735
|
const key = options.key;
|
|
3799
3736
|
if (!key) {
|
|
3800
|
-
console.log(
|
|
3801
|
-
console.log(
|
|
3737
|
+
console.log(chalk4.red("\n\u274C Please provide a cache key to inspect"));
|
|
3738
|
+
console.log(chalk4.gray(" Usage: chaincss cache inspect --key <key>\n"));
|
|
3802
3739
|
return;
|
|
3803
3740
|
}
|
|
3804
3741
|
try {
|
|
3805
3742
|
const entry = await persistentCache.get(key);
|
|
3806
3743
|
if (!entry) {
|
|
3807
|
-
console.log(
|
|
3744
|
+
console.log(chalk4.yellow(`
|
|
3808
3745
|
\u274C Cache entry not found: ${key}
|
|
3809
3746
|
`));
|
|
3810
3747
|
return;
|
|
3811
3748
|
}
|
|
3812
|
-
console.log(
|
|
3749
|
+
console.log(chalk4.cyan.bold(`
|
|
3813
3750
|
\u{1F50D} Cache Entry: ${key}
|
|
3814
3751
|
`));
|
|
3815
|
-
console.log(
|
|
3816
|
-
console.log(` Created: ${
|
|
3817
|
-
console.log(` Last accessed: ${
|
|
3818
|
-
console.log(` Access count: ${
|
|
3752
|
+
console.log(chalk4.white("Metadata:"));
|
|
3753
|
+
console.log(` Created: ${chalk4.gray(entry.createdAt ? new Date(entry.createdAt).toLocaleString() : "Unknown")}`);
|
|
3754
|
+
console.log(` Last accessed: ${chalk4.gray(entry.lastAccessed ? new Date(entry.lastAccessed).toLocaleString() : "Never")}`);
|
|
3755
|
+
console.log(` Access count: ${chalk4.gray(entry.accessCount || 0)}`);
|
|
3819
3756
|
if (entry.size) {
|
|
3820
|
-
console.log(` Size: ${
|
|
3757
|
+
console.log(` Size: ${chalk4.gray(formatBytes2(entry.size))}`);
|
|
3821
3758
|
}
|
|
3822
3759
|
if (entry.value) {
|
|
3823
|
-
console.log(
|
|
3760
|
+
console.log(chalk4.white.bold("\nContent Preview:"));
|
|
3824
3761
|
const valueStr = JSON.stringify(entry.value, null, 2);
|
|
3825
3762
|
const preview = valueStr.length > 500 ? valueStr.slice(0, 500) + "..." : valueStr;
|
|
3826
|
-
console.log(
|
|
3763
|
+
console.log(chalk4.gray(preview));
|
|
3827
3764
|
}
|
|
3828
3765
|
console.log();
|
|
3829
3766
|
} catch (error) {
|
|
3830
|
-
console.log(
|
|
3767
|
+
console.log(chalk4.red(`
|
|
3831
3768
|
\u274C Failed to inspect cache entry: ${error.message}
|
|
3832
3769
|
`));
|
|
3833
3770
|
}
|
|
@@ -3835,36 +3772,36 @@ async function cacheCommand(action, options) {
|
|
|
3835
3772
|
case "delete":
|
|
3836
3773
|
const deleteKey = options.key;
|
|
3837
3774
|
if (!deleteKey) {
|
|
3838
|
-
console.log(
|
|
3839
|
-
console.log(
|
|
3775
|
+
console.log(chalk4.red("\n\u274C Please provide a cache key to delete"));
|
|
3776
|
+
console.log(chalk4.gray(" Usage: chaincss cache delete --key <key>\n"));
|
|
3840
3777
|
return;
|
|
3841
3778
|
}
|
|
3842
3779
|
if (!options.force) {
|
|
3843
|
-
console.log(
|
|
3780
|
+
console.log(chalk4.yellow(`
|
|
3844
3781
|
\u26A0\uFE0F This will delete cache entry: ${deleteKey}`));
|
|
3845
|
-
console.log(
|
|
3782
|
+
console.log(chalk4.gray(" Use --force to confirm\n"));
|
|
3846
3783
|
return;
|
|
3847
3784
|
}
|
|
3848
3785
|
try {
|
|
3849
3786
|
const deleted = await persistentCache.delete(deleteKey);
|
|
3850
3787
|
if (deleted) {
|
|
3851
|
-
console.log(
|
|
3788
|
+
console.log(chalk4.green(`
|
|
3852
3789
|
\u2713 Deleted cache entry: ${deleteKey}
|
|
3853
3790
|
`));
|
|
3854
3791
|
} else {
|
|
3855
|
-
console.log(
|
|
3792
|
+
console.log(chalk4.yellow(`
|
|
3856
3793
|
\u274C Cache entry not found: ${deleteKey}
|
|
3857
3794
|
`));
|
|
3858
3795
|
}
|
|
3859
3796
|
} catch (error) {
|
|
3860
|
-
console.log(
|
|
3797
|
+
console.log(chalk4.red(`
|
|
3861
3798
|
\u274C Failed to delete cache entry: ${error.message}
|
|
3862
3799
|
`));
|
|
3863
3800
|
}
|
|
3864
3801
|
break;
|
|
3865
3802
|
case "validate":
|
|
3866
3803
|
try {
|
|
3867
|
-
console.log(
|
|
3804
|
+
console.log(chalk4.cyan.bold("\n\u{1F50D} Validating Cache Integrity\n"));
|
|
3868
3805
|
const entries = await persistentCache.listEntries();
|
|
3869
3806
|
let validCount = 0;
|
|
3870
3807
|
let invalidCount = 0;
|
|
@@ -3876,25 +3813,25 @@ async function cacheCommand(action, options) {
|
|
|
3876
3813
|
totalSize += entry.size || 0;
|
|
3877
3814
|
} else {
|
|
3878
3815
|
invalidCount++;
|
|
3879
|
-
console.log(
|
|
3816
|
+
console.log(chalk4.yellow(` \u2717 Invalid entry: ${entry.key}`));
|
|
3880
3817
|
}
|
|
3881
3818
|
}
|
|
3882
|
-
console.log(
|
|
3819
|
+
console.log(chalk4.white(`
|
|
3883
3820
|
Results:`));
|
|
3884
|
-
console.log(` Valid entries: ${
|
|
3885
|
-
console.log(` Invalid entries: ${invalidCount > 0 ?
|
|
3886
|
-
console.log(` Total size: ${
|
|
3821
|
+
console.log(` Valid entries: ${chalk4.green(validCount)}`);
|
|
3822
|
+
console.log(` Invalid entries: ${invalidCount > 0 ? chalk4.red(invalidCount) : chalk4.green(invalidCount)}`);
|
|
3823
|
+
console.log(` Total size: ${chalk4.gray(formatBytes2(totalSize))}`);
|
|
3887
3824
|
if (invalidCount > 0) {
|
|
3888
|
-
console.log(
|
|
3825
|
+
console.log(chalk4.yellow(`
|
|
3889
3826
|
\u26A0\uFE0F Found ${invalidCount} invalid entries. Run 'chaincss cache prune' to clean them.
|
|
3890
3827
|
`));
|
|
3891
3828
|
} else {
|
|
3892
|
-
console.log(
|
|
3829
|
+
console.log(chalk4.green(`
|
|
3893
3830
|
\u2713 All cache entries are valid
|
|
3894
3831
|
`));
|
|
3895
3832
|
}
|
|
3896
3833
|
} catch (error) {
|
|
3897
|
-
console.log(
|
|
3834
|
+
console.log(chalk4.red(`
|
|
3898
3835
|
\u274C Failed to validate cache: ${error.message}
|
|
3899
3836
|
`));
|
|
3900
3837
|
}
|
|
@@ -3902,7 +3839,7 @@ Results:`));
|
|
|
3902
3839
|
case "backup":
|
|
3903
3840
|
const backupPath = options.output || `./.chaincss-cache-backup-${Date.now()}.tar.gz`;
|
|
3904
3841
|
try {
|
|
3905
|
-
console.log(
|
|
3842
|
+
console.log(chalk4.cyan.bold("\n\u{1F4BE} Creating Cache Backup\n"));
|
|
3906
3843
|
const backupDir = path8.dirname(backupPath);
|
|
3907
3844
|
if (!fs9.existsSync(backupDir)) {
|
|
3908
3845
|
fs9.mkdirSync(backupDir, { recursive: true });
|
|
@@ -3926,34 +3863,34 @@ Results:`));
|
|
|
3926
3863
|
const backupCacheDir = backupPath.replace(/\.tar\.gz$/, "");
|
|
3927
3864
|
copyDir(cacheDir, backupCacheDir);
|
|
3928
3865
|
copyDir(persistentCacheDir, path8.join(backupCacheDir, "persistent"));
|
|
3929
|
-
console.log(
|
|
3930
|
-
console.log(
|
|
3866
|
+
console.log(chalk4.green(`\u2713 Cache backed up to ${backupCacheDir}`));
|
|
3867
|
+
console.log(chalk4.gray(` To restore, copy the contents back to the cache directory
|
|
3931
3868
|
`));
|
|
3932
3869
|
} catch (error) {
|
|
3933
|
-
console.log(
|
|
3870
|
+
console.log(chalk4.red(`
|
|
3934
3871
|
\u274C Failed to backup cache: ${error.message}
|
|
3935
3872
|
`));
|
|
3936
3873
|
}
|
|
3937
3874
|
break;
|
|
3938
3875
|
default:
|
|
3939
|
-
console.log(
|
|
3876
|
+
console.log(chalk4.yellow(`
|
|
3940
3877
|
\u274C Unknown action: ${action}`));
|
|
3941
|
-
console.log(
|
|
3942
|
-
console.log(
|
|
3943
|
-
console.log(
|
|
3944
|
-
console.log(
|
|
3945
|
-
console.log(
|
|
3946
|
-
console.log(
|
|
3947
|
-
console.log(
|
|
3948
|
-
console.log(
|
|
3949
|
-
console.log(
|
|
3950
|
-
console.log(
|
|
3951
|
-
console.log(
|
|
3952
|
-
console.log(
|
|
3953
|
-
console.log(
|
|
3954
|
-
console.log(
|
|
3955
|
-
console.log(
|
|
3956
|
-
console.log(
|
|
3878
|
+
console.log(chalk4.gray("\nAvailable actions:"));
|
|
3879
|
+
console.log(chalk4.cyan(" clear ") + chalk4.gray("- Clear all cache data"));
|
|
3880
|
+
console.log(chalk4.cyan(" stats ") + chalk4.gray("- Show cache statistics"));
|
|
3881
|
+
console.log(chalk4.cyan(" prune ") + chalk4.gray("- Remove expired entries"));
|
|
3882
|
+
console.log(chalk4.cyan(" list ") + chalk4.gray("- List all cache entries"));
|
|
3883
|
+
console.log(chalk4.cyan(" inspect ") + chalk4.gray("- Inspect a specific cache entry"));
|
|
3884
|
+
console.log(chalk4.cyan(" delete ") + chalk4.gray("- Delete a specific cache entry"));
|
|
3885
|
+
console.log(chalk4.cyan(" validate ") + chalk4.gray("- Validate cache integrity"));
|
|
3886
|
+
console.log(chalk4.cyan(" backup ") + chalk4.gray("- Backup cache to file"));
|
|
3887
|
+
console.log(chalk4.gray("\nOptions:"));
|
|
3888
|
+
console.log(chalk4.gray(" --key <key> Cache key for inspect/delete"));
|
|
3889
|
+
console.log(chalk4.gray(" --force Skip confirmation prompts"));
|
|
3890
|
+
console.log(chalk4.gray(" --max-age <days> Max age for cache entries"));
|
|
3891
|
+
console.log(chalk4.gray(" --max-size <MB> Max cache size in MB"));
|
|
3892
|
+
console.log(chalk4.gray(" --output <path> Output path for backup"));
|
|
3893
|
+
console.log(chalk4.gray(" --verbose Verbose output\n"));
|
|
3957
3894
|
}
|
|
3958
3895
|
}
|
|
3959
3896
|
var init_cache = __esm({
|
|
@@ -3969,7 +3906,7 @@ import { readFileSync, existsSync, writeFileSync } from "fs";
|
|
|
3969
3906
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
3970
3907
|
import path9 from "path";
|
|
3971
3908
|
import { glob } from "glob";
|
|
3972
|
-
import
|
|
3909
|
+
import chalk5 from "chalk";
|
|
3973
3910
|
|
|
3974
3911
|
// src/cli/utils/config-loader.ts
|
|
3975
3912
|
import fs from "fs";
|
|
@@ -4104,13 +4041,13 @@ var getCompiler = async (config) => {
|
|
|
4104
4041
|
return new ChainCSSCompiler2(config);
|
|
4105
4042
|
};
|
|
4106
4043
|
var handleError = (error, command) => {
|
|
4107
|
-
console.error(
|
|
4044
|
+
console.error(chalk5.red(`
|
|
4108
4045
|
\u274C Error running "${command}":`));
|
|
4109
4046
|
if (error instanceof Error) {
|
|
4110
|
-
console.error(
|
|
4047
|
+
console.error(chalk5.red(` ${error.message}`));
|
|
4111
4048
|
if (process.env.DEBUG) console.error(error.stack);
|
|
4112
4049
|
} else {
|
|
4113
|
-
console.error(
|
|
4050
|
+
console.error(chalk5.red(` ${String(error)}`));
|
|
4114
4051
|
}
|
|
4115
4052
|
process.exit(1);
|
|
4116
4053
|
};
|
|
@@ -4118,7 +4055,7 @@ program.command("init").description("Initialize ChainCSS configuration file").op
|
|
|
4118
4055
|
try {
|
|
4119
4056
|
const configPath = "chaincss.config.js";
|
|
4120
4057
|
if (existsSync(configPath) && !options.force) {
|
|
4121
|
-
console.log(
|
|
4058
|
+
console.log(chalk5.yellow("Config file already exists. Use --force to overwrite."));
|
|
4122
4059
|
return;
|
|
4123
4060
|
}
|
|
4124
4061
|
const config = `export default {
|
|
@@ -4137,7 +4074,7 @@ program.command("init").description("Initialize ChainCSS configuration file").op
|
|
|
4137
4074
|
verbose: true
|
|
4138
4075
|
};`;
|
|
4139
4076
|
writeFileSync(configPath, config);
|
|
4140
|
-
console.log(
|
|
4077
|
+
console.log(chalk5.green("\u2713 Created chaincss.config.js with Object-based output."));
|
|
4141
4078
|
} catch (error) {
|
|
4142
4079
|
handleError(error, "init");
|
|
4143
4080
|
}
|
|
@@ -4146,14 +4083,14 @@ program.command("build").option("-v, --verbose", "Verbose output").action(async
|
|
|
4146
4083
|
try {
|
|
4147
4084
|
const config = await loadConfig();
|
|
4148
4085
|
const compiler = await getCompiler(config);
|
|
4149
|
-
console.log(
|
|
4086
|
+
console.log(chalk5.blue("\u{1F680} Starting ChainCSS Build..."));
|
|
4150
4087
|
const patterns = config.inputs || ["src/**/*.chain.{js,ts}", "src/**/*.tsx"];
|
|
4151
4088
|
const files = await glob(patterns);
|
|
4152
4089
|
await compiler.compileComponents(files);
|
|
4153
4090
|
const stats = compiler.getStats();
|
|
4154
|
-
console.log(
|
|
4091
|
+
console.log(chalk5.green(`
|
|
4155
4092
|
\u2705 Build Complete!`));
|
|
4156
|
-
console.log(
|
|
4093
|
+
console.log(chalk5.cyan(`\u{1F4CA} Atomic Rules: ${stats.atomicStyles}`));
|
|
4157
4094
|
} catch (error) {
|
|
4158
4095
|
handleError(error, "build");
|
|
4159
4096
|
}
|
|
@@ -4165,9 +4102,9 @@ program.command("watch").description("Watch and automatically recompile styles")
|
|
|
4165
4102
|
const chokidar = await import("chokidar");
|
|
4166
4103
|
const patterns = config.inputs || ["src/**/*.chain.{js,ts}", "src/**/*.tsx"];
|
|
4167
4104
|
const watcher = chokidar.watch(patterns, { ignored: "**/node_modules/**" });
|
|
4168
|
-
console.log(
|
|
4105
|
+
console.log(chalk5.blue("\u{1F4E1} Watching for changes..."));
|
|
4169
4106
|
watcher.on("change", async (filePath) => {
|
|
4170
|
-
console.log(
|
|
4107
|
+
console.log(chalk5.yellow(`\r\u{1F504} Change detected: ${path9.basename(filePath)}`));
|
|
4171
4108
|
const files = await glob(patterns);
|
|
4172
4109
|
await compiler.compileComponents(files);
|
|
4173
4110
|
});
|
|
@@ -4176,22 +4113,22 @@ program.command("watch").description("Watch and automatically recompile styles")
|
|
|
4176
4113
|
}
|
|
4177
4114
|
});
|
|
4178
4115
|
program.command("timeline").description("Manage style timeline").argument("<action>", "Action: list, diff, export, clear").option("-s, --snapshot1 <id>", "First snapshot ID or selector for diff").option("--snapshot2 <id>", "Second snapshot ID or selector for diff").option("-o, --output <path>", "Output file for export").action(async (action, options) => {
|
|
4179
|
-
const { timelineCommand: timelineCommand2 } = await Promise.resolve().then(() => (
|
|
4116
|
+
const { timelineCommand: timelineCommand2 } = await Promise.resolve().then(() => (init_timeline2(), timeline_exports));
|
|
4180
4117
|
await timelineCommand2(action, options);
|
|
4181
4118
|
});
|
|
4182
4119
|
program.on("--help", () => {
|
|
4183
4120
|
console.log("");
|
|
4184
|
-
console.log(
|
|
4185
|
-
console.log(
|
|
4121
|
+
console.log(chalk5.cyan("Examples:"));
|
|
4122
|
+
console.log(chalk5.gray(" # Initialize a new project"));
|
|
4186
4123
|
console.log(" $ chaincss init");
|
|
4187
4124
|
console.log("");
|
|
4188
|
-
console.log(
|
|
4125
|
+
console.log(chalk5.gray(" # Build all styles"));
|
|
4189
4126
|
console.log(' $ chaincss build -c "src/**/*.chain.js"');
|
|
4190
4127
|
console.log("");
|
|
4191
|
-
console.log(
|
|
4128
|
+
console.log(chalk5.gray(" # Watch for changes"));
|
|
4192
4129
|
console.log(' $ chaincss watch -c "src/**/*.chain.js"');
|
|
4193
4130
|
console.log("");
|
|
4194
|
-
console.log(
|
|
4131
|
+
console.log(chalk5.cyan("Documentation:"));
|
|
4195
4132
|
console.log(" https://github.com/melcanz08/chaincss");
|
|
4196
4133
|
console.log("");
|
|
4197
4134
|
});
|