gmi-web/cli.js
Talon Poole 54280ba8d3 Use ES modules
use language for <html lang=""> too
2021-02-10 22:03:48 +00:00

93 lines
2.2 KiB
JavaScript
Executable file

#!/usr/bin/env node
import path from "path";
import fs from "vinyl-fs";
import map from "map-stream";
import tokenize from "./tokenize.js";
import toHTML from "./to-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 override = GMI_CSS_VARS.reduce((style, key) => {
if (argv[key]) {
style += `--${key}: ${argv[key]};`;
}
return style;
}, "");
fs.src(argv.files)
.pipe(map(tokenize))
.pipe(
map(
toHTML({
...argv,
override,
})
)
)
.pipe(fs.dest((file) => path.dirname(file.path)));
}
)
.showHelpOnFail(true, "Specify --help for available options")
.help().argv;