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

0% Statements 0/10
0% Branches 0/10
0% Functions 0/6
0% Lines 0/10

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                                                                                               
'use strict'
 
/**
 * Shared JSON output contract for every icons-release script.
 *
 * Rules (these are what make the skill a dumb orchestrator):
 *   - stdout carries EXACTLY ONE JSON object and nothing else.
 *   - stderr carries human diagnostics only (never parsed by the skill).
 *   - exit code 0 = success, non-zero = failure.
 *
 * Scripts must never print free-form logs to stdout.
 */
 
function log(...args) {
  process.stderr.write(args.join(' ') + '\n')
}
 
function succeed(step, data) {
  process.stdout.write(JSON.stringify({ success: true, step, data }, null, 2) + '\n')
  process.exit(0)
}
 
function failWith(step, reason, detail) {
  process.stdout.write(
    JSON.stringify(
      { success: false, step, error: { reason, detail: detail || null } },
      null,
      2
    ) + '\n'
  )
  process.exit(1)
}
 
/**
 * Wrap a script's main() so any thrown error becomes a structured failure
 * instead of a stack trace on stdout. The golden rule: fail loudly, in JSON.
 */
function run(step, main) {
  Promise.resolve()
    .then(() => main())
    .catch(err => {
      log(err && err.stack ? err.stack : String(err))
      failWith(step, 'unhandledError', err && err.message ? err.message : String(err))
    })
}
 
module.exports = { log, succeed, failWith, run }