@vuepress/core 2.0.0-beta.32 → 2.0.0-beta.33

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.
@@ -11,8 +11,8 @@ const resolveAppOptions_1 = require("./resolveAppOptions");
11
11
  const resolveAppSiteData_1 = require("./resolveAppSiteData");
12
12
  const resolveAppVersion_1 = require("./resolveAppVersion");
13
13
  const resolveAppWriteTemp_1 = require("./resolveAppWriteTemp");
14
- const resolvePluginsFromConfig_1 = require("./resolvePluginsFromConfig");
15
- const resolveThemeInfo_1 = require("./resolveThemeInfo");
14
+ const setupAppPlugins_1 = require("./setupAppPlugins");
15
+ const setupAppTheme_1 = require("./setupAppTheme");
16
16
  /**
17
17
  * Create vuepress app
18
18
  */
@@ -38,12 +38,11 @@ const createBaseApp = (config, isBuild = false) => {
38
38
  init: () => (0, appInit_1.appInit)(app),
39
39
  prepare: () => (0, appPrepare_1.appPrepare)(app),
40
40
  };
41
- // resolve theme info and set app layouts
42
- const themeInfo = (0, resolveThemeInfo_1.resolveThemeInfo)(app, options.theme, options.themeConfig);
43
- app.layouts = themeInfo.layouts;
44
- // resolve plugins
45
- const plugins = (0, resolvePluginsFromConfig_1.resolvePluginsFromConfig)(app, options.plugins);
46
- [...themeInfo.plugins, ...plugins].forEach((plugin) => app.use(plugin));
41
+ // setup theme and plugins
42
+ // notice that we setup theme before plugins,
43
+ // so user plugins could override theme plugins
44
+ (0, setupAppTheme_1.setupAppTheme)(app, config);
45
+ (0, setupAppPlugins_1.setupAppPlugins)(app);
47
46
  return app;
48
47
  };
49
48
  exports.createBaseApp = createBaseApp;
@@ -15,15 +15,7 @@ const resolveAppPages = async (app) => {
15
15
  cwd: app.dir.source(),
16
16
  });
17
17
  // create pages from files
18
- const pages = await Promise.all(pageFilePaths.map(async (filePath) => {
19
- const pageOptions = { filePath };
20
- // plugin hook: extendsPageOptions
21
- await app.pluginApi.hooks.extendsPageOptions.process(pageOptions, app);
22
- const page = await (0, page_1.createPage)(app, pageOptions);
23
- // plugin hook: extendsPage
24
- await app.pluginApi.hooks.extendsPage.process(page, app);
25
- return page;
26
- }));
18
+ const pages = await Promise.all(pageFilePaths.map((filePath) => (0, page_1.createPage)(app, { filePath })));
27
19
  // if there is no 404 page, add one
28
20
  if (!pages.some((page) => page.path === '/404.html')) {
29
21
  pages.push(await (0, page_1.createPage)(app, {
@@ -8,6 +8,7 @@ const resolveThemeObject_1 = require("./resolveThemeObject");
8
8
  * Resolve theme info and its parent theme info
9
9
  */
10
10
  const resolveThemeInfo = (app, theme, themeConfig) => {
11
+ var _a, _b;
11
12
  // resolve current theme info
12
13
  const themeObject = (0, resolveThemeObject_1.resolveThemeObject)(app, theme, themeConfig);
13
14
  const themeInfo = {
@@ -16,6 +17,8 @@ const resolveThemeInfo = (app, theme, themeConfig) => {
16
17
  ...(0, resolvePluginsFromConfig_1.resolvePluginsFromConfig)(app, themeObject.plugins),
17
18
  themeObject,
18
19
  ],
20
+ templateBuild: themeObject.templateBuild,
21
+ templateDev: themeObject.templateDev,
19
22
  };
20
23
  // return if current theme does not have a parent theme
21
24
  if (!themeObject.extends) {
@@ -26,6 +29,8 @@ const resolveThemeInfo = (app, theme, themeConfig) => {
26
29
  return {
27
30
  layouts: { ...parentThemeInfo.layouts, ...themeInfo.layouts },
28
31
  plugins: [...parentThemeInfo.plugins, ...themeInfo.plugins],
32
+ templateBuild: (_a = themeObject.templateBuild) !== null && _a !== void 0 ? _a : parentThemeInfo.templateBuild,
33
+ templateDev: (_b = themeObject.templateDev) !== null && _b !== void 0 ? _b : parentThemeInfo.templateDev,
29
34
  };
30
35
  };
31
36
  exports.resolveThemeInfo = resolveThemeInfo;
@@ -0,0 +1,5 @@
1
+ import type { App } from '../types';
2
+ /**
3
+ * Setup plugins for vuepress app
4
+ */
5
+ export declare const setupAppPlugins: (app: App) => void;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupAppPlugins = void 0;
4
+ const resolvePluginsFromConfig_1 = require("./resolvePluginsFromConfig");
5
+ /**
6
+ * Setup plugins for vuepress app
7
+ */
8
+ const setupAppPlugins = (app) => {
9
+ // resolve plugins from options
10
+ const plugins = (0, resolvePluginsFromConfig_1.resolvePluginsFromConfig)(app, app.options.plugins);
11
+ // use plugins
12
+ plugins.forEach((plugin) => app.use(plugin));
13
+ };
14
+ exports.setupAppPlugins = setupAppPlugins;
@@ -0,0 +1,5 @@
1
+ import type { App, AppConfig } from '../types';
2
+ /**
3
+ * Setup theme for vuepress app
4
+ */
5
+ export declare const setupAppTheme: (app: App, config: AppConfig) => void;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupAppTheme = void 0;
4
+ const resolveThemeInfo_1 = require("./resolveThemeInfo");
5
+ /**
6
+ * Setup theme for vuepress app
7
+ */
8
+ const setupAppTheme = (app, config) => {
9
+ var _a, _b, _c, _d;
10
+ // recursively resolve theme info
11
+ const themeInfo = (0, resolveThemeInfo_1.resolveThemeInfo)(app, app.options.theme, app.options.themeConfig);
12
+ // set up app layouts and templates
13
+ app.layouts = themeInfo.layouts;
14
+ app.options.templateDev =
15
+ (_b = (_a = config.templateDev) !== null && _a !== void 0 ? _a : themeInfo.templateDev) !== null && _b !== void 0 ? _b : app.options.templateDev;
16
+ app.options.templateBuild =
17
+ (_d = (_c = config.templateBuild) !== null && _c !== void 0 ? _c : themeInfo.templateBuild) !== null && _d !== void 0 ? _d : app.options.templateBuild;
18
+ // use theme plugins
19
+ themeInfo.plugins.forEach((plugin) => app.use(plugin));
20
+ };
21
+ exports.setupAppTheme = setupAppTheme;
@@ -19,6 +19,8 @@ const resolvePagePermalink_1 = require("./resolvePagePermalink");
19
19
  const resolvePageRouteMeta_1 = require("./resolvePageRouteMeta");
20
20
  const resolvePageSlug_1 = require("./resolvePageSlug");
21
21
  const createPage = async (app, options) => {
22
+ // plugin hook: extendsPageOptions
23
+ await app.pluginApi.hooks.extendsPageOptions.process(options, app);
22
24
  // resolve page file absolute path and relative path
23
25
  const { filePath, filePathRelative } = (0, resolvePageFilePath_1.resolvePageFilePath)({
24
26
  app,
@@ -126,6 +128,8 @@ const createPage = async (app, options) => {
126
128
  htmlFilePath,
127
129
  htmlFilePathRelative,
128
130
  };
131
+ // plugin hook: extendsPage
132
+ await app.pluginApi.hooks.extendsPage.process(page, app);
129
133
  return page;
130
134
  };
131
135
  exports.createPage = createPage;
@@ -22,7 +22,7 @@ const createHookQueue = (name) => {
22
22
  log(`process ${utils_1.chalk.magenta(name)} from ${utils_1.chalk.magenta(item.pluginName)}`);
23
23
  try {
24
24
  // process and get the result of the the hook item
25
- // @ts-ignore
25
+ // @ts-expect-error: the types could not be narrowed correctly
26
26
  const result = (await item.hook(...args));
27
27
  // push the result to results array
28
28
  if (result !== undefined) {
@@ -17,10 +17,30 @@ export declare type ThemeFunction<T extends ThemeConfig = ThemeConfig> = PluginF
17
17
  * Vuepress theme object
18
18
  */
19
19
  export interface ThemeObject extends PluginObject {
20
+ /**
21
+ * Theme plugin should never be multiple
22
+ */
20
23
  multiple?: false;
24
+ /**
25
+ * Extended parent theme
26
+ */
21
27
  extends?: string;
28
+ /**
29
+ * Specify the layouts directory or components map
30
+ */
22
31
  layouts?: string | Record<string, string>;
32
+ /**
33
+ * Allow using plugins in theme
34
+ */
23
35
  plugins?: PluginConfig[];
36
+ /**
37
+ * Allow overriding default templateBuild
38
+ */
39
+ templateBuild?: string;
40
+ /**
41
+ * Allow overriding default templateDev
42
+ */
43
+ templateDev?: string;
24
44
  }
25
45
  /**
26
46
  * Theme config to be used in user config file
@@ -44,4 +64,12 @@ export interface ThemeInfo {
44
64
  * Plugins, including theme itself and plugins used by theme
45
65
  */
46
66
  plugins: PluginObject[];
67
+ /**
68
+ * Default build template
69
+ */
70
+ templateBuild?: string;
71
+ /**
72
+ * Default dev template
73
+ */
74
+ templateDev?: string;
47
75
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/core",
3
- "version": "2.0.0-beta.32",
3
+ "version": "2.0.0-beta.33",
4
4
  "description": "Core package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -26,15 +26,15 @@
26
26
  "clean": "rimraf lib *.tsbuildinfo"
27
27
  },
28
28
  "dependencies": {
29
- "@vuepress/client": "2.0.0-beta.32",
30
- "@vuepress/markdown": "2.0.0-beta.32",
31
- "@vuepress/shared": "2.0.0-beta.32",
32
- "@vuepress/utils": "2.0.0-beta.32",
29
+ "@vuepress/client": "2.0.0-beta.33",
30
+ "@vuepress/markdown": "2.0.0-beta.33",
31
+ "@vuepress/shared": "2.0.0-beta.33",
32
+ "@vuepress/utils": "2.0.0-beta.33",
33
33
  "gray-matter": "^4.0.3",
34
34
  "toml": "^3.0.0"
35
35
  },
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "8ffa71313607fe78f3956e3ccb886fcae0ddf5e9"
39
+ "gitHead": "0934a5d6685922e0dc6391622b00a3b89140492c"
40
40
  }