Skip to content

Commit

Permalink
Add support for --base CLI argument (#4917)
Browse files Browse the repository at this point in the history
* feat(cli): add support for `--base` CLI argument

* chore: update CLI --help

* Update wise-swans-live.md

* Update wise-swans-live.md

Co-authored-by: Nate Moore <nate@astro.build>
  • Loading branch information
natemoo-re and natemoo-re committed Oct 26, 2022
1 parent bde7157 commit ddf2f83
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .changeset/wise-swans-live.md
@@ -0,0 +1,9 @@
---
'astro': minor
---

Add support for `--base` CLI argument, which will override the [`base`](https://docs.astro.build/en/reference/configuration-reference/#base) set in your `astro.config.mjs` file.

```
astro --site https://astro.build --base /docs
```
3 changes: 2 additions & 1 deletion examples/minimal/src/pages/index.astro
Expand Up @@ -10,6 +10,7 @@
<title>Astro</title>
</head>
<body>
<h1>Astro</h1>
<h1>SITE: {Astro.site}</h1>
<p>BASE_URL: {import.meta.env.BASE_URL}</p>
</body>
</html>
1 change: 1 addition & 0 deletions packages/astro/src/@types/astro.ts
Expand Up @@ -77,6 +77,7 @@ export interface AstroComponentMetadata {
export interface CLIFlags {
root?: string;
site?: string;
base?: string;
host?: string | boolean;
port?: number;
config?: string;
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/src/cli/index.ts
Expand Up @@ -61,6 +61,8 @@ function printAstroHelp() {
'Global Flags': [
['--config <path>', 'Specify your config file.'],
['--root <path>', 'Specify your project root folder.'],
['--site <url>', 'Specify your project site.'],
['--base <pathname>', 'Specify your project base.'],
['--verbose', 'Enable verbose logging.'],
['--silent', 'Disable all logging.'],
['--version', 'Show the version number and exit.'],
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/src/core/config/config.ts
Expand Up @@ -97,6 +97,7 @@ export function resolveFlags(flags: Partial<Flags>): CLIFlags {
return {
root: typeof flags.root === 'string' ? flags.root : undefined,
site: typeof flags.site === 'string' ? flags.site : undefined,
base: typeof flags.base === 'string' ? flags.base : undefined,
port: typeof flags.port === 'number' ? flags.port : undefined,
config: typeof flags.config === 'string' ? flags.config : undefined,
host:
Expand All @@ -114,6 +115,7 @@ function mergeCLIFlags(astroConfig: AstroUserConfig, flags: CLIFlags, cmd: strin
astroConfig.server = astroConfig.server || {};
astroConfig.markdown = astroConfig.markdown || {};
if (typeof flags.site === 'string') astroConfig.site = flags.site;
if (typeof flags.base === 'string') astroConfig.base = flags.base;
if (typeof flags.drafts === 'boolean') astroConfig.markdown.drafts = flags.drafts;
if (typeof flags.port === 'number') {
// @ts-expect-error astroConfig.server may be a function, but TS doesn't like attaching properties to a function.
Expand Down

0 comments on commit ddf2f83

Please sign in to comment.