From a2e2a10cfdbba82613d8209643a062a6d6beae58 Mon Sep 17 00:00:00 2001 From: spring-raining Date: Tue, 14 Jan 2025 21:03:38 +0900 Subject: [PATCH] chore: Add --host and --port command options --- src/commands/build.parser.ts | 2 ++ src/commands/preview.parser.ts | 2 ++ src/config/merge.ts | 6 ++++++ src/config/schema.ts | 16 ++++++++++++++++ 4 files changed, 26 insertions(+) diff --git a/src/commands/build.parser.ts b/src/commands/build.parser.ts index af6a35ee..e5886793 100644 --- a/src/commands/build.parser.ts +++ b/src/commands/build.parser.ts @@ -179,6 +179,8 @@ It is useful that using own viewer that has staging features. (ex: https://vivli `true to ignore HTTPS errors when Playwright browser opens a new page`, ), ) + .option('--host ', 'IP address the server should listen on') + .option('--port ', 'port the server should listen on', parseInt) .option('--no-enable-static-serve', 'disable static file serving') // TODO: Remove it in the next major version up .addOption(new Option('--executable-chromium ').hideHelp()) diff --git a/src/commands/preview.parser.ts b/src/commands/preview.parser.ts index 38396ea3..fc2b69f8 100644 --- a/src/commands/preview.parser.ts +++ b/src/commands/preview.parser.ts @@ -102,6 +102,8 @@ Currently, Firefox and Webkit support preview command only!`, `true to ignore HTTPS errors when Playwright browser opens a new page`, ), ) + .option('--host ', 'IP address the server should listen on') + .option('--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') diff --git a/src/config/merge.ts b/src/config/merge.ts index 7d08debd..bbe2f4a7 100644 --- a/src/config/merge.ts +++ b/src/config/merge.ts @@ -54,6 +54,8 @@ export function mergeInlineConfig( preflightOption, vite, viteConfigFile, + host, + port, ...overrideInlineOptions } = inlineConfig; @@ -84,6 +86,10 @@ export function mergeInlineConfig( preflightOption, }), })), + server: { + ...pruneObject(task.server ?? {}), + ...pruneObject({ host, port }), + }, })), inlineOptions: { ...pruneObject(inlineOptions), diff --git a/src/config/schema.ts b/src/config/schema.ts index 02319f4a..ffc3161d 100644 --- a/src/config/schema.ts +++ b/src/config/schema.ts @@ -1143,6 +1143,22 @@ export const VivliostyleInlineConfig = v.pipe( If a falsy value is provided, Vivliostyle CLI ignores the existing Vite config file. `), ), + host: v.pipe( + v.union([v.boolean(), ValidString]), + v.description($` + IP address the server should listen on. + Set to \`true\` to listen on all addresses. + (default: \`true\` if a PDF build with Docker render mode is required, otherwise \`false\`) + `), + ), + port: v.pipe( + v.number(), + v.minValue(0), + v.maxValue(65535), + v.description($` + Port the server should listen on. (default: \`13000\`) + `), + ), }), ), v.check(