All files / packages/icons/.claude/skills/icons-release/scripts copy-files.js

0% Statements 0/49
0% Branches 0/14
0% Functions 0/6
0% Lines 0/43

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                                                                                                                                                                                                 
#!/usr/bin/env node
'use strict'
 
/**
 * copy-files
 *
 * Materializes the validated working set into the repo:
 *   - copies SVGs into svg/<type>/common/<name>.svg
 *   - writes metadata into model/metadata/<type>/<name>.json
 *   - generates SLDS (yaml) + SDS (css) + release notes into .workflow/<release>/
 *
 * Reads from .workflow/<release>/. Run AFTER validate-icons passes.
 *
 * Usage:
 *   node .claude/skills/icons-release/scripts/copy-files.js --release R264 [--repo-root .]
 *
 * Output: { success, step, data: { copied, metadataWritten, artifacts } }
 */
 
const fs = require('fs')
const path = require('path')
 
const { succeed, failWith, run } = require('./lib/output')
const { parseArgs } = require('./lib/args')
const { loadWorkset } = require('./lib/workset')
const { readSvg } = require('./lib/svg')
const { sldsYaml, sdsCss, releaseNotes, metadataJson } = require('./lib/artifacts')
 
const STEP = 'copy-files'
 
function main() {
  const args = parseArgs(process.argv.slice(2))
  if (!args.release) {
    throw Object.assign(new Error('--release is required (e.g. --release R264)'), {
      code: 'MISSING_ARG'
    })
  }
  const repoRoot = args['repo-root'] || '.'
  const { release, location, icons } = loadWorkset(args.release)
 
  // Refuse to proceed if any working SVG is missing — that means the pipeline
  // ran out of order. Fail loudly rather than copy a partial set.
  const missing = icons.filter(icon => !fs.existsSync(icon.svgPath)).map(i => i.icon_name)
  if (missing.length > 0) {
    failWith(STEP, 'missingWorkingSvg', `Missing working SVGs: ${missing.join(', ')}. Re-run prepare-release.`)
  }
 
  const copied = []
  const metadataWritten = []
 
  for (const icon of icons) {
    const subDir = icon.has_ltr_rtl === 'yes' ? 'ltr' : 'common'
 
    // SVG -> repo
    const svgDestDir = path.join(repoRoot, 'svg', icon.icon_type, subDir)
    fs.mkdirSync(svgDestDir, { recursive: true })
    fs.copyFileSync(icon.svgPath, path.join(svgDestDir, `${icon.icon_name}.svg`))
    copied.push(`svg/${icon.icon_type}/${subDir}/${icon.icon_name}.svg`)
 
    // metadata -> repo
    const metaDir = path.join(repoRoot, 'model', 'metadata', icon.icon_type)
    fs.mkdirSync(metaDir, { recursive: true })
    fs.writeFileSync(path.join(metaDir, `${icon.icon_name}.json`), metadataJson(icon), { flag: 'w' })
    metadataWritten.push(`model/metadata/${icon.icon_type}/${icon.icon_name}.json`)
  }
 
  // --- artifacts (advisory; written into the workflow dir, not the repo) ---
  const standard = icons.filter(i => i.icon_type === 'standard')
  const action = icons.filter(i => i.icon_type === 'action')
  const artifacts = {}
 
  const writeArtifact = (relPath, content) => {
    const full = path.join(location, relPath)
    fs.mkdirSync(path.dirname(full), { recursive: true })
    fs.writeFileSync(full, content)
    return full
  }
 
  if (standard.length > 0) artifacts.sldsStandard = writeArtifact('slds/bg-standard.yml', sldsYaml(standard, 'standard'))
  if (action.length > 0) artifacts.sldsActions = writeArtifact('slds/bg-actions.yml', sldsYaml(action, 'actions'))
  if (standard.length + action.length > 0) {
    artifacts.sds = writeArtifact('sds/icon.type.css', sdsCss([...standard, ...action]))
  }
  artifacts.releaseNotes = writeArtifact('releasenotes.md', releaseNotes(icons))
 
  succeed(STEP, {
    release,
    copied: copied.length,
    metadataWritten: metadataWritten.length,
    files: copied,
    metadata: metadataWritten,
    artifacts
  })
}
 
run(STEP, main)