@vuepress/core 2.0.0-beta.29 → 2.0.0-beta.35

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.
Files changed (51) hide show
  1. package/lib/app/appInit.js +4 -4
  2. package/lib/app/appUse.js +2 -2
  3. package/lib/app/createBaseApp.js +23 -23
  4. package/lib/app/index.d.ts +9 -9
  5. package/lib/app/index.js +9 -9
  6. package/lib/app/{createAppDir.d.ts → resolveAppDir.d.ts} +2 -2
  7. package/lib/app/{createAppDir.js → resolveAppDir.js} +4 -4
  8. package/lib/app/resolveAppEnv.d.ts +5 -0
  9. package/lib/app/resolveAppEnv.js +12 -0
  10. package/lib/app/resolveAppMarkdown.d.ts +6 -0
  11. package/lib/app/{createAppMarkdown.js → resolveAppMarkdown.js} +4 -4
  12. package/lib/app/resolveAppOptions.d.ts +5 -0
  13. package/lib/app/{createAppOptions.js → resolveAppOptions.js} +7 -7
  14. package/lib/app/resolveAppPages.d.ts +5 -0
  15. package/lib/app/{createAppPages.js → resolveAppPages.js} +7 -15
  16. package/lib/app/resolveAppSiteData.d.ts +7 -0
  17. package/lib/app/{createAppSiteData.js → resolveAppSiteData.js} +4 -4
  18. package/lib/app/resolveAppVersion.d.ts +4 -0
  19. package/lib/app/resolveAppVersion.js +10 -0
  20. package/lib/app/resolveAppWriteTemp.d.ts +5 -0
  21. package/lib/app/{createAppWriteTemp.js → resolveAppWriteTemp.js} +4 -4
  22. package/lib/app/resolvePluginObject.d.ts +5 -0
  23. package/lib/app/{resolvePlugin.js → resolvePluginObject.js} +5 -5
  24. package/lib/app/resolvePluginsFromConfig.d.ts +1 -1
  25. package/lib/app/resolvePluginsFromConfig.js +3 -3
  26. package/lib/app/resolveThemeInfo.d.ts +2 -2
  27. package/lib/app/resolveThemeInfo.js +15 -7
  28. package/lib/app/resolveThemeObject.d.ts +5 -0
  29. package/lib/app/resolveThemeObject.js +22 -0
  30. package/lib/app/setupAppPlugins.d.ts +5 -0
  31. package/lib/app/setupAppPlugins.js +14 -0
  32. package/lib/app/setupAppTheme.d.ts +5 -0
  33. package/lib/app/setupAppTheme.js +21 -0
  34. package/lib/page/createPage.js +4 -0
  35. package/lib/pluginApi/createHookQueue.js +1 -1
  36. package/lib/types/app/app.d.ts +10 -10
  37. package/lib/types/app/options.d.ts +35 -22
  38. package/lib/types/theme.d.ts +28 -0
  39. package/package.json +6 -6
  40. package/lib/app/createAppEnv.d.ts +0 -5
  41. package/lib/app/createAppEnv.js +0 -12
  42. package/lib/app/createAppMarkdown.d.ts +0 -6
  43. package/lib/app/createAppOptions.d.ts +0 -5
  44. package/lib/app/createAppPages.d.ts +0 -5
  45. package/lib/app/createAppSiteData.d.ts +0 -7
  46. package/lib/app/createAppVersion.d.ts +0 -4
  47. package/lib/app/createAppVersion.js +0 -10
  48. package/lib/app/createAppWriteTemp.d.ts +0 -5
  49. package/lib/app/resolvePlugin.d.ts +0 -5
  50. package/lib/app/resolveTheme.d.ts +0 -5
  51. package/lib/app/resolveTheme.js +0 -22
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.appInit = void 0;
4
4
  const utils_1 = require("@vuepress/utils");
5
- const createAppMarkdown_1 = require("./createAppMarkdown");
6
- const createAppPages_1 = require("./createAppPages");
5
+ const resolveAppMarkdown_1 = require("./resolveAppMarkdown");
6
+ const resolveAppPages_1 = require("./resolveAppPages");
7
7
  const log = (0, utils_1.debug)('vuepress:core/app');
8
8
  /**
9
9
  * Initialize a vuepress app
@@ -17,9 +17,9 @@ const appInit = async (app) => {
17
17
  // hooks in plugins will take effect after `registerHooks()`
18
18
  app.pluginApi.registerHooks();
19
19
  // create markdown
20
- app.markdown = await (0, createAppMarkdown_1.createAppMarkdown)(app);
20
+ app.markdown = await (0, resolveAppMarkdown_1.resolveAppMarkdown)(app);
21
21
  // create pages
22
- app.pages = await (0, createAppPages_1.createAppPages)(app);
22
+ app.pages = await (0, resolveAppPages_1.resolveAppPages)(app);
23
23
  // plugin hook: onInitialized
24
24
  await app.pluginApi.hooks.onInitialized.process(app);
25
25
  log('init finish');
package/lib/app/appUse.js CHANGED
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.appUse = void 0;
4
4
  const utils_1 = require("@vuepress/utils");
5
- const resolvePlugin_1 = require("./resolvePlugin");
5
+ const resolvePluginObject_1 = require("./resolvePluginObject");
6
6
  const log = (0, utils_1.debug)('vuepress:core/app');
7
7
  const appUse = (app, rawPlugin, config) => {
8
- const plugin = (0, resolvePlugin_1.resolvePlugin)(app, rawPlugin, config);
8
+ const plugin = (0, resolvePluginObject_1.resolvePluginObject)(app, rawPlugin, config);
9
9
  log(`use plugin ${utils_1.chalk.magenta(plugin.name)}`);
10
10
  if (plugin.multiple !== true) {
11
11
  // remove duplicated plugin
@@ -5,44 +5,44 @@ const pluginApi_1 = require("../pluginApi");
5
5
  const appInit_1 = require("./appInit");
6
6
  const appPrepare_1 = require("./appPrepare");
7
7
  const appUse_1 = require("./appUse");
8
- const createAppDir_1 = require("./createAppDir");
9
- const createAppEnv_1 = require("./createAppEnv");
10
- const createAppOptions_1 = require("./createAppOptions");
11
- const createAppSiteData_1 = require("./createAppSiteData");
12
- const createAppVersion_1 = require("./createAppVersion");
13
- const createAppWriteTemp_1 = require("./createAppWriteTemp");
14
- const resolvePluginsFromConfig_1 = require("./resolvePluginsFromConfig");
15
- const resolveThemeInfo_1 = require("./resolveThemeInfo");
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 setupAppPlugins_1 = require("./setupAppPlugins");
15
+ const setupAppTheme_1 = require("./setupAppTheme");
16
16
  /**
17
17
  * Create vuepress app
18
18
  */
19
19
  const createBaseApp = (config, isBuild = false) => {
20
- const version = (0, createAppVersion_1.createAppVersion)();
21
- const options = (0, createAppOptions_1.createAppOptions)(config);
22
- const dir = (0, createAppDir_1.createAppDir)(options);
23
- const env = (0, createAppEnv_1.createAppEnv)(options, isBuild);
24
- const siteData = (0, createAppSiteData_1.createAppSiteData)(options);
20
+ const options = (0, resolveAppOptions_1.resolveAppOptions)(config);
21
+ const dir = (0, resolveAppDir_1.resolveAppDir)(options);
22
+ const env = (0, resolveAppEnv_1.resolveAppEnv)(options, isBuild);
25
23
  const pluginApi = (0, pluginApi_1.createPluginApi)();
26
- const writeTemp = (0, createAppWriteTemp_1.createAppWriteTemp)(dir);
24
+ const siteData = (0, resolveAppSiteData_1.resolveAppSiteData)(options);
25
+ const version = (0, resolveAppVersion_1.resolveAppVersion)();
26
+ const writeTemp = (0, resolveAppWriteTemp_1.resolveAppWriteTemp)(dir);
27
27
  const app = {
28
- version,
29
28
  options,
29
+ siteData,
30
+ version,
31
+ // utils
30
32
  dir,
31
33
  env,
32
- siteData,
33
34
  pluginApi,
34
35
  writeTemp,
36
+ // methods
35
37
  use: (...args) => (0, appUse_1.appUse)(app, ...args),
36
38
  init: () => (0, appInit_1.appInit)(app),
37
39
  prepare: () => (0, appPrepare_1.appPrepare)(app),
38
40
  };
39
- // resolve theme info and use theme plugins
40
- const themeInfo = (0, resolveThemeInfo_1.resolveThemeInfo)(app, options.theme);
41
- themeInfo.plugins.forEach((plugin) => app.use(plugin));
42
- app.layouts = themeInfo.layouts;
43
- // resolve plugins
44
- const plugins = (0, resolvePluginsFromConfig_1.resolvePluginsFromConfig)(app, options.plugins);
45
- 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);
46
46
  return app;
47
47
  };
48
48
  exports.createBaseApp = createBaseApp;
@@ -2,21 +2,21 @@ export * from './prepare';
2
2
  export * from './appInit';
3
3
  export * from './appPrepare';
4
4
  export * from './appUse';
5
- export * from './createAppDir';
6
- export * from './createAppEnv';
7
- export * from './createAppOptions';
8
- export * from './createAppPages';
9
- export * from './createAppSiteData';
10
- export * from './createAppVersion';
11
- export * from './createAppWriteTemp';
12
5
  export * from './createBaseApp';
13
6
  export * from './createBuildApp';
14
7
  export * from './createDevApp';
15
8
  export * from './normalizePluginConfig';
9
+ export * from './resolveAppDir';
10
+ export * from './resolveAppEnv';
11
+ export * from './resolveAppOptions';
12
+ export * from './resolveAppPages';
13
+ export * from './resolveAppSiteData';
14
+ export * from './resolveAppVersion';
15
+ export * from './resolveAppWriteTemp';
16
16
  export * from './resolveBundler';
17
- export * from './resolvePlugin';
17
+ export * from './resolvePluginObject';
18
18
  export * from './resolvePluginModule';
19
19
  export * from './resolvePluginsFromConfig';
20
- export * from './resolveTheme';
20
+ export * from './resolveThemeObject';
21
21
  export * from './resolveThemeInfo';
22
22
  export * from './resolveThemeLayouts';
package/lib/app/index.js CHANGED
@@ -14,21 +14,21 @@ __exportStar(require("./prepare"), exports);
14
14
  __exportStar(require("./appInit"), exports);
15
15
  __exportStar(require("./appPrepare"), exports);
16
16
  __exportStar(require("./appUse"), exports);
17
- __exportStar(require("./createAppDir"), exports);
18
- __exportStar(require("./createAppEnv"), exports);
19
- __exportStar(require("./createAppOptions"), exports);
20
- __exportStar(require("./createAppPages"), exports);
21
- __exportStar(require("./createAppSiteData"), exports);
22
- __exportStar(require("./createAppVersion"), exports);
23
- __exportStar(require("./createAppWriteTemp"), exports);
24
17
  __exportStar(require("./createBaseApp"), exports);
25
18
  __exportStar(require("./createBuildApp"), exports);
26
19
  __exportStar(require("./createDevApp"), exports);
27
20
  __exportStar(require("./normalizePluginConfig"), exports);
21
+ __exportStar(require("./resolveAppDir"), exports);
22
+ __exportStar(require("./resolveAppEnv"), exports);
23
+ __exportStar(require("./resolveAppOptions"), exports);
24
+ __exportStar(require("./resolveAppPages"), exports);
25
+ __exportStar(require("./resolveAppSiteData"), exports);
26
+ __exportStar(require("./resolveAppVersion"), exports);
27
+ __exportStar(require("./resolveAppWriteTemp"), exports);
28
28
  __exportStar(require("./resolveBundler"), exports);
29
- __exportStar(require("./resolvePlugin"), exports);
29
+ __exportStar(require("./resolvePluginObject"), exports);
30
30
  __exportStar(require("./resolvePluginModule"), exports);
31
31
  __exportStar(require("./resolvePluginsFromConfig"), exports);
32
- __exportStar(require("./resolveTheme"), exports);
32
+ __exportStar(require("./resolveThemeObject"), exports);
33
33
  __exportStar(require("./resolveThemeInfo"), exports);
34
34
  __exportStar(require("./resolveThemeLayouts"), exports);
@@ -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
- * Create directory utils for vuepress app
7
+ * Resolve directory utils for vuepress app
8
8
  */
9
- export declare const createAppDir: (options: AppOptions) => AppDir;
9
+ export declare const resolveAppDir: (options: AppOptions) => AppDir;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createAppDir = exports.createAppDirFunction = void 0;
3
+ exports.resolveAppDir = exports.createAppDirFunction = void 0;
4
4
  const utils_1 = require("@vuepress/utils");
5
5
  /**
6
6
  * Create directory util function
@@ -10,9 +10,9 @@ const createAppDirFunction = (baseDir) => {
10
10
  };
11
11
  exports.createAppDirFunction = createAppDirFunction;
12
12
  /**
13
- * Create directory utils for vuepress app
13
+ * Resolve directory utils for vuepress app
14
14
  */
15
- const createAppDir = (options) => {
15
+ const resolveAppDir = (options) => {
16
16
  const cache = (0, exports.createAppDirFunction)(options.cache);
17
17
  const temp = (0, exports.createAppDirFunction)(options.temp);
18
18
  const source = (0, exports.createAppDirFunction)(options.source);
@@ -29,4 +29,4 @@ const createAppDir = (options) => {
29
29
  public: publicDir,
30
30
  };
31
31
  };
32
- exports.createAppDir = createAppDir;
32
+ exports.resolveAppDir = resolveAppDir;
@@ -0,0 +1,5 @@
1
+ import type { AppEnv, AppOptions } from '../types';
2
+ /**
3
+ * Resolve environment flags for vuepress app
4
+ */
5
+ export declare const resolveAppEnv: (options: AppOptions, isBuild: boolean) => AppEnv;
@@ -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;
@@ -0,0 +1,6 @@
1
+ import type { Markdown } from '@vuepress/markdown';
2
+ import type { App } from '../types';
3
+ /**
4
+ * Resolve markdown-it instance for vuepress app
5
+ */
6
+ export declare const resolveAppMarkdown: (app: App) => Promise<Markdown>;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createAppMarkdown = void 0;
3
+ exports.resolveAppMarkdown = void 0;
4
4
  const markdown_1 = require("@vuepress/markdown");
5
5
  /**
6
- * Create markdown-it instance for vuepress app
6
+ * Resolve markdown-it instance for vuepress app
7
7
  */
8
- const createAppMarkdown = async (app) => {
8
+ const resolveAppMarkdown = async (app) => {
9
9
  // plugin hook: extendsMarkdownOptions
10
10
  await app.pluginApi.hooks.extendsMarkdownOptions.process(app.options.markdown, app);
11
11
  const markdown = (0, markdown_1.createMarkdown)(app.options.markdown);
@@ -13,4 +13,4 @@ const createAppMarkdown = async (app) => {
13
13
  await app.pluginApi.hooks.extendsMarkdown.process(markdown, app);
14
14
  return markdown;
15
15
  };
16
- exports.createAppMarkdown = createAppMarkdown;
16
+ exports.resolveAppMarkdown = resolveAppMarkdown;
@@ -0,0 +1,5 @@
1
+ import type { AppConfig, AppOptions } from '../types';
2
+ /**
3
+ * Create app options with default values
4
+ */
5
+ export declare const resolveAppOptions: ({ base, lang, title, description, head, locales, theme, themeConfig, bundler, bundlerConfig, source, dest, temp, cache, public: publicDir, markdown, host, port, debug, open, pagePatterns, templateDev, templateBuild, shouldPreload, shouldPrefetch, plugins, }: AppConfig) => AppOptions;
@@ -1,23 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createAppOptions = void 0;
3
+ exports.resolveAppOptions = void 0;
4
4
  const utils_1 = require("@vuepress/utils");
5
5
  /**
6
6
  * Create app options with default values
7
7
  */
8
- const createAppOptions = ({
8
+ const resolveAppOptions = ({
9
9
  // site config
10
10
  base = '/', lang = 'en-US', title = '', description = '', head = [], locales = {},
11
11
  // theme config
12
- theme = '@vuepress/default', themeConfig = {},
12
+ theme = '@vuepress/theme-default', themeConfig = {},
13
13
  // bundler config
14
- bundler = '@vuepress/vite', bundlerConfig = {},
14
+ bundler = '@vuepress/bundler-vite', bundlerConfig = {},
15
15
  // directory config
16
16
  source, dest = utils_1.path.resolve(source, '.vuepress/dist'), temp = utils_1.path.resolve(source, '.vuepress/.temp'), cache = utils_1.path.resolve(source, '.vuepress/.cache'), public: publicDir = utils_1.path.resolve(source, '.vuepress/public'),
17
17
  // markdown config
18
18
  markdown = {},
19
19
  // development config
20
- host = '0.0.0.0', port = 8080, debug = false, open = false, pagePatterns = ['**/*.md', '!.vuepress', '!node_modules'], templateDev = utils_1.path.normalize(require.resolve('@vuepress/client/templates/index.dev.html')), templateSSR = utils_1.path.normalize(require.resolve('@vuepress/client/templates/index.ssr.html')), shouldPreload = true, shouldPrefetch = false,
20
+ host = '0.0.0.0', port = 8080, debug = false, open = false, pagePatterns = ['**/*.md', '!.vuepress', '!node_modules'], templateDev = utils_1.path.normalize(require.resolve('@vuepress/client/templates/index.dev.html')), templateBuild = utils_1.path.normalize(require.resolve('@vuepress/client/templates/index.build.html')), shouldPreload = true, shouldPrefetch = false,
21
21
  // plugin config
22
22
  plugins = [], }) => ({
23
23
  base,
@@ -42,9 +42,9 @@ plugins = [], }) => ({
42
42
  open,
43
43
  pagePatterns,
44
44
  templateDev,
45
- templateSSR,
45
+ templateBuild,
46
46
  shouldPreload,
47
47
  shouldPrefetch,
48
48
  plugins,
49
49
  });
50
- exports.createAppOptions = createAppOptions;
50
+ exports.resolveAppOptions = resolveAppOptions;
@@ -0,0 +1,5 @@
1
+ import type { App, Page } from '../types';
2
+ /**
3
+ * Resolve pages for vuepress app
4
+ */
5
+ export declare const resolveAppPages: (app: App) => Promise<Page[]>;
@@ -1,29 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createAppPages = void 0;
3
+ exports.resolveAppPages = void 0;
4
4
  const utils_1 = require("@vuepress/utils");
5
5
  const page_1 = require("../page");
6
6
  const log = (0, utils_1.debug)('vuepress:core/app');
7
7
  /**
8
- * Create pages for vuepress app
8
+ * Resolve pages for vuepress app
9
9
  */
10
- const createAppPages = async (app) => {
11
- log('createAppPages start');
10
+ const resolveAppPages = async (app) => {
11
+ log('resolveAppPages start');
12
12
  // resolve page absolute file paths according to the page patterns
13
13
  const pageFilePaths = await (0, utils_1.globby)(app.options.pagePatterns, {
14
14
  absolute: true,
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, {
@@ -33,7 +25,7 @@ const createAppPages = async (app) => {
33
25
  },
34
26
  }));
35
27
  }
36
- log('createAppPages finish');
28
+ log('resolveAppPages finish');
37
29
  return pages;
38
30
  };
39
- exports.createAppPages = createAppPages;
31
+ exports.resolveAppPages = resolveAppPages;
@@ -0,0 +1,7 @@
1
+ import type { AppOptions, SiteData } from '../types';
2
+ /**
3
+ * Resolve site data for vuepress app
4
+ *
5
+ * Site data will also be used in client
6
+ */
7
+ export declare const resolveAppSiteData: (options: AppOptions) => SiteData;
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createAppSiteData = void 0;
3
+ exports.resolveAppSiteData = void 0;
4
4
  /**
5
- * Create site data for vuepress app
5
+ * Resolve site data for vuepress app
6
6
  *
7
7
  * Site data will also be used in client
8
8
  */
9
- const createAppSiteData = (options) => ({
9
+ const resolveAppSiteData = (options) => ({
10
10
  base: options.base,
11
11
  lang: options.lang,
12
12
  title: options.title,
@@ -14,4 +14,4 @@ const createAppSiteData = (options) => ({
14
14
  head: options.head,
15
15
  locales: options.locales,
16
16
  });
17
- exports.createAppSiteData = createAppSiteData;
17
+ exports.resolveAppSiteData = resolveAppSiteData;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Resolve version of vuepress app
3
+ */
4
+ export declare const resolveAppVersion: () => string;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveAppVersion = void 0;
4
+ /**
5
+ * Resolve version of vuepress app
6
+ */
7
+ const resolveAppVersion = () => {
8
+ return require('../../package.json').version;
9
+ };
10
+ exports.resolveAppVersion = resolveAppVersion;
@@ -0,0 +1,5 @@
1
+ import type { AppDir, AppWriteTemp } from '../types';
2
+ /**
3
+ * Resolve write temp file util for vuepress app
4
+ */
5
+ export declare const resolveAppWriteTemp: (dir: AppDir) => AppWriteTemp;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createAppWriteTemp = void 0;
3
+ exports.resolveAppWriteTemp = void 0;
4
4
  const utils_1 = require("@vuepress/utils");
5
5
  /**
6
- * Create write temp file util for vuepress app
6
+ * Resolve write temp file util for vuepress app
7
7
  */
8
- const createAppWriteTemp = (dir) => {
8
+ const resolveAppWriteTemp = (dir) => {
9
9
  const tempCache = new Map();
10
10
  const writeTemp = async (file, content) => {
11
11
  const filePath = dir.temp(file);
@@ -18,4 +18,4 @@ const createAppWriteTemp = (dir) => {
18
18
  };
19
19
  return writeTemp;
20
20
  };
21
- exports.createAppWriteTemp = createAppWriteTemp;
21
+ exports.resolveAppWriteTemp = resolveAppWriteTemp;
@@ -0,0 +1,5 @@
1
+ import type { App, Plugin, PluginObject, PluginOptions } from '../types';
2
+ /**
3
+ * Resolve a plugin object according to name / path / module and config
4
+ */
5
+ export declare const resolvePluginObject: <T extends PluginOptions = PluginOptions, U extends PluginObject = PluginObject>(app: App, plugin: string | Plugin<T, U>, pluginConfig?: Partial<T>) => U;
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolvePlugin = void 0;
3
+ exports.resolvePluginObject = void 0;
4
4
  const shared_1 = require("@vuepress/shared");
5
5
  const utils_1 = require("@vuepress/utils");
6
6
  const resolvePluginModule_1 = require("./resolvePluginModule");
7
7
  /**
8
- * Resolve a plugin according to name / path / module and config
8
+ * Resolve a plugin object according to name / path / module and config
9
9
  */
10
- const resolvePlugin = (app, plugin, config = {}) => {
10
+ const resolvePluginObject = (app, plugin, pluginConfig = {}) => {
11
11
  const pluginModule = (0, shared_1.isString)(plugin)
12
12
  ? (0, resolvePluginModule_1.resolvePluginModule)(plugin)
13
13
  : plugin;
@@ -15,8 +15,8 @@ const resolvePlugin = (app, plugin, config = {}) => {
15
15
  throw utils_1.logger.createError(`plugin is not found: ${utils_1.chalk.magenta(plugin)}`);
16
16
  }
17
17
  const pluginObject = (0, shared_1.isFunction)(pluginModule)
18
- ? pluginModule(config, app)
18
+ ? pluginModule(pluginConfig, app)
19
19
  : pluginModule;
20
20
  return pluginObject;
21
21
  };
22
- exports.resolvePlugin = resolvePlugin;
22
+ exports.resolvePluginObject = resolvePluginObject;
@@ -1,5 +1,5 @@
1
1
  import type { App, PluginConfig, PluginObject } from '../types';
2
2
  /**
3
- * Resolve plugins from plugin config array
3
+ * Resolve plugin objects from plugin config array
4
4
  */
5
5
  export declare const resolvePluginsFromConfig: (app: App, plugins?: PluginConfig[]) => PluginObject[];
@@ -2,14 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolvePluginsFromConfig = void 0;
4
4
  const normalizePluginConfig_1 = require("./normalizePluginConfig");
5
- const resolvePlugin_1 = require("./resolvePlugin");
5
+ const resolvePluginObject_1 = require("./resolvePluginObject");
6
6
  /**
7
- * Resolve plugins from plugin config array
7
+ * Resolve plugin objects from plugin config array
8
8
  */
9
9
  const resolvePluginsFromConfig = (app, plugins = []) => plugins.reduce((prev, item) => {
10
10
  const [plugin, config] = (0, normalizePluginConfig_1.normalizePluginConfig)(item);
11
11
  if (config !== false) {
12
- prev.push((0, resolvePlugin_1.resolvePlugin)(app, plugin, config === true ? {} : config));
12
+ prev.push((0, resolvePluginObject_1.resolvePluginObject)(app, plugin, config === true ? {} : config));
13
13
  }
14
14
  return prev;
15
15
  }, []);
@@ -1,5 +1,5 @@
1
- import type { App, ThemeInfo } from '../types';
1
+ import type { App, ThemeConfig, ThemeInfo } from '../types';
2
2
  /**
3
3
  * Resolve theme info and its parent theme info
4
4
  */
5
- export declare const resolveThemeInfo: (app: App, themeName: string) => ThemeInfo;
5
+ export declare const resolveThemeInfo: (app: App, theme: string, themeConfig: ThemeConfig) => ThemeInfo;
@@ -2,27 +2,35 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveThemeInfo = void 0;
4
4
  const resolvePluginsFromConfig_1 = require("./resolvePluginsFromConfig");
5
- const resolveTheme_1 = require("./resolveTheme");
6
5
  const resolveThemeLayouts_1 = require("./resolveThemeLayouts");
6
+ const resolveThemeObject_1 = require("./resolveThemeObject");
7
7
  /**
8
8
  * Resolve theme info and its parent theme info
9
9
  */
10
- const resolveThemeInfo = (app, themeName) => {
10
+ const resolveThemeInfo = (app, theme, themeConfig) => {
11
+ var _a, _b;
11
12
  // resolve current theme info
12
- const theme = (0, resolveTheme_1.resolveTheme)(app, themeName);
13
+ const themeObject = (0, resolveThemeObject_1.resolveThemeObject)(app, theme, themeConfig);
13
14
  const themeInfo = {
14
- layouts: (0, resolveThemeLayouts_1.resolveThemeLayouts)(theme.layouts),
15
- plugins: [...(0, resolvePluginsFromConfig_1.resolvePluginsFromConfig)(app, theme.plugins), theme],
15
+ layouts: (0, resolveThemeLayouts_1.resolveThemeLayouts)(themeObject.layouts),
16
+ plugins: [
17
+ ...(0, resolvePluginsFromConfig_1.resolvePluginsFromConfig)(app, themeObject.plugins),
18
+ themeObject,
19
+ ],
20
+ templateBuild: themeObject.templateBuild,
21
+ templateDev: themeObject.templateDev,
16
22
  };
17
23
  // return if current theme does not have a parent theme
18
- if (!theme.extends) {
24
+ if (!themeObject.extends) {
19
25
  return themeInfo;
20
26
  }
21
27
  // resolve parent theme info recursively
22
- const parentThemeInfo = (0, exports.resolveThemeInfo)(app, theme.extends);
28
+ const parentThemeInfo = (0, exports.resolveThemeInfo)(app, themeObject.extends, themeConfig);
23
29
  return {
24
30
  layouts: { ...parentThemeInfo.layouts, ...themeInfo.layouts },
25
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,
26
34
  };
27
35
  };
28
36
  exports.resolveThemeInfo = resolveThemeInfo;
@@ -0,0 +1,5 @@
1
+ import type { App, ThemeConfig, ThemeObject } from '../types';
2
+ /**
3
+ * Resolve a theme object according to the theme name
4
+ */
5
+ export declare const resolveThemeObject: (app: App, theme: string, themeConfig: ThemeConfig) => ThemeObject;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveThemeObject = void 0;
4
+ const shared_1 = require("@vuepress/shared");
5
+ const utils_1 = require("@vuepress/utils");
6
+ const resolvePluginObject_1 = require("./resolvePluginObject");
7
+ /**
8
+ * Resolve a theme object according to the theme name
9
+ */
10
+ const resolveThemeObject = (app, theme, themeConfig) => {
11
+ // resolve theme entry according to theme name
12
+ const themeEntry = (0, utils_1.requireResolve)(utils_1.path.isAbsolute(theme)
13
+ ? theme
14
+ : (0, shared_1.normalizePackageName)(theme, 'vuepress', 'theme'));
15
+ if (themeEntry === null) {
16
+ throw utils_1.logger.createError(`theme is not found: ${utils_1.chalk.magenta(theme)}`);
17
+ }
18
+ // resolve theme object from theme entry
19
+ const themeObject = (0, resolvePluginObject_1.resolvePluginObject)(app, themeEntry, themeConfig);
20
+ return themeObject;
21
+ };
22
+ exports.resolveThemeObject = resolveThemeObject;
@@ -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) {
@@ -10,14 +10,6 @@ import type { AppDir, AppEnv, AppWriteTemp } from './utils';
10
10
  * Vuepress app
11
11
  */
12
12
  export interface App {
13
- /**
14
- * Version of vuepress core
15
- */
16
- version: string;
17
- /**
18
- * Options that filled all optional fields with a default value
19
- */
20
- options: AppOptions;
21
13
  /**
22
14
  * Directory utils
23
15
  */
@@ -27,13 +19,21 @@ export interface App {
27
19
  */
28
20
  env: AppEnv;
29
21
  /**
30
- * Site data, which will be used in client side
22
+ * Options that filled all optional fields with a default value
31
23
  */
32
- siteData: SiteData;
24
+ options: AppOptions;
33
25
  /**
34
26
  * Plugin system
35
27
  */
36
28
  pluginApi: PluginApi;
29
+ /**
30
+ * Site data, which will be used in client side
31
+ */
32
+ siteData: SiteData;
33
+ /**
34
+ * Version of vuepress core
35
+ */
36
+ version: string;
37
37
  /**
38
38
  * Write temp file
39
39
  */
@@ -4,28 +4,41 @@ import type { BundlerConfig } from '../bundler';
4
4
  import type { PluginConfig } from '../plugin';
5
5
  import type { ThemeConfig } from '../theme';
6
6
  /**
7
- * Vuepress app options
7
+ * Config to create vuepress app
8
8
  */
9
- export interface AppOptions<T extends ThemeConfig = ThemeConfig, U extends BundlerConfig = BundlerConfig> extends SiteData {
10
- theme: string;
11
- themeConfig: Partial<T>;
12
- bundler: string;
13
- bundlerConfig: Partial<U>;
9
+ export declare type AppConfig<T extends ThemeConfig = ThemeConfig, U extends BundlerConfig = BundlerConfig> = Partial<SiteData> & AppConfigDev & AppConfigBuild & {
10
+ theme?: string;
11
+ themeConfig?: Partial<T>;
12
+ bundler?: string;
13
+ bundlerConfig?: Partial<U>;
14
14
  source: string;
15
- dest: string;
16
- temp: string;
17
- cache: string;
18
- public: string;
19
- debug: boolean;
20
- markdown: MarkdownOptions;
21
- pagePatterns: string[];
22
- plugins: PluginConfig[];
23
- host: string;
24
- port: number;
25
- open: boolean;
26
- templateDev: string;
27
- shouldPreload: ((file: string, type: string) => boolean) | boolean;
28
- shouldPrefetch: ((file: string, type: string) => boolean) | boolean;
29
- templateSSR: string;
15
+ dest?: string;
16
+ temp?: string;
17
+ cache?: string;
18
+ public?: string;
19
+ debug?: boolean;
20
+ pagePatterns?: string[];
21
+ markdown?: MarkdownOptions;
22
+ plugins?: PluginConfig[];
23
+ };
24
+ /**
25
+ * Vuepress app config for dev
26
+ */
27
+ export interface AppConfigDev {
28
+ host?: string;
29
+ port?: number;
30
+ open?: boolean;
31
+ templateDev?: string;
30
32
  }
31
- export declare type AppConfig<T extends ThemeConfig = ThemeConfig, U extends BundlerConfig = BundlerConfig> = Partial<AppOptions<T, U>> & Pick<AppOptions<T, U>, 'source'>;
33
+ /**
34
+ * Vuepress app config for build
35
+ */
36
+ export interface AppConfigBuild {
37
+ shouldPreload?: ((file: string, type: string) => boolean) | boolean;
38
+ shouldPrefetch?: ((file: string, type: string) => boolean) | boolean;
39
+ templateBuild?: string;
40
+ }
41
+ /**
42
+ * Vuepress app options
43
+ */
44
+ export declare type AppOptions<T extends ThemeConfig = ThemeConfig, U extends BundlerConfig = BundlerConfig> = Required<AppConfig<T, U>>;
@@ -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.29",
3
+ "version": "2.0.0-beta.35",
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.29",
30
- "@vuepress/markdown": "2.0.0-beta.29",
31
- "@vuepress/shared": "2.0.0-beta.28",
32
- "@vuepress/utils": "2.0.0-beta.28",
29
+ "@vuepress/client": "2.0.0-beta.35",
30
+ "@vuepress/markdown": "2.0.0-beta.35",
31
+ "@vuepress/shared": "2.0.0-beta.35",
32
+ "@vuepress/utils": "2.0.0-beta.35",
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": "2c6eb4270f96b6351cd1f565798bed1f662a6bb2"
39
+ "gitHead": "4bf1c55b6fb863c9251aa80178d5bc6475f5b315"
40
40
  }
@@ -1,5 +0,0 @@
1
- import type { AppEnv, AppOptions } from '../types';
2
- /**
3
- * Create environment flags for vuepress app
4
- */
5
- export declare const createAppEnv: (options: AppOptions, isBuild: boolean) => AppEnv;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createAppEnv = void 0;
4
- /**
5
- * Create environment flags for vuepress app
6
- */
7
- const createAppEnv = (options, isBuild) => ({
8
- isBuild,
9
- isDev: !isBuild,
10
- isDebug: options.debug,
11
- });
12
- exports.createAppEnv = createAppEnv;
@@ -1,6 +0,0 @@
1
- import type { Markdown } from '@vuepress/markdown';
2
- import type { App } from '../types';
3
- /**
4
- * Create markdown-it instance for vuepress app
5
- */
6
- export declare const createAppMarkdown: (app: App) => Promise<Markdown>;
@@ -1,5 +0,0 @@
1
- import type { AppConfig, AppOptions } from '../types';
2
- /**
3
- * Create app options with default values
4
- */
5
- export declare const createAppOptions: ({ base, lang, title, description, head, locales, theme, themeConfig, bundler, bundlerConfig, source, dest, temp, cache, public: publicDir, markdown, host, port, debug, open, pagePatterns, templateDev, templateSSR, shouldPreload, shouldPrefetch, plugins, }: AppConfig) => AppOptions;
@@ -1,5 +0,0 @@
1
- import type { App, Page } from '../types';
2
- /**
3
- * Create pages for vuepress app
4
- */
5
- export declare const createAppPages: (app: App) => Promise<Page[]>;
@@ -1,7 +0,0 @@
1
- import type { AppOptions, SiteData } from '../types';
2
- /**
3
- * Create site data for vuepress app
4
- *
5
- * Site data will also be used in client
6
- */
7
- export declare const createAppSiteData: (options: AppOptions) => SiteData;
@@ -1,4 +0,0 @@
1
- /**
2
- * Create version of vuepress app
3
- */
4
- export declare const createAppVersion: () => string;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createAppVersion = void 0;
4
- /**
5
- * Create version of vuepress app
6
- */
7
- const createAppVersion = () => {
8
- return require('../../package.json').version;
9
- };
10
- exports.createAppVersion = createAppVersion;
@@ -1,5 +0,0 @@
1
- import type { AppDir, AppWriteTemp } from '../types';
2
- /**
3
- * Create write temp file util for vuepress app
4
- */
5
- export declare const createAppWriteTemp: (dir: AppDir) => AppWriteTemp;
@@ -1,5 +0,0 @@
1
- import type { App, Plugin, PluginObject, PluginOptions } from '../types';
2
- /**
3
- * Resolve a plugin according to name / path / module and config
4
- */
5
- export declare const resolvePlugin: <T extends PluginOptions = PluginOptions, U extends PluginObject = PluginObject>(app: App, plugin: string | Plugin<T, U>, config?: Partial<T>) => U;
@@ -1,5 +0,0 @@
1
- import type { App, ThemeObject } from '../types';
2
- /**
3
- * Resolve a theme according to the theme name
4
- */
5
- export declare const resolveTheme: (app: App, themeName: string) => ThemeObject;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveTheme = void 0;
4
- const shared_1 = require("@vuepress/shared");
5
- const utils_1 = require("@vuepress/utils");
6
- const resolvePlugin_1 = require("./resolvePlugin");
7
- /**
8
- * Resolve a theme according to the theme name
9
- */
10
- const resolveTheme = (app, themeName) => {
11
- // resolve theme entry according to theme name
12
- const themeEntry = (0, utils_1.requireResolve)(utils_1.path.isAbsolute(themeName)
13
- ? themeName
14
- : (0, shared_1.normalizePackageName)(themeName, 'vuepress', 'theme'));
15
- if (themeEntry === null) {
16
- throw utils_1.logger.createError(`theme is not found: ${utils_1.chalk.magenta(themeName)}`);
17
- }
18
- // resolve theme from theme entry
19
- const theme = (0, resolvePlugin_1.resolvePlugin)(app, themeEntry, app.options.themeConfig);
20
- return theme;
21
- };
22
- exports.resolveTheme = resolveTheme;