Revert "Add PORT env var to be used (#952)"
This reverts commit 939b9d01a4
.
This commit is contained in:
parent
b54c01bf66
commit
aad336680c
1 changed files with 7 additions and 37 deletions
|
@ -35,44 +35,14 @@ interface CLIState {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
type TypeOf = 'string' | 'boolean' | 'number';
|
|
||||||
// Validates property types of object
|
|
||||||
const validateOptions = (opts: Record<string, any>, specs: Record<string, TypeOf | [(v: any) => unknown, TypeOf]>) =>
|
|
||||||
Object.entries(specs).reduce<Record<string, any>>((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 */
|
/** Determine which action the user requested */
|
||||||
function resolveArgs(flags: Arguments): CLIState {
|
function resolveArgs(flags: Arguments): CLIState {
|
||||||
const { PORT } = process.env;
|
const options: CLIState['options'] = {
|
||||||
|
projectRoot: typeof flags.projectRoot === 'string' ? flags.projectRoot : undefined,
|
||||||
// Merge options (Flags take priority)
|
site: typeof flags.site === 'string' ? flags.site : undefined,
|
||||||
const options = {
|
sitemap: typeof flags.sitemap === 'boolean' ? flags.sitemap : undefined,
|
||||||
...validateOptions(
|
port: typeof flags.port === 'number' ? flags.port : undefined,
|
||||||
{ port: PORT },
|
config: typeof flags.config === 'string' ? flags.config : undefined,
|
||||||
{
|
|
||||||
port: [parseInt, 'number'],
|
|
||||||
}
|
|
||||||
),
|
|
||||||
...validateOptions(flags, {
|
|
||||||
projectRoot: 'string',
|
|
||||||
site: 'string',
|
|
||||||
sitemap: 'boolean',
|
|
||||||
port: 'number',
|
|
||||||
config: 'string',
|
|
||||||
}),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (flags.version) {
|
if (flags.version) {
|
||||||
|
@ -131,7 +101,7 @@ function mergeCLIFlags(astroConfig: AstroConfig, flags: CLIState['options']) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Handle `astro run` command */
|
/** Handle `astro run` command */
|
||||||
async function runCommand(rawRoot: string, cmd: (a: AstroConfig, opts: any) => Promise<void>, options: CLIState['options']) {
|
async function runCommand(rawRoot: string, cmd: (a: AstroConfig, options: any) => Promise<void>, options: CLIState['options']) {
|
||||||
try {
|
try {
|
||||||
const projectRoot = options.projectRoot || rawRoot;
|
const projectRoot = options.projectRoot || rawRoot;
|
||||||
const astroConfig = await loadConfig(projectRoot, options.config);
|
const astroConfig = await loadConfig(projectRoot, options.config);
|
||||||
|
|
Loading…
Reference in a new issue