mirror of
https://github.com/withastro/astro.git
synced 2025-03-10 23:01:26 -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;
|
host?: string | boolean;
|
||||||
port?: number;
|
port?: number;
|
||||||
config?: string;
|
config?: string;
|
||||||
|
stage?: string;
|
||||||
open?: string | boolean;
|
open?: string | boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -502,6 +503,17 @@ export interface AstroUserConfig {
|
||||||
*/
|
*/
|
||||||
trailingSlash?: 'always' | 'never' | 'ignore';
|
trailingSlash?: 'always' | 'never' | 'ignore';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @docs
|
||||||
|
* @name stage
|
||||||
|
* @type {('development' | 'production')}
|
||||||
|
* @description
|
||||||
|
*
|
||||||
|
* TODO
|
||||||
|
*/
|
||||||
|
stage?: 'development' | 'production';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @docs
|
* @docs
|
||||||
* @name redirects
|
* @name redirects
|
||||||
|
|
|
@ -68,6 +68,7 @@ export function resolveFlags(flags: Partial<Flags>): CLIFlags {
|
||||||
typeof flags.host === 'string' || typeof flags.host === 'boolean' ? flags.host : undefined,
|
typeof flags.host === 'string' || typeof flags.host === 'boolean' ? flags.host : undefined,
|
||||||
open:
|
open:
|
||||||
typeof flags.open === 'string' || typeof flags.open === 'boolean' ? flags.open : undefined,
|
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({}) }))
|
.array(z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) }))
|
||||||
.default(ASTRO_CONFIG_DEFAULTS.integrations)
|
.default(ASTRO_CONFIG_DEFAULTS.integrations)
|
||||||
),
|
),
|
||||||
|
stage: z
|
||||||
|
.union([z.literal('development'), z.literal('production')])
|
||||||
|
.optional(),
|
||||||
build: z
|
build: z
|
||||||
.object({
|
.object({
|
||||||
format: z
|
format: z
|
||||||
|
|
|
@ -30,17 +30,22 @@ function astroDBIntegration(): AstroIntegration {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let command: 'dev' | 'build' | 'preview';
|
let command: 'dev' | 'build' | 'preview';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: 'astro:db',
|
name: 'astro:db',
|
||||||
hooks: {
|
hooks: {
|
||||||
'astro:config:setup': async ({ updateConfig, config, command: _command, logger }) => {
|
'astro:config:setup': async ({ updateConfig, config, command: _command, logger }) => {
|
||||||
|
if (command === 'preview') return;
|
||||||
|
|
||||||
command = _command;
|
command = _command;
|
||||||
root = config.root;
|
root = config.root;
|
||||||
|
|
||||||
if (command === 'preview') return;
|
|
||||||
|
|
||||||
let dbPlugin: VitePlugin | undefined = undefined;
|
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) {
|
if (connectToStudio) {
|
||||||
appToken = await getManagedAppTokenOrExit();
|
appToken = await getManagedAppTokenOrExit();
|
||||||
|
@ -68,6 +73,7 @@ function astroDBIntegration(): AstroIntegration {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
'astro:config:done': async ({ config }) => {
|
'astro:config:done': async ({ config }) => {
|
||||||
|
if (command === 'preview') return;
|
||||||
// TODO: refine where we load tables
|
// TODO: refine where we load tables
|
||||||
// @matthewp: may want to load tables by path at runtime
|
// @matthewp: may want to load tables by path at runtime
|
||||||
const { mod, dependencies } = await loadDbConfigFile(config.root);
|
const { mod, dependencies } = await loadDbConfigFile(config.root);
|
||||||
|
@ -90,6 +96,7 @@ function astroDBIntegration(): AstroIntegration {
|
||||||
await typegen({ tables: tables.get() ?? {}, root: config.root });
|
await typegen({ tables: tables.get() ?? {}, root: config.root });
|
||||||
},
|
},
|
||||||
'astro:server:start': async ({ logger }) => {
|
'astro:server:start': async ({ logger }) => {
|
||||||
|
if (command === 'preview') return;
|
||||||
// Wait for the server startup to log, so that this can come afterwards.
|
// Wait for the server startup to log, so that this can come afterwards.
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
logger.info(
|
logger.info(
|
||||||
|
@ -98,6 +105,7 @@ function astroDBIntegration(): AstroIntegration {
|
||||||
}, 100);
|
}, 100);
|
||||||
},
|
},
|
||||||
'astro:server:setup': async ({ server }) => {
|
'astro:server:setup': async ({ server }) => {
|
||||||
|
if (command === 'preview') return;
|
||||||
const filesToWatch = [
|
const filesToWatch = [
|
||||||
...CONFIG_FILE_NAMES.map((c) => new URL(c, getDbDirectoryUrl(root))),
|
...CONFIG_FILE_NAMES.map((c) => new URL(c, getDbDirectoryUrl(root))),
|
||||||
...configFileDependencies.map((c) => new URL(c, root)),
|
...configFileDependencies.map((c) => new URL(c, root)),
|
||||||
|
@ -110,9 +118,11 @@ function astroDBIntegration(): AstroIntegration {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
'astro:build:start': async ({ logger }) => {
|
'astro:build:start': async ({ logger }) => {
|
||||||
|
if (command === 'preview') return;
|
||||||
logger.info('database: ' + (connectToStudio ? yellow('remote') : blue('local database.')));
|
logger.info('database: ' + (connectToStudio ? yellow('remote') : blue('local database.')));
|
||||||
},
|
},
|
||||||
'astro:build:done': async ({}) => {
|
'astro:build:done': async ({}) => {
|
||||||
|
if (command === 'preview') return;
|
||||||
await appToken?.destroy();
|
await appToken?.destroy();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -240,6 +240,7 @@ export type DBSnapshot = {
|
||||||
|
|
||||||
export const dbConfigSchema = z.object({
|
export const dbConfigSchema = z.object({
|
||||||
tables: tablesSchema.optional(),
|
tables: tablesSchema.optional(),
|
||||||
|
stage: z.union([z.literal('development'), z.literal('production')]).optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type DBConfigInput = z.input<typeof dbConfigSchema>;
|
export type DBConfigInput = z.input<typeof dbConfigSchema>;
|
||||||
|
|
Loading…
Add table
Reference in a new issue