From aad336680c6b6e6bab4f8282f48d5a223275474f Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Wed, 11 Aug 2021 16:04:00 -0700 Subject: [PATCH] Revert "Add PORT env var to be used (#952)" This reverts commit 939b9d01a4c5ea8fcdc95be75c789b3eeee8f06f. --- packages/astro/src/cli.ts | 44 +++++++-------------------------------- 1 file changed, 7 insertions(+), 37 deletions(-) diff --git a/packages/astro/src/cli.ts b/packages/astro/src/cli.ts index 74d1e4302..accdb7978 100644 --- a/packages/astro/src/cli.ts +++ b/packages/astro/src/cli.ts @@ -35,44 +35,14 @@ interface CLIState { }; } -type TypeOf = 'string' | 'boolean' | 'number'; -// Validates property types of object -const validateOptions = (opts: Record, specs: Record unknown, TypeOf]>) => - Object.entries(specs).reduce>((options, [k, spec]) => { - const v = opts[k]; - - if (typeof spec === 'string' && typeof v === spec) { - options[k] = v; - } else if (Array.isArray(spec)) { - const [coercion, test] = spec; - const result = coercion(v); - if (typeof result === test) { - options[k] = result; - } - } - - return options; - }, {}); - /** Determine which action the user requested */ function resolveArgs(flags: Arguments): CLIState { - const { PORT } = process.env; - - // Merge options (Flags take priority) - const options = { - ...validateOptions( - { port: PORT }, - { - port: [parseInt, 'number'], - } - ), - ...validateOptions(flags, { - projectRoot: 'string', - site: 'string', - sitemap: 'boolean', - port: 'number', - config: 'string', - }), + const options: CLIState['options'] = { + projectRoot: typeof flags.projectRoot === 'string' ? flags.projectRoot : undefined, + site: typeof flags.site === 'string' ? flags.site : undefined, + sitemap: typeof flags.sitemap === 'boolean' ? flags.sitemap : undefined, + port: typeof flags.port === 'number' ? flags.port : undefined, + config: typeof flags.config === 'string' ? flags.config : undefined, }; if (flags.version) { @@ -131,7 +101,7 @@ function mergeCLIFlags(astroConfig: AstroConfig, flags: CLIState['options']) { } /** Handle `astro run` command */ -async function runCommand(rawRoot: string, cmd: (a: AstroConfig, opts: any) => Promise, options: CLIState['options']) { +async function runCommand(rawRoot: string, cmd: (a: AstroConfig, options: any) => Promise, options: CLIState['options']) { try { const projectRoot = options.projectRoot || rawRoot; const astroConfig = await loadConfig(projectRoot, options.config);