mirror of
https://github.com/withastro/astro.git
synced 2025-02-10 22:38:53 -05:00
Expose the database to the build output
This commit is contained in:
parent
69a4d72025
commit
9f5e9bb4b2
2 changed files with 14 additions and 1 deletions
|
@ -4,7 +4,7 @@ import { vitePluginInjectEnvTs } from './vite-plugin-inject-env-ts.js';
|
||||||
import { typegen } from './typegen.js';
|
import { typegen } from './typegen.js';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
import { mkdir, rm, writeFile } from 'fs/promises';
|
import { mkdir, rm, writeFile } from 'fs/promises';
|
||||||
import { getLocalDbUrl } from './consts.js';
|
import { getLocalDbUrl, DB_PATH } from './consts.js';
|
||||||
import { createLocalDatabaseClient, setupDbTables } from './internal.js';
|
import { createLocalDatabaseClient, setupDbTables } from './internal.js';
|
||||||
import { astroConfigWithDbSchema } from './config.js';
|
import { astroConfigWithDbSchema } from './config.js';
|
||||||
import { getAstroStudioEnv, type VitePlugin } from './utils.js';
|
import { getAstroStudioEnv, type VitePlugin } from './utils.js';
|
||||||
|
@ -73,6 +73,7 @@ export function integration(): AstroIntegration {
|
||||||
|
|
||||||
updateConfig({
|
updateConfig({
|
||||||
vite: {
|
vite: {
|
||||||
|
assetsInclude: [DB_PATH],
|
||||||
plugins: [dbPlugin, vitePluginInjectEnvTs(config)],
|
plugins: [dbPlugin, vitePluginInjectEnvTs(config)],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { DRIZZLE_MOD_IMPORT, INTERNAL_MOD_IMPORT, VIRTUAL_MODULE_ID, DB_PATH } from './consts.js';
|
import { DRIZZLE_MOD_IMPORT, INTERNAL_MOD_IMPORT, VIRTUAL_MODULE_ID, DB_PATH } from './consts.js';
|
||||||
import type { DBCollections } from './types.js';
|
import type { DBCollections } from './types.js';
|
||||||
import type { VitePlugin } from './utils.js';
|
import type { VitePlugin } from './utils.js';
|
||||||
|
import fs from 'node:fs';
|
||||||
|
|
||||||
const resolvedVirtualModuleId = '\0' + VIRTUAL_MODULE_ID;
|
const resolvedVirtualModuleId = '\0' + VIRTUAL_MODULE_ID;
|
||||||
|
|
||||||
|
@ -33,6 +34,17 @@ export function vitePluginDb(
|
||||||
}
|
}
|
||||||
return getVirtualModContents(params);
|
return getVirtualModContents(params);
|
||||||
},
|
},
|
||||||
|
async buildEnd() {
|
||||||
|
// For local use, emit the database into the output
|
||||||
|
if('dbUrl' in params) {
|
||||||
|
const data = await fs.promises.readFile(new URL(params.dbUrl));
|
||||||
|
this.emitFile({
|
||||||
|
fileName: 'content.db',
|
||||||
|
source: data,
|
||||||
|
type: 'asset'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue