gmi-web/cli.js

70 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-01-28 06:16:46 +00:00
#!/usr/bin/env node
2021-01-28 21:03:30 +00:00
const path = require("path");
const fs = require("vinyl-fs");
const map = require("map-stream");
const tokenize = require("./tokenize");
2021-01-28 23:07:57 +00:00
const toHTML = require("./to-html");
2021-01-28 06:16:46 +00:00
require("yargs")
.scriptName("gmi-web")
.command(
2021-01-29 06:15:23 +00:00
"$0 [--css] <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 00:24:22 +00:00
.option("images", {
type: "boolean",
default: false,
description: "Include images",
})
.option("audio", {
type: "boolean",
default: false,
description: "Include audio",
})
.option("video", {
type: "boolean",
default: false,
description: "Include video",
})
2021-01-29 06:15:23 +00:00
.option("silent", {
alias: "s",
type: "boolean",
default: false,
description: "No logging to stdout",
})
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 00:24:22 +00:00
description: "Include gmi.css",
}),
2021-01-28 06:16:46 +00:00
(argv) => {
2021-01-28 23:07:57 +00:00
fs.src(argv.files)
.pipe(map(tokenize))
2021-01-29 00:24:22 +00:00
.pipe(
map(
toHTML({
css: argv.css,
inline: {
images: argv.images,
audio: argv.audio,
video: argv.video,
},
2021-01-29 06:15:23 +00:00
silent: argv.silent,
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
}
)
.help().argv;
2021-01-28 21:03:30 +00:00
function log(file, cb) {
console.log(file.path, file.contents ? file.contents.toString("utf8") : "");
cb(null, file);
}