// Copyright 2014-2025 Jesper Larsson
//
// This file is part of Klipspringer, <https://klipspringer.avadeaux.net/>
//
// Klipspringer is free software: you can redistribute it and/or modify it under the terms of the
// GNU General Public License as published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// Klipspringer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with Klipspringer. If
// not, see <https://www.gnu.org/licenses/>.

import { readFile } from 'fs/promises';
import { expandFile } from './macros.js';
import * as svg_images from './svg_images.js';
import * as path from 'path';

const values = { };
let deps = undefined;
let i = 2;
while (i < process.argv.length) {
    const m = /^([A-Za-z_.]+)=(.*)$/.exec(process.argv[i]);
    if (m) {
        values[m[1]] = m[2];
        i++;
        continue;
    }
    if (process.argv[i][0] !== '-') {
        break;
    }
    if (process.argv[i] === '-v') {
        Object.assign(values, JSON.parse(await readFile(process.argv[i+1])));
        i += 2;
    } else if (process.argv[i] === '-d') {
        deps = [];
        i++;
    } else {
        console.error("Unrecognized option: "+process.argv[i]);
        process.exit(2);
    }
}

if (i+1 !== process.argv.length) {
    console.error("expected arguments: [-v <values.json>] [key=value ...] [-d] <infile>");
    process.exit(2);
}

const fnam = process.argv[i];
expandFile(path.basename(fnam), path.dirname(fnam), { ...svg_images, ...values }, deps).then(output => {
    if (deps) {
        console.log(fnam+" "+deps.join(" "));
    } else {
        console.log(output);
    }
});

Version: v4.3.2.2 (2026-05-16T17:03:34+02:00)
Raw file
Source code overview
Klipspringer home