docusaurus/packages/docusaurus/src/commands/commandUtils.ts
Joshua Chen 8e934450d8
refactor: remove unnecessary default values normalized during validation (#6864)
* refactor: remove unnecessary default values normalized during validation

* more
2022-03-07 19:23:30 +08:00

24 lines
703 B
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import choosePort from '../choosePort';
import type {HostPortCLIOptions} from '@docusaurus/types';
import {DEFAULT_PORT} from '@docusaurus/utils';
export function getCLIOptionHost(
hostOption: HostPortCLIOptions['host'],
): string {
return hostOption ?? 'localhost';
}
export async function getCLIOptionPort(
portOption: HostPortCLIOptions['port'],
host: string,
): Promise<number | null> {
const basePort = portOption ? parseInt(portOption, 10) : DEFAULT_PORT;
return choosePort(host, basePort);
}