diff options
Diffstat (limited to 'src/cli.ts')
-rw-r--r-- | src/cli.ts | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/cli.ts b/src/cli.ts index c56a4c098..be0dfe27a 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -20,14 +20,20 @@ type cliCommand = 'help' | 'version' | 'dev' | 'build'; interface CLIState { cmd: cliCommand; options: { + projectRoot?: string; sitemap?: boolean; + port?: number; + config?: string; }; } /** Determine which action the user requested */ function resolveArgs(flags: Arguments): CLIState { const options: CLIState['options'] = { + projectRoot: typeof flags.projectRoot === 'string' ? flags.projectRoot: 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) { @@ -52,13 +58,15 @@ function printHelp() { console.error(` ${colors.bold('astro')} - Futuristic web development tool. ${colors.bold('Commands:')} - astro dev Run Astro in development mode. - astro build Build a pre-compiled production version of your site. + astro dev Run Astro in development mode. + astro build Build a pre-compiled production version of your site. ${colors.bold('Flags:')} - --version Show the version number and exit. - --help Show this help message. + --config <path> Specify the path to the Astro config file. + --project-root <path> Specify the path to the project root folder. --no-sitemap Disable sitemap generation (build only). + --version Show the version number and exit. + --help Show this help message. `); } @@ -70,14 +78,17 @@ async function printVersion() { /** Merge CLI flags & config options (CLI flags take priority) */ function mergeCLIFlags(astroConfig: AstroConfig, flags: CLIState['options']) { - if (typeof flags.sitemap === 'boolean') astroConfig.sitemap = flags.sitemap; + if (typeof flags.sitemap === 'boolean') astroConfig.buildOptions.sitemap = flags.sitemap; + if (typeof flags.port === 'number') astroConfig.devOptions.port = flags.port; } /** Handle `astro run` command */ async function runCommand(rawRoot: string, cmd: (a: AstroConfig) => Promise<void>, options: CLIState['options']) { try { - const astroConfig = await loadConfig(rawRoot); + const projectRoot = options.projectRoot || rawRoot; + const astroConfig = await loadConfig(projectRoot, options.config); mergeCLIFlags(astroConfig, options); + return cmd(astroConfig); } catch (err) { console.error(colors.red(err.toString() || err)); |