mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-09 23:27:28 +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
|
@ -8,7 +8,7 @@
|
|||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import pluginContentBlog from '../index';
|
||||
import {DocusaurusConfig} from '../typesDocusaurus';
|
||||
import {DocusaurusConfig} from '@docusaurus/types';
|
||||
|
||||
describe('loadBlog', () => {
|
||||
test('simple website', async () => {
|
||||
|
|
|
@ -19,13 +19,13 @@ import {
|
|||
BlogContent,
|
||||
BlogItemsToModules,
|
||||
TagsModule,
|
||||
ConfigureWebpackUtils,
|
||||
} from './types';
|
||||
import {
|
||||
LoadContext,
|
||||
PluginContentLoadedActions,
|
||||
RouteModule,
|
||||
} from './typesDocusaurus';
|
||||
ConfigureWebpackUtils,
|
||||
} from '@docusaurus/types';
|
||||
import {Configuration} from 'webpack';
|
||||
|
||||
// YYYY-MM-DD-{name}.mdx?
|
||||
|
@ -57,7 +57,7 @@ export default function pluginContentBlog(
|
|||
context: LoadContext,
|
||||
opts: Partial<PluginOptions>,
|
||||
) {
|
||||
const options = {...DEFAULT_OPTIONS, ...opts};
|
||||
const options: PluginOptions = {...DEFAULT_OPTIONS, ...opts};
|
||||
const contentPath = path.resolve(context.siteDir, options.path);
|
||||
|
||||
return {
|
||||
|
@ -79,7 +79,7 @@ export default function pluginContentBlog(
|
|||
return null;
|
||||
}
|
||||
|
||||
const {baseUrl} = siteConfig;
|
||||
const {baseUrl = ''} = siteConfig;
|
||||
const blogFiles = await globby(include, {
|
||||
cwd: blogDir,
|
||||
});
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import {Loader} from 'webpack';
|
||||
|
||||
export interface BlogContent {
|
||||
blogPosts: BlogPost[];
|
||||
blogListPaginated: BlogPaginated[];
|
||||
|
@ -80,14 +78,3 @@ export interface TagModule {
|
|||
count: number;
|
||||
permalink: string;
|
||||
}
|
||||
|
||||
export interface ConfigureWebpackUtils {
|
||||
getStyleLoaders: (
|
||||
isServer: boolean,
|
||||
cssOptions: {
|
||||
[key: string]: any;
|
||||
},
|
||||
) => Loader[];
|
||||
getCacheLoader: (isServer: boolean, cacheOptions?: {}) => Loader | null;
|
||||
getBabelLoader: (isServer: boolean, babelOptions?: {}) => Loader;
|
||||
}
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
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 type PluginConfig = [string, Object | undefined] | string;
|
||||
|
||||
export type PresetConfig = [string, Object | undefined] | string;
|
||||
|
||||
export interface CLIOptions {
|
||||
[option: string]: any;
|
||||
}
|
||||
|
||||
export interface LoadContext {
|
||||
siteDir: string;
|
||||
generatedFilesDir?: string;
|
||||
siteConfig: DocusaurusConfig;
|
||||
cliOptions?: CLIOptions;
|
||||
outDir?: string;
|
||||
baseUrl?: string;
|
||||
}
|
||||
|
||||
export interface PluginContentLoadedActions {
|
||||
addRoute(config: RouteConfig): void;
|
||||
createData(name: string, data: Object): Promise<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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue