From 29d0edd9b27acbb0f9075f91ba8abb76929366d3 Mon Sep 17 00:00:00 2001 From: rakannimer Date: Thu, 6 Feb 2020 11:34:51 +0200 Subject: [PATCH] fix(docz-core): parse port when running serve --- core/docz-core/src/cli.ts | 4 ++-- core/docz-core/src/commands/serve.ts | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/core/docz-core/src/cli.ts b/core/docz-core/src/cli.ts index 7a1ffab36..bc2a06767 100644 --- a/core/docz-core/src/cli.ts +++ b/core/docz-core/src/cli.ts @@ -19,9 +19,9 @@ export const cli = () => { await commands.build(args) process.exit() }) - .command('serve', 'serve dir as static site', setArgs, async () => { + .command('serve', 'serve dir as static site', setArgs, async args => { setEnv('production') - await commands.serve() + await commands.serve(args) process.exit() }) .demandCommand() diff --git a/core/docz-core/src/commands/serve.ts b/core/docz-core/src/commands/serve.ts index f09d10e63..8480d37d0 100644 --- a/core/docz-core/src/commands/serve.ts +++ b/core/docz-core/src/commands/serve.ts @@ -1,10 +1,22 @@ import sh from 'shelljs' +import { Arguments } from 'yargs' import * as paths from '../config/paths' import { spawnSync } from '../utils/spawn' +import { parseConfig } from '../config/docz' -export const serve = async () => { +export const serve = async (args: Arguments) => { + const config = await parseConfig(args) const cliArgs = ['run', 'serve'] + + if (config.port) { + cliArgs.push('--') + // Append gatsby option `port`to CLI args + // https://www.gatsbyjs.org/docs/cheat-sheet/#cheat_sheet-text + cliArgs.push('--port') + cliArgs.push(String(config.port)) + } + sh.cd(paths.docz) spawnSync('npm', cliArgs) }