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.",
|
2021-01-28 17:56:02 +00:00
|
|
|
(yargs) =>
|
|
|
|
yargs
|
|
|
|
.positional("files", {
|
2021-01-29 00:24:22 +00:00
|
|
|
describe: "The *.gmi files to convert",
|
2021-01-28 17:56:02 +00:00
|
|
|
})
|
|
|
|
.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", {
|
2021-01-28 17:56:02 +00:00
|
|
|
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 17:56:02 +00:00
|
|
|
}),
|
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);
|
|
|
|
}
|