All files / packages/sds-subsystems/scripts/uif paths.js

0% Statements 0/8
100% Branches 0/0
0% Functions 0/5
0% Lines 0/8

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                                                                                                                                                     
/**
 * Path utilities for UIF file discovery and output path generation
 *
 * RFC File Naming Convention:
 *   {component}.foundation.uif.json       - Foundation layer (source)
 *   {component}.system.{designSystem}.uif.json - System layer (source)
 *   {component}.{designSystem}.uif.json   - Distributed/compiled output
 */
 
import path from 'path';
import * as glob from 'glob';
 
/**
 * Extract component name from UIF file path
 *
 * Handles all RFC naming patterns:
 *   /path/badge.foundation.uif.json → badge
 *   /path/badge.system.slds.uif.json → badge
 *   /path/badge.system.slackKit.uif.json → badge
 *   /path/badge.slds.uif.json → badge (compiled output)
 *   /path/action-menu.system.slds.uif.json → action-menu
 *   /path/button-group.foundation.uif.json → button-group
 */
export function getComponentName(filePath) {
  const fileName = path.basename(filePath);
  // Handle patterns in order of specificity:
  // 1. .system.{designSystem}.uif.json (source system layer)
  // 2. .foundation.uif.json (foundation layer)
  // 3. .{designSystem}.uif.json (compiled output)
  return fileName
    .replace(/\.system\.[^.]+\.uif\.json$/, '')
    .replace('.foundation.uif.json', '')
    .replace(/\.[^.]+\.uif\.json$/, '');
}
 
/**
 * Get output path for a foundation UIF
 * Example: badge → dist/components/badge/badge.foundation.uif.json
 */
export function getFoundationOutputPath(componentName, distDir) {
  return path.join(distDir, componentName, `${componentName}.foundation.uif.json`);
}
 
/**
 * Get output path for a resolved SLDS system layer UIF
 * Output uses the compiled format: {component}.{designSystem}.uif.json
 * Example: badge → dist/components/badge/badge.slds.uif.json
 */
export function getSldsOutputPath(componentName, distDir) {
  return path.join(distDir, componentName, `${componentName}.slds.uif.json`);
}
 
/**
 * Find all foundation UIF files in source directory
 * Pattern: **\/*.foundation.uif.json
 */
export function findFoundationUifs(srcDir) {
  const pattern = path.join(srcDir, '**/*.foundation.uif.json');
  // Sort for deterministic ordering (important for consistent builds and manifests)
  return glob.sync(pattern).sort();
}
 
/**
 * Find all SLDS system layer UIF files in source directory
 * Pattern: **\/*.system.slds.uif.json
 *
 * Per RFC convention, system layer source files use the pattern:
 *   {component}.system.{designSystem}.uif.json
 */
export function findSldsSystemLayerUifs(srcDir) {
  const pattern = path.join(srcDir, '**/*.system.slds.uif.json');
  // Sort for deterministic ordering (important for consistent builds and manifests)
  return glob.sync(pattern).sort();
}