UNPKG

3.85 kBTypeScriptView Raw
1/**
2 * Copyright (c) 2017-present, Facebook, Inc.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8import {Loader, Configuration} from 'webpack';
9import {Command} from 'commander';
10import {ParsedUrlQueryInput} from 'querystring';
11
12export interface DocusaurusConfig {
13 baseUrl: string;
14 favicon: string;
15 tagline: string;
16 title: string;
17 url: string;
18 organizationName?: string;
19 projectName?: string;
20 githubHost?: string;
21 plugins?: PluginConfig[];
22 themes?: PluginConfig[];
23 presets?: PresetConfig[];
24 themeConfig?: {
25 [key: string]: any;
26 };
27 customFields?: {
28 [key: string]: any;
29 };
30 scripts?: (
31 | string
32 | {
33 src: string;
34 [key: string]: any;
35 }
36 )[];
37 stylesheets?: (
38 | string
39 | {
40 href: string;
41 [key: string]: any;
42 }
43 )[];
44}
45
46export interface DocusaurusContext {
47 siteConfig?: DocusaurusConfig;
48}
49
50export interface Preset {
51 plugins?: PluginConfig[];
52 themes?: PluginConfig[];
53}
54
55export type PresetConfig = [string, Object] | [string] | string;
56
57export interface StartCLIOptions {
58 port: string;
59 host: string;
60 hotOnly: boolean;
61 open: boolean;
62}
63
64export interface BuildCLIOptions {
65 bundleAnalyzer: boolean;
66}
67
68export interface LoadContext {
69 siteDir: string;
70 generatedFilesDir: string;
71 siteConfig: DocusaurusConfig;
72 outDir: string;
73 baseUrl: string;
74}
75
76export interface InjectedHtmlTags {
77 headTags: string;
78 preBodyTags: string;
79 postBodyTags: string;
80}
81
82export type HtmlTags = string | HtmlTagObject | (string | HtmlTagObject)[];
83
84export interface Props extends LoadContext, InjectedHtmlTags {
85 routesPaths: string[];
86 plugins: Plugin<any>[];
87}
88
89export interface PluginContentLoadedActions {
90 addRoute(config: RouteConfig): void;
91 createData(name: string, data: any): Promise<string>;
92}
93
94export interface Plugin<T> {
95 name: string;
96 loadContent?(): Promise<T>;
97 contentLoaded?({
98 content,
99 actions,
100 }: {
101 content: T;
102 actions: PluginContentLoadedActions;
103 }): void;
104 postBuild?(props: Props): void;
105 postStart?(props: Props): void;
106 configureWebpack?(
107 config: Configuration,
108 isServer: boolean,
109 utils: ConfigureWebpackUtils,
110 ): Configuration;
111 getThemePath?(): string;
112 getPathsToWatch?(): string[];
113 getClientModules?(): string[];
114 extendCli?(cli: Command): void;
115 injectHtmlTags?(): {
116 headTags?: HtmlTags;
117 preBodyTags?: HtmlTags;
118 postBodyTags?: HtmlTags;
119 };
120}
121
122export type PluginConfig = [string, Object] | [string] | string;
123
124export interface ChunkRegistry {
125 loader: string;
126 modulePath: string;
127}
128
129export type Module =
130 | {
131 path: string;
132 __import?: boolean;
133 query?: ParsedUrlQueryInput;
134 }
135 | string;
136
137export interface RouteModule {
138 [module: string]: Module | RouteModule | RouteModule[];
139}
140
141export interface ChunkNames {
142 [name: string]: string | null | ChunkNames | ChunkNames[];
143}
144
145export interface RouteConfig {
146 path: string;
147 component: string;
148 modules?: RouteModule;
149 routes?: RouteConfig[];
150 exact?: boolean;
151 priority?: number;
152}
153
154export interface ThemeAlias {
155 [alias: string]: string;
156}
157
158export interface ConfigureWebpackUtils {
159 getStyleLoaders: (
160 isServer: boolean,
161 cssOptions: {
162 [key: string]: any;
163 },
164 ) => Loader[];
165 getCacheLoader: (isServer: boolean, cacheOptions?: {}) => Loader | null;
166 getBabelLoader: (isServer: boolean, babelOptions?: {}) => Loader;
167}
168
169interface HtmlTagObject {
170 /**
171 * Attributes of the html tag
172 * E.g. `{'disabled': true, 'value': 'demo', 'rel': 'preconnect'}`
173 */
174 attributes?: {
175 [attributeName: string]: string | boolean;
176 };
177 /**
178 * The tag name e.g. `div`, `script`, `link`, `meta`
179 */
180 tagName: string;
181 /**
182 * The inner HTML
183 */
184 innerHTML?: string;
185}