summaryrefslogtreecommitdiff
path: root/src/cli.ts
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@matthewphillips.info> 2021-04-22 08:25:57 -0400
committerGravatar GitHub <noreply@github.com> 2021-04-22 08:25:57 -0400
commitda033e27eada3bbcad5544be282e9edcf4799003 (patch)
tree8fa1203d4e318f006d254abff79caa2508a86fd2 /src/cli.ts
parenta7185735da7413e132f313ff5086db74304d7654 (diff)
downloadastro-da033e27eada3bbcad5544be282e9edcf4799003.tar.gz
astro-da033e27eada3bbcad5544be282e9edcf4799003.tar.zst
astro-da033e27eada3bbcad5544be282e9edcf4799003.zip
CLI docs (#121)
* Start of cli docs * Document the CLI Also adds support for the `--config` option and `--port` option for the dev server. * Add tests for --config and --port flags * Add port to validateConfig
Diffstat (limited to 'src/cli.ts')
-rw-r--r--src/cli.ts23
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));