scmJS docs

A first script

Open a map, say what is in it, run Check Map, change the name and write it out:

import { readFile, writeFile } from "node:fs/promises";
import { openMapBytes, writeMapBytes, scenarioName, setScenarioName, mapStatistics, statisticsText, validateScenario } from "@scm-js/core";

const map = await openMapBytes(await readFile("(2)Destination.scx"), "(2)Destination.scx");
const scn = map.scenario;

console.log(scenarioName(scn));
console.log(statisticsText(mapStatistics(scn, null, null, null)));
for (const issue of validateScenario(scn, { extras: map.extras })) console.log(issue.level, issue.where, issue.text);

setScenarioName(scn, "Destination, revised");
await writeFile("out.scx", await writeMapBytes(scn, { format: "scx", extras: map.extras, stored: map.stored }));

openMapBytes does what File ▸ Open does: reads the archive, parses the scenario, keeps the other members (sounds, scripts, anything else) in extras, restores a built map to the map it was built from, and puts the warnings the editor would show in scenario.warnings. writeMapBytes does what Save does, with the same options — compression, which sections to strip, and the rest — and everything kept and uncompressed when none are given. Pass extras and stored back in, or the sounds are lost.