@docusaurus/core 0.0.0-5857 → 0.0.0-5860

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/lib/commands/build.d.ts +2 -2
  2. package/lib/commands/build.js +6 -6
  3. package/lib/commands/deploy.d.ts +2 -2
  4. package/lib/commands/deploy.js +2 -2
  5. package/lib/commands/external.js +2 -2
  6. package/lib/commands/serve.d.ts +2 -2
  7. package/lib/commands/{start.d.ts → start/start.d.ts} +3 -3
  8. package/lib/commands/start/start.js +47 -0
  9. package/lib/commands/start/utils.d.ts +31 -0
  10. package/lib/commands/start/utils.js +88 -0
  11. package/lib/commands/start/watcher.d.ts +42 -0
  12. package/lib/commands/start/watcher.js +78 -0
  13. package/lib/commands/start/webpack.d.ts +15 -0
  14. package/lib/commands/start/webpack.js +133 -0
  15. package/lib/commands/swizzle/context.js +2 -2
  16. package/lib/commands/writeHeadingIds.js +2 -2
  17. package/lib/commands/writeTranslations.d.ts +2 -2
  18. package/lib/commands/writeTranslations.js +2 -2
  19. package/lib/index.d.ts +1 -1
  20. package/lib/index.js +1 -1
  21. package/lib/server/brokenLinks.js +2 -2
  22. package/lib/server/codegen/codegen.d.ts +20 -0
  23. package/lib/server/codegen/codegen.js +65 -0
  24. package/lib/server/codegen/codegenRoutes.d.ts +49 -0
  25. package/lib/server/codegen/codegenRoutes.js +190 -0
  26. package/lib/server/i18n.d.ts +2 -2
  27. package/lib/server/plugins/{index.d.ts → plugins.d.ts} +15 -4
  28. package/lib/server/plugins/plugins.js +176 -0
  29. package/lib/server/plugins/routeConfig.d.ts +1 -1
  30. package/lib/server/plugins/routeConfig.js +4 -4
  31. package/lib/server/routes.d.ts +4 -45
  32. package/lib/server/routes.js +15 -166
  33. package/lib/server/{index.d.ts → site.d.ts} +12 -4
  34. package/lib/server/site.js +167 -0
  35. package/lib/server/translations/translations.d.ts +3 -0
  36. package/lib/server/translations/translations.js +7 -1
  37. package/lib/server/utils.d.ts +0 -2
  38. package/lib/server/utils.js +1 -9
  39. package/lib/utils.d.ts +1 -0
  40. package/lib/utils.js +14 -3
  41. package/package.json +10 -10
  42. package/lib/commands/start.js +0 -242
  43. package/lib/server/index.js +0 -154
  44. package/lib/server/plugins/index.js +0 -106
@@ -1,242 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Facebook, Inc. and its affiliates.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.start = void 0;
10
- const tslib_1 = require("tslib");
11
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
- const path_1 = tslib_1.__importDefault(require("path"));
13
- const lodash_1 = tslib_1.__importDefault(require("lodash"));
14
- const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
15
- const utils_1 = require("@docusaurus/utils");
16
- const chokidar_1 = tslib_1.__importDefault(require("chokidar"));
17
- const openBrowser_1 = tslib_1.__importDefault(require("react-dev-utils/openBrowser"));
18
- const WebpackDevServerUtils_1 = require("react-dev-utils/WebpackDevServerUtils");
19
- const evalSourceMapMiddleware_1 = tslib_1.__importDefault(require("react-dev-utils/evalSourceMapMiddleware"));
20
- const webpack_1 = tslib_1.__importDefault(require("webpack"));
21
- const webpack_dev_server_1 = tslib_1.__importDefault(require("webpack-dev-server"));
22
- const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
23
- const server_1 = require("../server");
24
- const client_1 = require("../webpack/client");
25
- const utils_2 = require("../webpack/utils");
26
- const getHostPort_1 = require("../server/getHostPort");
27
- const utils_3 = require("../utils");
28
- async function start(siteDirParam = '.', cliOptions = {}) {
29
- // Temporary workaround to unlock the ability to translate the site config
30
- // We'll remove it if a better official API can be designed
31
- // See https://github.com/facebook/docusaurus/issues/4542
32
- process.env.DOCUSAURUS_CURRENT_LOCALE = cliOptions.locale;
33
- const siteDir = await fs_extra_1.default.realpath(siteDirParam);
34
- logger_1.default.info('Starting the development server...');
35
- async function loadSite() {
36
- utils_3.PerfLogger.start('Loading site');
37
- const result = await (0, server_1.load)({
38
- siteDir,
39
- config: cliOptions.config,
40
- locale: cliOptions.locale,
41
- localizePath: undefined, // Should this be configurable?
42
- });
43
- utils_3.PerfLogger.end('Loading site');
44
- return result;
45
- }
46
- // Process all related files as a prop.
47
- const props = await loadSite();
48
- const { host, port, getOpenUrl } = await createUrlUtils({ cliOptions });
49
- const openUrl = getOpenUrl({ baseUrl: props.baseUrl });
50
- logger_1.default.success `Docusaurus website is running at: url=${openUrl}`;
51
- // Reload files processing.
52
- const reload = lodash_1.default.debounce(() => {
53
- loadSite()
54
- .then(({ baseUrl: newBaseUrl }) => {
55
- const newOpenUrl = getOpenUrl({ baseUrl: newBaseUrl });
56
- if (newOpenUrl !== openUrl) {
57
- logger_1.default.success `Docusaurus website is running at: url=${newOpenUrl}`;
58
- }
59
- })
60
- .catch((err) => {
61
- logger_1.default.error(err.stack);
62
- });
63
- }, 500);
64
- // TODO this is historically not optimized!
65
- // When any site file changes, we reload absolutely everything :/
66
- // At least we should try to reload only one plugin individually?
67
- setupFileWatchers({
68
- props,
69
- cliOptions,
70
- onFileChange: () => {
71
- reload();
72
- },
73
- });
74
- const config = await getStartClientConfig({
75
- props,
76
- minify: cliOptions.minify ?? true,
77
- poll: cliOptions.poll,
78
- });
79
- const compiler = (0, webpack_1.default)(config);
80
- registerE2ETestHook(compiler);
81
- const defaultDevServerConfig = await createDevServerConfig({
82
- cliOptions,
83
- props,
84
- host,
85
- port,
86
- });
87
- // Allow plugin authors to customize/override devServer config
88
- const devServerConfig = (0, webpack_merge_1.default)([defaultDevServerConfig, config.devServer].filter(Boolean));
89
- const devServer = new webpack_dev_server_1.default(devServerConfig, compiler);
90
- devServer.startCallback(() => {
91
- if (cliOptions.open) {
92
- (0, openBrowser_1.default)(openUrl);
93
- }
94
- });
95
- ['SIGINT', 'SIGTERM'].forEach((sig) => {
96
- process.on(sig, () => {
97
- devServer.stop();
98
- process.exit();
99
- });
100
- });
101
- }
102
- exports.start = start;
103
- function createPollingOptions({ cliOptions }) {
104
- return {
105
- usePolling: !!cliOptions.poll,
106
- interval: Number.isInteger(cliOptions.poll)
107
- ? cliOptions.poll
108
- : undefined,
109
- };
110
- }
111
- function setupFileWatchers({ props, cliOptions, onFileChange, }) {
112
- const { siteDir } = props;
113
- const pathsToWatch = getPathsToWatch({ props });
114
- const pollingOptions = createPollingOptions({ cliOptions });
115
- const fsWatcher = chokidar_1.default.watch(pathsToWatch, {
116
- cwd: siteDir,
117
- ignoreInitial: true,
118
- ...{ pollingOptions },
119
- });
120
- ['add', 'change', 'unlink', 'addDir', 'unlinkDir'].forEach((event) => fsWatcher.on(event, onFileChange));
121
- }
122
- function getPathsToWatch({ props }) {
123
- const { siteDir, siteConfigPath, plugins, localizationDir } = props;
124
- const normalizeToSiteDir = (filepath) => {
125
- if (filepath && path_1.default.isAbsolute(filepath)) {
126
- return (0, utils_1.posixPath)(path_1.default.relative(siteDir, filepath));
127
- }
128
- return (0, utils_1.posixPath)(filepath);
129
- };
130
- const pluginsPaths = plugins
131
- .flatMap((plugin) => plugin.getPathsToWatch?.() ?? [])
132
- .filter(Boolean)
133
- .map(normalizeToSiteDir);
134
- return [...pluginsPaths, siteConfigPath, localizationDir];
135
- }
136
- async function createUrlUtils({ cliOptions }) {
137
- const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
138
- const { host, port } = await (0, getHostPort_1.getHostPort)(cliOptions);
139
- if (port === null) {
140
- return process.exit();
141
- }
142
- const getOpenUrl = ({ baseUrl }) => {
143
- const urls = (0, WebpackDevServerUtils_1.prepareUrls)(protocol, host, port);
144
- return (0, utils_1.normalizeUrl)([urls.localUrlForBrowser, baseUrl]);
145
- };
146
- return { host, port, getOpenUrl };
147
- }
148
- async function createDevServerConfig({ cliOptions, props, host, port, }) {
149
- const { baseUrl, siteDir, siteConfig } = props;
150
- const pollingOptions = createPollingOptions({ cliOptions });
151
- const httpsConfig = await (0, utils_2.getHttpsConfig)();
152
- // https://webpack.js.org/configuration/dev-server
153
- return {
154
- hot: cliOptions.hotOnly ? 'only' : true,
155
- liveReload: false,
156
- client: {
157
- progress: true,
158
- overlay: {
159
- warnings: false,
160
- errors: true,
161
- },
162
- webSocketURL: {
163
- hostname: '0.0.0.0',
164
- port: 0,
165
- },
166
- },
167
- headers: {
168
- 'access-control-allow-origin': '*',
169
- },
170
- devMiddleware: {
171
- publicPath: baseUrl,
172
- // Reduce log verbosity, see https://github.com/facebook/docusaurus/pull/5420#issuecomment-906613105
173
- stats: 'summary',
174
- },
175
- static: siteConfig.staticDirectories.map((dir) => ({
176
- publicPath: baseUrl,
177
- directory: path_1.default.resolve(siteDir, dir),
178
- watch: {
179
- // Useful options for our own monorepo using symlinks!
180
- // See https://github.com/webpack/webpack/issues/11612#issuecomment-879259806
181
- followSymlinks: true,
182
- ignored: /node_modules\/(?!@docusaurus)/,
183
- ...{ pollingOptions },
184
- },
185
- })),
186
- ...(httpsConfig && {
187
- server: typeof httpsConfig === 'object'
188
- ? {
189
- type: 'https',
190
- options: httpsConfig,
191
- }
192
- : 'https',
193
- }),
194
- historyApiFallback: {
195
- rewrites: [{ from: /\/*/, to: baseUrl }],
196
- },
197
- allowedHosts: 'all',
198
- host,
199
- port,
200
- setupMiddlewares: (middlewares, devServer) => {
201
- // This lets us fetch source contents from webpack for the error overlay.
202
- middlewares.unshift((0, evalSourceMapMiddleware_1.default)(devServer));
203
- return middlewares;
204
- },
205
- };
206
- }
207
- // E2E_TEST=true docusaurus start
208
- // Makes "docusaurus start" exit immediately on success/error, for E2E test
209
- function registerE2ETestHook(compiler) {
210
- compiler.hooks.done.tap('done', (stats) => {
211
- const errorsWarnings = stats.toJson('errors-warnings');
212
- const statsErrorMessage = (0, utils_2.formatStatsErrorMessage)(errorsWarnings);
213
- if (statsErrorMessage) {
214
- console.error(statsErrorMessage);
215
- }
216
- (0, utils_2.printStatsWarnings)(errorsWarnings);
217
- if (process.env.E2E_TEST) {
218
- if (stats.hasErrors()) {
219
- logger_1.default.error('E2E_TEST: Project has compiler errors.');
220
- process.exit(1);
221
- }
222
- logger_1.default.success('E2E_TEST: Project can compile.');
223
- process.exit(0);
224
- }
225
- });
226
- }
227
- async function getStartClientConfig({ props, minify, poll, }) {
228
- const { plugins, siteConfig } = props;
229
- let { clientConfig: config } = await (0, client_1.createStartClientConfig)({
230
- props,
231
- minify,
232
- poll,
233
- });
234
- config = (0, utils_2.executePluginsConfigurePostCss)({ plugins, config });
235
- config = (0, utils_2.executePluginsConfigureWebpack)({
236
- plugins,
237
- config,
238
- isServer: false,
239
- jsLoader: siteConfig.webpack?.jsLoader,
240
- });
241
- return config;
242
- }
@@ -1,154 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Facebook, Inc. and its affiliates.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.load = exports.loadContext = void 0;
10
- const tslib_1 = require("tslib");
11
- const path_1 = tslib_1.__importDefault(require("path"));
12
- const lodash_1 = tslib_1.__importDefault(require("lodash"));
13
- const utils_1 = require("@docusaurus/utils");
14
- const config_1 = require("./config");
15
- const clientModules_1 = require("./clientModules");
16
- const plugins_1 = require("./plugins");
17
- const routes_1 = require("./routes");
18
- const htmlTags_1 = require("./htmlTags");
19
- const siteMetadata_1 = require("./siteMetadata");
20
- const i18n_1 = require("./i18n");
21
- const translations_1 = require("./translations/translations");
22
- /**
23
- * Loading context is the very first step in site building. Its options are
24
- * directly acquired from CLI options. It mainly loads `siteConfig` and the i18n
25
- * context (which includes code translations). The `LoadContext` will be passed
26
- * to plugin constructors.
27
- */
28
- async function loadContext(options) {
29
- const { siteDir, outDir: baseOutDir = utils_1.DEFAULT_BUILD_DIR_NAME, locale, config: customConfigFilePath, } = options;
30
- const generatedFilesDir = path_1.default.resolve(siteDir, utils_1.GENERATED_FILES_DIR_NAME);
31
- const { siteConfig: initialSiteConfig, siteConfigPath } = await (0, config_1.loadSiteConfig)({
32
- siteDir,
33
- customConfigFilePath,
34
- });
35
- const i18n = await (0, i18n_1.loadI18n)(initialSiteConfig, { locale });
36
- const baseUrl = (0, utils_1.localizePath)({
37
- path: initialSiteConfig.baseUrl,
38
- i18n,
39
- options,
40
- pathType: 'url',
41
- });
42
- const outDir = (0, utils_1.localizePath)({
43
- path: path_1.default.resolve(siteDir, baseOutDir),
44
- i18n,
45
- options,
46
- pathType: 'fs',
47
- });
48
- const siteConfig = { ...initialSiteConfig, baseUrl };
49
- const localizationDir = path_1.default.resolve(siteDir, i18n.path, i18n.localeConfigs[i18n.currentLocale].path);
50
- const codeTranslationFileContent = (await (0, translations_1.readCodeTranslationFileContent)({ localizationDir })) ?? {};
51
- // We only need key->message for code translations
52
- const codeTranslations = lodash_1.default.mapValues(codeTranslationFileContent, (value) => value.message);
53
- return {
54
- siteDir,
55
- generatedFilesDir,
56
- localizationDir,
57
- siteConfig,
58
- siteConfigPath,
59
- outDir,
60
- baseUrl,
61
- i18n,
62
- codeTranslations,
63
- };
64
- }
65
- exports.loadContext = loadContext;
66
- /**
67
- * This is the crux of the Docusaurus server-side. It reads everything it needs—
68
- * code translations, config file, plugin modules... Plugins then use their
69
- * lifecycles to generate content and other data. It is side-effect-ful because
70
- * it generates temp files in the `.docusaurus` folder for the bundler.
71
- */
72
- async function load(options) {
73
- const { siteDir } = options;
74
- const context = await loadContext(options);
75
- const { generatedFilesDir, siteConfig, siteConfigPath, outDir, baseUrl, i18n, localizationDir, codeTranslations: siteCodeTranslations, } = context;
76
- const { plugins, pluginsRouteConfigs, globalData } = await (0, plugins_1.loadPlugins)(context);
77
- const clientModules = (0, clientModules_1.loadClientModules)(plugins);
78
- const { headTags, preBodyTags, postBodyTags } = (0, htmlTags_1.loadHtmlTags)(plugins);
79
- const { registry, routesChunkNames, routesConfig, routesPaths } = (0, routes_1.loadRoutes)(pluginsRouteConfigs, baseUrl, siteConfig.onDuplicateRoutes);
80
- const codeTranslations = {
81
- ...(await (0, translations_1.getPluginsDefaultCodeTranslationMessages)(plugins)),
82
- ...siteCodeTranslations,
83
- };
84
- const siteMetadata = await (0, siteMetadata_1.loadSiteMetadata)({ plugins, siteDir });
85
- // === Side-effects part ===
86
- const genWarning = (0, utils_1.generate)(generatedFilesDir,
87
- // cSpell:ignore DONT
88
- 'DONT-EDIT-THIS-FOLDER', `This folder stores temp files that Docusaurus' client bundler accesses.
89
-
90
- DO NOT hand-modify files in this folder because they will be overwritten in the
91
- next build. You can clear all build artifacts (including this folder) with the
92
- \`docusaurus clear\` command.
93
- `);
94
- const genSiteConfig = (0, utils_1.generate)(generatedFilesDir, `${utils_1.DEFAULT_CONFIG_FILE_NAME}.mjs`, `/*
95
- * AUTOGENERATED - DON'T EDIT
96
- * Your edits in this file will be overwritten in the next build!
97
- * Modify the docusaurus.config.js file at your site's root instead.
98
- */
99
- export default ${JSON.stringify(siteConfig, null, 2)};
100
- `);
101
- const genClientModules = (0, utils_1.generate)(generatedFilesDir, 'client-modules.js', `export default [
102
- ${clientModules
103
- // Use `require()` because `import()` is async but client modules can have CSS
104
- // and the order matters for loading CSS.
105
- .map((clientModule) => ` require("${(0, utils_1.escapePath)(clientModule)}"),`)
106
- .join('\n')}
107
- ];
108
- `);
109
- const genRegistry = (0, utils_1.generate)(generatedFilesDir, 'registry.js', `export default {
110
- ${Object.entries(registry)
111
- .sort((a, b) => a[0].localeCompare(b[0]))
112
- .map(([chunkName, modulePath]) =>
113
- // modulePath is already escaped by escapePath
114
- ` "${chunkName}": [() => import(/* webpackChunkName: "${chunkName}" */ "${modulePath}"), "${modulePath}", require.resolveWeak("${modulePath}")],`)
115
- .join('\n')}};
116
- `);
117
- const genRoutesChunkNames = (0, utils_1.generate)(generatedFilesDir, 'routesChunkNames.json', JSON.stringify(routesChunkNames, null, 2));
118
- const genRoutes = (0, utils_1.generate)(generatedFilesDir, 'routes.js', routesConfig);
119
- const genGlobalData = (0, utils_1.generate)(generatedFilesDir, 'globalData.json', JSON.stringify(globalData, null, 2));
120
- const genI18n = (0, utils_1.generate)(generatedFilesDir, 'i18n.json', JSON.stringify(i18n, null, 2));
121
- const genCodeTranslations = (0, utils_1.generate)(generatedFilesDir, 'codeTranslations.json', JSON.stringify(codeTranslations, null, 2));
122
- const genSiteMetadata = (0, utils_1.generate)(generatedFilesDir, 'site-metadata.json', JSON.stringify(siteMetadata, null, 2));
123
- await Promise.all([
124
- genWarning,
125
- genClientModules,
126
- genSiteConfig,
127
- genRegistry,
128
- genRoutesChunkNames,
129
- genRoutes,
130
- genGlobalData,
131
- genSiteMetadata,
132
- genI18n,
133
- genCodeTranslations,
134
- ]);
135
- return {
136
- siteConfig,
137
- siteConfigPath,
138
- siteMetadata,
139
- siteDir,
140
- outDir,
141
- baseUrl,
142
- i18n,
143
- localizationDir,
144
- generatedFilesDir,
145
- routes: pluginsRouteConfigs,
146
- routesPaths,
147
- plugins,
148
- headTags,
149
- preBodyTags,
150
- postBodyTags,
151
- codeTranslations,
152
- };
153
- }
154
- exports.load = load;
@@ -1,106 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Facebook, Inc. and its affiliates.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.loadPlugins = void 0;
10
- const tslib_1 = require("tslib");
11
- const path_1 = tslib_1.__importDefault(require("path"));
12
- const lodash_1 = tslib_1.__importDefault(require("lodash"));
13
- const utils_1 = require("@docusaurus/utils");
14
- const init_1 = require("./init");
15
- const synthetic_1 = require("./synthetic");
16
- const translations_1 = require("../translations/translations");
17
- const routeConfig_1 = require("./routeConfig");
18
- /**
19
- * Initializes the plugins, runs `loadContent`, `translateContent`,
20
- * `contentLoaded`, and `translateThemeConfig`. Because `contentLoaded` is
21
- * side-effect-ful (it generates temp files), so is this function. This function
22
- * would also mutate `context.siteConfig.themeConfig` to translate it.
23
- */
24
- async function loadPlugins(context) {
25
- // 1. Plugin Lifecycle - Initialization/Constructor.
26
- const plugins = await (0, init_1.initPlugins)(context);
27
- plugins.push((0, synthetic_1.createBootstrapPlugin)(context), (0, synthetic_1.createMDXFallbackPlugin)(context));
28
- // 2. Plugin Lifecycle - loadContent.
29
- // Currently plugins run lifecycle methods in parallel and are not
30
- // order-dependent. We could change this in future if there are plugins which
31
- // need to run in certain order or depend on others for data.
32
- // This would also translate theme config and content upfront, given the
33
- // translation files that the plugin declares.
34
- const loadedPlugins = await Promise.all(plugins.map(async (plugin) => {
35
- const content = await plugin.loadContent?.();
36
- const rawTranslationFiles = (await plugin.getTranslationFiles?.({ content })) ?? [];
37
- const translationFiles = await Promise.all(rawTranslationFiles.map((translationFile) => (0, translations_1.localizePluginTranslationFile)({
38
- localizationDir: context.localizationDir,
39
- translationFile,
40
- plugin,
41
- })));
42
- const translatedContent = plugin.translateContent?.({ content, translationFiles }) ?? content;
43
- const translatedThemeConfigSlice = plugin.translateThemeConfig?.({
44
- themeConfig: context.siteConfig.themeConfig,
45
- translationFiles,
46
- });
47
- // Side-effect to merge theme config translations. A plugin should only
48
- // translate its own slice of theme config and should make no assumptions
49
- // about other plugins' keys, so this is safe to run in parallel.
50
- Object.assign(context.siteConfig.themeConfig, translatedThemeConfigSlice);
51
- return { ...plugin, content: translatedContent };
52
- }));
53
- const allContent = lodash_1.default.chain(loadedPlugins)
54
- .groupBy((item) => item.name)
55
- .mapValues((nameItems) => lodash_1.default.chain(nameItems)
56
- .groupBy((item) => item.options.id)
57
- .mapValues((idItems) => idItems[0].content)
58
- .value())
59
- .value();
60
- // 3. Plugin Lifecycle - contentLoaded.
61
- const pluginsRouteConfigs = [];
62
- const globalData = {};
63
- await Promise.all(loadedPlugins.map(async ({ content, ...plugin }) => {
64
- if (!plugin.contentLoaded) {
65
- return;
66
- }
67
- const pluginId = plugin.options.id;
68
- // Plugins data files are namespaced by pluginName/pluginId
69
- const dataDir = path_1.default.join(context.generatedFilesDir, plugin.name, pluginId);
70
- const pluginRouteContextModulePath = path_1.default.join(dataDir, `${(0, utils_1.docuHash)('pluginRouteContextModule')}.json`);
71
- const pluginRouteContext = {
72
- name: plugin.name,
73
- id: pluginId,
74
- };
75
- await (0, utils_1.generate)('/', pluginRouteContextModulePath, JSON.stringify(pluginRouteContext, null, 2));
76
- const actions = {
77
- addRoute(initialRouteConfig) {
78
- // Trailing slash behavior is handled generically for all plugins
79
- const finalRouteConfig = (0, routeConfig_1.applyRouteTrailingSlash)(initialRouteConfig, context.siteConfig);
80
- pluginsRouteConfigs.push({
81
- ...finalRouteConfig,
82
- context: {
83
- ...(finalRouteConfig.context && { data: finalRouteConfig.context }),
84
- plugin: pluginRouteContextModulePath,
85
- },
86
- });
87
- },
88
- async createData(name, data) {
89
- const modulePath = path_1.default.join(dataDir, name);
90
- await (0, utils_1.generate)(dataDir, name, data);
91
- return modulePath;
92
- },
93
- setGlobalData(data) {
94
- var _a;
95
- globalData[_a = plugin.name] ?? (globalData[_a] = {});
96
- globalData[plugin.name][pluginId] = data;
97
- },
98
- };
99
- await plugin.contentLoaded({ content, actions, allContent });
100
- }));
101
- // Sort the route config. This ensures that route with nested
102
- // routes are always placed last.
103
- (0, routeConfig_1.sortConfig)(pluginsRouteConfigs, context.siteConfig.baseUrl);
104
- return { plugins: loadedPlugins, pluginsRouteConfigs, globalData };
105
- }
106
- exports.loadPlugins = loadPlugins;