@vuepress/core 2.0.0-beta.9 → 2.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +12 -0
- package/dist/index.d.ts +845 -0
- package/dist/index.js +1039 -0
- package/package.json +36 -19
- package/CHANGELOG.md +0 -338
- package/lib/app/appInit.d.ts +0 -7
- package/lib/app/appInit.js +0 -26
- package/lib/app/appPrepare.d.ts +0 -10
- package/lib/app/appPrepare.js +0 -46
- package/lib/app/appUse.d.ts +0 -2
- package/lib/app/appUse.js +0 -28
- package/lib/app/appUseByConfig.d.ts +0 -2
- package/lib/app/appUseByConfig.js +0 -11
- package/lib/app/createApp.d.ts +0 -5
- package/lib/app/createApp.js +0 -55
- package/lib/app/createAppDir.d.ts +0 -9
- package/lib/app/createAppDir.js +0 -32
- package/lib/app/createAppEnv.d.ts +0 -5
- package/lib/app/createAppEnv.js +0 -14
- package/lib/app/createAppOptions.d.ts +0 -5
- package/lib/app/createAppOptions.js +0 -47
- package/lib/app/createAppPages.d.ts +0 -5
- package/lib/app/createAppPages.js +0 -36
- package/lib/app/createAppSiteData.d.ts +0 -7
- package/lib/app/createAppSiteData.js +0 -19
- package/lib/app/createAppVersion.d.ts +0 -4
- package/lib/app/createAppVersion.js +0 -10
- package/lib/app/createAppWriteTemp.d.ts +0 -5
- package/lib/app/createAppWriteTemp.js +0 -21
- package/lib/app/index.d.ts +0 -16
- package/lib/app/index.js +0 -28
- package/lib/app/normalizePlugin.d.ts +0 -2
- package/lib/app/normalizePlugin.js +0 -17
- package/lib/app/normalizePluginConfig.d.ts +0 -2
- package/lib/app/normalizePluginConfig.js +0 -15
- package/lib/app/prepare/index.d.ts +0 -12
- package/lib/app/prepare/index.js +0 -24
- package/lib/app/prepare/prepareClientAppEnhances.d.ts +0 -5
- package/lib/app/prepare/prepareClientAppEnhances.js +0 -24
- package/lib/app/prepare/prepareClientAppRootComponents.d.ts +0 -5
- package/lib/app/prepare/prepareClientAppRootComponents.js +0 -24
- package/lib/app/prepare/prepareClientAppSetups.d.ts +0 -5
- package/lib/app/prepare/prepareClientAppSetups.js +0 -24
- package/lib/app/prepare/prepareLayoutComponents.d.ts +0 -5
- package/lib/app/prepare/prepareLayoutComponents.js +0 -20
- package/lib/app/prepare/preparePageComponent.d.ts +0 -5
- package/lib/app/prepare/preparePageComponent.js +0 -10
- package/lib/app/prepare/preparePageData.d.ts +0 -5
- package/lib/app/prepare/preparePageData.js +0 -37
- package/lib/app/prepare/preparePageRoutes.d.ts +0 -5
- package/lib/app/prepare/preparePageRoutes.js +0 -57
- package/lib/app/prepare/preparePagesComponent.d.ts +0 -5
- package/lib/app/prepare/preparePagesComponent.js +0 -23
- package/lib/app/prepare/preparePagesData.d.ts +0 -5
- package/lib/app/prepare/preparePagesData.js +0 -19
- package/lib/app/prepare/preparePagesRoutes.d.ts +0 -5
- package/lib/app/prepare/preparePagesRoutes.js +0 -25
- package/lib/app/prepare/prepareSiteData.d.ts +0 -5
- package/lib/app/prepare/prepareSiteData.js +0 -31
- package/lib/app/prepare/resolvePageData.d.ts +0 -5
- package/lib/app/prepare/resolvePageData.js +0 -18
- package/lib/app/resolveBundler.d.ts +0 -2
- package/lib/app/resolveBundler.js +0 -10
- package/lib/app/resolvePlugin.d.ts +0 -5
- package/lib/app/resolvePlugin.js +0 -20
- package/lib/index.d.ts +0 -5
- package/lib/index.js +0 -17
- package/lib/page/createPage.d.ts +0 -2
- package/lib/page/createPage.js +0 -112
- package/lib/page/index.d.ts +0 -18
- package/lib/page/index.js +0 -30
- package/lib/page/inferPagePath.d.ts +0 -11
- package/lib/page/inferPagePath.js +0 -27
- package/lib/page/resolvePageComponentInfo.d.ts +0 -20
- package/lib/page/resolvePageComponentInfo.js +0 -38
- package/lib/page/resolvePageContent.d.ts +0 -11
- package/lib/page/resolvePageContent.js +0 -30
- package/lib/page/resolvePageDataInfo.d.ts +0 -12
- package/lib/page/resolvePageDataInfo.js +0 -17
- package/lib/page/resolvePageDate.d.ts +0 -10
- package/lib/page/resolvePageDate.js +0 -46
- package/lib/page/resolvePageExcerpt.d.ts +0 -10
- package/lib/page/resolvePageExcerpt.js +0 -16
- package/lib/page/resolvePageFileContent.d.ts +0 -8
- package/lib/page/resolvePageFileContent.js +0 -24
- package/lib/page/resolvePageFilePath.d.ts +0 -11
- package/lib/page/resolvePageFilePath.js +0 -29
- package/lib/page/resolvePageFrontmatter.d.ts +0 -8
- package/lib/page/resolvePageFrontmatter.js +0 -12
- package/lib/page/resolvePageHtmlInfo.d.ts +0 -11
- package/lib/page/resolvePageHtmlInfo.js +0 -18
- package/lib/page/resolvePageKey.d.ts +0 -6
- package/lib/page/resolvePageKey.js +0 -9
- package/lib/page/resolvePageLang.d.ts +0 -9
- package/lib/page/resolvePageLang.js +0 -15
- package/lib/page/resolvePagePath.d.ts +0 -9
- package/lib/page/resolvePagePath.js +0 -19
- package/lib/page/resolvePagePermalink.d.ts +0 -11
- package/lib/page/resolvePagePermalink.js +0 -32
- package/lib/page/resolvePageRoutesInfo.d.ts +0 -11
- package/lib/page/resolvePageRoutesInfo.js +0 -15
- package/lib/page/resolvePageSlug.d.ts +0 -6
- package/lib/page/resolvePageSlug.js +0 -17
- package/lib/page/resolvePageTitle.d.ts +0 -9
- package/lib/page/resolvePageTitle.js +0 -26
- package/lib/pluginApi/createHookQueue.d.ts +0 -5
- package/lib/pluginApi/createHookQueue.js +0 -81
- package/lib/pluginApi/createPluginApi.d.ts +0 -2
- package/lib/pluginApi/createPluginApi.js +0 -16
- package/lib/pluginApi/createPluginApiHooks.d.ts +0 -2
- package/lib/pluginApi/createPluginApiHooks.js +0 -24
- package/lib/pluginApi/createPluginApiRegisterHooks.d.ts +0 -2
- package/lib/pluginApi/createPluginApiRegisterHooks.js +0 -54
- package/lib/pluginApi/index.d.ts +0 -6
- package/lib/pluginApi/index.js +0 -18
- package/lib/pluginApi/normalizeClientFilesHook.d.ts +0 -5
- package/lib/pluginApi/normalizeClientFilesHook.js +0 -28
- package/lib/pluginApi/normalizeReturnObjectHook.d.ts +0 -5
- package/lib/pluginApi/normalizeReturnObjectHook.js +0 -9
- package/lib/themeApi/createThemeApi.d.ts +0 -7
- package/lib/themeApi/createThemeApi.js +0 -30
- package/lib/themeApi/index.d.ts +0 -3
- package/lib/themeApi/index.js +0 -15
- package/lib/themeApi/resolveThemeInfo.d.ts +0 -2
- package/lib/themeApi/resolveThemeInfo.js +0 -32
- package/lib/themeApi/resolveThemeLayouts.d.ts +0 -5
- package/lib/themeApi/resolveThemeLayouts.js +0 -32
- package/lib/types/app/app.d.ts +0 -30
- package/lib/types/app/app.js +0 -2
- package/lib/types/app/index.d.ts +0 -3
- package/lib/types/app/index.js +0 -15
- package/lib/types/app/options.d.ts +0 -31
- package/lib/types/app/options.js +0 -2
- package/lib/types/app/utils.d.ts +0 -29
- package/lib/types/app/utils.js +0 -2
- package/lib/types/bundler.d.ts +0 -34
- package/lib/types/bundler.js +0 -2
- package/lib/types/index.d.ts +0 -9
- package/lib/types/index.js +0 -19
- package/lib/types/page.d.ts +0 -110
- package/lib/types/page.js +0 -2
- package/lib/types/plugin.d.ts +0 -48
- package/lib/types/plugin.js +0 -2
- package/lib/types/pluginApi/hooks.d.ts +0 -75
- package/lib/types/pluginApi/hooks.js +0 -2
- package/lib/types/pluginApi/index.d.ts +0 -2
- package/lib/types/pluginApi/index.js +0 -14
- package/lib/types/pluginApi/pluginApi.d.ts +0 -23
- package/lib/types/pluginApi/pluginApi.js +0 -2
- package/lib/types/theme.d.ts +0 -33
- package/lib/types/theme.js +0 -2
- package/lib/types/themeApi/index.d.ts +0 -1
- package/lib/types/themeApi/index.js +0 -13
- package/lib/types/themeApi/themeApi.d.ts +0 -44
- package/lib/types/themeApi/themeApi.js +0 -2
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolvePageFilePath = void 0;
|
|
4
|
-
const utils_1 = require("@vuepress/utils");
|
|
5
|
-
/**
|
|
6
|
-
* Resolve absolute and relative path of page file
|
|
7
|
-
*/
|
|
8
|
-
const resolvePageFilePath = ({ app, options: { filePath }, }) => {
|
|
9
|
-
// empty file path
|
|
10
|
-
if (!filePath) {
|
|
11
|
-
return {
|
|
12
|
-
filePath: null,
|
|
13
|
-
filePathRelative: null,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
// absolute file path
|
|
17
|
-
if (utils_1.path.isAbsolute(filePath)) {
|
|
18
|
-
return {
|
|
19
|
-
filePath,
|
|
20
|
-
filePathRelative: utils_1.path.relative(app.dir.source(), filePath),
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
// relative file path
|
|
24
|
-
return {
|
|
25
|
-
filePath: app.dir.source(filePath),
|
|
26
|
-
filePathRelative: filePath,
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
exports.resolvePageFilePath = resolvePageFilePath;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { PageFrontmatter, PageOptions } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Resolve page frontmatter from user frontmatter and options frontmatter
|
|
4
|
-
*/
|
|
5
|
-
export declare const resolvePageFrontmatter: ({ frontmatterRaw, options, }: {
|
|
6
|
-
frontmatterRaw: PageFrontmatter;
|
|
7
|
-
options: PageOptions;
|
|
8
|
-
}) => PageFrontmatter;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolvePageFrontmatter = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Resolve page frontmatter from user frontmatter and options frontmatter
|
|
6
|
-
*/
|
|
7
|
-
const resolvePageFrontmatter = ({ frontmatterRaw, options, }) => ({
|
|
8
|
-
// raw frontmatter take priority over options frontmatter
|
|
9
|
-
...options.frontmatter,
|
|
10
|
-
...frontmatterRaw,
|
|
11
|
-
});
|
|
12
|
-
exports.resolvePageFrontmatter = resolvePageFrontmatter;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { App } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Resolve page rendered html file path
|
|
4
|
-
*/
|
|
5
|
-
export declare const resolvePageHtmlInfo: ({ app, path: pagePath, }: {
|
|
6
|
-
app: App;
|
|
7
|
-
path: string;
|
|
8
|
-
}) => {
|
|
9
|
-
htmlFilePath: string;
|
|
10
|
-
htmlFilePathRelative: string;
|
|
11
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolvePageHtmlInfo = void 0;
|
|
4
|
-
const shared_1 = require("@vuepress/shared");
|
|
5
|
-
/**
|
|
6
|
-
* Resolve page rendered html file path
|
|
7
|
-
*/
|
|
8
|
-
const resolvePageHtmlInfo = ({ app, path: pagePath, }) => {
|
|
9
|
-
// /foo.html -> foo.html
|
|
10
|
-
// /foo/ -> foo/index.html
|
|
11
|
-
const htmlFilePathRelative = shared_1.removeLeadingSlash(pagePath.replace(/\/$/, '/index.html'));
|
|
12
|
-
const htmlFilePath = app.dir.dest(htmlFilePathRelative);
|
|
13
|
-
return {
|
|
14
|
-
htmlFilePath,
|
|
15
|
-
htmlFilePathRelative,
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
exports.resolvePageHtmlInfo = resolvePageHtmlInfo;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolvePageKey = void 0;
|
|
4
|
-
const utils_1 = require("@vuepress/utils");
|
|
5
|
-
/**
|
|
6
|
-
* Resolve page key to identify the page
|
|
7
|
-
*/
|
|
8
|
-
const resolvePageKey = ({ path }) => `v-${utils_1.hash(path)}`;
|
|
9
|
-
exports.resolvePageKey = resolvePageKey;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolvePageLang = void 0;
|
|
4
|
-
const shared_1 = require("@vuepress/shared");
|
|
5
|
-
/**
|
|
6
|
-
* Resolve language of page
|
|
7
|
-
*/
|
|
8
|
-
const resolvePageLang = ({ app, frontmatter, pathLocale, }) => {
|
|
9
|
-
var _a, _b;
|
|
10
|
-
if (shared_1.isString(frontmatter.lang) && frontmatter.lang) {
|
|
11
|
-
return frontmatter.lang;
|
|
12
|
-
}
|
|
13
|
-
return (_b = (_a = app.siteData.locales[pathLocale]) === null || _a === void 0 ? void 0 : _a.lang) !== null && _b !== void 0 ? _b : app.siteData.lang;
|
|
14
|
-
};
|
|
15
|
-
exports.resolvePageLang = resolvePageLang;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { PageOptions } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Resolve the final route path of a page
|
|
4
|
-
*/
|
|
5
|
-
export declare const resolvePagePath: ({ permalink, pathInferred, options, }: {
|
|
6
|
-
permalink: string | null;
|
|
7
|
-
pathInferred: string | null;
|
|
8
|
-
options: PageOptions;
|
|
9
|
-
}) => string;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolvePagePath = void 0;
|
|
4
|
-
const shared_1 = require("@vuepress/shared");
|
|
5
|
-
const utils_1 = require("@vuepress/utils");
|
|
6
|
-
/**
|
|
7
|
-
* Resolve the final route path of a page
|
|
8
|
-
*/
|
|
9
|
-
const resolvePagePath = ({ permalink, pathInferred, options, }) => {
|
|
10
|
-
let pagePath = permalink || pathInferred || options.path;
|
|
11
|
-
if (!pagePath) {
|
|
12
|
-
throw utils_1.logger.createError(`page path is empty, page options: ${JSON.stringify(options)}`);
|
|
13
|
-
}
|
|
14
|
-
if (!pagePath.endsWith('.html')) {
|
|
15
|
-
pagePath = shared_1.ensureEndingSlash(pagePath);
|
|
16
|
-
}
|
|
17
|
-
return encodeURI(pagePath);
|
|
18
|
-
};
|
|
19
|
-
exports.resolvePagePath = resolvePagePath;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { PageFrontmatter } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Resolve page permalink from frontmatter / options / pattern
|
|
4
|
-
*/
|
|
5
|
-
export declare const resolvePagePermalink: ({ frontmatter, slug, date, pathInferred, pathLocale, }: {
|
|
6
|
-
frontmatter: PageFrontmatter;
|
|
7
|
-
slug: string;
|
|
8
|
-
date: string;
|
|
9
|
-
pathInferred: string | null;
|
|
10
|
-
pathLocale: string;
|
|
11
|
-
}) => string | null;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolvePagePermalink = void 0;
|
|
4
|
-
const shared_1 = require("@vuepress/shared");
|
|
5
|
-
const utils_1 = require("@vuepress/utils");
|
|
6
|
-
/**
|
|
7
|
-
* Resolve page permalink from frontmatter / options / pattern
|
|
8
|
-
*/
|
|
9
|
-
const resolvePagePermalink = ({ frontmatter, slug, date, pathInferred, pathLocale, }) => {
|
|
10
|
-
var _a;
|
|
11
|
-
// use permalink in frontmatter directly
|
|
12
|
-
if (shared_1.isString(frontmatter.permalink)) {
|
|
13
|
-
return frontmatter.permalink;
|
|
14
|
-
}
|
|
15
|
-
// get permalink pattern from frontmatter or options
|
|
16
|
-
const pattern = shared_1.isString(frontmatter.permalinkPattern)
|
|
17
|
-
? frontmatter.permalinkPattern
|
|
18
|
-
: null;
|
|
19
|
-
if (!pattern) {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
// resolve permalink according to the pattern
|
|
23
|
-
const [year, month, day] = date.split('-');
|
|
24
|
-
const link = utils_1.path.join(pathLocale, pattern
|
|
25
|
-
.replace(/:year/, year)
|
|
26
|
-
.replace(/:month/, month)
|
|
27
|
-
.replace(/:day/, day)
|
|
28
|
-
.replace(/:slug/, slug)
|
|
29
|
-
.replace(/:raw/, (_a = pathInferred === null || pathInferred === void 0 ? void 0 : pathInferred.replace(/^\//, '')) !== null && _a !== void 0 ? _a : ''));
|
|
30
|
-
return shared_1.ensureLeadingSlash(link);
|
|
31
|
-
};
|
|
32
|
-
exports.resolvePagePermalink = resolvePagePermalink;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolvePageRoutesInfo = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Resolve page routes file path
|
|
6
|
-
*/
|
|
7
|
-
const resolvePageRoutesInfo = ({ app, key, }) => {
|
|
8
|
-
const routesFilePathRelative = `internal/pageRoutes/${key}.js`;
|
|
9
|
-
const routesFilePath = app.dir.temp(routesFilePathRelative);
|
|
10
|
-
return {
|
|
11
|
-
routesFilePath,
|
|
12
|
-
routesFilePathRelative,
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
exports.resolvePageRoutesInfo = resolvePageRoutesInfo;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolvePageSlug = void 0;
|
|
4
|
-
const utils_1 = require("@vuepress/utils");
|
|
5
|
-
const DATE_RE = /(\d{4}-\d{1,2}(-\d{1,2})?)-(.*)/;
|
|
6
|
-
/**
|
|
7
|
-
* Resolve page slug from filename
|
|
8
|
-
*/
|
|
9
|
-
const resolvePageSlug = ({ filePathRelative, }) => {
|
|
10
|
-
if (!filePathRelative) {
|
|
11
|
-
return '';
|
|
12
|
-
}
|
|
13
|
-
const filename = utils_1.path.parse(filePathRelative).name;
|
|
14
|
-
const match = filename.match(DATE_RE);
|
|
15
|
-
return match ? match[3] : filename;
|
|
16
|
-
};
|
|
17
|
-
exports.resolvePageSlug = resolvePageSlug;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { PageFrontmatter, PageHeader } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Resolve page title from frontmatter / file content
|
|
4
|
-
*/
|
|
5
|
-
export declare const resolvePageTitle: ({ content, frontmatter, headers, }: {
|
|
6
|
-
content: string;
|
|
7
|
-
frontmatter: PageFrontmatter;
|
|
8
|
-
headers: PageHeader[];
|
|
9
|
-
}) => string;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolvePageTitle = void 0;
|
|
4
|
-
const markdown_1 = require("@vuepress/markdown");
|
|
5
|
-
const shared_1 = require("@vuepress/shared");
|
|
6
|
-
/**
|
|
7
|
-
* Resolve page title from frontmatter / file content
|
|
8
|
-
*/
|
|
9
|
-
const resolvePageTitle = ({ content, frontmatter, headers, }) => {
|
|
10
|
-
// use title in frontmatter
|
|
11
|
-
if (shared_1.isString(frontmatter.title)) {
|
|
12
|
-
return markdown_1.parseEmoji(frontmatter.title);
|
|
13
|
-
}
|
|
14
|
-
// if the first header is <h1>, use it as the title
|
|
15
|
-
const firstHeader = headers[0];
|
|
16
|
-
if ((firstHeader === null || firstHeader === void 0 ? void 0 : firstHeader.level) === 1) {
|
|
17
|
-
return firstHeader.title;
|
|
18
|
-
}
|
|
19
|
-
// try to get the first `# title` from markdown content
|
|
20
|
-
const matchTitle = content.trimStart().match(/^#\s+(.*)/);
|
|
21
|
-
if (matchTitle) {
|
|
22
|
-
return markdown_1.parseEmoji(matchTitle[1]);
|
|
23
|
-
}
|
|
24
|
-
return '';
|
|
25
|
-
};
|
|
26
|
-
exports.resolvePageTitle = resolvePageTitle;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createHookQueue = void 0;
|
|
4
|
-
const shared_1 = require("@vuepress/shared");
|
|
5
|
-
const utils_1 = require("@vuepress/utils");
|
|
6
|
-
const log = utils_1.debug('vuepress:core/plugin-api');
|
|
7
|
-
/**
|
|
8
|
-
* Create hook queue for plugin system
|
|
9
|
-
*/
|
|
10
|
-
const createHookQueue = (name, parallel = false) => {
|
|
11
|
-
const items = [];
|
|
12
|
-
const hookQueue = {
|
|
13
|
-
// hook name
|
|
14
|
-
name,
|
|
15
|
-
// hook items array
|
|
16
|
-
items,
|
|
17
|
-
// add hook item to queue
|
|
18
|
-
add: (item) => {
|
|
19
|
-
items.push(item);
|
|
20
|
-
},
|
|
21
|
-
// process the hook queue and get the results
|
|
22
|
-
process: async (...args) => {
|
|
23
|
-
// store the results of all hook items
|
|
24
|
-
const results = [];
|
|
25
|
-
// process a hook item and store the result
|
|
26
|
-
const processItem = async (item, ...args) => {
|
|
27
|
-
log(`process ${utils_1.chalk.magenta(name)} from ${utils_1.chalk.magenta(item.pluginName)}`);
|
|
28
|
-
try {
|
|
29
|
-
// process and get the result of the the hook item
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
const result = (await item.hook(...args));
|
|
32
|
-
// push the result to results array
|
|
33
|
-
if (result !== undefined) {
|
|
34
|
-
results.push(result);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
utils_1.logger.error(`error in hook ${utils_1.chalk.magenta(name)} from ${utils_1.chalk.magenta(item.pluginName)}`);
|
|
39
|
-
throw error;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
// process all hook items in current queue
|
|
43
|
-
if (parallel) {
|
|
44
|
-
// process in parallel
|
|
45
|
-
await Promise.all(items.map((item) => processItem(item, ...args)));
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
// process in serial
|
|
49
|
-
for (const item of items) {
|
|
50
|
-
await processItem(item, ...args);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return results;
|
|
54
|
-
},
|
|
55
|
-
// process the hook queue and get the results
|
|
56
|
-
processSync: (...args) => {
|
|
57
|
-
// store the results of all hook items
|
|
58
|
-
const results = [];
|
|
59
|
-
// process all hook items
|
|
60
|
-
for (const item of items) {
|
|
61
|
-
log(`processSync ${utils_1.chalk.magenta(name)} from ${utils_1.chalk.magenta(item.pluginName)}`);
|
|
62
|
-
try {
|
|
63
|
-
// @ts-ignore
|
|
64
|
-
// process and get the result of the the hook item
|
|
65
|
-
const result = item.hook(...args);
|
|
66
|
-
// push the result to results array
|
|
67
|
-
if (result !== undefined && !shared_1.isPromise(result)) {
|
|
68
|
-
results.push(result);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
utils_1.logger.error(`error in hook ${utils_1.chalk.magenta(name)} from ${utils_1.chalk.magenta(item.pluginName)}`);
|
|
73
|
-
throw error;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return results;
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
return hookQueue;
|
|
80
|
-
};
|
|
81
|
-
exports.createHookQueue = createHookQueue;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createPluginApi = void 0;
|
|
4
|
-
const createPluginApiHooks_1 = require("./createPluginApiHooks");
|
|
5
|
-
const createPluginApiRegisterHooks_1 = require("./createPluginApiRegisterHooks");
|
|
6
|
-
const createPluginApi = () => {
|
|
7
|
-
const plugins = [];
|
|
8
|
-
const hooks = createPluginApiHooks_1.createPluginApiHooks();
|
|
9
|
-
const registerHooks = createPluginApiRegisterHooks_1.createPluginApiRegisterHooks(plugins, hooks);
|
|
10
|
-
return {
|
|
11
|
-
plugins,
|
|
12
|
-
hooks,
|
|
13
|
-
registerHooks,
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
exports.createPluginApi = createPluginApi;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createPluginApiHooks = void 0;
|
|
4
|
-
const createHookQueue_1 = require("./createHookQueue");
|
|
5
|
-
const createPluginApiHooks = () => ({
|
|
6
|
-
// life cycle hooks
|
|
7
|
-
onInitialized: createHookQueue_1.createHookQueue('onInitialized'),
|
|
8
|
-
onPrepared: createHookQueue_1.createHookQueue('onPrepared'),
|
|
9
|
-
onWatched: createHookQueue_1.createHookQueue('onWatched'),
|
|
10
|
-
onGenerated: createHookQueue_1.createHookQueue('onGenerated'),
|
|
11
|
-
// page hooks
|
|
12
|
-
extendsPageOptions: createHookQueue_1.createHookQueue('extendsPageOptions'),
|
|
13
|
-
extendsPageData: createHookQueue_1.createHookQueue('extendsPageData'),
|
|
14
|
-
// markdown hooks
|
|
15
|
-
extendsMarkdown: createHookQueue_1.createHookQueue('extendsMarkdown'),
|
|
16
|
-
// client files hooks
|
|
17
|
-
clientAppEnhanceFiles: createHookQueue_1.createHookQueue('clientAppEnhanceFiles', true),
|
|
18
|
-
clientAppRootComponentFiles: createHookQueue_1.createHookQueue('clientAppRootComponentFiles', true),
|
|
19
|
-
clientAppSetupFiles: createHookQueue_1.createHookQueue('clientAppSetupFiles', true),
|
|
20
|
-
// bundler hooks
|
|
21
|
-
alias: createHookQueue_1.createHookQueue('alias'),
|
|
22
|
-
define: createHookQueue_1.createHookQueue('define'),
|
|
23
|
-
});
|
|
24
|
-
exports.createPluginApiHooks = createPluginApiHooks;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createPluginApiRegisterHooks = void 0;
|
|
4
|
-
const normalizeReturnObjectHook_1 = require("./normalizeReturnObjectHook");
|
|
5
|
-
const normalizeClientFilesHook_1 = require("./normalizeClientFilesHook");
|
|
6
|
-
const createPluginApiRegisterHooks = (plugins, hooks) => () => {
|
|
7
|
-
plugins.forEach(({ name: pluginName, alias, define, clientAppEnhanceFiles, clientAppRootComponentFiles, clientAppSetupFiles, ...commonHooks }) => {
|
|
8
|
-
/**
|
|
9
|
-
* hooks that need to be normalized
|
|
10
|
-
*/
|
|
11
|
-
if (alias) {
|
|
12
|
-
hooks.alias.add({
|
|
13
|
-
pluginName,
|
|
14
|
-
hook: normalizeReturnObjectHook_1.normalizeReturnObjectHook(alias),
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
if (define) {
|
|
18
|
-
hooks.define.add({
|
|
19
|
-
pluginName,
|
|
20
|
-
hook: normalizeReturnObjectHook_1.normalizeReturnObjectHook(define),
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
if (clientAppEnhanceFiles) {
|
|
24
|
-
hooks.clientAppEnhanceFiles.add({
|
|
25
|
-
pluginName,
|
|
26
|
-
hook: normalizeClientFilesHook_1.normalizeClientFilesHook(clientAppEnhanceFiles),
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
if (clientAppRootComponentFiles) {
|
|
30
|
-
hooks.clientAppRootComponentFiles.add({
|
|
31
|
-
pluginName,
|
|
32
|
-
hook: normalizeClientFilesHook_1.normalizeClientFilesHook(clientAppRootComponentFiles),
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
if (clientAppSetupFiles) {
|
|
36
|
-
hooks.clientAppSetupFiles.add({
|
|
37
|
-
pluginName,
|
|
38
|
-
hook: normalizeClientFilesHook_1.normalizeClientFilesHook(clientAppSetupFiles),
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* common hooks
|
|
43
|
-
*/
|
|
44
|
-
Object.entries(commonHooks).forEach(([key, hook]) => {
|
|
45
|
-
if (hooks[key] && hook) {
|
|
46
|
-
hooks[key].add({
|
|
47
|
-
pluginName,
|
|
48
|
-
hook,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
exports.createPluginApiRegisterHooks = createPluginApiRegisterHooks;
|
package/lib/pluginApi/index.d.ts
DELETED
package/lib/pluginApi/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./createHookQueue"), exports);
|
|
14
|
-
__exportStar(require("./createPluginApi"), exports);
|
|
15
|
-
__exportStar(require("./createPluginApiHooks"), exports);
|
|
16
|
-
__exportStar(require("./createPluginApiRegisterHooks"), exports);
|
|
17
|
-
__exportStar(require("./normalizeReturnObjectHook"), exports);
|
|
18
|
-
__exportStar(require("./normalizeClientFilesHook"), exports);
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeClientFilesHook = void 0;
|
|
4
|
-
const shared_1 = require("@vuepress/shared");
|
|
5
|
-
const utils_1 = require("@vuepress/utils");
|
|
6
|
-
/**
|
|
7
|
-
* Normalize hook for client files
|
|
8
|
-
*/
|
|
9
|
-
const normalizeClientFilesHook = (hook) => async (app) => {
|
|
10
|
-
// resolve clientFiles result
|
|
11
|
-
const clientFilesResult = shared_1.isFunction(hook) ? await hook(app) : hook;
|
|
12
|
-
const clientFiles = shared_1.isArray(clientFilesResult)
|
|
13
|
-
? clientFilesResult
|
|
14
|
-
: [clientFilesResult];
|
|
15
|
-
// filter files that do not exist
|
|
16
|
-
const result = [];
|
|
17
|
-
for (const filePath of clientFiles) {
|
|
18
|
-
const isExisted = await utils_1.fs.pathExists(filePath);
|
|
19
|
-
if (isExisted) {
|
|
20
|
-
result.push(filePath);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
throw utils_1.logger.createError(`client file does not exist: ${filePath}`);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
|
-
exports.normalizeClientFilesHook = normalizeClientFilesHook;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeReturnObjectHook = void 0;
|
|
4
|
-
const shared_1 = require("@vuepress/shared");
|
|
5
|
-
/**
|
|
6
|
-
* Normalize hook that returns an object
|
|
7
|
-
*/
|
|
8
|
-
const normalizeReturnObjectHook = (hook) => (app) => shared_1.isFunction(hook) ? hook(app) : hook;
|
|
9
|
-
exports.normalizeReturnObjectHook = normalizeReturnObjectHook;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createThemeApi = void 0;
|
|
4
|
-
const resolveThemeInfo_1 = require("./resolveThemeInfo");
|
|
5
|
-
/**
|
|
6
|
-
* Create vuepress theme-api
|
|
7
|
-
*
|
|
8
|
-
* Resolve current theme, parent theme, theme layouts
|
|
9
|
-
*/
|
|
10
|
-
const createThemeApi = (app) => {
|
|
11
|
-
// resolve theme info
|
|
12
|
-
const theme = resolveThemeInfo_1.resolveThemeInfo(app, app.options.theme);
|
|
13
|
-
// resolve parent theme info
|
|
14
|
-
const parentTheme = theme.plugin.extends
|
|
15
|
-
? resolveThemeInfo_1.resolveThemeInfo(app, theme.plugin.extends)
|
|
16
|
-
: null;
|
|
17
|
-
// resolve theme layouts
|
|
18
|
-
const layouts = theme.layouts;
|
|
19
|
-
// layouts in child theme will override
|
|
20
|
-
// those with the same name in parent theme
|
|
21
|
-
if (parentTheme !== null) {
|
|
22
|
-
layouts.unshift(...parentTheme.layouts.filter(({ name: parentLayoutName }) => !theme.layouts.some(({ name: childLayoutName }) => childLayoutName === parentLayoutName)));
|
|
23
|
-
}
|
|
24
|
-
return {
|
|
25
|
-
theme,
|
|
26
|
-
parentTheme,
|
|
27
|
-
layouts,
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
exports.createThemeApi = createThemeApi;
|
package/lib/themeApi/index.d.ts
DELETED
package/lib/themeApi/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./createThemeApi"), exports);
|
|
14
|
-
__exportStar(require("./resolveThemeInfo"), exports);
|
|
15
|
-
__exportStar(require("./resolveThemeLayouts"), exports);
|