gmi-web/cli.js
2021-01-29 23:17:25 +00:00

92 lines
2.2 KiB
JavaScript
Executable file

#!/usr/bin/env node
const path = require("path");
const fs = require("vinyl-fs");
const map = require("map-stream");
const tokenize = require("./tokenize");
const toHTML = require("./to-html");
// 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",
];
require("yargs")
.scriptName("gmi-web")
.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 to for the bare-minimum <style>",
}),
(argv) => {
console.log(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;