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 | #!/usr/bin/env node
/**
* UIF Build Script for SLDS2
*
* Processes Universal Interface Format (UIF) files for the SLDS2 design system:
* 1. Copies foundation UIF files → dist/components/{name}/{name}.foundation.uif.json
* 2. Resolves SLDS system layer UIF files (*.system.slds.uif.json) by merging extends chains
* 3. Validates merged UIFs for correctness
* 4. Outputs resolved UIFs → dist/components/{name}/{name}.slds.uif.json
* 5. Generates manifest → dist/uif.manifest.json
*
* RFC Layer Types:
* foundation - Base component definitions (copied as-is)
* system - Design system layer that extends foundations (resolved/merged)
*
* Output Structure:
* dist/
* uif.manifest.json
* components/
* badge/
* badge.foundation.uif.json # Copied from src
* badge.slds.uif.json # Resolved with extends merged
*
* Performance:
* - Full build: Parallel processing for system layer resolution
* - Watch mode: Incremental builds (rebuilds only changed file)
* - Deterministic: Sorted file discovery for consistent output
*
* Usage:
* node scripts/buildUif.js [--watch] [--verbose]
*
* Options:
* --watch Watch for changes and rebuild automatically (uses incremental builds)
* --verbose Show detailed processing output
*/
import path from 'path';
import { fileURLToPath } from 'url';
import arg from 'arg';
import chokidar from 'chokidar';
import { clearResolveCache } from '@fds-uif/core';
import { createLogger } from './uif/logger.js';
import {
getComponentName,
getFoundationOutputPath,
findFoundationUifs,
findSldsSystemLayerUifs,
} from './uif/paths.js';
import { copyFoundation, processSldsSubsystem, buildSingleUif } from './uif/processors.js';
import { generateManifest, updateManifestForComponent, removeFromManifest } from './uif/manifest.js';
// ============================================================================
// Configuration
// ============================================================================
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const ROOT_DIR = path.resolve(__dirname, '../');
const args = arg({
'--watch': Boolean,
'--verbose': Boolean,
});
const VERBOSE = args['--verbose'] || false;
const WATCH = args['--watch'] || false;
const PATHS = {
src: path.resolve(ROOT_DIR, 'src/slds2'),
dist: path.resolve(ROOT_DIR, 'dist/components'),
manifest: path.resolve(ROOT_DIR, 'dist/uif.manifest.json'),
};
const log = createLogger(VERBOSE);
// ============================================================================
// Build
// ============================================================================
/**
* Run full UIF build for SLDS2
*/
async function build() {
const startTime = Date.now();
log.section('Building SLDS2 UIFs');
// Clear resolution cache for fresh build
clearResolveCache();
// Discover UIF files
const foundationFiles = findFoundationUifs(PATHS.src);
const sldsFiles = findSldsSystemLayerUifs(PATHS.src);
if (foundationFiles.length === 0 && sldsFiles.length === 0) {
log.warn('No UIF files found in src/slds2');
return { foundationResults: [], sldsResults: [], errorCount: 0 };
}
log.info(`Found ${foundationFiles.length} foundations, ${sldsFiles.length} SLDS system layers`);
const options = {
rootDir: ROOT_DIR,
distDir: PATHS.dist,
log,
verbose: VERBOSE,
};
// Step 1: Copy foundations
if (foundationFiles.length > 0) {
log.section('Copying Foundation Components');
const foundationResults = foundationFiles.map((file) => copyFoundation(file, options));
const foundationSuccessCount = foundationResults.filter((result) => result.success).length;
if (foundationSuccessCount === foundationFiles.length) {
log.success(`Copied ${foundationSuccessCount} foundation UIFs`);
} else {
log.warn(`Copied ${foundationSuccessCount}/${foundationFiles.length} foundations (some failed)`);
}
}
// Step 2: Resolve SLDS system layers (parallel for speed)
const IsldsResults = [];
if (sldsFiles.length > 0) {
log.section('Resolving SLDS System Layer Components');
// Process all system layers in parallel
const results = await Promise.all(sldsFiles.map((file) => processSldsSubsystem(file, options)));
sldsResults.push(...results);
const successCount = sldsResults.filter((result) => result.success).length;
const errorCount = sldsResults.length - successCount;
if (errorCount === 0) {
log.success(`Resolved ${successCount} SLDS system layer components`);
} else {
log.error(`Resolved ${successCount}/${sldsFiles.length} system layers (${errorCount} failed)`);
}
}
// Step 3: Generate manifest
const foundationResults = foundationFiles.map((file) => ({
success: true,
componentName: getComponentName(file),
inputPath: path.relative(ROOT_DIR, file),
outputPath: path.relative(ROOT_DIR, getFoundationOutputPath(getComponentName(file), PATHS.dist)),
}));
const manifest = generateManifest(foundationResults, sldsResults, PATHS.manifest);
// Summary
const duration = Date.now() - startTime;
const totalErrorCount = sldsResults.filter((result) => !result.success).length;
log.section('Build Complete');
log.dim(` Foundations: ${Object.keys(manifest.foundations).length}`);
log.dim(` System Layers: ${Object.keys(manifest.systems).length}`);
log.dim(` Duration: ${duration}ms`);
log.dim(` Manifest: ${path.relative(ROOT_DIR, PATHS.manifest)}`);
return { foundationResults, sldsResults, errorCount: totalErrorCount };
}
// ============================================================================
// Watch Mode
// ============================================================================
/**
* Watch for UIF changes and rebuild automatically (uses incremental builds)
*/
function watch() {
log.section('Watch Mode');
log.info('Watching src/slds2 for changes...');
log.dim(' Press Ctrl+C to exit\n');
const watcher = chokidar.watch(path.join(PATHS.src, '**/*.uif.json'), {
ignoreInitial: true,
awaitWriteFinish: {
stabilityThreshold: 100,
pollInterval: 50,
},
});
let rebuildTimeout = null;
const scheduleRebuild = (eventType, filePath) => {
const fileName = path.basename(filePath);
log.dim(` ${eventType}: ${fileName}`);
if (rebuildTimeout) clearTimeout(rebuildTimeout);
rebuildTimeout = setTimeout(async () => {
log.section('Incremental Build');
// Clear resolution cache for the changed file
clearResolveCache();
const options = {
rootDir: ROOT_DIR,
distDir: PATHS.dist,
log,
verbose: VERBOSE,
};
if (eventType === 'removed') {
// Handle file deletion by removing from manifest
const componentName = getComponentName(filePath);
removeFromManifest(componentName, PATHS.manifest, log);
} else {
// Build the single changed file
const result = await buildSingleUif(filePath, options);
if (result.success) {
updateManifestForComponent(result, PATHS.manifest, log);
}
}
}, 200);
};
watcher.on('add', (filePath) => scheduleRebuild('added', filePath));
watcher.on('change', (filePath) => scheduleRebuild('changed', filePath));
watcher.on('unlink', (filePath) => scheduleRebuild('removed', filePath));
}
// ============================================================================
// Main
// ============================================================================
async function main() {
try {
const { errorCount } = await build();
if (WATCH) {
watch();
} else {
process.exit(errorCount > 0 ? 1 : 0);
}
} catch (error) {
log.error(`Build failed: ${error.message}`);
if (VERBOSE) {
console.error(`\x1b[90m${error.stack}\x1b[0m`);
}
process.exit(1);
}
}
main();
|