@vuepress/core 2.0.0-beta.4 → 2.0.0-beta.42
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/lib/app/appInit.js +6 -16
- package/lib/app/appPrepare.js +12 -15
- package/lib/app/appUse.d.ts +2 -2
- package/lib/app/appUse.js +17 -15
- package/lib/app/createBaseApp.d.ts +5 -0
- package/lib/app/createBaseApp.js +46 -0
- package/lib/app/createBuildApp.d.ts +5 -0
- package/lib/app/createBuildApp.js +13 -0
- package/lib/app/createDevApp.d.ts +5 -0
- package/lib/app/createDevApp.js +13 -0
- package/lib/app/index.d.ts +13 -12
- package/lib/app/index.js +18 -13
- package/lib/app/prepare/index.d.ts +1 -3
- package/lib/app/prepare/index.js +6 -4
- package/lib/app/prepare/prepareLayoutComponents.js +2 -2
- package/lib/app/prepare/preparePageComponent.js +6 -1
- package/lib/app/prepare/preparePageData.js +7 -11
- package/lib/app/prepare/{preparePagesComponent.d.ts → preparePagesComponents.d.ts} +1 -1
- package/lib/app/prepare/preparePagesComponents.js +24 -0
- package/lib/app/prepare/preparePagesData.js +5 -4
- package/lib/app/prepare/preparePagesRoutes.js +61 -11
- package/lib/app/prepare/prepareSiteData.js +19 -1
- package/lib/app/{createAppDir.d.ts → resolveAppDir.d.ts} +2 -2
- package/lib/app/resolveAppDir.js +32 -0
- package/lib/app/resolveAppEnv.d.ts +5 -0
- package/lib/app/resolveAppEnv.js +12 -0
- package/lib/app/resolveAppMarkdown.d.ts +6 -0
- package/lib/app/resolveAppMarkdown.js +16 -0
- package/lib/app/resolveAppOptions.d.ts +5 -0
- package/lib/app/{createAppOptions.js → resolveAppOptions.js} +16 -20
- package/lib/app/resolveAppPages.d.ts +5 -0
- package/lib/app/resolveAppPages.js +31 -0
- package/lib/app/resolveAppSiteData.d.ts +7 -0
- package/lib/app/resolveAppSiteData.js +17 -0
- package/lib/app/resolveAppVersion.d.ts +4 -0
- package/lib/app/resolveAppVersion.js +10 -0
- package/lib/app/resolveAppWriteTemp.d.ts +5 -0
- package/lib/app/{createAppWriteTemp.js → resolveAppWriteTemp.js} +5 -5
- package/lib/app/resolvePluginObject.d.ts +5 -0
- package/lib/app/resolvePluginObject.js +9 -0
- package/lib/app/resolveThemeInfo.d.ts +5 -0
- package/lib/app/resolveThemeInfo.js +31 -0
- package/lib/app/resolveThemeLayouts.d.ts +5 -0
- package/lib/app/resolveThemeLayouts.js +25 -0
- package/lib/app/setupAppThemeAndPlugins.d.ts +5 -0
- package/lib/app/setupAppThemeAndPlugins.js +21 -0
- package/lib/index.d.ts +0 -1
- package/lib/index.js +5 -2
- package/lib/page/createPage.js +75 -39
- package/lib/page/index.d.ts +4 -3
- package/lib/page/index.js +9 -4
- package/lib/page/inferPagePath.js +2 -2
- package/lib/page/renderPageContent.d.ts +19 -0
- package/lib/page/renderPageContent.js +26 -0
- package/lib/page/renderPageExcerpt.d.ts +11 -0
- package/lib/page/renderPageExcerpt.js +17 -0
- package/lib/page/resolvePageComponentInfo.d.ts +2 -9
- package/lib/page/resolvePageComponentInfo.js +2 -24
- package/lib/page/resolvePageContent.js +1 -2
- package/lib/page/resolvePageDataInfo.d.ts +2 -1
- package/lib/page/resolvePageDataInfo.js +2 -2
- package/lib/page/resolvePageDate.d.ts +1 -1
- package/lib/page/resolvePageDate.js +6 -7
- package/lib/page/resolvePageFileContent.js +3 -4
- package/lib/page/resolvePageFilePath.d.ts +1 -1
- package/lib/page/resolvePageFilePath.js +6 -11
- package/lib/page/resolvePageHtmlInfo.d.ts +11 -0
- package/lib/page/resolvePageHtmlInfo.js +18 -0
- package/lib/page/resolvePageKey.js +1 -1
- package/lib/page/resolvePageLang.js +2 -3
- package/lib/page/resolvePagePath.js +12 -1
- package/lib/page/resolvePagePermalink.js +4 -5
- package/lib/page/resolvePageRouteMeta.d.ts +7 -0
- package/lib/page/resolvePageRouteMeta.js +8 -0
- package/lib/pluginApi/createHookQueue.d.ts +1 -1
- package/lib/pluginApi/createHookQueue.js +7 -46
- package/lib/pluginApi/createPluginApi.js +2 -2
- package/lib/pluginApi/createPluginApiHooks.js +15 -14
- package/lib/pluginApi/createPluginApiRegisterHooks.js +6 -6
- package/lib/pluginApi/index.js +5 -1
- package/lib/pluginApi/normalizeClientFilesHook.js +5 -2
- package/lib/pluginApi/normalizeReturnObjectHook.js +1 -1
- package/lib/types/app/app.d.ts +82 -14
- package/lib/types/app/index.js +5 -1
- package/lib/types/app/options.d.ts +78 -27
- package/lib/types/app/utils.d.ts +10 -3
- package/lib/types/bundler.d.ts +3 -24
- package/lib/types/index.d.ts +2 -3
- package/lib/types/index.js +6 -3
- package/lib/types/page.d.ts +78 -32
- package/lib/types/plugin.d.ts +5 -24
- package/lib/types/{plugin-api → pluginApi}/hooks.d.ts +8 -9
- package/lib/types/{plugin-api → pluginApi}/hooks.js +0 -0
- package/lib/types/{plugin-api → pluginApi}/index.d.ts +0 -0
- package/lib/types/{plugin-api → pluginApi}/index.js +5 -1
- package/lib/types/{plugin-api → pluginApi}/pluginApi.d.ts +0 -0
- package/lib/types/{plugin-api → pluginApi}/pluginApi.js +0 -0
- package/lib/types/theme.d.ts +42 -14
- package/package.json +14 -14
- package/CHANGELOG.md +0 -260
- package/lib/app/appUseByConfig.d.ts +0 -2
- package/lib/app/appUseByConfig.js +0 -14
- package/lib/app/createApp.d.ts +0 -5
- package/lib/app/createApp.js +0 -44
- 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/createAppPages.d.ts +0 -5
- package/lib/app/createAppPages.js +0 -33
- 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 -11
- package/lib/app/createAppWriteTemp.d.ts +0 -5
- package/lib/app/normalizePlugin.d.ts +0 -2
- package/lib/app/normalizePlugin.js +0 -19
- package/lib/app/normalizePluginConfig.d.ts +0 -2
- package/lib/app/normalizePluginConfig.js +0 -18
- package/lib/app/prepare/preparePageRoutes.d.ts +0 -5
- package/lib/app/prepare/preparePageRoutes.js +0 -57
- package/lib/app/prepare/preparePagesComponent.js +0 -23
- 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/page/resolvePageExcerpt.d.ts +0 -9
- package/lib/page/resolvePageExcerpt.js +0 -15
- package/lib/page/resolvePageRoutesInfo.d.ts +0 -11
- package/lib/page/resolvePageRoutesInfo.js +0 -16
- package/lib/page/resolvePageTitle.d.ts +0 -9
- package/lib/page/resolvePageTitle.js +0 -26
- package/lib/themeApi/createThemeApi.d.ts +0 -7
- package/lib/themeApi/createThemeApi.js +0 -30
- package/lib/themeApi/index.d.ts +0 -1
- package/lib/themeApi/index.js +0 -13
- package/lib/themeApi/resolveThemeInfo.d.ts +0 -2
- package/lib/themeApi/resolveThemeInfo.js +0 -34
- package/lib/themeApi/resolveThemeLayouts.d.ts +0 -5
- package/lib/themeApi/resolveThemeLayouts.js +0 -33
- package/lib/types/theme-api/index.d.ts +0 -1
- package/lib/types/theme-api/index.js +0 -13
- package/lib/types/theme-api/themeApi.d.ts +0 -44
- package/lib/types/theme-api/themeApi.js +0 -2
package/lib/app/appInit.js
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.appInit = void 0;
|
|
4
4
|
const utils_1 = require("@vuepress/utils");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const log = utils_1.debug('vuepress:core/app');
|
|
5
|
+
const resolveAppMarkdown_1 = require("./resolveAppMarkdown");
|
|
6
|
+
const resolveAppPages_1 = require("./resolveAppPages");
|
|
7
|
+
const log = (0, utils_1.debug)('vuepress:core/app');
|
|
9
8
|
/**
|
|
10
9
|
* Initialize a vuepress app
|
|
11
10
|
*
|
|
@@ -13,23 +12,14 @@ const log = utils_1.debug('vuepress:core/app');
|
|
|
13
12
|
*/
|
|
14
13
|
const appInit = async (app) => {
|
|
15
14
|
log('init start');
|
|
16
|
-
// create write temp util
|
|
17
|
-
app.writeTemp = await createAppWriteTemp_1.createAppWriteTemp(app);
|
|
18
|
-
// create theme api, resolve themes and layouts
|
|
19
|
-
app.themeApi = await themeApi_1.createThemeApi(app);
|
|
20
|
-
// use theme plugin
|
|
21
|
-
if (app.themeApi.parentTheme) {
|
|
22
|
-
app.use(app.themeApi.parentTheme.plugin);
|
|
23
|
-
}
|
|
24
|
-
app.use(app.themeApi.theme.plugin);
|
|
25
15
|
// register all hooks of plugins that have been used
|
|
26
16
|
// plugins should be used before `registerHooks()`
|
|
27
17
|
// hooks in plugins will take effect after `registerHooks()`
|
|
28
18
|
app.pluginApi.registerHooks();
|
|
29
|
-
//
|
|
30
|
-
await
|
|
19
|
+
// create markdown
|
|
20
|
+
app.markdown = await (0, resolveAppMarkdown_1.resolveAppMarkdown)(app);
|
|
31
21
|
// create pages
|
|
32
|
-
app.pages = await
|
|
22
|
+
app.pages = await (0, resolveAppPages_1.resolveAppPages)(app);
|
|
33
23
|
// plugin hook: onInitialized
|
|
34
24
|
await app.pluginApi.hooks.onInitialized.process(app);
|
|
35
25
|
log('init finish');
|
package/lib/app/appPrepare.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.appPrepare = void 0;
|
|
4
4
|
const utils_1 = require("@vuepress/utils");
|
|
5
5
|
const prepare_1 = require("./prepare");
|
|
6
|
-
const log = utils_1.debug('vuepress:core/app');
|
|
6
|
+
const log = (0, utils_1.debug)('vuepress:core/app');
|
|
7
7
|
/**
|
|
8
8
|
* Prepare files for development or build
|
|
9
9
|
*
|
|
@@ -16,29 +16,26 @@ const appPrepare = async (app) => {
|
|
|
16
16
|
log('prepare start');
|
|
17
17
|
// generate page component files
|
|
18
18
|
for (const page of app.pages) {
|
|
19
|
-
await prepare_1.preparePageComponent(app, page);
|
|
19
|
+
await (0, prepare_1.preparePageComponent)(app, page);
|
|
20
20
|
}
|
|
21
|
-
await prepare_1.
|
|
21
|
+
await (0, prepare_1.preparePagesComponents)(app);
|
|
22
22
|
// generate page data files
|
|
23
23
|
for (const page of app.pages) {
|
|
24
|
-
await prepare_1.preparePageData(app, page);
|
|
24
|
+
await (0, prepare_1.preparePageData)(app, page);
|
|
25
25
|
}
|
|
26
|
-
await prepare_1.preparePagesData(app);
|
|
27
|
-
// generate layout components map file
|
|
28
|
-
await prepare_1.prepareLayoutComponents(app);
|
|
26
|
+
await (0, prepare_1.preparePagesData)(app);
|
|
29
27
|
// generate routes file
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
await prepare_1.preparePagesRoutes(app);
|
|
28
|
+
await (0, prepare_1.preparePagesRoutes)(app);
|
|
29
|
+
// generate layout components map file
|
|
30
|
+
await (0, prepare_1.prepareLayoutComponents)(app);
|
|
34
31
|
// generate site data file
|
|
35
|
-
await prepare_1.prepareSiteData(app);
|
|
32
|
+
await (0, prepare_1.prepareSiteData)(app);
|
|
36
33
|
// generate client app enhances file
|
|
37
|
-
await prepare_1.prepareClientAppEnhances(app);
|
|
34
|
+
await (0, prepare_1.prepareClientAppEnhances)(app);
|
|
38
35
|
// generate client app root components file
|
|
39
|
-
await prepare_1.prepareClientAppRootComponents(app);
|
|
36
|
+
await (0, prepare_1.prepareClientAppRootComponents)(app);
|
|
40
37
|
// generate client app setups file
|
|
41
|
-
await prepare_1.prepareClientAppSetups(app);
|
|
38
|
+
await (0, prepare_1.prepareClientAppSetups)(app);
|
|
42
39
|
// plugin hook: onPrepared
|
|
43
40
|
await app.pluginApi.hooks.onPrepared.process(app);
|
|
44
41
|
log('prepare finish');
|
package/lib/app/appUse.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { App, Plugin
|
|
2
|
-
export declare const appUse:
|
|
1
|
+
import type { App, Plugin } from '../types';
|
|
2
|
+
export declare const appUse: (app: App, rawPlugin: Plugin) => App;
|
package/lib/app/appUse.js
CHANGED
|
@@ -2,25 +2,27 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.appUse = void 0;
|
|
4
4
|
const utils_1 = require("@vuepress/utils");
|
|
5
|
-
const
|
|
6
|
-
const log = utils_1.debug('vuepress:core/app');
|
|
7
|
-
const appUse = (app, rawPlugin
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
const resolvePluginObject_1 = require("./resolvePluginObject");
|
|
6
|
+
const log = (0, utils_1.debug)('vuepress:core/app');
|
|
7
|
+
const appUse = (app, rawPlugin) => {
|
|
8
|
+
const pluginObject = (0, resolvePluginObject_1.resolvePluginObject)(app, rawPlugin);
|
|
9
|
+
// ignore anonymous plugins or theme
|
|
10
|
+
if (!pluginObject.name) {
|
|
11
|
+
(0, utils_1.warn)(`an anonymous plugin or theme was detected and ignored`);
|
|
12
|
+
return app;
|
|
13
|
+
}
|
|
14
|
+
log(`use plugin ${utils_1.chalk.magenta(pluginObject.name)}`);
|
|
15
|
+
// handle duplicated plugins
|
|
16
|
+
if (pluginObject.multiple !== true) {
|
|
17
|
+
const duplicateIndex = app.pluginApi.plugins.findIndex(({ name }) => name === pluginObject.name);
|
|
14
18
|
if (duplicateIndex !== -1) {
|
|
19
|
+
// remove the previous duplicated plugin
|
|
15
20
|
app.pluginApi.plugins.splice(duplicateIndex, 1);
|
|
21
|
+
(0, utils_1.warn)(`plugin ${utils_1.chalk.magenta(pluginObject.name)} has been used multiple times, only the last one will take effect`);
|
|
16
22
|
}
|
|
17
23
|
}
|
|
18
24
|
// use plugin
|
|
19
|
-
app.pluginApi.plugins.push(
|
|
20
|
-
|
|
21
|
-
// if the plugin uses other plugins
|
|
22
|
-
if (plugin.plugins) {
|
|
23
|
-
plugin.plugins.forEach(app.useByConfig);
|
|
24
|
-
}
|
|
25
|
+
app.pluginApi.plugins.push(pluginObject);
|
|
26
|
+
return app;
|
|
25
27
|
};
|
|
26
28
|
exports.appUse = appUse;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createBaseApp = void 0;
|
|
4
|
+
const pluginApi_1 = require("../pluginApi");
|
|
5
|
+
const appInit_1 = require("./appInit");
|
|
6
|
+
const appPrepare_1 = require("./appPrepare");
|
|
7
|
+
const appUse_1 = require("./appUse");
|
|
8
|
+
const resolveAppDir_1 = require("./resolveAppDir");
|
|
9
|
+
const resolveAppEnv_1 = require("./resolveAppEnv");
|
|
10
|
+
const resolveAppOptions_1 = require("./resolveAppOptions");
|
|
11
|
+
const resolveAppSiteData_1 = require("./resolveAppSiteData");
|
|
12
|
+
const resolveAppVersion_1 = require("./resolveAppVersion");
|
|
13
|
+
const resolveAppWriteTemp_1 = require("./resolveAppWriteTemp");
|
|
14
|
+
const setupAppThemeAndPlugins_1 = require("./setupAppThemeAndPlugins");
|
|
15
|
+
/**
|
|
16
|
+
* Create vuepress app
|
|
17
|
+
*/
|
|
18
|
+
const createBaseApp = (config, isBuild = false) => {
|
|
19
|
+
const options = (0, resolveAppOptions_1.resolveAppOptions)(config);
|
|
20
|
+
const dir = (0, resolveAppDir_1.resolveAppDir)(options);
|
|
21
|
+
const env = (0, resolveAppEnv_1.resolveAppEnv)(options, isBuild);
|
|
22
|
+
const pluginApi = (0, pluginApi_1.createPluginApi)();
|
|
23
|
+
const siteData = (0, resolveAppSiteData_1.resolveAppSiteData)(options);
|
|
24
|
+
const version = (0, resolveAppVersion_1.resolveAppVersion)();
|
|
25
|
+
const writeTemp = (0, resolveAppWriteTemp_1.resolveAppWriteTemp)(dir);
|
|
26
|
+
const app = {
|
|
27
|
+
options,
|
|
28
|
+
siteData,
|
|
29
|
+
version,
|
|
30
|
+
// utils
|
|
31
|
+
dir,
|
|
32
|
+
env,
|
|
33
|
+
pluginApi,
|
|
34
|
+
writeTemp,
|
|
35
|
+
// methods
|
|
36
|
+
use: (...args) => (0, appUse_1.appUse)(app, ...args),
|
|
37
|
+
init: () => (0, appInit_1.appInit)(app),
|
|
38
|
+
prepare: () => (0, appPrepare_1.appPrepare)(app),
|
|
39
|
+
};
|
|
40
|
+
// setup theme and plugins
|
|
41
|
+
// notice that we setup theme before plugins,
|
|
42
|
+
// so user plugins could override theme plugins
|
|
43
|
+
(0, setupAppThemeAndPlugins_1.setupAppThemeAndPlugins)(app, config);
|
|
44
|
+
return app;
|
|
45
|
+
};
|
|
46
|
+
exports.createBaseApp = createBaseApp;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createBuildApp = void 0;
|
|
4
|
+
const createBaseApp_1 = require("./createBaseApp");
|
|
5
|
+
/**
|
|
6
|
+
* Create vuepress build app
|
|
7
|
+
*/
|
|
8
|
+
const createBuildApp = (config) => {
|
|
9
|
+
const app = (0, createBaseApp_1.createBaseApp)(config, true);
|
|
10
|
+
app.build = () => app.options.bundler.build(app);
|
|
11
|
+
return app;
|
|
12
|
+
};
|
|
13
|
+
exports.createBuildApp = createBuildApp;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDevApp = void 0;
|
|
4
|
+
const createBaseApp_1 = require("./createBaseApp");
|
|
5
|
+
/**
|
|
6
|
+
* Create vuepress dev app
|
|
7
|
+
*/
|
|
8
|
+
const createDevApp = (config) => {
|
|
9
|
+
const app = (0, createBaseApp_1.createBaseApp)(config, false);
|
|
10
|
+
app.dev = () => app.options.bundler.dev(app);
|
|
11
|
+
return app;
|
|
12
|
+
};
|
|
13
|
+
exports.createDevApp = createDevApp;
|
package/lib/app/index.d.ts
CHANGED
|
@@ -2,15 +2,16 @@ export * from './prepare';
|
|
|
2
2
|
export * from './appInit';
|
|
3
3
|
export * from './appPrepare';
|
|
4
4
|
export * from './appUse';
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './
|
|
14
|
-
export * from './
|
|
15
|
-
export * from './
|
|
16
|
-
export * from './
|
|
5
|
+
export * from './createBaseApp';
|
|
6
|
+
export * from './createBuildApp';
|
|
7
|
+
export * from './createDevApp';
|
|
8
|
+
export * from './resolveAppDir';
|
|
9
|
+
export * from './resolveAppEnv';
|
|
10
|
+
export * from './resolveAppOptions';
|
|
11
|
+
export * from './resolveAppPages';
|
|
12
|
+
export * from './resolveAppSiteData';
|
|
13
|
+
export * from './resolveAppVersion';
|
|
14
|
+
export * from './resolveAppWriteTemp';
|
|
15
|
+
export * from './resolvePluginObject';
|
|
16
|
+
export * from './resolveThemeInfo';
|
|
17
|
+
export * from './resolveThemeLayouts';
|
package/lib/app/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -14,15 +18,16 @@ __exportStar(require("./prepare"), exports);
|
|
|
14
18
|
__exportStar(require("./appInit"), exports);
|
|
15
19
|
__exportStar(require("./appPrepare"), exports);
|
|
16
20
|
__exportStar(require("./appUse"), exports);
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./
|
|
20
|
-
__exportStar(require("./
|
|
21
|
-
__exportStar(require("./
|
|
22
|
-
__exportStar(require("./
|
|
23
|
-
__exportStar(require("./
|
|
24
|
-
__exportStar(require("./
|
|
25
|
-
__exportStar(require("./
|
|
26
|
-
__exportStar(require("./
|
|
27
|
-
__exportStar(require("./
|
|
28
|
-
__exportStar(require("./
|
|
21
|
+
__exportStar(require("./createBaseApp"), exports);
|
|
22
|
+
__exportStar(require("./createBuildApp"), exports);
|
|
23
|
+
__exportStar(require("./createDevApp"), exports);
|
|
24
|
+
__exportStar(require("./resolveAppDir"), exports);
|
|
25
|
+
__exportStar(require("./resolveAppEnv"), exports);
|
|
26
|
+
__exportStar(require("./resolveAppOptions"), exports);
|
|
27
|
+
__exportStar(require("./resolveAppPages"), exports);
|
|
28
|
+
__exportStar(require("./resolveAppSiteData"), exports);
|
|
29
|
+
__exportStar(require("./resolveAppVersion"), exports);
|
|
30
|
+
__exportStar(require("./resolveAppWriteTemp"), exports);
|
|
31
|
+
__exportStar(require("./resolvePluginObject"), exports);
|
|
32
|
+
__exportStar(require("./resolveThemeInfo"), exports);
|
|
33
|
+
__exportStar(require("./resolveThemeLayouts"), exports);
|
|
@@ -4,9 +4,7 @@ export * from './prepareClientAppSetups';
|
|
|
4
4
|
export * from './prepareLayoutComponents';
|
|
5
5
|
export * from './preparePageComponent';
|
|
6
6
|
export * from './preparePageData';
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './preparePagesComponent';
|
|
7
|
+
export * from './preparePagesComponents';
|
|
9
8
|
export * from './preparePagesData';
|
|
10
9
|
export * from './preparePagesRoutes';
|
|
11
10
|
export * from './prepareSiteData';
|
|
12
|
-
export * from './resolvePageData';
|
package/lib/app/prepare/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -16,9 +20,7 @@ __exportStar(require("./prepareClientAppSetups"), exports);
|
|
|
16
20
|
__exportStar(require("./prepareLayoutComponents"), exports);
|
|
17
21
|
__exportStar(require("./preparePageComponent"), exports);
|
|
18
22
|
__exportStar(require("./preparePageData"), exports);
|
|
19
|
-
__exportStar(require("./
|
|
20
|
-
__exportStar(require("./preparePagesComponent"), exports);
|
|
23
|
+
__exportStar(require("./preparePagesComponents"), exports);
|
|
21
24
|
__exportStar(require("./preparePagesData"), exports);
|
|
22
25
|
__exportStar(require("./preparePagesRoutes"), exports);
|
|
23
26
|
__exportStar(require("./prepareSiteData"), exports);
|
|
24
|
-
__exportStar(require("./resolvePageData"), exports);
|
|
@@ -9,8 +9,8 @@ const prepareLayoutComponents = async (app) => {
|
|
|
9
9
|
import { defineAsyncComponent } from 'vue'
|
|
10
10
|
|
|
11
11
|
export const layoutComponents = {\
|
|
12
|
-
${app.
|
|
13
|
-
.map((
|
|
12
|
+
${Object.entries(app.layouts)
|
|
13
|
+
.map(([name, path]) => `
|
|
14
14
|
${JSON.stringify(name)}: defineAsyncComponent(() => import(${app.env.isDebug ? `/* webpackChunkName: "layout-${name}" */` : ''}${JSON.stringify(path)})),`)
|
|
15
15
|
.join('')}
|
|
16
16
|
}
|
|
@@ -5,6 +5,11 @@ exports.preparePageComponent = void 0;
|
|
|
5
5
|
* Generate page component temp file of a single page
|
|
6
6
|
*/
|
|
7
7
|
const preparePageComponent = async (app, page) => {
|
|
8
|
-
await app.writeTemp(page.componentFilePathRelative,
|
|
8
|
+
await app.writeTemp(page.componentFilePathRelative, [
|
|
9
|
+
// take the rendered markdown content as <template>
|
|
10
|
+
`<template>${page.contentRendered}</template>\n`,
|
|
11
|
+
// hoist `<script>`, `<style>` and other custom blocks
|
|
12
|
+
...page.hoistedTags,
|
|
13
|
+
].join('\n'));
|
|
9
14
|
};
|
|
10
15
|
exports.preparePageComponent = preparePageComponent;
|
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.preparePageData = void 0;
|
|
4
|
-
const resolvePageData_1 = require("./resolvePageData");
|
|
5
4
|
const HMR_CODE = `
|
|
6
5
|
if (import.meta.webpackHot) {
|
|
7
6
|
import.meta.webpackHot.accept()
|
|
8
|
-
__VUE_HMR_RUNTIME__.updatePageData
|
|
7
|
+
if (__VUE_HMR_RUNTIME__.updatePageData) {
|
|
8
|
+
__VUE_HMR_RUNTIME__.updatePageData(data)
|
|
9
|
+
}
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
if (import.meta.hot) {
|
|
12
|
-
import.meta.hot.accept()
|
|
13
|
-
|
|
13
|
+
import.meta.hot.accept(({ data }) => {
|
|
14
|
+
__VUE_HMR_RUNTIME__.updatePageData(data)
|
|
15
|
+
})
|
|
14
16
|
}
|
|
15
17
|
`;
|
|
16
18
|
/**
|
|
17
19
|
* Generate page data temp file of a single page
|
|
18
20
|
*/
|
|
19
21
|
const preparePageData = async (app, page) => {
|
|
20
|
-
// resolve default page data
|
|
21
|
-
const pageData = resolvePageData_1.resolvePageData(page);
|
|
22
|
-
// plugin hook: extendsPageData
|
|
23
|
-
const extendsPageData = await app.pluginApi.hooks.extendsPageData.process(page, app);
|
|
24
|
-
// extends default page data
|
|
25
|
-
extendsPageData.forEach((item) => Object.assign(pageData, item));
|
|
26
22
|
// page data file content
|
|
27
|
-
let content = `export const data = ${JSON.stringify(
|
|
23
|
+
let content = `export const data = ${JSON.stringify(page.data, null, 2)}\n`;
|
|
28
24
|
// inject HMR code
|
|
29
25
|
if (app.env.isDev) {
|
|
30
26
|
content += HMR_CODE;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.preparePagesComponents = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Generate page key to page component map temp file
|
|
6
|
+
*/
|
|
7
|
+
const preparePagesComponents = async (app) => {
|
|
8
|
+
// generate page component map file
|
|
9
|
+
const content = `\
|
|
10
|
+
import { defineAsyncComponent } from 'vue'
|
|
11
|
+
|
|
12
|
+
export const pagesComponents = {\
|
|
13
|
+
${app.pages
|
|
14
|
+
.map(({ key, path, componentFilePath, componentFileChunkName }) => `
|
|
15
|
+
// path: ${path}
|
|
16
|
+
${JSON.stringify(key)}: defineAsyncComponent(() => import(${componentFileChunkName
|
|
17
|
+
? `/* webpackChunkName: "${componentFileChunkName}" */`
|
|
18
|
+
: ''}${JSON.stringify(componentFilePath)})),`)
|
|
19
|
+
.join('')}
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
22
|
+
await app.writeTemp('internal/pagesComponents.js', content);
|
|
23
|
+
};
|
|
24
|
+
exports.preparePagesComponents = preparePagesComponents;
|
|
@@ -7,11 +7,12 @@ exports.preparePagesData = void 0;
|
|
|
7
7
|
const preparePagesData = async (app) => {
|
|
8
8
|
// generate page data map
|
|
9
9
|
const content = `\
|
|
10
|
-
export const pagesData = {
|
|
10
|
+
export const pagesData = {\
|
|
11
11
|
${app.pages
|
|
12
|
-
.map(({ path, dataFilePath, dataFileChunkName }) =>
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
.map(({ key, path, dataFilePath, dataFileChunkName }) => `
|
|
13
|
+
// path: ${path}
|
|
14
|
+
${JSON.stringify(key)}: () => import(${dataFileChunkName ? `/* webpackChunkName: "${dataFileChunkName}" */` : ''}${JSON.stringify(dataFilePath)}).then(({ data }) => data),`)
|
|
15
|
+
.join('')}
|
|
15
16
|
}
|
|
16
17
|
`;
|
|
17
18
|
await app.writeTemp('internal/pagesData.js', content);
|
|
@@ -1,24 +1,74 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.preparePagesRoutes = void 0;
|
|
4
|
+
const shared_1 = require("@vuepress/shared");
|
|
5
|
+
/**
|
|
6
|
+
* Transform a page object to a route item
|
|
7
|
+
*/
|
|
8
|
+
const transformPageToRouteItem = ({ key, path, pathInferred, filePathRelative, routeMeta, }) => {
|
|
9
|
+
// paths that should redirect to this page, use set to dedupe
|
|
10
|
+
const redirectsSet = new Set();
|
|
11
|
+
// redirect from decoded path
|
|
12
|
+
redirectsSet.add(decodeURI(path));
|
|
13
|
+
if (path.endsWith('/')) {
|
|
14
|
+
// redirect from index path
|
|
15
|
+
redirectsSet.add(path + 'index.html');
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
// redirect from the path that does not end with `.html`
|
|
19
|
+
redirectsSet.add(path.replace(/.html$/, ''));
|
|
20
|
+
}
|
|
21
|
+
// redirect from inferred path
|
|
22
|
+
if (pathInferred !== null) {
|
|
23
|
+
redirectsSet.add(pathInferred);
|
|
24
|
+
redirectsSet.add(encodeURI(pathInferred));
|
|
25
|
+
}
|
|
26
|
+
// redirect from filename path
|
|
27
|
+
if (filePathRelative !== null) {
|
|
28
|
+
const filenamePath = (0, shared_1.ensureLeadingSlash)(filePathRelative);
|
|
29
|
+
redirectsSet.add(filenamePath);
|
|
30
|
+
redirectsSet.add(encodeURI(filenamePath));
|
|
31
|
+
}
|
|
32
|
+
// avoid redirect from the page path itself
|
|
33
|
+
redirectsSet.delete(path);
|
|
34
|
+
return [key, path, routeMeta, [...redirectsSet]];
|
|
35
|
+
};
|
|
4
36
|
/**
|
|
5
37
|
* Generate routes temp file
|
|
6
38
|
*/
|
|
7
39
|
const preparePagesRoutes = async (app) => {
|
|
40
|
+
const routeItems = app.pages.map(transformPageToRouteItem);
|
|
8
41
|
const content = `\
|
|
9
|
-
import { Vuepress } from '@vuepress/client
|
|
10
|
-
${app.pages
|
|
11
|
-
.map(({ routesFilePath }, index) => `import pageRoutes${index} from '${routesFilePath}'`)
|
|
12
|
-
.join('\n')}
|
|
42
|
+
import { Vuepress } from '@vuepress/client'
|
|
13
43
|
|
|
14
|
-
|
|
15
|
-
${
|
|
16
|
-
{
|
|
17
|
-
name: "404",
|
|
18
|
-
path: "/:catchAll(.*)",
|
|
19
|
-
component: Vuepress,
|
|
20
|
-
},
|
|
44
|
+
const routeItems = [\
|
|
45
|
+
${routeItems.map((routeItem) => `\n ${JSON.stringify(routeItem)},`).join('')}
|
|
21
46
|
]
|
|
47
|
+
|
|
48
|
+
export const pagesRoutes = routeItems.reduce(
|
|
49
|
+
(result, [name, path, meta, redirects]) => {
|
|
50
|
+
result.push(
|
|
51
|
+
{
|
|
52
|
+
name,
|
|
53
|
+
path,
|
|
54
|
+
component: Vuepress,
|
|
55
|
+
meta,
|
|
56
|
+
},
|
|
57
|
+
...redirects.map((item) => ({
|
|
58
|
+
path: item,
|
|
59
|
+
redirect: path,
|
|
60
|
+
}))
|
|
61
|
+
)
|
|
62
|
+
return result
|
|
63
|
+
},
|
|
64
|
+
[
|
|
65
|
+
{
|
|
66
|
+
name: '404',
|
|
67
|
+
path: '/:catchAll(.*)',
|
|
68
|
+
component: Vuepress,
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
)
|
|
22
72
|
`;
|
|
23
73
|
await app.writeTemp('internal/pagesRoutes.js', content);
|
|
24
74
|
};
|
|
@@ -1,13 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.prepareSiteData = void 0;
|
|
4
|
+
const HMR_CODE = `
|
|
5
|
+
if (import.meta.webpackHot) {
|
|
6
|
+
import.meta.webpackHot.accept()
|
|
7
|
+
if (__VUE_HMR_RUNTIME__.updateSiteData) {
|
|
8
|
+
__VUE_HMR_RUNTIME__.updateSiteData(siteData)
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (import.meta.hot) {
|
|
13
|
+
import.meta.hot.accept(({ siteData }) => {
|
|
14
|
+
__VUE_HMR_RUNTIME__.updateSiteData(siteData)
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
4
18
|
/**
|
|
5
19
|
* Generate site data temp file
|
|
6
20
|
*/
|
|
7
21
|
const prepareSiteData = async (app) => {
|
|
8
|
-
|
|
22
|
+
let content = `\
|
|
9
23
|
export const siteData = ${JSON.stringify(app.siteData, null, 2)}
|
|
10
24
|
`;
|
|
25
|
+
// inject HMR code
|
|
26
|
+
if (app.env.isDev) {
|
|
27
|
+
content += HMR_CODE;
|
|
28
|
+
}
|
|
11
29
|
await app.writeTemp('internal/siteData.js', content);
|
|
12
30
|
};
|
|
13
31
|
exports.prepareSiteData = prepareSiteData;
|
|
@@ -4,6 +4,6 @@ import type { AppDir, AppDirFunction, AppOptions } from '../types';
|
|
|
4
4
|
*/
|
|
5
5
|
export declare const createAppDirFunction: (baseDir: string) => AppDirFunction;
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Resolve directory utils for vuepress app
|
|
8
8
|
*/
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const resolveAppDir: (options: AppOptions) => AppDir;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveAppDir = exports.createAppDirFunction = void 0;
|
|
4
|
+
const utils_1 = require("@vuepress/utils");
|
|
5
|
+
/**
|
|
6
|
+
* Create directory util function
|
|
7
|
+
*/
|
|
8
|
+
const createAppDirFunction = (baseDir) => {
|
|
9
|
+
return (...args) => utils_1.path.resolve(baseDir, ...args);
|
|
10
|
+
};
|
|
11
|
+
exports.createAppDirFunction = createAppDirFunction;
|
|
12
|
+
/**
|
|
13
|
+
* Resolve directory utils for vuepress app
|
|
14
|
+
*/
|
|
15
|
+
const resolveAppDir = (options) => {
|
|
16
|
+
const cache = (0, exports.createAppDirFunction)(options.cache);
|
|
17
|
+
const temp = (0, exports.createAppDirFunction)(options.temp);
|
|
18
|
+
const source = (0, exports.createAppDirFunction)(options.source);
|
|
19
|
+
const dest = (0, exports.createAppDirFunction)(options.dest);
|
|
20
|
+
const publicDir = (0, exports.createAppDirFunction)(options.public);
|
|
21
|
+
// @vuepress/client
|
|
22
|
+
const client = (0, exports.createAppDirFunction)(utils_1.path.resolve(require.resolve('@vuepress/client/package.json'), '..'));
|
|
23
|
+
return {
|
|
24
|
+
cache,
|
|
25
|
+
temp,
|
|
26
|
+
source,
|
|
27
|
+
dest,
|
|
28
|
+
client,
|
|
29
|
+
public: publicDir,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
exports.resolveAppDir = resolveAppDir;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveAppEnv = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Resolve environment flags for vuepress app
|
|
6
|
+
*/
|
|
7
|
+
const resolveAppEnv = (options, isBuild) => ({
|
|
8
|
+
isBuild,
|
|
9
|
+
isDev: !isBuild,
|
|
10
|
+
isDebug: options.debug,
|
|
11
|
+
});
|
|
12
|
+
exports.resolveAppEnv = resolveAppEnv;
|