gmi-web/cli.js

37 lines
972 B
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-28 21:03:30 +00:00
"$0 [--no-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", {
describe: ".gmi files to convert to .html",
})
.required("files", true)
2021-01-28 23:07:57 +00:00
.option("css", {
type: "boolean",
2021-01-28 23:07:57 +00:00
default: true,
description: "Toggle inclusion of 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-28 23:13:02 +00:00
.pipe(map(toHTML({ css: argv["css"] })))
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);
}