mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-03 00:39:45 +02:00
refactor(v2): add common typing package @docusaurus/types
(#1797)
* add common typing package `@docusaurus/typing-common` . * change name to `@docusaurus/types` * refactor `packages/docusaurus/src/server/types` * use directly `index.d.ts` . * add missing dependency `@docusaurus/types` on `@docusaurus/core` * add missing dependency `@types/webpack` * fix mistaken type * typing package move to dev dependency * Update package.json see https://stackoverflow.com/questions/45176661/how-do-i-decide-whether-types-goes-into-dependencies-or-devdependencies
This commit is contained in:
parent
0397f7b719
commit
961eb44ab1
28 changed files with 81 additions and 113 deletions
15
packages/docusaurus-types/package.json
Normal file
15
packages/docusaurus-types/package.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "@docusaurus/types",
|
||||
"version": "2.0.0-alpha.24",
|
||||
"description": "Common used typings for Docusaurus packages",
|
||||
"main": "./src/index.js",
|
||||
"types": "./src/index.d.ts",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/webpack": "^4.32.0",
|
||||
"querystring": "0.2.0"
|
||||
}
|
||||
}
|
116
packages/docusaurus-types/src/index.d.ts
vendored
Normal file
116
packages/docusaurus-types/src/index.d.ts
vendored
Normal file
|
@ -0,0 +1,116 @@
|
|||
import {Loader, Configuration} from 'webpack';
|
||||
import {ParsedUrlQueryInput} from 'querystring';
|
||||
|
||||
export interface DocusaurusConfig {
|
||||
baseUrl: string;
|
||||
favicon: string;
|
||||
tagline: string;
|
||||
title: string;
|
||||
url: string;
|
||||
organizationName?: string;
|
||||
projectName?: string;
|
||||
githubHost?: string;
|
||||
plugins?: PluginConfig[];
|
||||
themes?: PluginConfig[];
|
||||
presets?: PresetConfig[];
|
||||
themeConfig?: {
|
||||
[key: string]: any;
|
||||
};
|
||||
customFields?: {
|
||||
[key: string]: any;
|
||||
};
|
||||
}
|
||||
|
||||
export interface DocusaurusContext {
|
||||
siteConfig?: Partial<DocusaurusConfig>;
|
||||
}
|
||||
|
||||
export interface Preset {
|
||||
plugins?: PluginConfig[];
|
||||
themes?: PluginConfig[];
|
||||
}
|
||||
|
||||
export type PresetConfig = [string, Object] | [string] | string;
|
||||
|
||||
export interface CLIOptions {
|
||||
[option: string]: any;
|
||||
}
|
||||
|
||||
export interface LoadContext {
|
||||
siteDir: string;
|
||||
generatedFilesDir: string;
|
||||
siteConfig: Partial<DocusaurusConfig>;
|
||||
cliOptions: CLIOptions;
|
||||
outDir: string;
|
||||
baseUrl: string;
|
||||
}
|
||||
|
||||
export interface Props extends LoadContext {
|
||||
routesPaths: string[];
|
||||
plugins: Plugin<any>[];
|
||||
}
|
||||
|
||||
export interface PluginContentLoadedActions {
|
||||
addRoute(config: RouteConfig): void;
|
||||
createData(name: string, data: Object): Promise<string>;
|
||||
}
|
||||
|
||||
export interface Plugin<T> {
|
||||
name: string;
|
||||
loadContent?(): T;
|
||||
contentLoaded?({
|
||||
content,
|
||||
actions,
|
||||
}: {
|
||||
content: T;
|
||||
actions: PluginContentLoadedActions;
|
||||
}): void;
|
||||
postBuild?(props: Props): void;
|
||||
postStart?(props: Props): void;
|
||||
configureWebpack?(config: Configuration, isServer: boolean): Configuration;
|
||||
getThemePath?(): string;
|
||||
getPathsToWatch?(): string[];
|
||||
getClientModules?(): string[];
|
||||
}
|
||||
|
||||
export type PluginConfig = [string, Object] | [string] | string;
|
||||
|
||||
export interface ChunkRegistry {
|
||||
importStatement: string;
|
||||
modulePath: string;
|
||||
}
|
||||
|
||||
export type Module =
|
||||
| {
|
||||
path: string;
|
||||
__import?: boolean;
|
||||
query?: ParsedUrlQueryInput;
|
||||
}
|
||||
| string;
|
||||
|
||||
export interface RouteModule {
|
||||
[module: string]: Module | RouteModule | RouteModule[];
|
||||
}
|
||||
|
||||
export interface RouteConfig {
|
||||
path: string;
|
||||
component: string;
|
||||
modules?: RouteModule;
|
||||
routes?: RouteConfig[];
|
||||
exact?: boolean;
|
||||
}
|
||||
|
||||
export interface ThemeAlias {
|
||||
[alias: string]: string;
|
||||
}
|
||||
|
||||
export interface ConfigureWebpackUtils {
|
||||
getStyleLoaders: (
|
||||
isServer: boolean,
|
||||
cssOptions: {
|
||||
[key: string]: any;
|
||||
},
|
||||
) => Loader[];
|
||||
getCacheLoader: (isServer: boolean, cacheOptions?: {}) => Loader | null;
|
||||
getBabelLoader: (isServer: boolean, babelOptions?: {}) => Loader;
|
||||
}
|
3
packages/docusaurus-types/src/index.js
Normal file
3
packages/docusaurus-types/src/index.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
/* eslint-disable */
|
||||
'use strict';
|
||||
Object.defineProperty(exports, '__esModule', {value: true});
|
Loading…
Add table
Add a link
Reference in a new issue