@vivliostyle/cli
Version:
Save the pdf file via headless browser and Vivliostyle.
117 lines (115 loc) • 4.51 kB
JavaScript
import {
preview
} from "../chunk-LGOHUEEQ.js";
import "../chunk-MU7JCDMK.js";
import "../chunk-C4HQHRXQ.js";
import "../chunk-ECEGM36O.js";
import {
createParserProgram,
gracefulError
} from "../chunk-DBK27BAR.js";
import "../chunk-7GIJVX4M.js";
import {
versionForDisplay
} from "../chunk-OAFXM4ES.js";
import "../chunk-I7BWSAN6.js";
// src/commands/preview.parser.ts
import { Command, Option } from "commander";
import upath from "upath";
function setupPreviewParserProgram() {
const program = new Command();
program.name("vivliostyle preview").description("launch preview server").arguments("[input]").option("-c, --config <config_file>", "path to vivliostyle.config.js").option("-T, --theme <theme...>", "theme path or package name").option(
"-s, --size <size>",
`output pdf size
preset: A5, A4, A3, B5, B4, JIS-B5, JIS-B4, letter, legal, ledger
custom(comma separated): 182mm,257mm or 8.5in,11in`
).option("-m, --crop-marks", "print crop marks").option(
"--bleed <bleed>",
"extent of the bleed area for printing with crop marks [3mm]"
).option(
"--crop-offset <offset>",
"distance between the edge of the trim size and the edge of the media size. [auto (13mm + bleed)]"
).option(
"--css <CSS>",
'custom style CSS code. (ex: ":root {--my-color: lime;}")'
).option(
"--style <stylesheet>",
"Additional stylesheet for Vivliostyle viewer."
).option(
"--user-style <user_stylesheet>",
"Additional user stylesheet for Vivliostyle viewer."
).option("-d, --single-doc", "single HTML document input").option("-q, --quick", "quick loading with rough page count").option("--title <title>", "title").option("--author <author>", "author").option("-l, --language <language>", "language").addOption(
new Option(
"--reading-progression <direction>",
"Direction of reading progression"
).choices(["ltr", "rtl"])
).addOption(new Option("--sandbox", `launch chrome with sandbox`).hideHelp()).option(
"--executable-browser <path>",
"specify a path of executable browser you installed"
).option(
"--viewer <URL>",
`specify a URL of displaying viewer instead of vivliostyle-cli's one
It is useful that using own viewer that has staging features. (ex: https://vivliostyle.vercel.app/)`
).option(
"--viewer-param <parameters>",
`specify viewer parameters. (ex: "allowScripts=false&pixelRatio=16")`
).addOption(
new Option(
"--browser <browser>",
`Specify a browser type and version to launch the Vivliostyle viewer (ex: chrome@129, firefox) [chrome]`
)
).addOption(
new Option(
"--proxy-server <proxyServer>",
`HTTP/SOCK proxy server url for underlying Playwright`
)
).addOption(
new Option(
"--proxy-bypass <proxyBypass>",
`optional comma-separated domains to bypass proxy`
)
).addOption(
new Option(
"--proxy-user <proxyUser>",
`optional username for HTTP proxy authentication`
)
).addOption(
new Option(
"--proxy-pass <proxyPass>",
`optional password for HTTP proxy authentication`
)
).addOption(
new Option(
"--log-level <level>",
"specify a log level of console outputs"
).choices(["silent", "info", "verbose", "debug"]).default("info")
).addOption(
new Option(
"--ignore-https-errors",
`true to ignore HTTPS errors when Playwright browser opens a new page`
)
).option("--host <host>", "IP address the server should listen on").option("--port <port>", "port the server should listen on", parseInt).option("--no-open-viewer", "do not open viewer").option("--no-enable-static-serve", "disable static file serving").option("--no-enable-viewer-start-page", "disable viewer start page").option("--vite-config-file <path>", "Vite config file path").option(
"--no-vite-config-file",
"ignore Vite config file even if it exists"
).version(versionForDisplay, "-v, --version");
return program;
}
var parsePreviewCommand = createParserProgram({
setupProgram: setupPreviewParserProgram,
parseArgs: (options, [input]) => {
if (input && !options.config && upath.basename(input).startsWith("vivliostyle.config")) {
return { ...options, config: input };
}
return { ...options, input };
}
});
// src/commands/preview.ts
try {
const inlineConfig = parsePreviewCommand(process.argv);
await preview(inlineConfig);
} catch (err) {
if (err instanceof Error) {
gracefulError(err);
}
}
//# sourceMappingURL=preview.js.map