gmi-web/cli.js

91 lines
2.1 KiB
JavaScript
Raw Normal View History

2021-01-28 06:16:46 +00:00
#!/usr/bin/env node
import path from "path";
import fs from "vinyl-fs";
import map from "map-stream";
2021-02-11 02:24:00 +00:00
import toHTML from "./gmi.html.js";
import yargs from "yargs";
2021-01-28 23:07:57 +00:00
2021-01-29 22:32:30 +00:00
// 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))
2021-01-28 06:16:46 +00:00
.scriptName("gmi-web")
2021-01-29 23:59:12 +00:00
.config()
2021-01-28 06:16:46 +00:00
.command(
2021-01-29 23:59:12 +00:00
"$0 [files..]",
2021-01-28 23:07:57 +00:00
"Convert .gmi to .html. See gmi-web(1) for more details.",
(yargs) =>
yargs
.positional("files", {
2021-01-29 00:24:22 +00:00
describe: "The *.gmi files to convert",
})
.required("files", true)
2021-01-29 23:17:25 +00:00
.option("language", {
alias: "lang",
required: true,
type: "string",
describe: "Set the document meta language tag",
})
2021-01-29 00:24:22 +00:00
.option("images", {
type: "boolean",
default: false,
2021-01-29 22:32:30 +00:00
describe: "Include images",
2021-01-29 00:24:22 +00:00
})
.option("audio", {
type: "boolean",
default: false,
2021-01-29 22:32:30 +00:00
describe: "Include audio",
2021-01-29 00:24:22 +00:00
})
.option("video", {
type: "boolean",
default: false,
2021-01-29 22:32:30 +00:00
describe: "Include video",
2021-01-29 06:15:23 +00:00
})
2021-01-28 23:07:57 +00:00
.option("css", {
type: "boolean",
2021-01-28 23:07:57 +00:00
default: true,
2021-01-29 22:32:30 +00:00
describe:
2021-01-30 16:15:08 +00:00
"gmi.css is included by default. Use --no-css for the bare minimum <style>",
}),
2021-01-28 06:16:46 +00:00
(argv) => {
2021-02-11 02:24:00 +00:00
const styles = GMI_CSS_VARS.reduce((style, key) => {
2021-01-29 22:32:30 +00:00
if (argv[key]) {
style += `--${key}: ${argv[key]};`;
}
return style;
}, "");
2021-01-28 23:07:57 +00:00
fs.src(argv.files)
2021-01-29 00:24:22 +00:00
.pipe(
map(
toHTML({
2021-01-29 23:17:25 +00:00
...argv,
2021-02-11 02:24:00 +00:00
styles,
2021-01-29 00:24:22 +00:00
})
)
)
2021-01-28 23:07:57 +00:00
.pipe(fs.dest((file) => path.dirname(file.path)));
2021-01-28 06:16:46 +00:00
}
)
2021-01-29 22:32:30 +00:00
.showHelpOnFail(true, "Specify --help for available options")
2021-01-28 06:16:46 +00:00
.help().argv;