#!/usr/bin/env node // Rewrites .archify files from JSON to YAML in place (JSON input is also // valid YAML, so already-converted files are simply re-formatted). // Usage: node scripts/to-yaml.mjs ... import fs from 'node:fs'; import { Document, isSeq, parse, visit } from 'yaml'; export function archifyYaml(value) { const doc = new Document(value); // Short all-scalar lists such as pos/size/viewBox stay on one line. visit(doc, { Seq(_, node) { if (isSeq(node) && node.items.length <= 4 && node.items.every((item) => typeof item.value === 'number')) node.flow = true; }, }); return doc.toString({ lineWidth: 0, flowCollectionPadding: false }); } for (const file of process.argv.slice(2)) { const value = parse(fs.readFileSync(file, 'utf8')); fs.writeFileSync(file, archifyYaml(value)); console.log(`yaml: ${file}`); }