Add support for --base
CLI argument (#4917)
* 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>
This commit is contained in:
parent
bde715700c
commit
ddf2f8390e
5 changed files with 16 additions and 1 deletions
9
.changeset/wise-swans-live.md
Normal file
9
.changeset/wise-swans-live.md
Normal file
|
@ -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
|
||||||
|
```
|
|
@ -10,6 +10,7 @@
|
||||||
<title>Astro</title>
|
<title>Astro</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Astro</h1>
|
<h1>SITE: {Astro.site}</h1>
|
||||||
|
<p>BASE_URL: {import.meta.env.BASE_URL}</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -77,6 +77,7 @@ export interface AstroComponentMetadata {
|
||||||
export interface CLIFlags {
|
export interface CLIFlags {
|
||||||
root?: string;
|
root?: string;
|
||||||
site?: string;
|
site?: string;
|
||||||
|
base?: string;
|
||||||
host?: string | boolean;
|
host?: string | boolean;
|
||||||
port?: number;
|
port?: number;
|
||||||
config?: string;
|
config?: string;
|
||||||
|
|
|
@ -61,6 +61,8 @@ function printAstroHelp() {
|
||||||
'Global Flags': [
|
'Global Flags': [
|
||||||
['--config <path>', 'Specify your config file.'],
|
['--config <path>', 'Specify your config file.'],
|
||||||
['--root <path>', 'Specify your project root folder.'],
|
['--root <path>', 'Specify your project root folder.'],
|
||||||
|
['--site <url>', 'Specify your project site.'],
|
||||||
|
['--base <pathname>', 'Specify your project base.'],
|
||||||
['--verbose', 'Enable verbose logging.'],
|
['--verbose', 'Enable verbose logging.'],
|
||||||
['--silent', 'Disable all logging.'],
|
['--silent', 'Disable all logging.'],
|
||||||
['--version', 'Show the version number and exit.'],
|
['--version', 'Show the version number and exit.'],
|
||||||
|
|
|
@ -97,6 +97,7 @@ export function resolveFlags(flags: Partial<Flags>): CLIFlags {
|
||||||
return {
|
return {
|
||||||
root: typeof flags.root === 'string' ? flags.root : undefined,
|
root: typeof flags.root === 'string' ? flags.root : undefined,
|
||||||
site: typeof flags.site === 'string' ? flags.site : 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,
|
port: typeof flags.port === 'number' ? flags.port : undefined,
|
||||||
config: typeof flags.config === 'string' ? flags.config : undefined,
|
config: typeof flags.config === 'string' ? flags.config : undefined,
|
||||||
host:
|
host:
|
||||||
|
@ -114,6 +115,7 @@ function mergeCLIFlags(astroConfig: AstroUserConfig, flags: CLIFlags, cmd: strin
|
||||||
astroConfig.server = astroConfig.server || {};
|
astroConfig.server = astroConfig.server || {};
|
||||||
astroConfig.markdown = astroConfig.markdown || {};
|
astroConfig.markdown = astroConfig.markdown || {};
|
||||||
if (typeof flags.site === 'string') astroConfig.site = flags.site;
|
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.drafts === 'boolean') astroConfig.markdown.drafts = flags.drafts;
|
||||||
if (typeof flags.port === 'number') {
|
if (typeof flags.port === 'number') {
|
||||||
// @ts-expect-error astroConfig.server may be a function, but TS doesn't like attaching properties to a function.
|
// @ts-expect-error astroConfig.server may be a function, but TS doesn't like attaching properties to a function.
|
||||||
|
|
Loading…
Reference in a new issue