UNPKG

@vivliostyle/cli

Version:

Save the pdf file via headless browser and Vivliostyle.

193 lines (190 loc) 7.17 kB
import { build } from "../chunk-ERDN47XG.js"; import "../chunk-MU7JCDMK.js"; import "../chunk-C4HQHRXQ.js"; import "../chunk-ECEGM36O.js"; import { Logger, createParserProgram, gracefulError, isInContainer } from "../chunk-DBK27BAR.js"; import "../chunk-7GIJVX4M.js"; import { versionForDisplay } from "../chunk-OAFXM4ES.js"; import "../chunk-I7BWSAN6.js"; // src/commands/build.ts import process from "node:process"; // src/commands/build.parser.ts import { Command, Option } from "commander"; import upath from "upath"; function setupBuildParserProgram() { const targets = []; const outputOptionProcessor = (value, previous) => { if (targets.length === 0 || "path" in targets[targets.length - 1]) { targets.push({ path: value }); } else { targets[targets.length - 1].path = value; } return [...previous || [], value]; }; const formatOptionProcessor = (value, previous) => { if (targets.length === 0 || "format" in targets[targets.length - 1]) { targets.push({ format: value }); } else { targets[targets.length - 1].format = value; } return [...previous || [], value]; }; const program = new Command(); program.name("vivliostyle build").description("build and create PDF file").arguments("[input]").option( "-c, --config <config_file>", "path to vivliostyle.config.js [vivliostyle.config.js]" ).option( "-o, --output <path>", `specify output file name or directory [<title>.pdf] This option can be specified multiple, then each -o options can be supplied one -f option. ex: -o output1 -f webpub -o output2.pdf -f pdf`, outputOptionProcessor ).option( "-f, --format <format>", `specify output format corresponding output target If an extension is specified on -o option, this field will be inferenced automatically.`, formatOptionProcessor ).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( "-p, --press-ready", `make generated PDF compatible with press ready PDF/X-1a [false] This option is equivalent with "--preflight press-ready"` ).option( "-t, --timeout <seconds>", `timeout limit for waiting Vivliostyle process [300]`, validateTimeoutFlag ).option("-T, --theme <theme...>", "theme path or package name").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( "--render-mode <mode>", "if docker is set, Vivliostyle try to render PDF on Docker container [local]" ).choices(["local", "docker"]) ).addOption( new Option( "--preflight <mode>", "apply the process to generate PDF for printing" ).choices(["press-ready", "press-ready-local"]) ).option( "--preflight-option <options...>", `options for preflight process (ex: gray-scale, enforce-outline) Please refer the document of press-ready for further information. https://github.com/vibranthq/press-ready` ).option("--cmyk", "convert device-cmyk() colors to CMYK in the output PDF").addOption(new Option("--sandbox", `launch chrome with sandbox`).hideHelp()).option( "--executable-browser <path>", "specify a path of executable browser you installed" ).option("--image <image>", "specify a docker image to render").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-enable-static-serve", "disable static file serving").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").action((_arg, option) => { let invalid = targets.find((it) => !("path" in it)); if (invalid) { throw new Error( `Couldn't find the output option corresponding --format ${invalid.format} option. Please check the command options.` ); } option.output = targets; }); return program; } function validateTimeoutFlag(val) { return Number.isFinite(+val) ? +val * 1e3 : void 0; } var parseBuildCommand = createParserProgram({ setupProgram: setupBuildParserProgram, parseArgs: (options, [input]) => { if (input && !options.config && upath.basename(input).startsWith("vivliostyle.config")) { return { ...options, config: input }; } return { ...options, input }; } }); // src/commands/build.ts try { let inlineConfig = parseBuildCommand(process.argv); let containerForkMode = false; if (isInContainer() && process.env.VS_CLI_BUILD_PDF_OPTIONS) { inlineConfig = JSON.parse(process.env.VS_CLI_BUILD_PDF_OPTIONS); containerForkMode = true; Logger.debug("bypassedPdfBuilderOption %O", inlineConfig); } await build(inlineConfig, { containerForkMode }); } catch (err) { if (err instanceof Error) { gracefulError(err); } } //# sourceMappingURL=build.js.map