From 5709c57daef1724cd455865f0c56e619086ffb0e Mon Sep 17 00:00:00 2001 From: meteorlxy Date: Fri, 13 Sep 2024 01:53:31 +0800 Subject: [PATCH] refactor(core): improve comments --- e2e/docs/.vuepress/plugins/foo/fooPlugin.ts | 3 +- packages/core/src/app/appInit.ts | 2 + packages/core/src/app/appPrepare.ts | 2 + packages/core/src/app/appUse.ts | 7 ++ packages/core/src/app/createBaseApp.ts | 6 +- packages/core/src/app/createBuildApp.ts | 2 +- packages/core/src/app/createDevApp.ts | 2 +- .../src/app/prepare/prepareClientConfigs.ts | 2 + .../core/src/app/prepare/prepareSiteData.ts | 2 + packages/core/src/app/resolveAppDir.ts | 2 + packages/core/src/app/resolveAppEnv.ts | 2 + packages/core/src/app/resolveAppMarkdown.ts | 2 + packages/core/src/app/resolveAppOptions.ts | 2 + packages/core/src/app/resolveAppPages.ts | 2 + packages/core/src/app/resolveAppSiteData.ts | 2 + packages/core/src/app/resolveAppVersion.ts | 2 + packages/core/src/app/resolveAppWriteTemp.ts | 2 + packages/core/src/app/resolvePluginObject.ts | 2 + packages/core/src/app/resolveThemeInfo.ts | 2 + .../core/src/app/setupAppThemeAndPlugins.ts | 2 + packages/core/src/page/createPage.ts | 3 + packages/core/src/page/inferPagePath.ts | 2 + packages/core/src/page/parsePageContent.ts | 2 + .../core/src/page/renderPageSfcBlocksToVue.ts | 2 + .../core/src/page/resolvePageChunkInfo.ts | 2 + .../core/src/page/resolvePageComponentInfo.ts | 2 + packages/core/src/page/resolvePageContent.ts | 2 + packages/core/src/page/resolvePageDate.ts | 2 + packages/core/src/page/resolvePageFilePath.ts | 2 + packages/core/src/page/resolvePageHtmlInfo.ts | 2 + packages/core/src/page/resolvePageLang.ts | 2 + packages/core/src/page/resolvePagePath.ts | 2 + .../core/src/page/resolvePagePermalink.ts | 2 + .../core/src/page/resolvePageRouteMeta.ts | 2 + packages/core/src/page/resolvePageSlug.ts | 2 + .../core/src/pluginApi/createHookQueue.ts | 2 + .../core/src/pluginApi/createPluginApi.ts | 5 ++ .../src/pluginApi/createPluginApiHooks.ts | 5 ++ .../pluginApi/createPluginApiRegisterHooks.ts | 5 ++ .../src/pluginApi/normalizeAliasDefineHook.ts | 2 + .../normalizeClientConfigFileHook.ts | 2 + packages/core/src/types/app/options.ts | 90 ++++++++++++++++++- packages/core/src/types/app/utils.ts | 23 +++++ packages/core/src/types/bundler.ts | 11 +++ packages/core/src/types/plugin.ts | 8 +- 45 files changed, 225 insertions(+), 9 deletions(-) diff --git a/e2e/docs/.vuepress/plugins/foo/fooPlugin.ts b/e2e/docs/.vuepress/plugins/foo/fooPlugin.ts index 93ef0c8cff..a6031278ff 100644 --- a/e2e/docs/.vuepress/plugins/foo/fooPlugin.ts +++ b/e2e/docs/.vuepress/plugins/foo/fooPlugin.ts @@ -1,8 +1,9 @@ +import type { Plugin } from 'vuepress/core' import { getDirname, path } from 'vuepress/utils' const __dirname = getDirname(import.meta.url) -export const fooPlugin = { +export const fooPlugin: Plugin = { name: 'test-plugin', clientConfigFile: path.resolve( __dirname, diff --git a/packages/core/src/app/appInit.ts b/packages/core/src/app/appInit.ts index 1db287fd28..95ce110178 100644 --- a/packages/core/src/app/appInit.ts +++ b/packages/core/src/app/appInit.ts @@ -9,6 +9,8 @@ const log = debug('vuepress:core/app') * Initialize a vuepress app * * Plugins should be used before initialization. + * + * @internal */ export const appInit = async (app: App): Promise => { log('init start') diff --git a/packages/core/src/app/appPrepare.ts b/packages/core/src/app/appPrepare.ts index f8d2585f50..15dd6986b7 100644 --- a/packages/core/src/app/appPrepare.ts +++ b/packages/core/src/app/appPrepare.ts @@ -18,6 +18,8 @@ const log = debug('vuepress:core/app') * - routes * - site data * - other files that generated by plugins + * + * @internal */ export const appPrepare = async (app: App): Promise => { log('prepare start') diff --git a/packages/core/src/app/appUse.ts b/packages/core/src/app/appUse.ts index df53e43cab..9c98443a39 100644 --- a/packages/core/src/app/appUse.ts +++ b/packages/core/src/app/appUse.ts @@ -4,6 +4,13 @@ import { resolvePluginObject } from './resolvePluginObject.js' const log = debug('vuepress:core/app') +/** + * Use a plugin in vuepress app. + * + * Should be called before initialization. + * + * @internal + */ export const appUse = (app: App, rawPlugin: Plugin): App => { const pluginObject = resolvePluginObject(app, rawPlugin) diff --git a/packages/core/src/app/createBaseApp.ts b/packages/core/src/app/createBaseApp.ts index dc2b2ecaf4..dc8b18750d 100644 --- a/packages/core/src/app/createBaseApp.ts +++ b/packages/core/src/app/createBaseApp.ts @@ -17,7 +17,11 @@ import { resolveAppWriteTemp } from './resolveAppWriteTemp.js' import { setupAppThemeAndPlugins } from './setupAppThemeAndPlugins.js' /** - * Create vuepress app + * Create base vuepress app. + * + * Notice that the base app could not be used for dev nor build. + * + * It would be used for creating dev app or build app, or for testing. */ export const createBaseApp = (config: AppConfig): App => { const options = resolveAppOptions(config) diff --git a/packages/core/src/app/createBuildApp.ts b/packages/core/src/app/createBuildApp.ts index 2bc29eddff..13e1651b8e 100644 --- a/packages/core/src/app/createBuildApp.ts +++ b/packages/core/src/app/createBuildApp.ts @@ -2,7 +2,7 @@ import type { AppConfig, BuildApp } from '../types/index.js' import { createBaseApp } from './createBaseApp.js' /** - * Create vuepress build app + * Create vuepress build app. */ export const createBuildApp = (config: AppConfig): BuildApp => { const app = createBaseApp(config) as BuildApp diff --git a/packages/core/src/app/createDevApp.ts b/packages/core/src/app/createDevApp.ts index 3a0f4003e6..3d21ea35ed 100644 --- a/packages/core/src/app/createDevApp.ts +++ b/packages/core/src/app/createDevApp.ts @@ -2,7 +2,7 @@ import type { AppConfig, DevApp } from '../types/index.js' import { createBaseApp } from './createBaseApp.js' /** - * Create vuepress dev app + * Create vuepress dev app. */ export const createDevApp = (config: AppConfig): DevApp => { const app = createBaseApp(config) as DevApp diff --git a/packages/core/src/app/prepare/prepareClientConfigs.ts b/packages/core/src/app/prepare/prepareClientConfigs.ts index 59bb1f5624..4636bd5556 100644 --- a/packages/core/src/app/prepare/prepareClientConfigs.ts +++ b/packages/core/src/app/prepare/prepareClientConfigs.ts @@ -2,6 +2,8 @@ import type { App } from '../../types/index.js' /** * Generate client configs temp file + * + * @internal */ export const prepareClientConfigs = async (app: App): Promise => { // plugin hook: clientConfigFile diff --git a/packages/core/src/app/prepare/prepareSiteData.ts b/packages/core/src/app/prepare/prepareSiteData.ts index c2749c0dc2..7121e72845 100644 --- a/packages/core/src/app/prepare/prepareSiteData.ts +++ b/packages/core/src/app/prepare/prepareSiteData.ts @@ -17,6 +17,8 @@ if (import.meta.hot) { /** * Generate site data temp file + * + * @internal */ export const prepareSiteData = async (app: App): Promise => { let content = `\ diff --git a/packages/core/src/app/resolveAppDir.ts b/packages/core/src/app/resolveAppDir.ts index 5e78b9d344..18819dca9d 100644 --- a/packages/core/src/app/resolveAppDir.ts +++ b/packages/core/src/app/resolveAppDir.ts @@ -6,6 +6,8 @@ const require = createRequire(import.meta.url) /** * Create directory util function + * + * @internal */ export const createAppDirFunction = (baseDir: string): AppDirFunction => diff --git a/packages/core/src/app/resolveAppEnv.ts b/packages/core/src/app/resolveAppEnv.ts index 7ec4bf96c0..d0b069c6a4 100644 --- a/packages/core/src/app/resolveAppEnv.ts +++ b/packages/core/src/app/resolveAppEnv.ts @@ -2,6 +2,8 @@ import type { AppEnv, AppOptions } from '../types/index.js' /** * Resolve environment flags for vuepress app + * + * @internal */ export const resolveAppEnv = (options: AppOptions): AppEnv => ({ isBuild: false, diff --git a/packages/core/src/app/resolveAppMarkdown.ts b/packages/core/src/app/resolveAppMarkdown.ts index 84ce7d0a1a..d3b35b4ef2 100644 --- a/packages/core/src/app/resolveAppMarkdown.ts +++ b/packages/core/src/app/resolveAppMarkdown.ts @@ -4,6 +4,8 @@ import type { App } from '../types/index.js' /** * Resolve markdown-it instance for vuepress app + * + * @internal */ export const resolveAppMarkdown = async (app: App): Promise => { // plugin hook: extendsMarkdownOptions diff --git a/packages/core/src/app/resolveAppOptions.ts b/packages/core/src/app/resolveAppOptions.ts index 63b9379962..756227ffe5 100644 --- a/packages/core/src/app/resolveAppOptions.ts +++ b/packages/core/src/app/resolveAppOptions.ts @@ -6,6 +6,8 @@ const require = createRequire(import.meta.url) /** * Create app options with default values + * + * @internal */ export const resolveAppOptions = ({ // site config diff --git a/packages/core/src/app/resolveAppPages.ts b/packages/core/src/app/resolveAppPages.ts index d8cd00bd41..51ed100308 100644 --- a/packages/core/src/app/resolveAppPages.ts +++ b/packages/core/src/app/resolveAppPages.ts @@ -6,6 +6,8 @@ const log = debug('vuepress:core/app') /** * Resolve pages for vuepress app + * + * @internal */ export const resolveAppPages = async (app: App): Promise => { log('resolveAppPages start') diff --git a/packages/core/src/app/resolveAppSiteData.ts b/packages/core/src/app/resolveAppSiteData.ts index 9f2b654e3e..bc37720131 100644 --- a/packages/core/src/app/resolveAppSiteData.ts +++ b/packages/core/src/app/resolveAppSiteData.ts @@ -4,6 +4,8 @@ import type { AppOptions, SiteData } from '../types/index.js' * Resolve site data for vuepress app * * Site data will also be used in client + * + * @internal */ export const resolveAppSiteData = (options: AppOptions): SiteData => ({ base: options.base, diff --git a/packages/core/src/app/resolveAppVersion.ts b/packages/core/src/app/resolveAppVersion.ts index 590340ffc4..5f356432a3 100644 --- a/packages/core/src/app/resolveAppVersion.ts +++ b/packages/core/src/app/resolveAppVersion.ts @@ -5,6 +5,8 @@ const require = createRequire(import.meta.url) /** * Resolve version of vuepress app + * + * @internal */ export const resolveAppVersion = (): string => { const pkgJson = fs.readJsonSync( diff --git a/packages/core/src/app/resolveAppWriteTemp.ts b/packages/core/src/app/resolveAppWriteTemp.ts index f4e3b6c7d5..2a3560f072 100644 --- a/packages/core/src/app/resolveAppWriteTemp.ts +++ b/packages/core/src/app/resolveAppWriteTemp.ts @@ -3,6 +3,8 @@ import type { AppDir, AppWriteTemp } from '../types/index.js' /** * Resolve write temp file util for vuepress app + * + * @internal */ export const resolveAppWriteTemp = (dir: AppDir): AppWriteTemp => { const writeTemp: AppWriteTemp = async (file: string, content: string) => { diff --git a/packages/core/src/app/resolvePluginObject.ts b/packages/core/src/app/resolvePluginObject.ts index 8ccdd72aaa..4636f48ac0 100644 --- a/packages/core/src/app/resolvePluginObject.ts +++ b/packages/core/src/app/resolvePluginObject.ts @@ -3,6 +3,8 @@ import type { App, Plugin, PluginObject } from '../types/index.js' /** * Resolve a plugin object according to name / path / module and config + * + * @internal */ export const resolvePluginObject = ( app: App, diff --git a/packages/core/src/app/resolveThemeInfo.ts b/packages/core/src/app/resolveThemeInfo.ts index 34e9ff3b0d..b16c371429 100644 --- a/packages/core/src/app/resolveThemeInfo.ts +++ b/packages/core/src/app/resolveThemeInfo.ts @@ -3,6 +3,8 @@ import { resolvePluginObject } from './resolvePluginObject.js' /** * Resolve theme info and its parent theme info + * + * @internal */ export const resolveThemeInfo = (app: App, theme: Theme): ThemeInfo => { // resolve current theme info diff --git a/packages/core/src/app/setupAppThemeAndPlugins.ts b/packages/core/src/app/setupAppThemeAndPlugins.ts index f28c9f04e7..39aceda92b 100644 --- a/packages/core/src/app/setupAppThemeAndPlugins.ts +++ b/packages/core/src/app/setupAppThemeAndPlugins.ts @@ -3,6 +3,8 @@ import { resolveThemeInfo } from './resolveThemeInfo.js' /** * Setup theme and plugins for vuepress app + * + * @internal */ export const setupAppThemeAndPlugins = (app: App, config: AppConfig): void => { // recursively resolve theme info diff --git a/packages/core/src/page/createPage.ts b/packages/core/src/page/createPage.ts index 600d60d63d..2e9946dec2 100644 --- a/packages/core/src/page/createPage.ts +++ b/packages/core/src/page/createPage.ts @@ -13,6 +13,9 @@ import { resolvePagePermalink } from './resolvePagePermalink.js' import { resolvePageRouteMeta } from './resolvePageRouteMeta.js' import { resolvePageSlug } from './resolvePageSlug.js' +/** + * Create vuepress page object + */ export const createPage = async ( app: App, options: PageOptions, diff --git a/packages/core/src/page/inferPagePath.ts b/packages/core/src/page/inferPagePath.ts index 8d082ea93c..2a406c7b66 100644 --- a/packages/core/src/page/inferPagePath.ts +++ b/packages/core/src/page/inferPagePath.ts @@ -7,6 +7,8 @@ import type { App } from '../types/index.js' /** * Infer page path according to file path + * + * @internal */ export const inferPagePath = ({ app, diff --git a/packages/core/src/page/parsePageContent.ts b/packages/core/src/page/parsePageContent.ts index 8af9d92b96..03e036a87e 100644 --- a/packages/core/src/page/parsePageContent.ts +++ b/packages/core/src/page/parsePageContent.ts @@ -9,6 +9,8 @@ import type { App, PageFrontmatter, PageOptions } from '../types/index.js' /** * Render page content and extract related info + * + * @internal */ export const parsePageContent = ({ app, diff --git a/packages/core/src/page/renderPageSfcBlocksToVue.ts b/packages/core/src/page/renderPageSfcBlocksToVue.ts index 7428643823..79f15e92ca 100644 --- a/packages/core/src/page/renderPageSfcBlocksToVue.ts +++ b/packages/core/src/page/renderPageSfcBlocksToVue.ts @@ -2,6 +2,8 @@ import type { MarkdownSfcBlocks } from '@vuepress/markdown' /** * Render page sfc blocks to vue component + * + * @internal */ export const renderPageSfcBlocksToVue = ( sfcBlocks: MarkdownSfcBlocks, diff --git a/packages/core/src/page/resolvePageChunkInfo.ts b/packages/core/src/page/resolvePageChunkInfo.ts index 037018c6cc..0d5c6b994f 100644 --- a/packages/core/src/page/resolvePageChunkInfo.ts +++ b/packages/core/src/page/resolvePageChunkInfo.ts @@ -3,6 +3,8 @@ import type { App } from '../types/index.js' /** * Resolve page data file path + * + * @internal */ export const resolvePageChunkInfo = ({ app, diff --git a/packages/core/src/page/resolvePageComponentInfo.ts b/packages/core/src/page/resolvePageComponentInfo.ts index b1ee312cc4..1e5d4d6156 100644 --- a/packages/core/src/page/resolvePageComponentInfo.ts +++ b/packages/core/src/page/resolvePageComponentInfo.ts @@ -3,6 +3,8 @@ import type { App } from '../types/index.js' /** * Resolve page component and related info + * + * @internal */ export const resolvePageComponentInfo = ({ app, diff --git a/packages/core/src/page/resolvePageContent.ts b/packages/core/src/page/resolvePageContent.ts index c4bda0732b..51a1aa3ab2 100644 --- a/packages/core/src/page/resolvePageContent.ts +++ b/packages/core/src/page/resolvePageContent.ts @@ -9,6 +9,8 @@ const FALLBACK_CONTENT = '' /** * Resolve page content according to `content` or `filePath` + * + * @internal */ export const resolvePageContent = async ({ filePath, diff --git a/packages/core/src/page/resolvePageDate.ts b/packages/core/src/page/resolvePageDate.ts index d371062f68..f9b2d5312c 100644 --- a/packages/core/src/page/resolvePageDate.ts +++ b/packages/core/src/page/resolvePageDate.ts @@ -10,6 +10,8 @@ const DEFAULT_DATE = '0000-00-00' * Resolve page date according to frontmatter or file path * * It will be resolved as 'yyyy-MM-dd' format + * + * @internal */ export const resolvePageDate = ({ frontmatter, diff --git a/packages/core/src/page/resolvePageFilePath.ts b/packages/core/src/page/resolvePageFilePath.ts index ee5a1b01ed..32d34e23a5 100644 --- a/packages/core/src/page/resolvePageFilePath.ts +++ b/packages/core/src/page/resolvePageFilePath.ts @@ -3,6 +3,8 @@ import type { App, PageOptions } from '../types/index.js' /** * Resolve absolute and relative path of page file + * + * @internal */ export const resolvePageFilePath = ({ app, diff --git a/packages/core/src/page/resolvePageHtmlInfo.ts b/packages/core/src/page/resolvePageHtmlInfo.ts index 677921ed04..0417e4edbe 100644 --- a/packages/core/src/page/resolvePageHtmlInfo.ts +++ b/packages/core/src/page/resolvePageHtmlInfo.ts @@ -3,6 +3,8 @@ import type { App } from '../types/index.js' /** * Resolve page rendered html file path + * + * @internal */ export const resolvePageHtmlInfo = ({ app, diff --git a/packages/core/src/page/resolvePageLang.ts b/packages/core/src/page/resolvePageLang.ts index 3f2f243256..d0774e871c 100644 --- a/packages/core/src/page/resolvePageLang.ts +++ b/packages/core/src/page/resolvePageLang.ts @@ -3,6 +3,8 @@ import type { App, PageFrontmatter } from '../types/index.js' /** * Resolve language of page + * + * @internal */ export const resolvePageLang = ({ app, diff --git a/packages/core/src/page/resolvePagePath.ts b/packages/core/src/page/resolvePagePath.ts index c40e366455..0edac439de 100644 --- a/packages/core/src/page/resolvePagePath.ts +++ b/packages/core/src/page/resolvePagePath.ts @@ -3,6 +3,8 @@ import type { PageOptions } from '../types/index.js' /** * Resolve the final route path of a page + * + * @internal */ export const resolvePagePath = ({ permalink, diff --git a/packages/core/src/page/resolvePagePermalink.ts b/packages/core/src/page/resolvePagePermalink.ts index 15a421dec1..4b62c069f7 100644 --- a/packages/core/src/page/resolvePagePermalink.ts +++ b/packages/core/src/page/resolvePagePermalink.ts @@ -4,6 +4,8 @@ import type { App, PageFrontmatter } from '../types/index.js' /** * Resolve page permalink from frontmatter / options / pattern + * + * @internal */ export const resolvePagePermalink = ({ app, diff --git a/packages/core/src/page/resolvePageRouteMeta.ts b/packages/core/src/page/resolvePageRouteMeta.ts index 76e5030a91..fa66e39d36 100644 --- a/packages/core/src/page/resolvePageRouteMeta.ts +++ b/packages/core/src/page/resolvePageRouteMeta.ts @@ -2,6 +2,8 @@ import type { PageFrontmatter } from '../types/index.js' /** * Resolve page route meta + * + * @internal */ export const resolvePageRouteMeta = ({ frontmatter, diff --git a/packages/core/src/page/resolvePageSlug.ts b/packages/core/src/page/resolvePageSlug.ts index a7329ffbaa..f9c3704571 100644 --- a/packages/core/src/page/resolvePageSlug.ts +++ b/packages/core/src/page/resolvePageSlug.ts @@ -4,6 +4,8 @@ const DATE_RE = /(\d{4}-\d{1,2}(-\d{1,2})?)-(.*)/ /** * Resolve page slug from filename + * + * @internal */ export const resolvePageSlug = ({ filePathRelative, diff --git a/packages/core/src/pluginApi/createHookQueue.ts b/packages/core/src/pluginApi/createHookQueue.ts index 09331eee3e..9fb70cc9ad 100644 --- a/packages/core/src/pluginApi/createHookQueue.ts +++ b/packages/core/src/pluginApi/createHookQueue.ts @@ -10,6 +10,8 @@ const log = debug('vuepress:core/plugin-api') /** * Create hook queue for plugin system + * + * @internal */ export const createHookQueue = (name: T): HookQueue => { const items: HookItem[] = [] diff --git a/packages/core/src/pluginApi/createPluginApi.ts b/packages/core/src/pluginApi/createPluginApi.ts index 4f90cda435..18aa270ed7 100644 --- a/packages/core/src/pluginApi/createPluginApi.ts +++ b/packages/core/src/pluginApi/createPluginApi.ts @@ -2,6 +2,11 @@ import type { PluginApi } from '../types/index.js' import { createPluginApiHooks } from './createPluginApiHooks.js' import { createPluginApiRegisterHooks } from './createPluginApiRegisterHooks.js' +/** + * Create vuepress plugin api + * + * @internal + */ export const createPluginApi = (): PluginApi => { const plugins: PluginApi['plugins'] = [] const hooks = createPluginApiHooks() diff --git a/packages/core/src/pluginApi/createPluginApiHooks.ts b/packages/core/src/pluginApi/createPluginApiHooks.ts index 0cefc33067..d8369985bb 100644 --- a/packages/core/src/pluginApi/createPluginApiHooks.ts +++ b/packages/core/src/pluginApi/createPluginApiHooks.ts @@ -1,6 +1,11 @@ import type { PluginApi } from '../types/index.js' import { createHookQueue } from './createHookQueue.js' +/** + * Create hooks for plugin api + * + * @internal + */ export const createPluginApiHooks = (): PluginApi['hooks'] => ({ // life cycle hooks onInitialized: createHookQueue('onInitialized'), diff --git a/packages/core/src/pluginApi/createPluginApiRegisterHooks.ts b/packages/core/src/pluginApi/createPluginApiRegisterHooks.ts index 79ee344016..22c94c4a01 100644 --- a/packages/core/src/pluginApi/createPluginApiRegisterHooks.ts +++ b/packages/core/src/pluginApi/createPluginApiRegisterHooks.ts @@ -2,6 +2,11 @@ import type { PluginApi } from '../types/index.js' import { normalizeAliasDefineHook } from './normalizeAliasDefineHook.js' import { normalizeClientConfigFileHook } from './normalizeClientConfigFileHook.js' +/** + * Create registerHooks method for plugin api + * + * @internal + */ export const createPluginApiRegisterHooks = ( plugins: PluginApi['plugins'], diff --git a/packages/core/src/pluginApi/normalizeAliasDefineHook.ts b/packages/core/src/pluginApi/normalizeAliasDefineHook.ts index 6c3da1a21b..1b12ac361b 100644 --- a/packages/core/src/pluginApi/normalizeAliasDefineHook.ts +++ b/packages/core/src/pluginApi/normalizeAliasDefineHook.ts @@ -3,6 +3,8 @@ import type { AliasDefineHook } from '../types/index.js' /** * Normalize alias and define hook + * + * @internal */ export const normalizeAliasDefineHook = (hook: AliasDefineHook['exposed']): AliasDefineHook['normalized'] => diff --git a/packages/core/src/pluginApi/normalizeClientConfigFileHook.ts b/packages/core/src/pluginApi/normalizeClientConfigFileHook.ts index bba349702c..a6475852e4 100644 --- a/packages/core/src/pluginApi/normalizeClientConfigFileHook.ts +++ b/packages/core/src/pluginApi/normalizeClientConfigFileHook.ts @@ -4,6 +4,8 @@ import type { ClientConfigFileHook } from '../types/index.js' /** * Normalize hook for client config file + * + * @internal */ export const normalizeClientConfigFileHook = (hook: ClientConfigFileHook['exposed']): ClientConfigFileHook['normalized'] => diff --git a/packages/core/src/types/app/options.ts b/packages/core/src/types/app/options.ts index 4cbcabbc37..74a11478f6 100644 --- a/packages/core/src/types/app/options.ts +++ b/packages/core/src/types/app/options.ts @@ -9,18 +9,98 @@ import type { Theme } from '../theme.js' * Vuepress app common config that shared between dev and build */ export interface AppConfigCommon extends Partial { + /** + * Source directory of the markdown files. + * + * Vuepress will load markdown files from this directory. + * + * @required + */ source: string + + /** + * Destination directory of the output files. + * + * Vuepress will output the static site files to this directory. + * + * @default `${source}/.vuepress/dist` + */ dest?: string + + /** + * Temp files directory. + * + * Vuepress will write temp files to this directory. + * + * @default `${source}/.vuepress/.temp` + */ temp?: string + + /** + * Cache files directory. + * + * Vuepress will write cache files to this directory. + * + * @default `${source}/.vuepress/.cache` + */ cache?: string + + /** + * Public files directory. + * + * Vuepress will copy the files from public directory to the output directory. + * + * @default `${source}/.vuepress/public` + */ public?: string + /** + * Whether to enable debug mode + * + * @default false + */ debug?: boolean + + /** + * Markdown options + * + * @default {} + */ markdown?: MarkdownOptions + + /** + * Patterns to match the markdown files as pages + * + * @default ['**\/*.md', '!.vuepress', '!node_modules'] + */ pagePatterns?: string[] + + /** + * Pattern to generate permalink for pages + * + * @default null + */ permalinkPattern?: string | null + + /** + * Vuepress bundler + * + * @required + */ bundler: Bundler + + /** + * Vuepress theme + * + * @required + */ theme: Theme + + /** + * Vuepress plugins + * + * @default [] + */ plugins?: PluginConfig } @@ -87,17 +167,21 @@ export interface AppConfigBuild { /** * Specify the HTML template renderer to be used for build * - * @default templateRenderer from '@vuepress/utils' + * @default `import { templateRenderer } from '@vuepress/utils'` */ templateBuildRenderer?: TemplateRenderer } /** - * Vuepress app config + * Vuepress app user config. + * + * It would be provided by user, typically via a config file. */ export type AppConfig = AppConfigBuild & AppConfigCommon & AppConfigDev /** - * Vuepress app options + * Vuepress app options that resolved from user config. + * + * It fills all optional fields with a default value. */ export type AppOptions = Required diff --git a/packages/core/src/types/app/utils.ts b/packages/core/src/types/app/utils.ts index 0e70eb5508..fdfb3fd4a7 100644 --- a/packages/core/src/types/app/utils.ts +++ b/packages/core/src/types/app/utils.ts @@ -7,11 +7,34 @@ export type AppDirFunction = (...args: string[]) => string * Directory utils */ export interface AppDir { + /** + * Resolve file path in cache directory + */ cache: AppDirFunction + + /** + * Resolve file path in temp directory + */ temp: AppDirFunction + + /** + * Resolve file path in source directory + */ source: AppDirFunction + + /** + * Resolve file path in dest directory + */ dest: AppDirFunction + + /** + * Resolve file path in public directory + */ public: AppDirFunction + + /** + * Resolve file path in client directory + */ client: AppDirFunction } diff --git a/packages/core/src/types/bundler.ts b/packages/core/src/types/bundler.ts index cd3b8dc2a7..0f8e64fa78 100644 --- a/packages/core/src/types/bundler.ts +++ b/packages/core/src/types/bundler.ts @@ -8,8 +8,19 @@ import type { App } from './app/index.js' * - build: bundle assets for deployment */ export interface Bundler { + /** + * Name of the bundler + */ name: string + + /** + * Method to run vuepress app in dev mode, starting dev server + */ dev: (app: App) => Promise<() => Promise> + + /** + * Method to run vuepress app in build mode, generating static pages and assets + */ build: (app: App) => Promise } diff --git a/packages/core/src/types/plugin.ts b/packages/core/src/types/plugin.ts index ae52a6b334..99e65f7517 100644 --- a/packages/core/src/types/plugin.ts +++ b/packages/core/src/types/plugin.ts @@ -27,10 +27,14 @@ export type PluginFunction = ( * Vuepress plugin object */ export interface PluginObject extends Partial { - // plugin name + /** + * Name of the plugin + */ name: string - // allow use a plugin multiple times or not + /** + * Allow the plugin to be used multiple times or not + */ multiple?: boolean }