Skip to content

Commit 5709c57

Browse files
committed
refactor(core): improve comments
1 parent 017abb3 commit 5709c57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+225
-9
lines changed

e2e/docs/.vuepress/plugins/foo/fooPlugin.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import type { Plugin } from 'vuepress/core'
12
import { getDirname, path } from 'vuepress/utils'
23

34
const __dirname = getDirname(import.meta.url)
45

5-
export const fooPlugin = {
6+
export const fooPlugin: Plugin = {
67
name: 'test-plugin',
78
clientConfigFile: path.resolve(
89
__dirname,

packages/core/src/app/appInit.ts

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const log = debug('vuepress:core/app')
99
* Initialize a vuepress app
1010
*
1111
* Plugins should be used before initialization.
12+
*
13+
* @internal
1214
*/
1315
export const appInit = async (app: App): Promise<void> => {
1416
log('init start')

packages/core/src/app/appPrepare.ts

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const log = debug('vuepress:core/app')
1818
* - routes
1919
* - site data
2020
* - other files that generated by plugins
21+
*
22+
* @internal
2123
*/
2224
export const appPrepare = async (app: App): Promise<void> => {
2325
log('prepare start')

packages/core/src/app/appUse.ts

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import { resolvePluginObject } from './resolvePluginObject.js'
44

55
const log = debug('vuepress:core/app')
66

7+
/**
8+
* Use a plugin in vuepress app.
9+
*
10+
* Should be called before initialization.
11+
*
12+
* @internal
13+
*/
714
export const appUse = (app: App, rawPlugin: Plugin): App => {
815
const pluginObject = resolvePluginObject(app, rawPlugin)
916

packages/core/src/app/createBaseApp.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ import { resolveAppWriteTemp } from './resolveAppWriteTemp.js'
1717
import { setupAppThemeAndPlugins } from './setupAppThemeAndPlugins.js'
1818

1919
/**
20-
* Create vuepress app
20+
* Create base vuepress app.
21+
*
22+
* Notice that the base app could not be used for dev nor build.
23+
*
24+
* It would be used for creating dev app or build app, or for testing.
2125
*/
2226
export const createBaseApp = (config: AppConfig): App => {
2327
const options = resolveAppOptions(config)

packages/core/src/app/createBuildApp.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { AppConfig, BuildApp } from '../types/index.js'
22
import { createBaseApp } from './createBaseApp.js'
33

44
/**
5-
* Create vuepress build app
5+
* Create vuepress build app.
66
*/
77
export const createBuildApp = (config: AppConfig): BuildApp => {
88
const app = createBaseApp(config) as BuildApp

packages/core/src/app/createDevApp.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { AppConfig, DevApp } from '../types/index.js'
22
import { createBaseApp } from './createBaseApp.js'
33

44
/**
5-
* Create vuepress dev app
5+
* Create vuepress dev app.
66
*/
77
export const createDevApp = (config: AppConfig): DevApp => {
88
const app = createBaseApp(config) as DevApp

packages/core/src/app/prepare/prepareClientConfigs.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { App } from '../../types/index.js'
22

33
/**
44
* Generate client configs temp file
5+
*
6+
* @internal
57
*/
68
export const prepareClientConfigs = async (app: App): Promise<void> => {
79
// plugin hook: clientConfigFile

packages/core/src/app/prepare/prepareSiteData.ts

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ if (import.meta.hot) {
1717

1818
/**
1919
* Generate site data temp file
20+
*
21+
* @internal
2022
*/
2123
export const prepareSiteData = async (app: App): Promise<void> => {
2224
let content = `\

packages/core/src/app/resolveAppDir.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const require = createRequire(import.meta.url)
66

77
/**
88
* Create directory util function
9+
*
10+
* @internal
911
*/
1012
export const createAppDirFunction =
1113
(baseDir: string): AppDirFunction =>

packages/core/src/app/resolveAppEnv.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { AppEnv, AppOptions } from '../types/index.js'
22

33
/**
44
* Resolve environment flags for vuepress app
5+
*
6+
* @internal
57
*/
68
export const resolveAppEnv = (options: AppOptions): AppEnv => ({
79
isBuild: false,

packages/core/src/app/resolveAppMarkdown.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type { App } from '../types/index.js'
44

55
/**
66
* Resolve markdown-it instance for vuepress app
7+
*
8+
* @internal
79
*/
810
export const resolveAppMarkdown = async (app: App): Promise<Markdown> => {
911
// plugin hook: extendsMarkdownOptions

packages/core/src/app/resolveAppOptions.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const require = createRequire(import.meta.url)
66

77
/**
88
* Create app options with default values
9+
*
10+
* @internal
911
*/
1012
export const resolveAppOptions = ({
1113
// site config

packages/core/src/app/resolveAppPages.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const log = debug('vuepress:core/app')
66

77
/**
88
* Resolve pages for vuepress app
9+
*
10+
* @internal
911
*/
1012
export const resolveAppPages = async (app: App): Promise<Page[]> => {
1113
log('resolveAppPages start')

packages/core/src/app/resolveAppSiteData.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type { AppOptions, SiteData } from '../types/index.js'
44
* Resolve site data for vuepress app
55
*
66
* Site data will also be used in client
7+
*
8+
* @internal
79
*/
810
export const resolveAppSiteData = (options: AppOptions): SiteData => ({
911
base: options.base,

packages/core/src/app/resolveAppVersion.ts

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const require = createRequire(import.meta.url)
55

66
/**
77
* Resolve version of vuepress app
8+
*
9+
* @internal
810
*/
911
export const resolveAppVersion = (): string => {
1012
const pkgJson = fs.readJsonSync(

packages/core/src/app/resolveAppWriteTemp.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { AppDir, AppWriteTemp } from '../types/index.js'
33

44
/**
55
* Resolve write temp file util for vuepress app
6+
*
7+
* @internal
68
*/
79
export const resolveAppWriteTemp = (dir: AppDir): AppWriteTemp => {
810
const writeTemp: AppWriteTemp = async (file: string, content: string) => {

packages/core/src/app/resolvePluginObject.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { App, Plugin, PluginObject } from '../types/index.js'
33

44
/**
55
* Resolve a plugin object according to name / path / module and config
6+
*
7+
* @internal
68
*/
79
export const resolvePluginObject = <T extends PluginObject = PluginObject>(
810
app: App,

packages/core/src/app/resolveThemeInfo.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { resolvePluginObject } from './resolvePluginObject.js'
33

44
/**
55
* Resolve theme info and its parent theme info
6+
*
7+
* @internal
68
*/
79
export const resolveThemeInfo = (app: App, theme: Theme): ThemeInfo => {
810
// resolve current theme info

packages/core/src/app/setupAppThemeAndPlugins.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { resolveThemeInfo } from './resolveThemeInfo.js'
33

44
/**
55
* Setup theme and plugins for vuepress app
6+
*
7+
* @internal
68
*/
79
export const setupAppThemeAndPlugins = (app: App, config: AppConfig): void => {
810
// recursively resolve theme info

packages/core/src/page/createPage.ts

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import { resolvePagePermalink } from './resolvePagePermalink.js'
1313
import { resolvePageRouteMeta } from './resolvePageRouteMeta.js'
1414
import { resolvePageSlug } from './resolvePageSlug.js'
1515

16+
/**
17+
* Create vuepress page object
18+
*/
1619
export const createPage = async (
1720
app: App,
1821
options: PageOptions,

packages/core/src/page/inferPagePath.ts

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import type { App } from '../types/index.js'
77

88
/**
99
* Infer page path according to file path
10+
*
11+
* @internal
1012
*/
1113
export const inferPagePath = ({
1214
app,

packages/core/src/page/parsePageContent.ts

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import type { App, PageFrontmatter, PageOptions } from '../types/index.js'
99

1010
/**
1111
* Render page content and extract related info
12+
*
13+
* @internal
1214
*/
1315
export const parsePageContent = ({
1416
app,

packages/core/src/page/renderPageSfcBlocksToVue.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { MarkdownSfcBlocks } from '@vuepress/markdown'
22

33
/**
44
* Render page sfc blocks to vue component
5+
*
6+
* @internal
57
*/
68
export const renderPageSfcBlocksToVue = (
79
sfcBlocks: MarkdownSfcBlocks,

packages/core/src/page/resolvePageChunkInfo.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { App } from '../types/index.js'
33

44
/**
55
* Resolve page data file path
6+
*
7+
* @internal
68
*/
79
export const resolvePageChunkInfo = ({
810
app,

packages/core/src/page/resolvePageComponentInfo.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { App } from '../types/index.js'
33

44
/**
55
* Resolve page component and related info
6+
*
7+
* @internal
68
*/
79
export const resolvePageComponentInfo = ({
810
app,

packages/core/src/page/resolvePageContent.ts

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const FALLBACK_CONTENT = ''
99

1010
/**
1111
* Resolve page content according to `content` or `filePath`
12+
*
13+
* @internal
1214
*/
1315
export const resolvePageContent = async ({
1416
filePath,

packages/core/src/page/resolvePageDate.ts

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const DEFAULT_DATE = '0000-00-00'
1010
* Resolve page date according to frontmatter or file path
1111
*
1212
* It will be resolved as 'yyyy-MM-dd' format
13+
*
14+
* @internal
1315
*/
1416
export const resolvePageDate = ({
1517
frontmatter,

packages/core/src/page/resolvePageFilePath.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { App, PageOptions } from '../types/index.js'
33

44
/**
55
* Resolve absolute and relative path of page file
6+
*
7+
* @internal
68
*/
79
export const resolvePageFilePath = ({
810
app,

packages/core/src/page/resolvePageHtmlInfo.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { App } from '../types/index.js'
33

44
/**
55
* Resolve page rendered html file path
6+
*
7+
* @internal
68
*/
79
export const resolvePageHtmlInfo = ({
810
app,

packages/core/src/page/resolvePageLang.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { App, PageFrontmatter } from '../types/index.js'
33

44
/**
55
* Resolve language of page
6+
*
7+
* @internal
68
*/
79
export const resolvePageLang = ({
810
app,

packages/core/src/page/resolvePagePath.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { PageOptions } from '../types/index.js'
33

44
/**
55
* Resolve the final route path of a page
6+
*
7+
* @internal
68
*/
79
export const resolvePagePath = ({
810
permalink,

packages/core/src/page/resolvePagePermalink.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type { App, PageFrontmatter } from '../types/index.js'
44

55
/**
66
* Resolve page permalink from frontmatter / options / pattern
7+
*
8+
* @internal
79
*/
810
export const resolvePagePermalink = ({
911
app,

packages/core/src/page/resolvePageRouteMeta.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { PageFrontmatter } from '../types/index.js'
22

33
/**
44
* Resolve page route meta
5+
*
6+
* @internal
57
*/
68
export const resolvePageRouteMeta = ({
79
frontmatter,

packages/core/src/page/resolvePageSlug.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const DATE_RE = /(\d{4}-\d{1,2}(-\d{1,2})?)-(.*)/
44

55
/**
66
* Resolve page slug from filename
7+
*
8+
* @internal
79
*/
810
export const resolvePageSlug = ({
911
filePathRelative,

packages/core/src/pluginApi/createHookQueue.ts

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const log = debug('vuepress:core/plugin-api')
1010

1111
/**
1212
* Create hook queue for plugin system
13+
*
14+
* @internal
1315
*/
1416
export const createHookQueue = <T extends HooksName>(name: T): HookQueue<T> => {
1517
const items: HookItem<T>[] = []

packages/core/src/pluginApi/createPluginApi.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import type { PluginApi } from '../types/index.js'
22
import { createPluginApiHooks } from './createPluginApiHooks.js'
33
import { createPluginApiRegisterHooks } from './createPluginApiRegisterHooks.js'
44

5+
/**
6+
* Create vuepress plugin api
7+
*
8+
* @internal
9+
*/
510
export const createPluginApi = (): PluginApi => {
611
const plugins: PluginApi['plugins'] = []
712
const hooks = createPluginApiHooks()

packages/core/src/pluginApi/createPluginApiHooks.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import type { PluginApi } from '../types/index.js'
22
import { createHookQueue } from './createHookQueue.js'
33

4+
/**
5+
* Create hooks for plugin api
6+
*
7+
* @internal
8+
*/
49
export const createPluginApiHooks = (): PluginApi['hooks'] => ({
510
// life cycle hooks
611
onInitialized: createHookQueue('onInitialized'),

packages/core/src/pluginApi/createPluginApiRegisterHooks.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import type { PluginApi } from '../types/index.js'
22
import { normalizeAliasDefineHook } from './normalizeAliasDefineHook.js'
33
import { normalizeClientConfigFileHook } from './normalizeClientConfigFileHook.js'
44

5+
/**
6+
* Create registerHooks method for plugin api
7+
*
8+
* @internal
9+
*/
510
export const createPluginApiRegisterHooks =
611
(
712
plugins: PluginApi['plugins'],

packages/core/src/pluginApi/normalizeAliasDefineHook.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { AliasDefineHook } from '../types/index.js'
33

44
/**
55
* Normalize alias and define hook
6+
*
7+
* @internal
68
*/
79
export const normalizeAliasDefineHook =
810
(hook: AliasDefineHook['exposed']): AliasDefineHook['normalized'] =>

packages/core/src/pluginApi/normalizeClientConfigFileHook.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type { ClientConfigFileHook } from '../types/index.js'
44

55
/**
66
* Normalize hook for client config file
7+
*
8+
* @internal
79
*/
810
export const normalizeClientConfigFileHook =
911
(hook: ClientConfigFileHook['exposed']): ClientConfigFileHook['normalized'] =>

0 commit comments

Comments
 (0)