Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 | #!/usr/bin/env node
import fs from 'fs';
import path from 'node:path';
import chalk from 'chalk';
import Table from 'cli-table3';
import { fileURLToPath } from 'url';
import { parseValidatorArgs, exitWithStatus, loadKnownIssues, colorSwatch } from './validator-utils.js';
import { MODE_EXTENSION_KEY } from '../style-dictionary/utils/constants.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const knownIssues = loadKnownIssues();
/**
* TEMPORARY JSON Comparison Tool (TO BE REMOVED AFTER MIGRATION)
*
* Compare styling hook JSON files between sds-styling-hooks and design-tokens packages
* This script helps verify that both packages generate identical JSON output (not CSS)
*
* COMPARES: .raw.json files (JSON format, separate shared/component files)
* NOT: .css files - use temp-compare-css.js for CSS comparison
*
* NOTE: This is a temporary migration tool that should be deleted once the
* design token migration from legacy (Theo) to modern (Style Dictionary + W3C)
* is complete and verified.
*
* Usage:
* yarn temp:compare:json # Summary only
* yarn temp:compare:json --verbose # Show detailed issue tables
* yarn temp:compare:json --report # Show full table of all properties
* yarn temp:compare:json --theme=cosmos # Compare only cosmos theme
* yarn temp:compare:json --type=shared # Compare only shared hooks
*/
// Paths to the two packages
const SDS_STYLING_HOOKS_PATH = path.resolve(__dirname, '../../../sds-styling-hooks/dist/themes');
const DESIGN_TOKENS_PATH = path.resolve(__dirname, '../../dist/themes');
// Themes to compare
const THEMES = ['slds', 'cosmos'];
// Hook types to compare
const HOOK_TYPES = [
{ name: 'shared', suffix: 'shared.hooks.raw.json' },
{ name: 'component', suffix: 'component.hooks.raw.json' },
];
// Parse command line arguments
const args = process.argv.slice(2);
const { themeFilter, isVerbose, isReport } = parseValidatorArgs();
const flags = {
theme: themeFilter,
type: args.find((arg) => arg.startsWith('--type='))?.split('=')[1],
limit: parseInt(args.find((arg) => arg.startsWith('--limit='))?.split('=')[1]) || null,
verbose: isVerbose,
report: isReport,
};
/**
* Normalize token values for comparison
* Converts both formats to a common comparable form
*/
function normalizeTokenValue(value) {
// Convert numbers to strings for consistent comparison
if (typeof value === 'number') {
return String(value);
}
if (typeof value !== 'string') return value;
// Handle specific palette cases FIRST (before general var(--slds-g-) rule)
// Convert var(--slds-g-color-palette-yellow-90) -> alias.palette.yellow.90
if (value.startsWith('var(--slds-g-color-palette-')) {
return value.replace('var(--slds-g-color-palette-', 'alias.palette.').replace(')', '').replace(/-/g, '.');
}
// Handle special transparent case
if (value === 'var(--slds-g-transparent)') {
return 'transparent';
}
// Convert var(--slds-g-color-accent-container-3) -> slds.g.color.accent.container.3
if (value.startsWith('var(--slds-g-')) {
return value.replace('var(--slds-g-', 'slds.g.').replace(')', '').replace(/-/g, '.');
}
// Convert {slds.g.color.accent.container.3} -> slds.g.color.accent.container.3
if (value.startsWith('{slds.g.') && value.endsWith('}')) {
return value.slice(1, -1); // Remove { and }
}
// Convert {alias.palette.yellow.90} -> alias.palette.yellow.90
if (value.startsWith('{alias.') && value.endsWith('}')) {
return value.slice(1, -1); // Remove { and }
}
// Handle trailing semicolons - normalize by removing them
if (value.endsWith(';')) {
value = value.slice(0, -1);
}
// Return value as-is for other formats (like plain values "0", "#ffffff", etc.)
return value;
}
/**
* Compare CSS custom properties between two packages
*/
function compareCustomProperties(sdsProps, designTokensProps) {
const differences = [];
// Get all property names
const sdsKeys = new Set(Object.keys(sdsProps));
const designTokensKeys = new Set(Object.keys(designTokensProps));
const allKeys = new Set([...sdsKeys, ...designTokensKeys]);
// Check for missing properties
for (const key of sdsKeys) {
if (!designTokensKeys.has(key)) {
differences.push({
path: key,
issue: 'MISSING_IN_DESIGN_TOKENS',
sdsStyleHooks: sdsProps[key].value,
designTokens: undefined,
});
}
}
for (const key of designTokensKeys) {
if (!sdsKeys.has(key)) {
differences.push({
path: key,
issue: 'MISSING_IN_SDS_STYLING_HOOKS',
sdsStyleHooks: undefined,
designTokens: designTokensProps[key].value,
});
}
}
// Compare values for common properties using normalized values
for (const key of allKeys) {
if (sdsKeys.has(key) && designTokensKeys.has(key)) {
const sdsValue = sdsProps[key].value;
const designTokensValue = designTokensProps[key].value;
// Normalize both values for comparison
const normalizedSdsValue = normalizeTokenValue(sdsValue);
const normalizedDesignTokensValue = normalizeTokenValue(designTokensValue);
if (normalizedSdsValue !== normalizedDesignTokensValue) {
differences.push({
path: key,
issue: 'VALUE_MISMATCH',
sdsStyleHooks: sdsValue,
designTokens: designTokensValue,
normalizedSds: normalizedSdsValue,
normalizedDesignTokens: normalizedDesignTokensValue,
});
}
}
}
return differences;
}
/**
* Deep compare two objects (kept for backwards compatibility)
*/
function deepCompare(obj1, obj2, path = '') {
const differences = [];
if (typeof obj1 !== typeof obj2) {
differences.push({
path,
issue: 'TYPE_MISMATCH',
sdsStyleHooks: typeof obj1,
designTokens: typeof obj2,
});
return differences;
}
if (obj1 === null || obj2 === null) {
if (obj1 !== obj2) {
differences.push({
path,
issue: 'NULL_MISMATCH',
sdsStyleHooks: obj1,
designTokens: obj2,
});
}
return differences;
}
if (typeof obj1 !== 'object') {
if (obj1 !== obj2) {
differences.push({
path,
issue: 'VALUE_MISMATCH',
sdsStyleHooks: obj1,
designTokens: obj2,
});
}
return differences;
}
// Get all keys from both objects
const keys1 = new Set(Object.keys(obj1));
const keys2 = new Set(Object.keys(obj2));
const allKeys = new Set([...keys1, ...keys2]);
// Check for missing keys
for (const key of keys1) {
if (!keys2.has(key)) {
differences.push({
path: path ? `${path}.${key}` : key,
issue: 'MISSING_IN_DESIGN_TOKENS',
sdsStyleHooks: obj1[key],
designTokens: undefined,
});
}
}
for (const key of keys2) {
if (!keys1.has(key)) {
differences.push({
path: path ? `${path}.${key}` : key,
issue: 'MISSING_IN_SDS_STYLING_HOOKS',
sdsStyleHooks: undefined,
designTokens: obj2[key],
});
}
}
// Compare common keys recursively
for (const key of allKeys) {
if (keys1.has(key) && keys2.has(key)) {
const newPath = path ? `${path}.${key}` : key;
differences.push(...deepCompare(obj1[key], obj2[key], newPath));
}
}
return differences;
}
/**
* Extract custom properties from sds-styling-hooks format
*/
function extractFromStylingHooks(data) {
const properties = {};
if (data.props) {
for (const [key, value] of Object.entries(data.props)) {
// Replace underscores with hyphens in the key
const processedKey = key.replace(/_/g, '-');
// Add underscore prefix for private tokens (based on the "private" field)
const privatePrefix = value.private === true ? '_' : '';
const hookName = `--${privatePrefix}slds-${value.scope === 'shared' ? 's' : 'c'}-${processedKey}`;
properties[hookName] = {
value: value.value,
description: value.comment || '',
scope: value.scope,
type: value.type,
private: value.private,
};
}
}
return properties;
}
/**
* Normalize $value from design-tokens format to string
*/
function normalizeDesignTokenValue(value) {
// If it's an object with value and unit, convert to string
if (value && typeof value === 'object' && 'value' in value && 'unit' in value) {
return `${value.value}${value.unit}`;
}
// Otherwise return as-is
return value;
}
/**
* Extract custom properties from design-tokens format
*/
function extractFromDesignTokens(obj, prefix = '', scope = '') {
const properties = {};
for (const [key, value] of Object.entries(obj)) {
// Skip the top-level "slds" wrapper and go directly to scope keys
if (key === 'slds' && !scope && !prefix) {
Object.assign(properties, extractFromDesignTokens(value, '', ''));
continue;
}
if (key === 's' && !scope) {
// Shared scope
Object.assign(properties, extractFromDesignTokens(value, '', 'shared'));
} else if (key === 'c' && !scope) {
// Component scope
Object.assign(properties, extractFromDesignTokens(value, '', 'component'));
} else if (value && typeof value === 'object') {
const currentPath = prefix ? `${prefix}-${key}` : key;
if (value.$value !== undefined) {
// This is a token with a value
const scopePrefix = scope === 'shared' ? 's' : 'c';
const hookName = `--slds-${scopePrefix}-${currentPath.replace(/_/g, '-')}`;
// Check if there's a dark mode extension and convert to light-dark() format
let tokenValue = normalizeDesignTokenValue(value.$value);
if (value.$extensions?.[MODE_EXTENSION_KEY]?.dark?.$value) {
const darkValue = normalizeDesignTokenValue(value.$extensions[MODE_EXTENSION_KEY].dark.$value);
tokenValue = `light-dark(${tokenValue}, ${darkValue})`;
}
properties[hookName] = {
value: tokenValue,
description: value.$description || '',
dynamic: value.dynamic || false,
scope: scope,
};
} else {
// Recurse deeper
Object.assign(properties, extractFromDesignTokens(value, currentPath, scope));
}
}
}
return properties;
}
/**
* Extract custom properties from either format
*/
function extractCustomProperties(data, isDesignTokens = false) {
if (isDesignTokens) {
return extractFromDesignTokens(data);
} else {
return extractFromStylingHooks(data);
}
}
/**
* Compare hook files between packages
*/
function compareHookFiles(theme, hookType) {
const sdsStyleHooksFile = path.join(SDS_STYLING_HOOKS_PATH, theme, `${theme}.${hookType.suffix}`);
const designTokensFile = path.join(DESIGN_TOKENS_PATH, theme, `${theme}.${hookType.suffix}`);
// Check if files exist
if (!fs.existsSync(sdsStyleHooksFile)) {
console.log(chalk.red(` ❌ Missing sds-styling-hooks file: ${sdsStyleHooksFile}`));
return { differences: [], missing: 'sds-styling-hooks' };
}
if (!fs.existsSync(designTokensFile)) {
console.log(chalk.red(` ❌ Missing design-tokens file: ${designTokensFile}`));
return { differences: [], missing: 'design-tokens' };
}
try {
// Read and parse JSON files
const sdsStyleHooksData = JSON.parse(fs.readFileSync(sdsStyleHooksFile, 'utf8'));
const designTokensData = JSON.parse(fs.readFileSync(designTokensFile, 'utf8'));
// Extract custom properties
const sdsStyleHooksProps = extractCustomProperties(sdsStyleHooksData, false);
const designTokensProps = extractCustomProperties(designTokensData, true);
console.log(` sds-styling-hooks: ${Object.keys(sdsStyleHooksProps).length} properties`);
console.log(` design-tokens: ${Object.keys(designTokensProps).length} properties`);
// Compare the CSS custom properties instead of raw structures
const allDifferences = compareCustomProperties(sdsStyleHooksProps, designTokensProps);
// Separate into new vs known issues
const scopeKey = hookType.name; // 'shared' or 'component'
const themeKnownIssuesConfig = knownIssues.json?.[theme]?.[scopeKey] || {};
const newMissing = allDifferences.filter(
(d) => d.issue === 'MISSING_IN_DESIGN_TOKENS' && !themeKnownIssuesConfig.missing?.includes(d.path),
);
const newExtra = allDifferences.filter(
(d) => d.issue === 'MISSING_IN_SDS_STYLING_HOOKS' && !themeKnownIssuesConfig.extra?.includes(d.path),
);
const newMismatches = allDifferences.filter(
(d) => d.issue === 'VALUE_MISMATCH' && !themeKnownIssuesConfig.value_mismatches?.includes(d.path),
);
const knownMissing = allDifferences.filter(
(d) => d.issue === 'MISSING_IN_DESIGN_TOKENS' && themeKnownIssuesConfig.missing?.includes(d.path),
);
const knownExtra = allDifferences.filter(
(d) => d.issue === 'MISSING_IN_SDS_STYLING_HOOKS' && themeKnownIssuesConfig.extra?.includes(d.path),
);
const knownMismatches = allDifferences.filter(
(d) => d.issue === 'VALUE_MISMATCH' && themeKnownIssuesConfig.value_mismatches?.includes(d.path),
);
const newIssues = [...newMissing, ...newExtra, ...newMismatches];
const knownIssuesArr = [...knownMissing, ...knownExtra, ...knownMismatches];
// Calculate coverage
const totalProps = Object.keys(sdsStyleHooksProps).length;
const matching =
totalProps - allDifferences.filter((d) => d.issue !== 'MISSING_IN_SDS_STYLING_HOOKS').length;
const coverage = totalProps > 0 ? ((matching / totalProps) * 100).toFixed(1) : '0.0';
console.log(` ${chalk.green('✅ Covered:')} ${matching} (${coverage}%)`);
if (newIssues.length > 0) {
console.log(` ${chalk.red('❌')} New issues: ${newIssues.length}`);
if (newMismatches.length > 0) {
console.log(` ${chalk.red('❌')} Mismatches: ${newMismatches.length}`);
}
if (newMissing.length > 0) {
console.log(` ${chalk.red('❌')} Missing: ${newMissing.length}`);
}
if (newExtra.length > 0) {
console.log(` ${chalk.red('➕')} Extra: ${newExtra.length}`);
}
}
if (knownIssuesArr.length > 0) {
console.log(` ${chalk.yellow('⚠️')} Known issues: ${knownIssuesArr.length}`);
if (knownMismatches.length > 0) {
console.log(` ${chalk.yellow('⚠️')} Mismatches: ${knownMismatches.length}`);
}
if (knownMissing.length > 0) {
console.log(` ${chalk.yellow('⚠️')} Missing: ${knownMissing.length}`);
}
if (knownExtra.length > 0) {
console.log(` ${chalk.yellow('⚠️')} Extra: ${knownExtra.length}`);
}
}
return {
differences: allDifferences,
newIssues,
knownIssues: knownIssuesArr,
sdsStyleHooksProps,
designTokensProps,
sdsStyleHooksCount: Object.keys(sdsStyleHooksProps).length,
designTokensCount: Object.keys(designTokensProps).length,
matching,
};
} catch (error) {
console.log(chalk.red(` ❌ Error parsing JSON files: ${error.message}`));
return { differences: [], error: error.message };
}
}
/**
* Main comparison function
*/
function main() {
console.log(
chalk.bold.blue(
'\n🔄 TEMPORARY JSON Comparison (TO BE REMOVED): sds-styling-hooks (source of truth) vs design-tokens',
),
);
console.log(chalk.gray('(RAW JSON HOOK FILES)\n'));
const results = {
themes: {},
allNewIssues: [],
allKnownIssues: [],
summary: {
totalMatching: 0,
totalNewMissing: 0,
totalNewExtra: 0,
totalNewMismatches: 0,
totalKnownMissing: 0,
totalKnownExtra: 0,
totalKnownMismatches: 0,
},
};
const themesToCompare = flags.theme ? [flags.theme] : THEMES;
const hookTypesToCompare = flags.type ? HOOK_TYPES.filter((h) => h.name === flags.type) : HOOK_TYPES;
for (const theme of themesToCompare) {
if (!THEMES.includes(theme)) {
console.log(chalk.red(`❌ Unknown theme: ${theme}. Available themes: ${THEMES.join(', ')}`));
continue;
}
console.log(chalk.bold(`\nTheme: ${theme.toUpperCase()}`));
console.log('='.repeat(50));
results.themes[theme] = {};
for (const hookType of hookTypesToCompare) {
console.log(chalk.bold(`\n${hookType.name.toUpperCase()} SCOPE:`));
const result = compareHookFiles(theme, hookType);
results.themes[theme][hookType.name] = result;
if (!result.error && !result.missing) {
results.summary.totalMatching += result.matching || 0;
// Collect issues for verbose mode
if (flags.verbose && result.newIssues) {
result.newIssues.forEach((issue) => {
results.allNewIssues.push({
theme,
scope: hookType.name,
...issue,
});
});
}
if (flags.verbose && result.knownIssues) {
result.knownIssues.forEach((issue) => {
results.allKnownIssues.push({
theme,
scope: hookType.name,
...issue,
});
});
}
// Count new issues
const newMissing =
result.newIssues?.filter((d) => d.issue === 'MISSING_IN_DESIGN_TOKENS').length || 0;
const newExtra =
result.newIssues?.filter((d) => d.issue === 'MISSING_IN_SDS_STYLING_HOOKS').length || 0;
const newMismatches = result.newIssues?.filter((d) => d.issue === 'VALUE_MISMATCH').length || 0;
results.summary.totalNewMissing += newMissing;
results.summary.totalNewExtra += newExtra;
results.summary.totalNewMismatches += newMismatches;
// Count known issues
const knownMissing =
result.knownIssues?.filter((d) => d.issue === 'MISSING_IN_DESIGN_TOKENS').length || 0;
const knownExtra =
result.knownIssues?.filter((d) => d.issue === 'MISSING_IN_SDS_STYLING_HOOKS').length || 0;
const knownMismatches = result.knownIssues?.filter((d) => d.issue === 'VALUE_MISMATCH').length || 0;
results.summary.totalKnownMissing += knownMissing;
results.summary.totalKnownExtra += knownExtra;
results.summary.totalKnownMismatches += knownMismatches;
}
}
}
// Report mode: show full table of all properties
if (flags.report) {
console.log(chalk.bold.blue('\n📋 All Shared & Component JSON Properties:'));
console.log('='.repeat(50));
for (const theme of themesToCompare) {
for (const hookType of hookTypesToCompare) {
const result = results.themes[theme]?.[hookType.name];
if (!result || result.error || result.missing) continue;
const allProps = new Map();
// Collect all properties
for (const [prop, data] of Object.entries(result.sdsStyleHooksProps || {})) {
allProps.set(prop, { sds: data.value, design: result.designTokensProps?.[prop]?.value });
}
for (const [prop, data] of Object.entries(result.designTokensProps || {})) {
if (!allProps.has(prop)) {
allProps.set(prop, { sds: null, design: data.value });
}
}
if (allProps.size === 0) continue;
console.log(
chalk.bold(
`\n${theme.toUpperCase()} - ${hookType.name.toUpperCase()} (${allProps.size} properties):\n`,
),
);
const table = new Table({
head: ['#', 'Property', 'sds-styling-hooks', 'design-tokens', 'Status'],
colWidths: [5, 40, 35, 35, 12],
style: { head: ['cyan'] },
wordWrap: true,
});
const sortedProps = Array.from(allProps.keys()).sort();
sortedProps.forEach((prop, index) => {
const { sds, design } = allProps.get(prop);
let sdsValue = sds || chalk.gray('—');
let designValue = design || chalk.gray('—');
let status = '';
// Add color swatches
if (typeof sdsValue === 'string' && sdsValue.match(/^#[0-9a-fA-F]{3,8}$/)) {
sdsValue = `${colorSwatch(sdsValue)} ${sdsValue}`;
}
if (typeof designValue === 'string' && designValue.match(/^#[0-9a-fA-F]{3,8}$/)) {
designValue = `${colorSwatch(designValue)} ${designValue}`;
}
// Determine status
if (!sds) {
status = chalk.green('➕ Extra');
} else if (!design) {
status = chalk.red('❌ Missing');
} else if (normalizeTokenValue(sds) !== normalizeTokenValue(design)) {
status = chalk.red('❌ Mismatch');
} else {
status = chalk.green('✓');
}
table.push([index + 1, prop, sdsValue, designValue, status]);
});
console.log(table.toString());
}
}
console.log('');
}
// Print verbose tables if requested
if (flags.verbose && (results.allNewIssues.length > 0 || results.allKnownIssues.length > 0)) {
printVerboseTables(results.allNewIssues, results.allKnownIssues);
}
// Print summary
console.log(chalk.bold.blue('\n📊 Summary:'));
const totalNewIssues =
results.summary.totalNewMissing + results.summary.totalNewExtra + results.summary.totalNewMismatches;
const totalKnownIssues =
results.summary.totalKnownMissing +
results.summary.totalKnownExtra +
results.summary.totalKnownMismatches;
const totalTests = results.summary.totalMatching + totalNewIssues + totalKnownIssues;
console.log(`${results.summary.totalMatching}/${totalTests} tests passed`);
console.log(`${chalk.green('✅')} Matching: ${results.summary.totalMatching}`);
if (totalNewIssues > 0) {
console.log(`${chalk.red('❌')} New failures: ${totalNewIssues}`);
if (results.summary.totalNewMismatches > 0) {
console.log(` ${chalk.red('❌')} Mismatches: ${results.summary.totalNewMismatches}`);
}
if (results.summary.totalNewMissing > 0) {
console.log(` ${chalk.red('❌')} Missing: ${results.summary.totalNewMissing}`);
}
if (results.summary.totalNewExtra > 0) {
console.log(` ${chalk.red('➕')} Extra: ${results.summary.totalNewExtra}`);
}
}
if (totalKnownIssues > 0) {
console.log(`${chalk.yellow('⚠️')} Known issues: ${totalKnownIssues}`);
if (results.summary.totalKnownMismatches > 0) {
console.log(` ${chalk.yellow('⚠️')} Mismatches: ${results.summary.totalKnownMismatches}`);
}
if (results.summary.totalKnownMissing > 0) {
console.log(` ${chalk.yellow('⚠️')} Missing: ${results.summary.totalKnownMissing}`);
}
if (results.summary.totalKnownExtra > 0) {
console.log(` ${chalk.yellow('⚠️')} Extra: ${results.summary.totalKnownExtra}`);
}
}
if (!flags.verbose && !flags.report && (totalNewIssues > 0 || totalKnownIssues > 0)) {
console.log(chalk.gray('\nRun with --verbose to see detailed issues or --report to see all properties'));
}
console.log('─'.repeat(60));
// Overall status - exitWithStatus handles the messaging and exit codes
exitWithStatus(totalNewIssues, totalKnownIssues);
}
/**
* Print verbose tables for new and known issues
*/
function printVerboseTables(newIssues, knownIssues) {
console.log(chalk.bold('\n📋 Detailed Issues:'));
console.log('='.repeat(50));
const printIssuesTable = (issues, title, headerColor) => {
if (issues.length === 0) return;
// Group by theme and scope
const grouped = {};
issues.forEach((issue) => {
const key = `${issue.theme}|${issue.scope}`;
if (!grouped[key]) grouped[key] = [];
grouped[key].push(issue);
});
console.log(chalk.bold(`\n${title}`));
Object.keys(grouped).forEach((key) => {
const [theme, scope] = key.split('|');
const scopeIssues = grouped[key];
console.log(chalk.bold(`\n${theme.toUpperCase()} - ${scope.toUpperCase()}:`));
const table = new Table({
head: ['#', 'Property', 'sds-styling-hooks', 'design-tokens', 'Type'],
colWidths: [5, 40, 40, 40, 15],
style: { head: [headerColor] },
wordWrap: true,
});
scopeIssues.forEach((issue, index) => {
let sdsValue = issue.sdsStyleHooks || '-';
let dtValue = issue.designTokens || '-';
// Add color swatches for hex colors
if (typeof sdsValue === 'string' && sdsValue.match(/^#[0-9a-fA-F]{3,8}$/)) {
sdsValue = `${colorSwatch(sdsValue)} ${sdsValue}`;
}
if (typeof dtValue === 'string' && dtValue.match(/^#[0-9a-fA-F]{3,8}$/)) {
dtValue = `${colorSwatch(dtValue)} ${dtValue}`;
}
// Determine type display
let typeDisplay = '';
const isKnown = title.includes('KNOWN');
if (issue.issue === 'MISSING_IN_DESIGN_TOKENS') {
typeDisplay = isKnown ? `${chalk.yellow('⚠️ Missing')}` : `${chalk.red('❌ Missing')}`;
} else if (issue.issue === 'MISSING_IN_SDS_STYLING_HOOKS') {
typeDisplay = isKnown ? `${chalk.yellow('⚠️ Extra')}` : `${chalk.green('➕ Extra')}`;
} else if (issue.issue === 'VALUE_MISMATCH') {
typeDisplay = isKnown ? `${chalk.yellow('⚠️ Mismatch')}` : `${chalk.red('❌ Mismatch')}`;
}
table.push([index + 1, issue.path, sdsValue, dtValue, typeDisplay]);
});
console.log(table.toString());
});
};
if (newIssues.length > 0) {
printIssuesTable(newIssues, '🔴 NEW ISSUES', 'red');
}
if (knownIssues.length > 0) {
printIssuesTable(knownIssues, '⚠️ KNOWN ISSUES', 'yellow');
}
}
// Run the comparison
if (
import.meta.url.startsWith('file:') &&
process.argv[1] &&
import.meta.url === new URL(process.argv[1], 'file:').href
) {
main();
}
export { compareHookFiles, extractCustomProperties, deepCompare };
|