mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
wip
This commit is contained in:
parent
2db9031a9f
commit
96bfb75886
5 changed files with 30 additions and 3 deletions
|
@ -163,6 +163,7 @@ export interface CLIFlags {
|
|||
host?: string | boolean;
|
||||
port?: number;
|
||||
config?: string;
|
||||
stage?: string;
|
||||
open?: string | boolean;
|
||||
}
|
||||
|
||||
|
@ -502,6 +503,17 @@ export interface AstroUserConfig {
|
|||
*/
|
||||
trailingSlash?: 'always' | 'never' | 'ignore';
|
||||
|
||||
|
||||
/**
|
||||
* @docs
|
||||
* @name stage
|
||||
* @type {('development' | 'production')}
|
||||
* @description
|
||||
*
|
||||
* TODO
|
||||
*/
|
||||
stage?: 'development' | 'production';
|
||||
|
||||
/**
|
||||
* @docs
|
||||
* @name redirects
|
||||
|
|
|
@ -68,6 +68,7 @@ export function resolveFlags(flags: Partial<Flags>): CLIFlags {
|
|||
typeof flags.host === 'string' || typeof flags.host === 'boolean' ? flags.host : undefined,
|
||||
open:
|
||||
typeof flags.open === 'string' || typeof flags.open === 'boolean' ? flags.open : undefined,
|
||||
stage: typeof flags.stage === 'string' ? flags.stage : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -116,6 +116,9 @@ export const AstroConfigSchema = z.object({
|
|||
.array(z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) }))
|
||||
.default(ASTRO_CONFIG_DEFAULTS.integrations)
|
||||
),
|
||||
stage: z
|
||||
.union([z.literal('development'), z.literal('production')])
|
||||
.optional(),
|
||||
build: z
|
||||
.object({
|
||||
format: z
|
||||
|
|
|
@ -30,17 +30,22 @@ function astroDBIntegration(): AstroIntegration {
|
|||
},
|
||||
};
|
||||
let command: 'dev' | 'build' | 'preview';
|
||||
|
||||
return {
|
||||
name: 'astro:db',
|
||||
hooks: {
|
||||
'astro:config:setup': async ({ updateConfig, config, command: _command, logger }) => {
|
||||
if (command === 'preview') return;
|
||||
|
||||
command = _command;
|
||||
root = config.root;
|
||||
|
||||
if (command === 'preview') return;
|
||||
|
||||
let dbPlugin: VitePlugin | undefined = undefined;
|
||||
connectToStudio = command === 'build';
|
||||
if (!config.stage && command === 'build') {
|
||||
throw new Error('stage is required in db/config.js');
|
||||
} else {
|
||||
connectToStudio = dbConfig.stage === 'production';
|
||||
}
|
||||
|
||||
if (connectToStudio) {
|
||||
appToken = await getManagedAppTokenOrExit();
|
||||
|
@ -68,6 +73,7 @@ function astroDBIntegration(): AstroIntegration {
|
|||
});
|
||||
},
|
||||
'astro:config:done': async ({ config }) => {
|
||||
if (command === 'preview') return;
|
||||
// TODO: refine where we load tables
|
||||
// @matthewp: may want to load tables by path at runtime
|
||||
const { mod, dependencies } = await loadDbConfigFile(config.root);
|
||||
|
@ -90,6 +96,7 @@ function astroDBIntegration(): AstroIntegration {
|
|||
await typegen({ tables: tables.get() ?? {}, root: config.root });
|
||||
},
|
||||
'astro:server:start': async ({ logger }) => {
|
||||
if (command === 'preview') return;
|
||||
// Wait for the server startup to log, so that this can come afterwards.
|
||||
setTimeout(() => {
|
||||
logger.info(
|
||||
|
@ -98,6 +105,7 @@ function astroDBIntegration(): AstroIntegration {
|
|||
}, 100);
|
||||
},
|
||||
'astro:server:setup': async ({ server }) => {
|
||||
if (command === 'preview') return;
|
||||
const filesToWatch = [
|
||||
...CONFIG_FILE_NAMES.map((c) => new URL(c, getDbDirectoryUrl(root))),
|
||||
...configFileDependencies.map((c) => new URL(c, root)),
|
||||
|
@ -110,9 +118,11 @@ function astroDBIntegration(): AstroIntegration {
|
|||
});
|
||||
},
|
||||
'astro:build:start': async ({ logger }) => {
|
||||
if (command === 'preview') return;
|
||||
logger.info('database: ' + (connectToStudio ? yellow('remote') : blue('local database.')));
|
||||
},
|
||||
'astro:build:done': async ({}) => {
|
||||
if (command === 'preview') return;
|
||||
await appToken?.destroy();
|
||||
},
|
||||
},
|
||||
|
|
|
@ -240,6 +240,7 @@ export type DBSnapshot = {
|
|||
|
||||
export const dbConfigSchema = z.object({
|
||||
tables: tablesSchema.optional(),
|
||||
stage: z.union([z.literal('development'), z.literal('production')]).optional(),
|
||||
});
|
||||
|
||||
export type DBConfigInput = z.input<typeof dbConfigSchema>;
|
||||
|
|
Loading…
Reference in a new issue