gmi-web/cli.js
2021-02-11 02:24:00 +00:00

91 lines
2.1 KiB
JavaScript
Executable file

#!/usr/bin/env node
import path from "path";
import fs from "vinyl-fs";
import map from "map-stream";
import toHTML from "./gmi.html.js";
import yargs from "yargs";
// TODO: automatically pull these in from gmi.css (also for gmi.css(5))
const GMI_CSS_VARS = [
"foreground",
"background",
"p-size",
"p-indent",
"p-line-height",
"a-size",
"pre-size",
"pre-line-height",
"h1-size",
"h2-size",
"h3-size",
"heading-line-height",
"ul-size",
"ul-line-height",
"blockquote-size",
"blockquote-line-height",
"mono",
"serif",
"sans-serif",
];
yargs(process.argv.slice(2))
.scriptName("gmi-web")
.config()
.command(
"$0 [files..]",
"Convert .gmi to .html. See gmi-web(1) for more details.",
(yargs) =>
yargs
.positional("files", {
describe: "The *.gmi files to convert",
})
.required("files", true)
.option("language", {
alias: "lang",
required: true,
type: "string",
describe: "Set the document meta language tag",
})
.option("images", {
type: "boolean",
default: false,
describe: "Include images",
})
.option("audio", {
type: "boolean",
default: false,
describe: "Include audio",
})
.option("video", {
type: "boolean",
default: false,
describe: "Include video",
})
.option("css", {
type: "boolean",
default: true,
describe:
"gmi.css is included by default. Use --no-css for the bare minimum <style>",
}),
(argv) => {
const styles = GMI_CSS_VARS.reduce((style, key) => {
if (argv[key]) {
style += `--${key}: ${argv[key]};`;
}
return style;
}, "");
fs.src(argv.files)
.pipe(
map(
toHTML({
...argv,
styles,
})
)
)
.pipe(fs.dest((file) => path.dirname(file.path)));
}
)
.showHelpOnFail(true, "Specify --help for available options")
.help().argv;