@vuepress/core 2.0.0-beta.50-pre → 2.0.0-beta.51

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/dist/index.js ADDED
@@ -0,0 +1,1014 @@
1
+ // src/app/prepare/prepareClientConfigs.ts
2
+ var prepareClientConfigs = async (app) => {
3
+ const clientConfigFiles = await app.pluginApi.hooks.clientConfigFile.process(
4
+ app
5
+ );
6
+ const content = `${clientConfigFiles.map((filePath, index) => `import clientConfig${index} from '${filePath}'`).join("\n")}
7
+
8
+ export const clientConfigs = [
9
+ ${clientConfigFiles.map((_, index) => ` clientConfig${index},`).join("\n")}
10
+ ]
11
+ `;
12
+ await app.writeTemp("internal/clientConfigs.js", content);
13
+ };
14
+
15
+ // src/app/prepare/preparePageComponent.ts
16
+ var preparePageComponent = async (app, page) => {
17
+ await app.writeTemp(
18
+ page.componentFilePathRelative,
19
+ [
20
+ `${page.sfcBlocks.template?.tagOpen}<div>${page.sfcBlocks.template?.contentStripped}</div>${page.sfcBlocks.template?.tagClose}
21
+ `,
22
+ page.sfcBlocks.script?.content,
23
+ page.sfcBlocks.scriptSetup?.content,
24
+ ...page.sfcBlocks.styles.map((item) => item.content),
25
+ ...page.sfcBlocks.customBlocks.map((item) => item.content)
26
+ ].join("\n")
27
+ );
28
+ };
29
+
30
+ // src/app/prepare/preparePageData.ts
31
+ var HMR_CODE = `
32
+ if (import.meta.webpackHot) {
33
+ import.meta.webpackHot.accept()
34
+ if (__VUE_HMR_RUNTIME__.updatePageData) {
35
+ __VUE_HMR_RUNTIME__.updatePageData(data)
36
+ }
37
+ }
38
+
39
+ if (import.meta.hot) {
40
+ import.meta.hot.accept(({ data }) => {
41
+ __VUE_HMR_RUNTIME__.updatePageData(data)
42
+ })
43
+ }
44
+ `;
45
+ var preparePageData = async (app, page) => {
46
+ let content = `export const data = JSON.parse(${JSON.stringify(
47
+ JSON.stringify(page.data)
48
+ )})
49
+ `;
50
+ if (app.env.isDev) {
51
+ content += HMR_CODE;
52
+ }
53
+ await app.writeTemp(page.dataFilePathRelative, content);
54
+ };
55
+
56
+ // src/app/prepare/preparePagesComponents.ts
57
+ var preparePagesComponents = async (app) => {
58
+ const content = `import { defineAsyncComponent } from 'vue'
59
+
60
+ export const pagesComponents = {${app.pages.map(
61
+ ({ key, path: path9, componentFilePath, componentFileChunkName }) => `
62
+ // path: ${path9}
63
+ ${JSON.stringify(key)}: defineAsyncComponent(() => import(${componentFileChunkName ? `/* webpackChunkName: "${componentFileChunkName}" */` : ""}${JSON.stringify(componentFilePath)})),`
64
+ ).join("")}
65
+ }
66
+ `;
67
+ await app.writeTemp("internal/pagesComponents.js", content);
68
+ };
69
+
70
+ // src/app/prepare/preparePagesData.ts
71
+ var preparePagesData = async (app) => {
72
+ const content = `export const pagesData = {${app.pages.map(
73
+ ({ key, path: path9, dataFilePath, dataFileChunkName }) => `
74
+ // path: ${path9}
75
+ ${JSON.stringify(key)}: () => import(${dataFileChunkName ? `/* webpackChunkName: "${dataFileChunkName}" */` : ""}${JSON.stringify(dataFilePath)}).then(({ data }) => data),`
76
+ ).join("")}
77
+ }
78
+ `;
79
+ await app.writeTemp("internal/pagesData.js", content);
80
+ };
81
+
82
+ // src/app/prepare/preparePagesRoutes.ts
83
+ import { ensureLeadingSlash } from "@vuepress/shared";
84
+ var resolvePageRouteItem = ({
85
+ key,
86
+ path: path9,
87
+ pathInferred,
88
+ filePathRelative,
89
+ routeMeta
90
+ }) => {
91
+ const redirectsSet = /* @__PURE__ */ new Set();
92
+ redirectsSet.add(decodeURI(path9));
93
+ if (path9.endsWith("/")) {
94
+ redirectsSet.add(path9 + "index.html");
95
+ } else {
96
+ redirectsSet.add(path9.replace(/.html$/, ""));
97
+ }
98
+ if (pathInferred !== null) {
99
+ redirectsSet.add(pathInferred);
100
+ redirectsSet.add(encodeURI(pathInferred));
101
+ }
102
+ if (filePathRelative !== null) {
103
+ const filenamePath = ensureLeadingSlash(filePathRelative);
104
+ redirectsSet.add(filenamePath);
105
+ redirectsSet.add(encodeURI(filenamePath));
106
+ }
107
+ redirectsSet.delete(path9);
108
+ return [key, path9, routeMeta, [...redirectsSet]];
109
+ };
110
+ var preparePagesRoutes = async (app) => {
111
+ const routeItems = app.pages.map(resolvePageRouteItem);
112
+ const content = `export const pagesRoutes = [${routeItems.map((routeItem) => `
113
+ ${JSON.stringify(routeItem)},`).join("")}
114
+ ]
115
+ `;
116
+ await app.writeTemp("internal/pagesRoutes.js", content);
117
+ };
118
+
119
+ // src/app/prepare/prepareSiteData.ts
120
+ var HMR_CODE2 = `
121
+ if (import.meta.webpackHot) {
122
+ import.meta.webpackHot.accept()
123
+ if (__VUE_HMR_RUNTIME__.updateSiteData) {
124
+ __VUE_HMR_RUNTIME__.updateSiteData(siteData)
125
+ }
126
+ }
127
+
128
+ if (import.meta.hot) {
129
+ import.meta.hot.accept(({ siteData }) => {
130
+ __VUE_HMR_RUNTIME__.updateSiteData(siteData)
131
+ })
132
+ }
133
+ `;
134
+ var prepareSiteData = async (app) => {
135
+ let content = `export const siteData = JSON.parse(${JSON.stringify(
136
+ JSON.stringify(app.siteData)
137
+ )})
138
+ `;
139
+ if (app.env.isDev) {
140
+ content += HMR_CODE2;
141
+ }
142
+ await app.writeTemp("internal/siteData.js", content);
143
+ };
144
+
145
+ // src/app/appInit.ts
146
+ import { debug as debug3 } from "@vuepress/utils";
147
+
148
+ // src/app/resolveAppMarkdown.ts
149
+ import { createMarkdown } from "@vuepress/markdown";
150
+ var resolveAppMarkdown = async (app) => {
151
+ await app.pluginApi.hooks.extendsMarkdownOptions.process(
152
+ app.options.markdown,
153
+ app
154
+ );
155
+ const markdown = createMarkdown(app.options.markdown);
156
+ await app.pluginApi.hooks.extendsMarkdown.process(markdown, app);
157
+ return markdown;
158
+ };
159
+
160
+ // src/app/resolveAppPages.ts
161
+ import { debug as debug2, globby } from "@vuepress/utils";
162
+
163
+ // src/page/inferPagePath.ts
164
+ import { ensureLeadingSlash as ensureLeadingSlash2, resolveLocalePath } from "@vuepress/shared";
165
+ var inferPagePath = ({
166
+ app,
167
+ filePathRelative
168
+ }) => {
169
+ if (!filePathRelative) {
170
+ return {
171
+ pathInferred: null,
172
+ pathLocale: "/"
173
+ };
174
+ }
175
+ const pathInferred = ensureLeadingSlash2(filePathRelative).replace(/\.md$/, ".html").replace(/\/(README|index).html$/i, "/");
176
+ const pathLocale = resolveLocalePath(app.siteData.locales, pathInferred);
177
+ return {
178
+ pathInferred,
179
+ pathLocale
180
+ };
181
+ };
182
+
183
+ // src/page/renderPageContent.ts
184
+ var renderPageContent = async ({
185
+ app,
186
+ content,
187
+ filePath,
188
+ filePathRelative,
189
+ options
190
+ }) => {
191
+ const markdownEnv = {
192
+ base: app.options.base,
193
+ filePath,
194
+ filePathRelative,
195
+ frontmatter: { ...options.frontmatter }
196
+ };
197
+ const contentRendered = app.markdown.render(content, markdownEnv);
198
+ const {
199
+ excerpt = "",
200
+ frontmatter = {},
201
+ headers = [],
202
+ importedFiles = [],
203
+ links = [],
204
+ sfcBlocks = {
205
+ template: null,
206
+ script: null,
207
+ scriptSetup: null,
208
+ styles: [],
209
+ customBlocks: []
210
+ },
211
+ title = ""
212
+ } = markdownEnv;
213
+ return {
214
+ contentRendered,
215
+ deps: importedFiles,
216
+ excerpt,
217
+ frontmatter,
218
+ headers,
219
+ links,
220
+ sfcBlocks,
221
+ title: frontmatter.title ?? title
222
+ };
223
+ };
224
+
225
+ // src/page/resolvePageComponentInfo.ts
226
+ import { path } from "@vuepress/utils";
227
+ var resolvePageComponentInfo = async ({
228
+ app,
229
+ htmlFilePathRelative,
230
+ key
231
+ }) => {
232
+ const componentFilePathRelative = path.join(
233
+ "pages",
234
+ `${htmlFilePathRelative}.vue`
235
+ );
236
+ const componentFilePath = app.dir.temp(componentFilePathRelative);
237
+ const componentFileChunkName = key;
238
+ return {
239
+ componentFilePath,
240
+ componentFilePathRelative,
241
+ componentFileChunkName
242
+ };
243
+ };
244
+
245
+ // src/page/resolvePageDataInfo.ts
246
+ import { path as path2 } from "@vuepress/utils";
247
+ var resolvePageDataInfo = ({
248
+ app,
249
+ htmlFilePathRelative,
250
+ key
251
+ }) => {
252
+ const dataFilePathRelative = path2.join("pages", `${htmlFilePathRelative}.js`);
253
+ const dataFilePath = app.dir.temp(dataFilePathRelative);
254
+ const dataFileChunkName = key;
255
+ return {
256
+ dataFilePath,
257
+ dataFilePathRelative,
258
+ dataFileChunkName
259
+ };
260
+ };
261
+
262
+ // src/page/resolvePageDate.ts
263
+ import { formatDateString, isString } from "@vuepress/shared";
264
+ import { path as path3 } from "@vuepress/utils";
265
+ var FILENAME_DATE_RE = /^(\d{4})-(\d{1,2})(?:-(\d{1,2}))?-(.*)$/;
266
+ var DIRNAME_DATE_RE = /(\d{4})\/(\d{1,2})(?:\/(\d{1,2}))?(\/|$)/;
267
+ var DEFAULT_DATE = "0000-00-00";
268
+ var resolvePageDate = ({
269
+ frontmatter,
270
+ filePathRelative
271
+ }) => {
272
+ if (frontmatter.date instanceof Date) {
273
+ return formatDateString(
274
+ [
275
+ frontmatter.date.getUTCFullYear(),
276
+ frontmatter.date.getUTCMonth() + 1,
277
+ frontmatter.date.getUTCDate()
278
+ ].join("-"),
279
+ DEFAULT_DATE
280
+ );
281
+ }
282
+ if (isString(frontmatter.date)) {
283
+ return formatDateString(frontmatter.date, DEFAULT_DATE);
284
+ }
285
+ if (filePathRelative === null) {
286
+ return DEFAULT_DATE;
287
+ }
288
+ const filename = path3.parse(filePathRelative).name;
289
+ if (filename) {
290
+ const matches = filename.match(FILENAME_DATE_RE);
291
+ if (matches) {
292
+ return formatDateString(
293
+ `${matches[1]}-${matches[2]}-${matches[3] ?? "01"}`,
294
+ DEFAULT_DATE
295
+ );
296
+ }
297
+ }
298
+ const dirname = path3.dirname(filePathRelative);
299
+ if (dirname !== ".") {
300
+ const matches = dirname.match(DIRNAME_DATE_RE);
301
+ if (matches) {
302
+ return formatDateString(
303
+ `${matches[1]}-${matches[2]}-${matches[3] ?? "01"}`,
304
+ DEFAULT_DATE
305
+ );
306
+ }
307
+ }
308
+ return DEFAULT_DATE;
309
+ };
310
+
311
+ // src/page/resolvePageFileContent.ts
312
+ import { debug, fs } from "@vuepress/utils";
313
+ var log = debug("vuepress:core/page");
314
+ var resolvePageFileContent = async ({
315
+ filePath,
316
+ options
317
+ }) => {
318
+ if (filePath) {
319
+ try {
320
+ const content = await fs.readFile(filePath, "utf-8");
321
+ return content;
322
+ } catch (e) {
323
+ log(e instanceof Error ? e.message : e);
324
+ }
325
+ }
326
+ return options.content ?? "";
327
+ };
328
+
329
+ // src/page/resolvePageFilePath.ts
330
+ import { logger, path as path4 } from "@vuepress/utils";
331
+ var resolvePageFilePath = ({
332
+ app,
333
+ options
334
+ }) => {
335
+ if (!options.filePath) {
336
+ return {
337
+ filePath: null,
338
+ filePathRelative: null
339
+ };
340
+ }
341
+ if (!path4.isAbsolute(options.filePath)) {
342
+ throw logger.createError(
343
+ `filePath is not absolute file path: ${options.filePath}}`
344
+ );
345
+ }
346
+ return {
347
+ filePath: options.filePath,
348
+ filePathRelative: path4.relative(app.dir.source(), options.filePath)
349
+ };
350
+ };
351
+
352
+ // src/page/resolvePageHtmlInfo.ts
353
+ import { removeLeadingSlash } from "@vuepress/shared";
354
+ var resolvePageHtmlInfo = ({
355
+ app,
356
+ path: pagePath
357
+ }) => {
358
+ const htmlFilePathRelative = removeLeadingSlash(
359
+ decodeURI(pagePath.replace(/\/$/, "/index.html"))
360
+ );
361
+ const htmlFilePath = app.dir.dest(htmlFilePathRelative);
362
+ return {
363
+ htmlFilePath,
364
+ htmlFilePathRelative
365
+ };
366
+ };
367
+
368
+ // src/page/resolvePageKey.ts
369
+ import { hash } from "@vuepress/utils";
370
+ var resolvePageKey = ({ path: path9 }) => `v-${hash(path9)}`;
371
+
372
+ // src/page/resolvePageLang.ts
373
+ import { isString as isString2 } from "@vuepress/shared";
374
+ var resolvePageLang = ({
375
+ app,
376
+ frontmatter,
377
+ pathLocale
378
+ }) => {
379
+ if (isString2(frontmatter.lang) && frontmatter.lang) {
380
+ return frontmatter.lang;
381
+ }
382
+ return app.siteData.locales[pathLocale]?.lang ?? app.siteData.lang;
383
+ };
384
+
385
+ // src/page/resolvePagePath.ts
386
+ import { ensureEndingSlash } from "@vuepress/shared";
387
+ import { logger as logger2 } from "@vuepress/utils";
388
+ var resolvePagePath = ({
389
+ permalink,
390
+ pathInferred,
391
+ options
392
+ }) => {
393
+ let pagePath = options.path || permalink || pathInferred;
394
+ if (!pagePath) {
395
+ throw logger2.createError(
396
+ `page path is empty, page options: ${JSON.stringify(options, null, 2)}`
397
+ );
398
+ }
399
+ if (!pagePath.endsWith(".html")) {
400
+ pagePath = ensureEndingSlash(pagePath);
401
+ }
402
+ return encodeURI(pagePath);
403
+ };
404
+
405
+ // src/page/resolvePagePermalink.ts
406
+ import { ensureLeadingSlash as ensureLeadingSlash3, isString as isString3 } from "@vuepress/shared";
407
+ import { path as path5 } from "@vuepress/utils";
408
+ var resolvePagePermalink = ({
409
+ app,
410
+ frontmatter,
411
+ slug,
412
+ date,
413
+ pathInferred,
414
+ pathLocale
415
+ }) => {
416
+ if (isString3(frontmatter.permalink)) {
417
+ return frontmatter.permalink;
418
+ }
419
+ const permalinkPattern = getPermalinkPattern({ app, frontmatter });
420
+ if (permalinkPattern === null) {
421
+ return null;
422
+ }
423
+ const [year, month, day] = date.split("-");
424
+ const link = path5.join(
425
+ pathLocale,
426
+ permalinkPattern.replace(/:year/, year).replace(/:month/, month).replace(/:day/, day).replace(/:slug/, slug).replace(/:raw/, pathInferred?.replace(/^\//, "") ?? "")
427
+ );
428
+ return ensureLeadingSlash3(link);
429
+ };
430
+ var getPermalinkPattern = ({
431
+ app,
432
+ frontmatter
433
+ }) => {
434
+ if (frontmatter.permalinkPattern === null) {
435
+ return null;
436
+ }
437
+ if (isString3(frontmatter.permalinkPattern)) {
438
+ return frontmatter.permalinkPattern;
439
+ }
440
+ return app.options.permalinkPattern;
441
+ };
442
+
443
+ // src/page/resolvePageRouteMeta.ts
444
+ var resolvePageRouteMeta = ({
445
+ frontmatter
446
+ }) => frontmatter.routeMeta ?? {};
447
+
448
+ // src/page/resolvePageSlug.ts
449
+ import { path as path6 } from "@vuepress/utils";
450
+ var DATE_RE = /(\d{4}-\d{1,2}(-\d{1,2})?)-(.*)/;
451
+ var resolvePageSlug = ({
452
+ filePathRelative
453
+ }) => {
454
+ if (!filePathRelative) {
455
+ return "";
456
+ }
457
+ const filename = path6.parse(filePathRelative).name;
458
+ const match = filename.match(DATE_RE);
459
+ return match ? match[3] : filename;
460
+ };
461
+
462
+ // src/page/createPage.ts
463
+ var createPage = async (app, options) => {
464
+ await app.pluginApi.hooks.extendsPageOptions.process(options, app);
465
+ const { filePath, filePathRelative } = resolvePageFilePath({
466
+ app,
467
+ options
468
+ });
469
+ const content = await resolvePageFileContent({ filePath, options });
470
+ const {
471
+ contentRendered,
472
+ deps,
473
+ excerpt,
474
+ frontmatter,
475
+ headers,
476
+ links,
477
+ sfcBlocks,
478
+ title
479
+ } = await renderPageContent({
480
+ app,
481
+ content,
482
+ filePath,
483
+ filePathRelative,
484
+ options
485
+ });
486
+ const routeMeta = resolvePageRouteMeta({ frontmatter });
487
+ const slug = resolvePageSlug({ filePathRelative });
488
+ const date = resolvePageDate({ frontmatter, filePathRelative });
489
+ const { pathInferred, pathLocale } = inferPagePath({ app, filePathRelative });
490
+ const lang = resolvePageLang({ app, frontmatter, pathLocale });
491
+ const permalink = resolvePagePermalink({
492
+ app,
493
+ frontmatter,
494
+ slug,
495
+ date,
496
+ pathInferred,
497
+ pathLocale
498
+ });
499
+ const path9 = resolvePagePath({ permalink, pathInferred, options });
500
+ const key = resolvePageKey({ path: path9 });
501
+ const { htmlFilePath, htmlFilePathRelative } = resolvePageHtmlInfo({
502
+ app,
503
+ path: path9
504
+ });
505
+ const {
506
+ componentFilePath,
507
+ componentFilePathRelative,
508
+ componentFileChunkName
509
+ } = await resolvePageComponentInfo({
510
+ app,
511
+ htmlFilePathRelative,
512
+ key
513
+ });
514
+ const { dataFilePath, dataFilePathRelative, dataFileChunkName } = resolvePageDataInfo({ app, htmlFilePathRelative, key });
515
+ const page = {
516
+ data: {
517
+ key,
518
+ path: path9,
519
+ title,
520
+ lang,
521
+ frontmatter,
522
+ excerpt,
523
+ headers
524
+ },
525
+ key,
526
+ path: path9,
527
+ title,
528
+ lang,
529
+ frontmatter,
530
+ excerpt,
531
+ headers,
532
+ content,
533
+ contentRendered,
534
+ date,
535
+ deps,
536
+ links,
537
+ pathInferred,
538
+ pathLocale,
539
+ permalink,
540
+ routeMeta,
541
+ sfcBlocks,
542
+ slug,
543
+ filePath,
544
+ filePathRelative,
545
+ componentFilePath,
546
+ componentFilePathRelative,
547
+ componentFileChunkName,
548
+ dataFilePath,
549
+ dataFilePathRelative,
550
+ dataFileChunkName,
551
+ htmlFilePath,
552
+ htmlFilePathRelative
553
+ };
554
+ await app.pluginApi.hooks.extendsPage.process(page, app);
555
+ return page;
556
+ };
557
+
558
+ // src/app/resolveAppPages.ts
559
+ var log2 = debug2("vuepress:core/app");
560
+ var resolveAppPages = async (app) => {
561
+ log2("resolveAppPages start");
562
+ const pageFilePaths = await globby(app.options.pagePatterns, {
563
+ absolute: true,
564
+ cwd: app.dir.source()
565
+ });
566
+ const pages = await Promise.all(
567
+ pageFilePaths.map((filePath) => createPage(app, { filePath }))
568
+ );
569
+ if (!pages.some((page) => page.path === "/404.html")) {
570
+ pages.push(
571
+ await createPage(app, {
572
+ path: "/404.html",
573
+ frontmatter: {
574
+ layout: "NotFound"
575
+ }
576
+ })
577
+ );
578
+ }
579
+ log2("resolveAppPages finish");
580
+ return pages;
581
+ };
582
+
583
+ // src/app/appInit.ts
584
+ var log3 = debug3("vuepress:core/app");
585
+ var appInit = async (app) => {
586
+ log3("init start");
587
+ app.pluginApi.registerHooks();
588
+ app.markdown = await resolveAppMarkdown(app);
589
+ app.pages = await resolveAppPages(app);
590
+ await app.pluginApi.hooks.onInitialized.process(app);
591
+ log3("init finish");
592
+ };
593
+
594
+ // src/app/appPrepare.ts
595
+ import { debug as debug4 } from "@vuepress/utils";
596
+ var log4 = debug4("vuepress:core/app");
597
+ var appPrepare = async (app) => {
598
+ log4("prepare start");
599
+ for (const page of app.pages) {
600
+ await preparePageComponent(app, page);
601
+ }
602
+ await preparePagesComponents(app);
603
+ for (const page of app.pages) {
604
+ await preparePageData(app, page);
605
+ }
606
+ await preparePagesData(app);
607
+ await preparePagesRoutes(app);
608
+ await prepareSiteData(app);
609
+ await prepareClientConfigs(app);
610
+ await app.pluginApi.hooks.onPrepared.process(app);
611
+ log4("prepare finish");
612
+ };
613
+
614
+ // src/app/appUse.ts
615
+ import { chalk, debug as debug5, warn } from "@vuepress/utils";
616
+
617
+ // src/app/resolvePluginObject.ts
618
+ import { isFunction } from "@vuepress/shared";
619
+ var resolvePluginObject = (app, plugin) => isFunction(plugin) ? plugin(app) : plugin;
620
+
621
+ // src/app/appUse.ts
622
+ var log5 = debug5("vuepress:core/app");
623
+ var appUse = (app, rawPlugin) => {
624
+ const pluginObject = resolvePluginObject(app, rawPlugin);
625
+ if (!pluginObject.name) {
626
+ warn(`an anonymous plugin or theme was detected and ignored`);
627
+ return app;
628
+ }
629
+ log5(`use plugin ${chalk.magenta(pluginObject.name)}`);
630
+ if (pluginObject.multiple !== true) {
631
+ const duplicateIndex = app.pluginApi.plugins.findIndex(
632
+ ({ name }) => name === pluginObject.name
633
+ );
634
+ if (duplicateIndex !== -1) {
635
+ app.pluginApi.plugins.splice(duplicateIndex, 1);
636
+ warn(
637
+ `plugin ${chalk.magenta(
638
+ pluginObject.name
639
+ )} has been used multiple times, only the last one will take effect`
640
+ );
641
+ }
642
+ }
643
+ app.pluginApi.plugins.push(pluginObject);
644
+ return app;
645
+ };
646
+
647
+ // src/pluginApi/createHookQueue.ts
648
+ import { chalk as chalk2, debug as debug6, logger as logger3 } from "@vuepress/utils";
649
+ var log6 = debug6("vuepress:core/plugin-api");
650
+ var createHookQueue = (name) => {
651
+ const items = [];
652
+ const hookQueue = {
653
+ name,
654
+ items,
655
+ add: (item) => {
656
+ items.push(item);
657
+ },
658
+ process: async (...args) => {
659
+ const results = [];
660
+ for (const item of items) {
661
+ log6(
662
+ `process ${chalk2.magenta(name)} from ${chalk2.magenta(
663
+ item.pluginName
664
+ )}`
665
+ );
666
+ try {
667
+ const result = await item.hook(...args);
668
+ if (result !== void 0) {
669
+ results.push(result);
670
+ }
671
+ } catch (e) {
672
+ logger3.error(
673
+ `error in hook ${chalk2.magenta(name)} from ${chalk2.magenta(
674
+ item.pluginName
675
+ )}`
676
+ );
677
+ throw e;
678
+ }
679
+ }
680
+ return results;
681
+ }
682
+ };
683
+ return hookQueue;
684
+ };
685
+
686
+ // src/pluginApi/createPluginApiHooks.ts
687
+ var createPluginApiHooks = () => ({
688
+ onInitialized: createHookQueue("onInitialized"),
689
+ onPrepared: createHookQueue("onPrepared"),
690
+ onWatched: createHookQueue("onWatched"),
691
+ onGenerated: createHookQueue("onGenerated"),
692
+ extendsMarkdownOptions: createHookQueue("extendsMarkdownOptions"),
693
+ extendsMarkdown: createHookQueue("extendsMarkdown"),
694
+ extendsPageOptions: createHookQueue("extendsPageOptions"),
695
+ extendsPage: createHookQueue("extendsPage"),
696
+ extendsBundlerOptions: createHookQueue("extendsBundlerOptions"),
697
+ clientConfigFile: createHookQueue("clientConfigFile"),
698
+ alias: createHookQueue("alias"),
699
+ define: createHookQueue("define")
700
+ });
701
+
702
+ // src/pluginApi/normalizeAliasDefineHook.ts
703
+ import { isFunction as isFunction2 } from "@vuepress/shared";
704
+ var normalizeAliasDefineHook = (hook) => async (app, isServer) => isFunction2(hook) ? hook(app, isServer) : hook;
705
+
706
+ // src/pluginApi/normalizeClientConfigFileHook.ts
707
+ import { isFunction as isFunction3 } from "@vuepress/shared";
708
+ import { fs as fs2, logger as logger4 } from "@vuepress/utils";
709
+ var normalizeClientConfigFileHook = (hook) => async (app) => {
710
+ const clientConfigFileResult = isFunction3(hook) ? await hook(app) : hook;
711
+ const isExisted = await fs2.pathExists(clientConfigFileResult);
712
+ if (!isExisted) {
713
+ throw logger4.createError(
714
+ `client config file does not exist: ${clientConfigFileResult}`
715
+ );
716
+ }
717
+ return clientConfigFileResult;
718
+ };
719
+
720
+ // src/pluginApi/createPluginApiRegisterHooks.ts
721
+ var createPluginApiRegisterHooks = (plugins, hooks) => () => {
722
+ plugins.forEach(
723
+ ({
724
+ name: pluginName,
725
+ alias,
726
+ define,
727
+ clientConfigFile,
728
+ ...commonHooks
729
+ }) => {
730
+ if (alias) {
731
+ hooks.alias.add({
732
+ pluginName,
733
+ hook: normalizeAliasDefineHook(alias)
734
+ });
735
+ }
736
+ if (define) {
737
+ hooks.define.add({
738
+ pluginName,
739
+ hook: normalizeAliasDefineHook(define)
740
+ });
741
+ }
742
+ if (clientConfigFile) {
743
+ hooks.clientConfigFile.add({
744
+ pluginName,
745
+ hook: normalizeClientConfigFileHook(clientConfigFile)
746
+ });
747
+ }
748
+ Object.entries(commonHooks).forEach(([key, hook]) => {
749
+ if (hooks[key] && hook) {
750
+ hooks[key].add({
751
+ pluginName,
752
+ hook
753
+ });
754
+ }
755
+ });
756
+ }
757
+ );
758
+ };
759
+
760
+ // src/pluginApi/createPluginApi.ts
761
+ var createPluginApi = () => {
762
+ const plugins = [];
763
+ const hooks = createPluginApiHooks();
764
+ const registerHooks = createPluginApiRegisterHooks(plugins, hooks);
765
+ return {
766
+ plugins,
767
+ hooks,
768
+ registerHooks
769
+ };
770
+ };
771
+
772
+ // src/app/resolveAppDir.ts
773
+ import { createRequire } from "module";
774
+ import { path as path7 } from "@vuepress/utils";
775
+ var require2 = createRequire(import.meta.url);
776
+ var createAppDirFunction = (baseDir) => {
777
+ return (...args) => path7.resolve(baseDir, ...args);
778
+ };
779
+ var resolveAppDir = (options) => {
780
+ const cache = createAppDirFunction(options.cache);
781
+ const temp = createAppDirFunction(options.temp);
782
+ const source = createAppDirFunction(options.source);
783
+ const dest = createAppDirFunction(options.dest);
784
+ const publicDir = createAppDirFunction(options.public);
785
+ const client = createAppDirFunction(
786
+ path7.resolve(require2.resolve("@vuepress/client/package.json"), "..")
787
+ );
788
+ return {
789
+ cache,
790
+ temp,
791
+ source,
792
+ dest,
793
+ client,
794
+ public: publicDir
795
+ };
796
+ };
797
+
798
+ // src/app/resolveAppEnv.ts
799
+ var resolveAppEnv = (options, isBuild) => ({
800
+ isBuild,
801
+ isDev: !isBuild,
802
+ isDebug: options.debug
803
+ });
804
+
805
+ // src/app/resolveAppOptions.ts
806
+ import { createRequire as createRequire2 } from "module";
807
+ import { path as path8 } from "@vuepress/utils";
808
+ var require3 = createRequire2(import.meta.url);
809
+ var resolveAppOptions = ({
810
+ base = "/",
811
+ lang = "en-US",
812
+ title = "",
813
+ description = "",
814
+ head = [],
815
+ locales = {},
816
+ source,
817
+ dest = path8.resolve(source, ".vuepress/dist"),
818
+ temp = path8.resolve(source, ".vuepress/.temp"),
819
+ cache = path8.resolve(source, ".vuepress/.cache"),
820
+ public: publicDir = path8.resolve(source, ".vuepress/public"),
821
+ host = "0.0.0.0",
822
+ port = 8080,
823
+ open = false,
824
+ templateDev = path8.normalize(
825
+ require3.resolve("@vuepress/client/templates/dev.html")
826
+ ),
827
+ shouldPreload = true,
828
+ shouldPrefetch = true,
829
+ templateBuild = path8.normalize(
830
+ require3.resolve("@vuepress/client/templates/build.html")
831
+ ),
832
+ bundler,
833
+ debug: debug7 = false,
834
+ markdown = {},
835
+ pagePatterns = ["**/*.md", "!.vuepress", "!node_modules"],
836
+ permalinkPattern = null,
837
+ plugins = [],
838
+ theme
839
+ }) => ({
840
+ base,
841
+ lang,
842
+ title,
843
+ description,
844
+ head,
845
+ locales,
846
+ source,
847
+ dest,
848
+ temp,
849
+ cache,
850
+ public: publicDir,
851
+ host,
852
+ port,
853
+ open,
854
+ templateDev,
855
+ shouldPreload,
856
+ shouldPrefetch,
857
+ templateBuild,
858
+ bundler,
859
+ debug: debug7,
860
+ markdown,
861
+ pagePatterns,
862
+ permalinkPattern,
863
+ plugins,
864
+ theme
865
+ });
866
+
867
+ // src/app/resolveAppSiteData.ts
868
+ var resolveAppSiteData = (options) => ({
869
+ base: options.base,
870
+ lang: options.lang,
871
+ title: options.title,
872
+ description: options.description,
873
+ head: options.head,
874
+ locales: options.locales
875
+ });
876
+
877
+ // src/app/resolveAppVersion.ts
878
+ import { createRequire as createRequire3 } from "module";
879
+ import { fs as fs3 } from "@vuepress/utils";
880
+ var require4 = createRequire3(import.meta.url);
881
+ var resolveAppVersion = () => {
882
+ const pkgJson = fs3.readJsonSync(
883
+ require4.resolve("@vuepress/core/package.json")
884
+ );
885
+ return pkgJson.version;
886
+ };
887
+
888
+ // src/app/resolveAppWriteTemp.ts
889
+ import { fs as fs4 } from "@vuepress/utils";
890
+ var resolveAppWriteTemp = (dir) => {
891
+ const tempCache = /* @__PURE__ */ new Map();
892
+ const writeTemp = async (file, content) => {
893
+ const filePath = dir.temp(file);
894
+ const contentCached = tempCache.get(filePath);
895
+ if (contentCached !== content) {
896
+ await fs4.outputFile(filePath, content);
897
+ tempCache.set(filePath, content);
898
+ }
899
+ return filePath;
900
+ };
901
+ return writeTemp;
902
+ };
903
+
904
+ // src/app/resolveThemeInfo.ts
905
+ var resolveThemeInfo = (app, theme) => {
906
+ const themeObject = resolvePluginObject(app, theme);
907
+ const themeInfo = {
908
+ plugins: [...themeObject.plugins ?? [], themeObject],
909
+ templateBuild: themeObject.templateBuild,
910
+ templateDev: themeObject.templateDev
911
+ };
912
+ if (!themeObject.extends) {
913
+ return themeInfo;
914
+ }
915
+ const parentThemeInfo = resolveThemeInfo(app, themeObject.extends);
916
+ return {
917
+ plugins: [...parentThemeInfo.plugins, ...themeInfo.plugins],
918
+ templateBuild: themeObject.templateBuild ?? parentThemeInfo.templateBuild,
919
+ templateDev: themeObject.templateDev ?? parentThemeInfo.templateDev
920
+ };
921
+ };
922
+
923
+ // src/app/setupAppThemeAndPlugins.ts
924
+ var setupAppThemeAndPlugins = (app, config) => {
925
+ const themeInfo = resolveThemeInfo(app, app.options.theme);
926
+ app.options.templateDev = config.templateDev ?? themeInfo.templateDev ?? app.options.templateDev;
927
+ app.options.templateBuild = config.templateBuild ?? themeInfo.templateBuild ?? app.options.templateBuild;
928
+ [...themeInfo.plugins, ...app.options.plugins].flat().forEach((plugin) => app.use(plugin));
929
+ };
930
+
931
+ // src/app/createBaseApp.ts
932
+ var createBaseApp = (config, isBuild = false) => {
933
+ const options = resolveAppOptions(config);
934
+ const dir = resolveAppDir(options);
935
+ const env = resolveAppEnv(options, isBuild);
936
+ const pluginApi = createPluginApi();
937
+ const siteData = resolveAppSiteData(options);
938
+ const version = resolveAppVersion();
939
+ const writeTemp = resolveAppWriteTemp(dir);
940
+ const app = {
941
+ options,
942
+ siteData,
943
+ version,
944
+ dir,
945
+ env,
946
+ pluginApi,
947
+ writeTemp,
948
+ use: (plugin) => appUse(app, plugin),
949
+ init: () => appInit(app),
950
+ prepare: () => appPrepare(app)
951
+ };
952
+ setupAppThemeAndPlugins(app, config);
953
+ return app;
954
+ };
955
+
956
+ // src/app/createBuildApp.ts
957
+ var createBuildApp = (config) => {
958
+ const app = createBaseApp(config, true);
959
+ app.build = () => app.options.bundler.build(app);
960
+ return app;
961
+ };
962
+
963
+ // src/app/createDevApp.ts
964
+ var createDevApp = (config) => {
965
+ const app = createBaseApp(config, false);
966
+ app.dev = () => app.options.bundler.dev(app);
967
+ return app;
968
+ };
969
+ export {
970
+ appInit,
971
+ appPrepare,
972
+ appUse,
973
+ createAppDirFunction,
974
+ createBaseApp,
975
+ createBuildApp,
976
+ createDevApp,
977
+ createHookQueue,
978
+ createPage,
979
+ createPluginApi,
980
+ createPluginApiHooks,
981
+ createPluginApiRegisterHooks,
982
+ inferPagePath,
983
+ normalizeAliasDefineHook,
984
+ normalizeClientConfigFileHook,
985
+ prepareClientConfigs,
986
+ preparePageComponent,
987
+ preparePageData,
988
+ preparePagesComponents,
989
+ preparePagesData,
990
+ preparePagesRoutes,
991
+ prepareSiteData,
992
+ renderPageContent,
993
+ resolveAppDir,
994
+ resolveAppEnv,
995
+ resolveAppOptions,
996
+ resolveAppPages,
997
+ resolveAppSiteData,
998
+ resolveAppVersion,
999
+ resolveAppWriteTemp,
1000
+ resolvePageComponentInfo,
1001
+ resolvePageDataInfo,
1002
+ resolvePageDate,
1003
+ resolvePageFileContent,
1004
+ resolvePageFilePath,
1005
+ resolvePageHtmlInfo,
1006
+ resolvePageKey,
1007
+ resolvePageLang,
1008
+ resolvePagePath,
1009
+ resolvePagePermalink,
1010
+ resolvePageRouteMeta,
1011
+ resolvePageSlug,
1012
+ resolvePluginObject,
1013
+ resolveThemeInfo
1014
+ };