|
| 1 | +import { Application } from "express"; |
| 2 | +import WebpackDevServer from "webpack-dev-server"; |
| 3 | +import { UserPlugins, PluginOptions } from "./plugin"; |
| 4 | +import { ChainWebpack, Hook, AsyncHook } from "./shared"; |
| 5 | +import { Page, Context } from "./context"; |
| 6 | +import { ExtendMarkdown } from "./markdown"; |
| 7 | + |
| 8 | +export type PlainObjectWithStringValue = Record<string, string>; |
| 9 | + |
| 10 | +/** |
| 11 | + * Plugin Life Cycle |
| 12 | + */ |
| 13 | +export type LifeCycleHook$Ready = AsyncHook<[], unknown>; |
| 14 | +export type LifeCycleHook$Updated = Hook<[], unknown>; |
| 15 | +export type LifeCycleHook$Generated = Hook<[], unknown>; |
| 16 | + |
| 17 | +/** |
| 18 | + * Plugin Options API |
| 19 | + */ |
| 20 | +export type PluginEntryOptions = { |
| 21 | + /** |
| 22 | + * Current name |
| 23 | + */ |
| 24 | + name: string; |
| 25 | + /** |
| 26 | + * Sub plugins |
| 27 | + */ |
| 28 | + plugins: UserPlugins; |
| 29 | + /** |
| 30 | + * Edit the internal webpack config with webpack-chain. |
| 31 | + * |
| 32 | + * @see https://vuepress.vuejs.org/plugin/option-api.html#chainwebpack |
| 33 | + */ |
| 34 | + chainWebpack?: ChainWebpack; |
| 35 | + /** |
| 36 | + * Specify define |
| 37 | + * |
| 38 | + * @see https://vuepress.vuejs.org/plugin/option-api.html#define |
| 39 | + */ |
| 40 | + define?: PlainObjectWithStringValue | Hook<[], PlainObjectWithStringValue>; |
| 41 | + /** |
| 42 | + * Specify alias |
| 43 | + * |
| 44 | + * @see https://vuepress.vuejs.org/plugin/option-api.html#alias |
| 45 | + */ |
| 46 | + alias?: PlainObjectWithStringValue; |
| 47 | + /** |
| 48 | + * Equivalent to `before` in `webpack-dev-server` |
| 49 | + * |
| 50 | + * @see https://vuepress.vuejs.org/plugin/option-api.html#beforedevserver |
| 51 | + */ |
| 52 | + beforeDevServer?: Hook<[Application, WebpackDevServer], unknown>; |
| 53 | + /** |
| 54 | + * Equivalent to `after` in `webpack-dev-server` |
| 55 | + * |
| 56 | + * @see https://vuepress.vuejs.org/plugin/option-api.html#afterdevserver |
| 57 | + */ |
| 58 | + afterDevServer?: Hook<[Application, WebpackDevServer], unknown>; |
| 59 | + /** |
| 60 | + * A function to edit default config or apply extra plugins to the `markdown-it` instance. |
| 61 | + * |
| 62 | + * @see https://vuepress.vuejs.org/plugin/option-api.html#extendmarkdown |
| 63 | + */ |
| 64 | + extendMarkdown?: ExtendMarkdown; |
| 65 | + /** |
| 66 | + * Edit the internal Markdown config with `markdown-it-chain` |
| 67 | + * |
| 68 | + * @see https://vuepress.vuejs.org/plugin/option-api.html#chainmarkdown |
| 69 | + */ |
| 70 | + chainMarkdown?: Hook<[], unknown>; |
| 71 | + /** |
| 72 | + * This option accepts absolute file path(s) pointing to the enhancement file(s). |
| 73 | + * |
| 74 | + * @see https://vuepress.vuejs.org/plugin/option-api.html#enhanceappfiles |
| 75 | + */ |
| 76 | + enhanceAppFiles?: |
| 77 | + | string |
| 78 | + | string[] |
| 79 | + | AsyncHook<[], { name: string; content: string }>; |
| 80 | + /** |
| 81 | + * Generate some client modules at compile time. |
| 82 | + * |
| 83 | + * @see https://vuepress.vuejs.org/plugin/option-api.html#clientdynamicmodules |
| 84 | + */ |
| 85 | + clientDynamicModules?: AsyncHook<[], { name: string; content: string }>; |
| 86 | + /** |
| 87 | + * A function used to extend or edit the $page object |
| 88 | + * |
| 89 | + * @see https://vuepress.vuejs.org/plugin/option-api.html#extendpagedata |
| 90 | + */ |
| 91 | + extendPageData: Hook<[Page], unknown>; |
| 92 | + /** |
| 93 | + * A path to the mixin file which allows you to control the lifecycle of root component. |
| 94 | + * |
| 95 | + * @see https://vuepress.vuejs.org/plugin/option-api.html#clientrootmixin |
| 96 | + */ |
| 97 | + clientRootMixin: string; |
| 98 | + /** |
| 99 | + * Add extra pages pointing to a Markdown file: |
| 100 | + * |
| 101 | + * @see https://vuepress.vuejs.org/plugin/option-api.html#additionalpages |
| 102 | + */ |
| 103 | + additionalPages: |
| 104 | + | Array<{ path: string; filePath: string }> |
| 105 | + | AsyncHook< |
| 106 | + [], |
| 107 | + Array<{ |
| 108 | + path: string; |
| 109 | + content: string; |
| 110 | + frontmatter: Record<string, any>; |
| 111 | + }> |
| 112 | + >; |
| 113 | + /** |
| 114 | + * Define global ui components fixed somewhere on the page. |
| 115 | + * |
| 116 | + * @see https://vuepress.vuejs.org/plugin/option-api.html#globaluicomponents |
| 117 | + */ |
| 118 | + globalUIComponents?: string | string[]; |
| 119 | + /** |
| 120 | + * Register a extra command to enhance the CLI of VuePress. |
| 121 | + * |
| 122 | + * @see https://vuepress.vuejs.org/plugin/option-api.html#extendcli |
| 123 | + */ |
| 124 | + extendCli?: Function; |
| 125 | +}; |
| 126 | + |
| 127 | +/** |
| 128 | + * Export type of plugin entry |
| 129 | + * |
| 130 | + * @see https://vuepress.vuejs.org/plugin/writing-a-plugin.html |
| 131 | + */ |
| 132 | +export type PluginEntry = PluginEntryOptions & { |
| 133 | + /** |
| 134 | + * The ready hook is executed after the application is initialized. |
| 135 | + * |
| 136 | + * @see https://vuepress.vuejs.org/plugin/life-cycle.html#ready |
| 137 | + */ |
| 138 | + ready: AsyncHook<[], unknown>; |
| 139 | + /** |
| 140 | + * Trigger when a new compilation is triggered |
| 141 | + * |
| 142 | + * @see https://vuepress.vuejs.org/plugin/life-cycle.html#updated |
| 143 | + */ |
| 144 | + updated: Hook<[], unknown>; |
| 145 | + /** |
| 146 | + * Called when a (production) build finishes, with an array of generated page HTML paths. |
| 147 | + * |
| 148 | + * @see https://vuepress.vuejs.org/plugin/life-cycle.html#generated |
| 149 | + */ |
| 150 | + generated: AsyncHook<[string[]], unknown>; |
| 151 | +}; |
| 152 | + |
| 153 | +/** |
| 154 | + * Export type of plugin entry with function support |
| 155 | + * |
| 156 | + * @see https://vuepress.vuejs.org/plugin/writing-a-plugin.html |
| 157 | + */ |
| 158 | +export type UserPluginEntry<T extends PluginOptions = PluginOptions> = |
| 159 | + | PluginEntry |
| 160 | + | ((options: T, ctx: Context) => PluginEntry); |
0 commit comments