UNPKG

4.29 kBTypeScriptView Raw
1import type AtomAssetsParser from "./assetParsers/atom";
2import type { IParsedBlockAsset } from "./assetParsers/block";
3import type { IDumiDemoProps } from "./client/theme-api/DumiDemo";
4import type { ILocalesConfig, IThemeConfig } from "./client/theme-api/types";
5import type { IContentTab } from "./features/tabs";
6import type { IThemeLoadResult } from "./features/theme/loader";
7import type { IModify } from '@umijs/core';
8import type { AssetsPackage, ExampleBlockAsset } from 'dumi-assets-types';
9import type { Element } from 'hast';
10import type { defineConfig as defineUmiConfig, IApi as IUmiApi } from 'umi';
11type Subset<K> = {
12 [attr in keyof K]?: K[attr] extends Array<any> ? K[attr] : K[attr] extends Function | undefined ? K[attr] : K[attr] extends object ? Subset<K[attr]> : K[attr] extends object | null ? Subset<K[attr]> | null : K[attr] extends object | null | undefined ? Subset<K[attr]> | null | undefined : K[attr];
13};
14type NoStringIndex<T> = {
15 [K in keyof T as string extends K ? never : K]: T[K];
16};
17type IUmiConfig = Omit<NoStringIndex<Parameters<typeof defineUmiConfig>[0]>, 'resolve' | 'extraRemarkPlugins' | 'extraRehypePlugins' | 'themeConfig'>;
18interface IDumiExtendsConfig {
19 resolve: {
20 docDirs: (string | {
21 type?: string;
22 dir: string;
23 })[];
24 atomDirs: {
25 type: string;
26 subType?: string;
27 dir: string;
28 }[];
29 codeBlockMode: 'active' | 'passive';
30 entryFile?: string;
31 forceKebabCaseRouting: boolean;
32 };
33 locales: ILocalesConfig;
34 themeConfig: IThemeConfig;
35 autoAlias?: boolean;
36 /**
37 * extra unified plugins
38 */
39 extraRemarkPlugins?: (string | Function | [string | Function, object])[];
40 extraRehypePlugins?: (string | Function | [string | Function, object])[];
41}
42export type IDumiConfig = Omit<IUmiConfig, 'locales'> & IDumiExtendsConfig;
43export type IDumiUserConfig = Subset<Omit<IDumiConfig, 'locales'>> & {
44 locales?: Exclude<IDumiConfig['locales'][0], {
45 base: string;
46 }>[] | Omit<Exclude<IDumiConfig['locales'][0], {
47 suffix: string;
48 }>, 'base'>[];
49 [key: string]: any;
50};
51export declare abstract class IDumiTechStack {
52 /**
53 * tech stack name, such as 'react'
54 */
55 abstract name: string;
56 /**
57 * transform code
58 */
59 abstract isSupported(node: Element, lang: string): boolean;
60 /**
61 * transform for parse demo source to react component
62 */
63 abstract transformCode(raw: string, opts: {
64 type: 'external' | 'code-block';
65 fileAbsPath: string;
66 }): string;
67 /**
68 * generator for return asset metadata
69 */
70 abstract generateMetadata?(asset: ExampleBlockAsset, opts: {
71 type: Parameters<IDumiTechStack['transformCode']>[1]['type'];
72 mdAbsPath: string;
73 fileAbsPath?: string;
74 entryPointCode?: string;
75 }): Promise<ExampleBlockAsset> | ExampleBlockAsset;
76 /**
77 * generator for return previewer props
78 */
79 abstract generatePreviewerProps?(props: IDumiDemoProps['previewerProps'], opts: Parameters<NonNullable<IDumiTechStack['generateMetadata']>>[1]): Promise<IDumiDemoProps['previewerProps']> | IDumiDemoProps['previewerProps'];
80 /**
81 * generator for return file path of demo sources
82 */
83 abstract generateSources?(sources: IParsedBlockAsset['sources'], opts: Parameters<NonNullable<IDumiTechStack['generateMetadata']>>[1]): Promise<IParsedBlockAsset['sources']> | IParsedBlockAsset['sources'];
84}
85export type IApi = IUmiApi & {
86 config: IDumiConfig & {
87 [key: string]: any;
88 };
89 userConfig: IDumiUserConfig;
90 service: IUmiApi['service'] & {
91 themeData: IThemeLoadResult;
92 atomParser: AtomAssetsParser;
93 };
94 /**
95 * register a new tech stack
96 */
97 registerTechStack: (fn: () => IDumiTechStack) => void;
98 /**
99 * modify original theme data
100 */
101 modifyTheme: IModify<IThemeLoadResult, null>;
102 /**
103 * add content tab
104 */
105 addContentTab: (fn: () => IContentTab) => void;
106 /**
107 * modify assets metadata
108 */
109 modifyAssetsMetadata: IModify<AssetsPackage, null>;
110 /**
111 * get assets metadata
112 */
113 getAssetsMetadata?: () => Promise<AssetsPackage>;
114};
115export {};