Files
root-at-skic d2f52d43ac 0.3.0: .archify files are YAML and open straight into the diagram
- .archify content is YAML (JSON still accepted); converted to JSON for the renderer
- Archify Diagram custom editor is the default for *.archify; Show Source opens the YAML beside it
- YAML syntax errors and validation problems mapped to YAML lines
- yamlValidation for schema completion with redhat.vscode-yaml
- scripts/to-yaml.mjs converts existing .archify files
2026-09-30 15:21:55 +03:00

24 lines
867 B
JavaScript

#!/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 <file.archify>...
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}`);
}