-
Notifications
You must be signed in to change notification settings - Fork 84
/
processPluginOptions.ts
29 lines (27 loc) · 1011 Bytes
/
processPluginOptions.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
28
29
import path from "path";
import { PluginOptions, ProcessedPluginOptions } from "../../shared/interfaces";
export function processPluginOptions(
options: PluginOptions | undefined,
siteDir: string
): ProcessedPluginOptions {
const config = { ...options } as ProcessedPluginOptions;
ensureArray(config, "docsRouteBasePath");
ensureArray(config, "blogRouteBasePath");
ensureArray(config, "language");
ensureArray(config, "docsDir");
ensureArray(config, "blogDir");
config.docsRouteBasePath = config.docsRouteBasePath.map((basePath) =>
basePath.replace(/^\//, "")
);
config.blogRouteBasePath = config.blogRouteBasePath.map((basePath) =>
basePath.replace(/^\//, "")
);
config.docsDir = config.docsDir.map((dir) => path.resolve(siteDir, dir));
config.blogDir = config.blogDir.map((dir) => path.resolve(siteDir, dir));
return config;
}
function ensureArray<T>(object: T, key: keyof T): void {
if (!Array.isArray(object[key])) {
(object as any)[key] = [object[key]];
}
}