forked from facebook/docusaurus
/
context.ts
27 lines (24 loc) · 861 Bytes
/
context.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {loadContext} from '../../server';
import {initPlugins} from '../../server/plugins/init';
import {loadPluginConfigs} from '../../server/plugins/configs';
import type {SwizzleCLIOptions, SwizzleContext} from './common';
export async function initSwizzleContext(
siteDir: string,
options: SwizzleCLIOptions,
): Promise<SwizzleContext> {
const context = await loadContext({siteDir, config: options.config});
const plugins = await initPlugins(context);
const pluginConfigs = await loadPluginConfigs(context);
return {
plugins: plugins.map((plugin, pluginIndex) => ({
plugin: pluginConfigs[pluginIndex]!,
instance: plugin,
})),
};
}