From f1641a2544233dbd46051ae1d20e45ecef9bdf6b Mon Sep 17 00:00:00 2001 From: wuls Date: Fri, 17 Mar 2023 18:01:27 +0800 Subject: [PATCH 1/6] add --open flag --- packages/astro/src/@types/astro.ts | 1 + packages/astro/src/core/config/config.ts | 5 +++++ packages/astro/src/core/config/schema.ts | 3 +++ packages/astro/src/core/dev/container.ts | 4 ++-- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 2d4bcfa1578e..87dff541e240 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -88,6 +88,7 @@ export interface CLIFlags { port?: number; config?: string; drafts?: boolean; + open?: boolean; experimentalAssets?: boolean; } diff --git a/packages/astro/src/core/config/config.ts b/packages/astro/src/core/config/config.ts index 9c45c9c5f79f..4fc6747afe75 100644 --- a/packages/astro/src/core/config/config.ts +++ b/packages/astro/src/core/config/config.ts @@ -130,6 +130,11 @@ function mergeCLIFlags(astroConfig: AstroUserConfig, flags: CLIFlags) { // TODO: Come back here and refactor to remove this expected error. astroConfig.server.host = flags.host; } + if (typeof flags.open === 'boolean') { + // @ts-expect-error astroConfig.server may be a function, but TS doesn't like attaching properties to a function. + // TODO: Come back here and refactor to remove this expected error. + astroConfig.server.open = flags.open; + } return astroConfig; } diff --git a/packages/astro/src/core/config/schema.ts b/packages/astro/src/core/config/schema.ts index 5c7a31909ad4..5b374ce33ec3 100644 --- a/packages/astro/src/core/config/schema.ts +++ b/packages/astro/src/core/config/schema.ts @@ -26,6 +26,7 @@ const ASTRO_CONFIG_DEFAULTS: AstroUserConfig & any = { host: false, port: 3000, streaming: true, + open: false, }, integrations: [], markdown: { @@ -108,6 +109,7 @@ export const AstroConfigSchema = z.object({ // validate z .object({ + open: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.server.open), host: z .union([z.string(), z.boolean()]) .optional() @@ -246,6 +248,7 @@ export function createRelativeSchema(cmd: string, fileProtocolRoot: URL) { .optional() .default(ASTRO_CONFIG_DEFAULTS.server.host), port: z.number().optional().default(ASTRO_CONFIG_DEFAULTS.server.port), + open: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.server.open), headers: z.custom().optional(), streaming: z.boolean().optional().default(true), }) diff --git a/packages/astro/src/core/dev/container.ts b/packages/astro/src/core/dev/container.ts index 1b1ccca678ff..161a3bdf61f7 100644 --- a/packages/astro/src/core/dev/container.ts +++ b/packages/astro/src/core/dev/container.ts @@ -71,7 +71,7 @@ export async function createContainer(params: CreateContainerParams = {}): Promi logging, isRestart, }); - const { host, headers } = settings.config.server; + const { host, headers, open } = settings.config.server; // The client entrypoint for renderers. Since these are imported dynamically // we need to tell Vite to preoptimize them. @@ -82,7 +82,7 @@ export async function createContainer(params: CreateContainerParams = {}): Promi const viteConfig = await createVite( { mode: 'development', - server: { host, headers }, + server: { host, headers, open }, optimizeDeps: { include: rendererClientEntries, }, From 653771258d9904108642138b37d71230cd93b8e7 Mon Sep 17 00:00:00 2001 From: wuls Date: Sun, 19 Mar 2023 17:18:59 +0800 Subject: [PATCH 2/6] add flag with open for preview --- .changeset/hip-avocados-grow.md | 5 +++++ packages/astro/src/core/preview/static-preview-server.ts | 1 + 2 files changed, 6 insertions(+) create mode 100644 .changeset/hip-avocados-grow.md diff --git a/.changeset/hip-avocados-grow.md b/.changeset/hip-avocados-grow.md new file mode 100644 index 000000000000..dd3ad5391b7f --- /dev/null +++ b/.changeset/hip-avocados-grow.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +add new flag of the open for dev and preview diff --git a/packages/astro/src/core/preview/static-preview-server.ts b/packages/astro/src/core/preview/static-preview-server.ts index 52cd7da73e1f..b908f74377dc 100644 --- a/packages/astro/src/core/preview/static-preview-server.ts +++ b/packages/astro/src/core/preview/static-preview-server.ts @@ -37,6 +37,7 @@ export default async function createStaticPreviewServer( host: settings.config.server.host, port: settings.config.server.port, headers: settings.config.server.headers, + open: settings.config.server.open, }, plugins: [vitePluginAstroPreview(settings)], }); From 255e95445bf61df7fe186a82ffc312033c7a36cf Mon Sep 17 00:00:00 2001 From: wuls Date: Sun, 19 Mar 2023 17:19:47 +0800 Subject: [PATCH 3/6] adjusting the changeset name --- .changeset/hip-avocados-grow.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/hip-avocados-grow.md b/.changeset/hip-avocados-grow.md index dd3ad5391b7f..c0de570a95a4 100644 --- a/.changeset/hip-avocados-grow.md +++ b/.changeset/hip-avocados-grow.md @@ -2,4 +2,4 @@ 'astro': patch --- -add new flag of the open for dev and preview +add new flag with open for dev and preview From 44265f9f07c9dffc08feada4cedbdbea572a8ee8 Mon Sep 17 00:00:00 2001 From: wuls Date: Tue, 21 Mar 2023 13:26:55 +0800 Subject: [PATCH 4/6] According to the Bluwy said, the suggestion which adds more help details for the dev and the preview --- .changeset/hip-avocados-grow.md | 2 +- packages/astro/src/core/config/config.ts | 1 + packages/astro/src/core/dev/dev.ts | 1 + packages/astro/src/core/preview/index.ts | 5 ++++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.changeset/hip-avocados-grow.md b/.changeset/hip-avocados-grow.md index c0de570a95a4..ba92ed186fe6 100644 --- a/.changeset/hip-avocados-grow.md +++ b/.changeset/hip-avocados-grow.md @@ -1,5 +1,5 @@ --- -'astro': patch +'astro': minor --- add new flag with open for dev and preview diff --git a/packages/astro/src/core/config/config.ts b/packages/astro/src/core/config/config.ts index 4fc6747afe75..9c09a934f566 100644 --- a/packages/astro/src/core/config/config.ts +++ b/packages/astro/src/core/config/config.ts @@ -96,6 +96,7 @@ export function resolveFlags(flags: Partial): CLIFlags { site: typeof flags.site === 'string' ? flags.site : undefined, base: typeof flags.base === 'string' ? flags.base : undefined, port: typeof flags.port === 'number' ? flags.port : undefined, + open: typeof flags.open === 'boolean' ? flags.open : undefined, config: typeof flags.config === 'string' ? flags.config : undefined, host: typeof flags.host === 'string' || typeof flags.host === 'boolean' ? flags.host : undefined, diff --git a/packages/astro/src/core/dev/dev.ts b/packages/astro/src/core/dev/dev.ts index 888c5afc69e5..00a799e998d3 100644 --- a/packages/astro/src/core/dev/dev.ts +++ b/packages/astro/src/core/dev/dev.ts @@ -45,6 +45,7 @@ export default async function dev( ['--host', `Listen on all addresses, including LAN and public addresses.`], ['--host ', `Expose on a network IP address at `], ['--help (-h)', 'See all available flags.'], + ['--open (-h)', 'automatically open the app in the browser on server start'], ], }, description: `Check ${cyan( diff --git a/packages/astro/src/core/preview/index.ts b/packages/astro/src/core/preview/index.ts index 9dd5fcb38f47..0fa17707382b 100644 --- a/packages/astro/src/core/preview/index.ts +++ b/packages/astro/src/core/preview/index.ts @@ -26,7 +26,10 @@ export default async function preview( commandName: 'astro preview', usage: '[...flags]', tables: { - Flags: [['--help (-h)', 'See all available flags.']], + Flags: [ + ['--help (-h)', 'See all available flags.'], + ['--open (-h)', 'automatically open the app in the browser on server start'], + ], }, description: `Starts a local server to serve your static dist/ directory. Check ${cyan( 'https://docs.astro.build/en/reference/cli-reference/#astro-preview' From 423871c47ea7e3df5263d2cce395fde90f00fcbe Mon Sep 17 00:00:00 2001 From: wuls Date: Tue, 28 Mar 2023 09:47:47 +0800 Subject: [PATCH 5/6] fix word --- packages/astro/src/core/dev/dev.ts | 2 +- packages/astro/src/core/preview/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/astro/src/core/dev/dev.ts b/packages/astro/src/core/dev/dev.ts index 00a799e998d3..bde2a5e0a17d 100644 --- a/packages/astro/src/core/dev/dev.ts +++ b/packages/astro/src/core/dev/dev.ts @@ -45,7 +45,7 @@ export default async function dev( ['--host', `Listen on all addresses, including LAN and public addresses.`], ['--host ', `Expose on a network IP address at `], ['--help (-h)', 'See all available flags.'], - ['--open (-h)', 'automatically open the app in the browser on server start'], + ['--open (-h)', 'Automatically open the app in the browser on server start'], ], }, description: `Check ${cyan( diff --git a/packages/astro/src/core/preview/index.ts b/packages/astro/src/core/preview/index.ts index 0fa17707382b..267622e95942 100644 --- a/packages/astro/src/core/preview/index.ts +++ b/packages/astro/src/core/preview/index.ts @@ -28,7 +28,7 @@ export default async function preview( tables: { Flags: [ ['--help (-h)', 'See all available flags.'], - ['--open (-h)', 'automatically open the app in the browser on server start'], + ['--open (-h)', 'Automatically open the app in the browser on server start'], ], }, description: `Starts a local server to serve your static dist/ directory. Check ${cyan( From 5feafad5003aa2048802d63eed7c766d4452c956 Mon Sep 17 00:00:00 2001 From: bluwy Date: Tue, 28 Mar 2023 19:47:56 +0800 Subject: [PATCH 6/6] Fix flag name --- packages/astro/src/core/dev/dev.ts | 2 +- packages/astro/src/core/preview/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/astro/src/core/dev/dev.ts b/packages/astro/src/core/dev/dev.ts index bde2a5e0a17d..8dbaabddf884 100644 --- a/packages/astro/src/core/dev/dev.ts +++ b/packages/astro/src/core/dev/dev.ts @@ -44,8 +44,8 @@ export default async function dev( ['--port', `Specify which port to run on. Defaults to 3000.`], ['--host', `Listen on all addresses, including LAN and public addresses.`], ['--host ', `Expose on a network IP address at `], + ['--open', 'Automatically open the app in the browser on server start'], ['--help (-h)', 'See all available flags.'], - ['--open (-h)', 'Automatically open the app in the browser on server start'], ], }, description: `Check ${cyan( diff --git a/packages/astro/src/core/preview/index.ts b/packages/astro/src/core/preview/index.ts index 267622e95942..faaa67428ab0 100644 --- a/packages/astro/src/core/preview/index.ts +++ b/packages/astro/src/core/preview/index.ts @@ -27,8 +27,8 @@ export default async function preview( usage: '[...flags]', tables: { Flags: [ + ['--open', 'Automatically open the app in the browser on server start'], ['--help (-h)', 'See all available flags.'], - ['--open (-h)', 'Automatically open the app in the browser on server start'], ], }, description: `Starts a local server to serve your static dist/ directory. Check ${cyan(