|
1 | 1 | import type { AstroIntegration } from "astro"; |
2 | 2 | import { loadConfig } from "./config/loader.js"; |
| 3 | +import { |
| 4 | + loadPlugins, |
| 5 | + runConfigHook, |
| 6 | + getPluginIntegrations, |
| 7 | +} from "./plugins/loader.js"; |
3 | 8 | import type { BarodocOptions, ResolvedBarodocConfig } from "./types.js"; |
| 9 | +import type { PluginContext } from "./plugins/types.js"; |
4 | 10 |
|
5 | 11 | const VIRTUAL_CONFIG_ID = "virtual:barodoc/config"; |
6 | 12 | const VIRTUAL_I18N_ID = "virtual:barodoc/i18n"; |
@@ -53,36 +59,55 @@ export default function barodoc(options: BarodocOptions): AstroIntegration { |
53 | 59 | config, |
54 | 60 | updateConfig, |
55 | 61 | logger, |
| 62 | + command, |
56 | 63 | }) => { |
57 | 64 | logger.info("Loading Barodoc configuration..."); |
58 | 65 |
|
59 | 66 | // Convert URL to string path |
60 | | - const rootPath = config.root instanceof URL |
61 | | - ? config.root.pathname |
| 67 | + const rootPath = config.root instanceof URL |
| 68 | + ? config.root.pathname |
62 | 69 | : String(config.root); |
63 | 70 |
|
64 | 71 | // Load config |
65 | 72 | resolvedConfig = await loadConfig(configPath, rootPath); |
66 | 73 | logger.info(`Loaded config: ${resolvedConfig.name}`); |
67 | 74 |
|
| 75 | + const mode = command === "dev" ? "development" : "production"; |
| 76 | + const pluginContext: PluginContext = { |
| 77 | + config: resolvedConfig, |
| 78 | + root: rootPath, |
| 79 | + mode, |
| 80 | + }; |
| 81 | + |
| 82 | + // Load and run plugins |
| 83 | + const pluginConfigs = resolvedConfig.plugins ?? []; |
| 84 | + const plugins = await loadPlugins(pluginConfigs, pluginContext); |
| 85 | + resolvedConfig = await runConfigHook( |
| 86 | + plugins, |
| 87 | + resolvedConfig, |
| 88 | + pluginContext |
| 89 | + ); |
| 90 | + pluginContext.config = resolvedConfig; |
| 91 | + |
| 92 | + if (plugins.length > 0) { |
| 93 | + logger.info(`Loaded ${plugins.length} plugin(s)`); |
| 94 | + } |
| 95 | + |
68 | 96 | // Setup i18n |
69 | 97 | const i18nConfig = resolvedConfig.i18n || { |
70 | 98 | defaultLocale: "en", |
71 | 99 | locales: ["en"], |
72 | 100 | }; |
73 | 101 |
|
74 | | - // Merge theme integration |
| 102 | + // Theme + plugin integrations |
75 | 103 | const themeIntegration = options.theme.integration(); |
76 | | - |
77 | | - // Merge theme integration |
78 | | - // Note: i18n should be configured in astro.config.mjs, not here |
79 | | - // to avoid Astro 5.x merge issues |
| 104 | + const pluginIntegrations = getPluginIntegrations(plugins, pluginContext); |
80 | 105 |
|
81 | 106 | updateConfig({ |
82 | 107 | vite: { |
83 | 108 | plugins: [createVirtualModulesPlugin(resolvedConfig) as any], |
84 | 109 | }, |
85 | | - integrations: [themeIntegration], |
| 110 | + integrations: [themeIntegration, ...pluginIntegrations], |
86 | 111 | }); |
87 | 112 |
|
88 | 113 | logger.info( |
|
0 commit comments