All files / packages/design-system/scripts/scs sync-from.js

0% Statements 0/40
0% Branches 0/12
0% Functions 0/3
0% Lines 0/38

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                                                                                                                                                                                                   
#!/usr/bin/env node
/**
 * Sync release-state directories from a source directory (typically the
 * `.scs-clone/` working tree, or any local checkout of aura/slds-scs) into
 * `packages/slds-scs/`, which is the source path used by `.validation/scs.js`.
 *
 * Use this when you've made manual edits in `.scs-clone/` and want
 * `release:scs:compare` to diff against them.
 *
 * Synced contents (anything else in source/dest is ignored):
 *   - slds/         (overwritten — deletes files in dest not in source)
 *   - scs/          (same)
 *   - tnrp/         (same)
 *   - package.json  (overwritten)
 *
 * Usage:
 *   node scripts/scs/sync-from.js <source-dir>
 *   node scripts/scs/sync-from.js .scs-clone   # relative to monorepo root
 */
import path from 'node:path';
import fs from 'fs-extra';
import chalk from 'chalk';
import yargs from 'yargs';
import { fileURLToPath } from 'node:url';
 
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const PACKAGE_ROOT = path.resolve(__dirname, '../..');
const MONOREPO_ROOT = path.resolve(PACKAGE_ROOT, '../..');
const SCS_PACKAGE_DIR = path.join(MONOREPO_ROOT, 'packages/slds-scs');
 
const SYNC_DIRS = ['slds', 'scs', 'tnrp'];
const SYNC_FILES = ['package.json'];
 
const argv = yargs(process.argv.slice(2))
  .usage('Usage: $0 <source-dir>')
  .demandCommand(1, 'A source directory is required (typically `.scs-clone`).')
  .help()
  .argv;
 
function resolveSource(input) {
  if (path.isAbsolute(input)) return input;
  // Try relative-to-CWD first, then relative-to-monorepo-root.
  const cwdResolved = path.resolve(process.cwd(), input);
  if (fs.existsSync(cwdResolved)) return cwdResolved;
  return path.resolve(MONOREPO_ROOT, input);
}
 
function copyDirReplacing(src, dest) {
  if (!fs.existsSync(src)) {
    return { skipped: true };
  }
  fs.removeSync(dest);
  fs.copySync(src, dest);
  return { skipped: false, count: fs.readdirSync(dest).length };
}
 
function main() {
  const source = resolveSource(argv._[0]);
 
  if (!fs.existsSync(source)) {
    console.error(chalk.red(`āŒ Source directory not found: ${source}`));
    process.exit(1);
  }
 
  console.log(chalk.blue(`\nšŸ”„ Syncing SCS release state\n`));
  console.log(chalk.gray(`   Source: ${source}`));
  console.log(chalk.gray(`   Target: ${SCS_PACKAGE_DIR}\n`));
 
  fs.ensureDirSync(SCS_PACKAGE_DIR);
 
  for (const dir of SYNC_DIRS) {
    const result = copyDirReplacing(
      path.join(source, dir),
      path.join(SCS_PACKAGE_DIR, dir),
    );
    if (result.skipped) {
      console.log(chalk.yellow(`   ⚠ ${dir}/ — not present in source, skipped`));
    } else {
      console.log(chalk.green(`   āœ“ ${dir}/ — ${result.count} entries`));
    }
  }
 
  for (const file of SYNC_FILES) {
    const src = path.join(source, file);
    const dest = path.join(SCS_PACKAGE_DIR, file);
    if (fs.existsSync(src)) {
      fs.copyFileSync(src, dest);
      console.log(chalk.green(`   āœ“ ${file}`));
    } else {
      console.log(chalk.yellow(`   ⚠ ${file} — not present in source, skipped`));
    }
  }
 
  console.log(chalk.green(`\nāœ… Sync complete. Run release:scs:compare to validate.\n`));
}
 
main();