@jpmorganchase/mosaic-plugins 0.1.0-beta.5 → 0.1.0-beta.52

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 (65) hide show
  1. package/dist/$AliasPlugin.d.ts +10 -0
  2. package/dist/$AliasPlugin.js +39 -48
  3. package/dist/$AliasPlugin.js.map +1 -1
  4. package/dist/$CodeModPlugin.d.ts +7 -0
  5. package/dist/$CodeModPlugin.js +18 -30
  6. package/dist/$CodeModPlugin.js.map +1 -1
  7. package/dist/$RefPlugin.d.ts +31 -0
  8. package/dist/$RefPlugin.js +130 -127
  9. package/dist/$RefPlugin.js.map +1 -1
  10. package/dist/$TagPlugin.d.ts +28 -0
  11. package/dist/$TagPlugin.js +37 -56
  12. package/dist/$TagPlugin.js.map +1 -1
  13. package/dist/BreadcrumbsPlugin.d.ts +19 -0
  14. package/dist/BreadcrumbsPlugin.js +72 -32
  15. package/dist/BreadcrumbsPlugin.js.map +1 -1
  16. package/dist/BrokenLinksPlugin.d.ts +10 -0
  17. package/dist/BrokenLinksPlugin.js +80 -0
  18. package/dist/BrokenLinksPlugin.js.map +1 -0
  19. package/dist/FragmentPlugin.d.ts +7 -0
  20. package/dist/FragmentPlugin.js +92 -0
  21. package/dist/FragmentPlugin.js.map +1 -0
  22. package/dist/LazyPagePlugin.d.ts +14 -0
  23. package/dist/LazyPagePlugin.js +55 -87
  24. package/dist/LazyPagePlugin.js.map +1 -1
  25. package/dist/PagesWithoutFileExtPlugin.d.ts +9 -0
  26. package/dist/PagesWithoutFileExtPlugin.js +19 -31
  27. package/dist/PagesWithoutFileExtPlugin.js.map +1 -1
  28. package/dist/PropsTablePlugin.d.ts +6 -0
  29. package/dist/PropsTablePlugin.js +88 -0
  30. package/dist/PropsTablePlugin.js.map +1 -0
  31. package/dist/PublicAssetsPlugin.d.ts +18 -0
  32. package/dist/PublicAssetsPlugin.js +28 -0
  33. package/dist/PublicAssetsPlugin.js.map +1 -0
  34. package/dist/ReadingTimePlugin.d.ts +10 -0
  35. package/dist/ReadingTimePlugin.js +23 -0
  36. package/dist/ReadingTimePlugin.js.map +1 -0
  37. package/dist/SearchIndexPlugin.d.ts +56 -0
  38. package/dist/SearchIndexPlugin.js +154 -0
  39. package/dist/SearchIndexPlugin.js.map +1 -0
  40. package/dist/SharedConfigPlugin.d.ts +14 -0
  41. package/dist/SharedConfigPlugin.js +134 -38
  42. package/dist/SharedConfigPlugin.js.map +1 -1
  43. package/dist/SidebarPlugin.d.ts +38 -0
  44. package/dist/SidebarPlugin.js +196 -95
  45. package/dist/SidebarPlugin.js.map +1 -1
  46. package/dist/SiteMapPlugin.d.ts +9 -0
  47. package/dist/SiteMapPlugin.js +20 -36
  48. package/dist/SiteMapPlugin.js.map +1 -1
  49. package/dist/TableOfContentsPlugin.d.ts +20 -0
  50. package/dist/TableOfContentsPlugin.js +43 -0
  51. package/dist/TableOfContentsPlugin.js.map +1 -0
  52. package/dist/utils/PluginError.d.ts +7 -0
  53. package/dist/utils/PluginError.js +13 -0
  54. package/dist/utils/PluginError.js.map +1 -0
  55. package/dist/utils/normaliseRefs.d.ts +1 -0
  56. package/dist/utils/normaliseRefs.js +52 -69
  57. package/dist/utils/normaliseRefs.js.map +1 -1
  58. package/package.json +46 -15
  59. package/CHANGELOG.md +0 -50
  60. package/dist/NextPrevPagePlugin.js +0 -63
  61. package/dist/NextPrevPagePlugin.js.map +0 -1
  62. package/dist/ReadingTimePlugin.mjs +0 -119
  63. package/dist/ReadingTimePlugin.mjs.map +0 -1
  64. package/dist/TableOfContentsPlugin.mjs +0 -140
  65. package/dist/TableOfContentsPlugin.mjs.map +0 -1
@@ -1,95 +1,63 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const fs_1 = __importDefault(require("fs"));
27
- const fs_extra_1 = __importDefault(require("fs-extra"));
28
- const merge_1 = __importDefault(require("lodash/merge"));
29
- const escapeRegExp_1 = __importDefault(require("lodash/escapeRegExp"));
30
- const path_1 = __importDefault(require("path"));
1
+ import fs from 'fs';
2
+ import fsExtra from 'fs-extra';
3
+ import { merge, escapeRegExp } from 'lodash-es';
4
+ import path from 'path';
5
+ function createPageTest(ignorePages, pageExtensions) {
6
+ const extTest = new RegExp(`${pageExtensions.map(escapeRegExp).join('|')}$`);
7
+ const ignoreTest = new RegExp(`${ignorePages.map(escapeRegExp).join('|')}$`);
8
+ return file => !ignoreTest.test(file) && extTest.test(file) && !path.basename(file).startsWith('.');
9
+ }
10
+ function createFileGlob(url, pageExtensions) {
11
+ if (pageExtensions.length === 1) {
12
+ return `${url}${pageExtensions[0]}`;
13
+ }
14
+ return `${url}{${pageExtensions.join(',')}}`;
15
+ }
31
16
  const LazyPagePlugin = {
32
- afterUpdate(mutableFilesystem, { ignorePages, config, pageExtensions, serialiser }) {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
35
- // This adds a hook that triggers everytime a non-cached page is read from the filesystem.
36
- mutableFilesystem.__internal_do_not_use_addReadFileHook((pagePath, fileData) => __awaiter(this, void 0, void 0, function* () {
37
- // If this is a 'page' - read the original file from disk and try to inject anything that's missing.
38
- if (isNonHiddenPage(pagePath)) {
39
- const currentPage = yield serialiser.deserialise(pagePath, fileData);
40
- if (config.data.hddPaths[pagePath]) {
41
- const page = yield serialiser.deserialise(pagePath, yield fs_1.default.promises.readFile(config.data.hddPaths[pagePath]));
42
- const completePage = yield serialiser.serialise(pagePath, (0, merge_1.default)(page, currentPage, { content: page.content }));
43
- return completePage;
44
- }
17
+ async afterUpdate(mutableFilesystem, { ignorePages, config, pageExtensions, serialiser }) {
18
+ const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
19
+ // This adds a hook that triggers everytime a non-cached page is read from the filesystem.
20
+ mutableFilesystem.__internal_do_not_use_addReadFileHook(async (pagePath, fileData) => {
21
+ // If this is a 'page' - read the original file from disk and try to inject anything that's missing.
22
+ if (isNonHiddenPage(pagePath)) {
23
+ const currentPage = await serialiser.deserialise(pagePath, fileData);
24
+ if (config.data.hddPaths?.[pagePath]) {
25
+ const page = await serialiser.deserialise(pagePath, await fs.promises.readFile(config.data.hddPaths[pagePath]));
26
+ const completePage = await serialiser.serialise(pagePath, merge(page, currentPage, { content: page.content }));
27
+ return completePage;
45
28
  }
46
- return fileData;
47
- }));
29
+ }
30
+ return fileData;
48
31
  });
49
32
  },
50
- $beforeSend(mutableFilesystem, { config, serialiser, ignorePages, pageExtensions }, options) {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- const hddPaths = {};
53
- let originalDiskSize = 0;
54
- let newDiskSize = 0;
55
- const allPages = yield mutableFilesystem.promises.glob(createFileGlob('**', pageExtensions), {
56
- ignore: ignorePages.map(ignore => `**/${ignore}`),
57
- cwd: '/',
58
- onlyFiles: true
59
- });
60
- const baseDir = path_1.default.join(process.cwd(), options.cacheDir || '.mosaic-lazy-page-plugin-cache');
61
- yield fs_extra_1.default.ensureDir(baseDir);
62
- for (const filePath of allPages) {
63
- const rawPage = yield mutableFilesystem.promises.readFile(String(filePath));
64
- const page = yield serialiser.deserialise(String(filePath), rawPage);
65
- originalDiskSize += rawPage.length;
66
- yield fs_1.default.promises.mkdir(path_1.default.dirname(path_1.default.join(baseDir, String(filePath))), {
67
- recursive: true
68
- });
69
- yield fs_1.default.promises.writeFile(path_1.default.join(baseDir, String(filePath)), yield serialiser.serialise(String(filePath), page));
70
- const { content } = page, pageRest = __rest(page, ["content"]);
71
- hddPaths[String(filePath)] = path_1.default.join(baseDir, String(filePath));
72
- const redactedPage = yield serialiser.serialise(String(filePath), pageRest);
73
- newDiskSize += redactedPage.length;
74
- }
75
- config.setData({ hddPaths });
76
- const reduction = originalDiskSize - newDiskSize;
77
- console.info(`[PullDocs] LazyPagePlugin moved ${((reduction / originalDiskSize) * 100).toFixed(2)}% of virtual filesystem content to the hard disk. This reduced the virtual filesystem size from ${(originalDiskSize / 1000000).toFixed(2)}mb to ${(newDiskSize / 1000000).toFixed(2)}mb (yay!)`);
33
+ async $beforeSend(mutableFilesystem, { config, serialiser, ignorePages, pageExtensions }, options) {
34
+ const hddPaths = {};
35
+ let originalDiskSize = 0;
36
+ let newDiskSize = 0;
37
+ const allPages = await mutableFilesystem.promises.glob(createFileGlob('**', pageExtensions), {
38
+ ignore: ignorePages.map(ignore => `**/${ignore}`),
39
+ cwd: '/',
40
+ onlyFiles: true
78
41
  });
42
+ const baseDir = path.join(process.cwd(), options.cacheDir || '.mosaic-lazy-page-plugin-cache');
43
+ await fsExtra.ensureDir(baseDir);
44
+ for (const filePath of allPages) {
45
+ const rawPage = await mutableFilesystem.promises.readFile(String(filePath));
46
+ const page = await serialiser.deserialise(String(filePath), rawPage);
47
+ originalDiskSize += rawPage.length;
48
+ await fs.promises.mkdir(path.dirname(path.join(baseDir, String(filePath))), {
49
+ recursive: true
50
+ });
51
+ await fs.promises.writeFile(path.join(baseDir, String(filePath)), await serialiser.serialise(String(filePath), page));
52
+ const { content, ...pageRest } = page;
53
+ hddPaths[String(filePath)] = path.join(baseDir, String(filePath));
54
+ const redactedPage = await serialiser.serialise(String(filePath), pageRest);
55
+ newDiskSize += redactedPage.length;
56
+ }
57
+ config.setData({ hddPaths });
58
+ const reduction = originalDiskSize - newDiskSize;
59
+ console.info(`[Mosaic] LazyPagePlugin moved ${((reduction / originalDiskSize) * 100).toFixed(2)}% of virtual filesystem content to the hard disk. This reduced the virtual filesystem size from ${(originalDiskSize / 1000000).toFixed(2)}mb to ${(newDiskSize / 1000000).toFixed(2)}mb (yay!)`);
79
60
  }
80
61
  };
81
- function createFileGlob(url, pageExtensions) {
82
- if (pageExtensions.length === 1) {
83
- return `${url}${pageExtensions[0]}`;
84
- }
85
- return `${url}{${pageExtensions.join(',')}}`;
86
- }
87
- exports.default = LazyPagePlugin;
88
- function createPageTest(ignorePages, pageExtensions) {
89
- const extTest = new RegExp(`${pageExtensions.map(escapeRegExp_1.default).join('|')}$`);
90
- const ignoreTest = new RegExp(`${ignorePages.map(escapeRegExp_1.default).join('|')}$`);
91
- return file => {
92
- return !ignoreTest.test(file) && extTest.test(file) && !path_1.default.basename(file).startsWith('.');
93
- };
94
- }
62
+ export default LazyPagePlugin;
95
63
  //# sourceMappingURL=LazyPagePlugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"LazyPagePlugin.js","sourceRoot":"","sources":["../src/LazyPagePlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,4CAAoB;AACpB,wDAA+B;AAC/B,yDAAiC;AACjC,uEAA+C;AAC/C,gDAAwB;AAGxB,MAAM,cAAc,GAGhB;IACI,WAAW,CAAC,iBAAiB,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE;;YACtF,MAAM,eAAe,GAAG,cAAc,CAAC,WAAW,EAAE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CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;YAC5E,WAAW,IAAI,YAAY,CAAC,MAAM,CAAC;SACpC;QAED,MAAM,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QAE7B,MAAM,SAAS,GAAG,gBAAgB,GAAG,WAAW,CAAC;QACjD,OAAO,CAAC,IAAI,CACV,iCAAiC,CAAC,CAAC,SAAS,GAAG,gBAAgB,CAAC,GAAG,GAAG,CAAC,CAAC,OAAO,CAC7E,CAAC,CACF,mGAAmG,CAClG,gBAAgB,GAAG,OAAO,CAC3B,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,GAAG,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CACnE,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { Plugin as PluginType } from '@jpmorganchase/mosaic-types';
2
+ /**
3
+ * Plugin that creates aliases without the file extension for every page emitted by the source.
4
+ * This allows pages to be retrieved from the filesystem without specifying `.mdx` (or whatever file extension is specified in `options.stripExt`).
5
+ * The plugin also modifies the `route` to point to the shorter alias. Friendly fullPaths are the shortest possible paths that
6
+ * will point to the page (see `Page` docs)
7
+ */
8
+ declare const PagesWithoutFileExtPlugin: PluginType;
9
+ export default PagesWithoutFileExtPlugin;
@@ -1,19 +1,11 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const lodash_1 = require("lodash");
16
- const path_1 = __importDefault(require("path"));
1
+ import { escapeRegExp } from 'lodash-es';
2
+ import path from 'path';
3
+ import PluginError from './utils/PluginError.js';
4
+ function createPageTest(ignorePages, pageExtensions) {
5
+ const extTest = new RegExp(`${pageExtensions.map(escapeRegExp).join('|')}$`);
6
+ const ignoreTest = new RegExp(`${ignorePages.map(escapeRegExp).join('|')}$`);
7
+ return file => !ignoreTest.test(file) && extTest.test(file) && !path.basename(file).startsWith('.');
8
+ }
17
9
  /**
18
10
  * Plugin that creates aliases without the file extension for every page emitted by the source.
19
11
  * This allows pages to be retrieved from the filesystem without specifying `.mdx` (or whatever file extension is specified in `options.stripExt`).
@@ -21,27 +13,23 @@ const path_1 = __importDefault(require("path"));
21
13
  * will point to the page (see `Page` docs)
22
14
  */
23
15
  const PagesWithoutFileExtPlugin = {
24
- $afterSource(pages, { config, ignorePages, pageExtensions }) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
27
- const pageTest = new RegExp(`${pageExtensions.map(lodash_1.escapeRegExp).join('|')}$`);
28
- for (const page of pages) {
16
+ async $afterSource(pages, { config, ignorePages, pageExtensions }) {
17
+ const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
18
+ const pageTest = new RegExp(`${pageExtensions.map(escapeRegExp).join('|')}$`);
19
+ for (const page of pages) {
20
+ try {
29
21
  if (!isNonHiddenPage(page.fullPath)) {
30
22
  continue;
31
23
  }
32
24
  page.route = page.route.replace(pageTest, '');
33
25
  config.setAliases(page.fullPath, [page.route]);
34
26
  }
35
- return pages;
36
- });
27
+ catch (e) {
28
+ throw new PluginError(e.message, page.fullPath);
29
+ }
30
+ }
31
+ return pages;
37
32
  }
38
33
  };
39
- exports.default = PagesWithoutFileExtPlugin;
40
- function createPageTest(ignorePages, pageExtensions) {
41
- const extTest = new RegExp(`${pageExtensions.map(lodash_1.escapeRegExp).join('|')}$`);
42
- const ignoreTest = new RegExp(`${ignorePages.map(lodash_1.escapeRegExp).join('|')}$`);
43
- return file => {
44
- return !ignoreTest.test(file) && extTest.test(file) && !path_1.default.basename(file).startsWith('.');
45
- };
46
- }
34
+ export default PagesWithoutFileExtPlugin;
47
35
  //# sourceMappingURL=PagesWithoutFileExtPlugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PagesWithoutFileExtPlugin.js","sourceRoot":"","sources":["../src/PagesWithoutFileExtPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,mCAAsC;AACtC,gDAAwB;AAExB;;;;;GAKG;AACH,MAAM,yBAAyB,GAAmB;IAC1C,YAAY,CAAC,KAAa,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE;;YACvE,MAAM,eAAe,GAAG,cAAc,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;YACpE,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,GAAG,cAAc,CAAC,GAAG,CAAC,qBAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAE9E,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;gBACxB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;oBACnC,SAAS;iBACV;gBACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;gBAC9C,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;aAChD;YACD,OAAO,KAAK,CAAC;QACf,CAAC;KAAA;CACF,CAAC;AAEF,kBAAe,yBAAyB,CAAC;AAEzC,SAAS,cAAc,CAAC,WAAW,EAAE,cAAc;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AG,CAAC,CAAC;AACzF,CAAC;AAED;;;;;GAKG;AACH,MAAM,yBAAyB,GAAe;IAC5C,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE;QAC/D,MAAM,eAAe,GAAG,cAAc,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QACpE,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,GAAG,cAAc,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAE9E,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,IAAI;gBACF,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;oBACnC,SAAS;iBACV;gBACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;gBAC9C,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;aAChD;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;aACjD;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC;AAEF,eAAe,yBAAyB,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
2
+ interface PropsTablePluginPage extends Page {
3
+ content: string;
4
+ }
5
+ declare const PropsTablePlugin: PluginType<PropsTablePluginPage>;
6
+ export default PropsTablePlugin;
@@ -0,0 +1,88 @@
1
+ import remarkDirective from 'remark-directive';
2
+ import remarkGfm from 'remark-gfm';
3
+ import { remark } from 'remark';
4
+ import remarkMdx from 'remark-mdx';
5
+ import { visit } from 'unist-util-visit';
6
+ import { parse } from 'react-docgen-typescript';
7
+ import path from 'path';
8
+ import PluginError from './utils/PluginError.js';
9
+ const options = {
10
+ propFilter: prop => !/@types[\\/]react[\\/]/.test(prop.parent?.fileName || '')
11
+ };
12
+ const PropsTablePlugin = {
13
+ // TODO: add support for active mode
14
+ async $afterSource(pages) {
15
+ const processor = remark().use(remarkMdx).use(remarkDirective).use(remarkGfm);
16
+ for (const page of pages) {
17
+ try {
18
+ const tree = await processor.parse(page.content);
19
+ visit(tree, (node) => node.type === 'textDirective', (node) => {
20
+ if (node.name !== 'propsTable')
21
+ return;
22
+ const componentPath = path.resolve(node.attributes.src);
23
+ const propsTableData = parse(componentPath, options)[0]?.props;
24
+ const tableHeaders = {
25
+ type: 'tableRow',
26
+ children: [
27
+ {
28
+ type: 'tableCell',
29
+ children: [{ type: 'text', value: 'Name' }]
30
+ },
31
+ {
32
+ type: 'tableCell',
33
+ children: [{ type: 'text', value: 'Type' }]
34
+ },
35
+ {
36
+ type: 'tableCell',
37
+ children: [{ type: 'text', value: 'Description' }]
38
+ },
39
+ {
40
+ type: 'tableCell',
41
+ children: [{ type: 'text', value: 'Default' }]
42
+ }
43
+ ]
44
+ };
45
+ const tableBody = Object.values(propsTableData).map(({ name, type, description, defaultValue }) => ({
46
+ type: 'tableRow',
47
+ children: [
48
+ {
49
+ type: 'tableCell',
50
+ children: [{ type: 'text', value: name }]
51
+ },
52
+ {
53
+ type: 'tableCell',
54
+ children: [{ type: 'inlineCode', value: type.name }]
55
+ },
56
+ {
57
+ type: 'tableCell',
58
+ children: [{ type: 'html', value: description.replace(/\n/g, ' ') }]
59
+ },
60
+ {
61
+ type: 'tableCell',
62
+ children: [
63
+ { type: 'inlineCode', value: defaultValue ? defaultValue.value : '-' }
64
+ ]
65
+ }
66
+ ]
67
+ }));
68
+ const table = [tableHeaders, ...tableBody];
69
+ // Replaces the current node with a new table node containing the props
70
+ node.type = 'table';
71
+ node.children = table;
72
+ });
73
+ page.content = remark()
74
+ .data('settings', { fences: true })
75
+ .use(remarkMdx)
76
+ .use(remarkDirective)
77
+ .use(remarkGfm)
78
+ .stringify(tree);
79
+ }
80
+ catch (e) {
81
+ throw new PluginError(e.message, page.fullPath);
82
+ }
83
+ }
84
+ return pages;
85
+ }
86
+ };
87
+ export default PropsTablePlugin;
88
+ //# sourceMappingURL=PropsTablePlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PropsTablePlugin.js","sourceRoot":"","sources":["../src/PropsTablePlugin.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAC/C,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,WAAW,MAAM,wBAAwB,CAAC;AAEjD,MAAM,OAAO,GAAG;IACd,UAAU,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,IAAI,EAAE,CAAC;CAC/E,CAAC;AAaF,MAAM,gBAAgB,GAAqC;IACzD,oCAAoC;IACpC,KAAK,CAAC,YAAY,CAAC,KAAK;QACtB,MAAM,SAAS,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC9E,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,IAAI;gBACF,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBAEjD,KAAK,CACH,IAAY,EACZ,CAAC,IAAU,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,eAAe,E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gCACjB,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;6BACrD;4BACD;gCACE,IAAI,EAAE,WAAW;gCACjB,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC;6BACrE;4BACD;gCACE,IAAI,EAAE,WAAW;gCACjB,QAAQ,EAAE;oCACR,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE;iCACvE;6BACF;yBACF;qBACF,CAAC,CACH,CAAC;oBAEF,MAAM,KAAK,GAAG,CAAC,YAAY,EAAE,GAAG,SAAS,CAAC,CAAC;oBAE3C,uEAAuE;oBACvE,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;oBACpB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;gBACxB,CAAC,CACF,CAAC;gBAEF,IAAI,CAAC,OAAO,GAAG,MAAM,EAAE;qBACpB,IAAI,CAAC,UAAU,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;qBAClC,GAAG,CAAC,SAAS,CAAC;qBACd,GAAG,CAAC,eAAe,CAAC;qBACpB,GAAG,CAAC,SAAS,CAAC;qBACd,SAAS,CAAC,IAAI,CAAC,CAAC;aACpB;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;aACjD;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
2
+ interface PublicAssetsPluginOptions {
3
+ /**
4
+ * The directory to copy the assets to
5
+ * @default './public'
6
+ */
7
+ outputDir?: string;
8
+ /**
9
+ * A collection of filenames to copy to the outputDir
10
+ */
11
+ assets?: string[];
12
+ }
13
+ /**
14
+ * Plugin that finds `assets` in the Mosaic filesytem and copies them to the specified outputDir.
15
+ * Typical use case is for assets like a sitemap
16
+ */
17
+ declare const PublicAssetsPlugin: PluginType<Page, PublicAssetsPluginOptions>;
18
+ export default PublicAssetsPlugin;
@@ -0,0 +1,28 @@
1
+ import path from 'node:path';
2
+ import fs from 'node:fs';
3
+ import fsExtra from 'fs-extra';
4
+ /**
5
+ * Plugin that finds `assets` in the Mosaic filesytem and copies them to the specified outputDir.
6
+ * Typical use case is for assets like a sitemap
7
+ */
8
+ const PublicAssetsPlugin = {
9
+ async afterUpdate(_, { sharedFilesystem }, { assets = [], outputDir = './public' }) {
10
+ if (assets.length > 0) {
11
+ await fsExtra.ensureDir(outputDir);
12
+ await Promise.all(assets.map(async (asset) => {
13
+ const allFiles = await sharedFilesystem.promises.glob(`**/${asset}`, {
14
+ cwd: '/',
15
+ onlyFiles: true
16
+ });
17
+ if (allFiles?.length > 0) {
18
+ await Promise.all(allFiles.map(async (file) => {
19
+ const data = await sharedFilesystem.promises.readFile(file);
20
+ await fs.promises.writeFile(path.posix.join(path.posix.resolve(outputDir), file), data);
21
+ }));
22
+ }
23
+ }));
24
+ }
25
+ }
26
+ };
27
+ export default PublicAssetsPlugin;
28
+ //# sourceMappingURL=PublicAssetsPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PublicAssetsPlugin.js","sourceRoot":"","sources":["../src/PublicAssetsPlugin.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,OAAO,MAAM,UAAU,CAAC;AAc/B;;;GAGG;AACH,MAAM,kBAAkB,GAAgD;IACtE,KAAK,CAAC,WAAW,CAAC,CAAC,EAAE,EAAE,gBAAgB,EAAE,EAAE,EAAE,MAAM,GAAG,EAAE,EAAE,SAAS,GAAG,UAAU,EAAE;QAChF,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YACrB,MAAM,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;YAEnC,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,GAAG,CAAC,KAAK,EAAC,KAAK,EAAC,EAAE;gBACvB,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,KAAK,EAAE,EAAE;oBACnE,GAAG,EAAE,GAAG;oBACR,SAAS,EAAE,IAAI;iBAChB,CAAC,CAAC;gBAEH,IAAI,QAAQ,EAAE,MAAM,GAAG,CAAC,EAAE;oBACxB,MAAM,OAAO,CAAC,GAAG,CACf,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAC,IAAI,EAAC,EAAE;wBACxB,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;wBAC5D,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CACzB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,EACpD,IAAI,CACL,CAAC;oBACJ,CAAC,CAAC,CACH,CAAC;iBACH;YACH,CAAC,CAAC,CACH,CAAC;SACH;IACH,CAAC;CACF,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
2
+ import getReadingTime from 'reading-time';
3
+ interface ReadingTimePluginPage extends Page {
4
+ readingTime?: ReturnType<typeof getReadingTime>;
5
+ }
6
+ /**
7
+ * Calculates reading time for pages and adds to frontmatter
8
+ */
9
+ declare const ReadingTimePlugin: PluginType<ReadingTimePluginPage>;
10
+ export default ReadingTimePlugin;
@@ -0,0 +1,23 @@
1
+ import getReadingTime from 'reading-time';
2
+ import markdown from 'remark-parse';
3
+ import { unified } from 'unified';
4
+ import { visit } from 'unist-util-visit';
5
+ /**
6
+ * Calculates reading time for pages and adds to frontmatter
7
+ */
8
+ const ReadingTimePlugin = {
9
+ async $afterSource(pages) {
10
+ const processor = unified().use(markdown);
11
+ for (const page of pages) {
12
+ const tree = await processor.parse(page.content);
13
+ let textContent = '';
14
+ visit(tree, node => node.type === 'text' || node.type === 'code', (node) => {
15
+ textContent += node.value;
16
+ });
17
+ page.readingTime = getReadingTime(textContent);
18
+ }
19
+ return pages;
20
+ }
21
+ };
22
+ export default ReadingTimePlugin;
23
+ //# sourceMappingURL=ReadingTimePlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReadingTimePlugin.js","sourceRoot":"","sources":["../src/ReadingTimePlugin.ts"],"names":[],"mappings":"AACA,OAAO,cAAc,MAAM,cAAc,CAAC;AAC1C,OAAO,QAAQ,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAWzC;;GAEG;AACH,MAAM,iBAAiB,GAAsC;IAC3D,KAAK,CAAC,YAAY,CAAC,KAAK;QACtB,MAAM,SAAS,GAAG,OAAO,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC1C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,MAAM,IAAI,GAAS,MAAM,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACvD,IAAI,WAAW,GAAG,EAAE,CAAC;YAErB,KAAK,CACH,IAAI,EACJ,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EACpD,CAAC,IAAc,EAAE,EAAE;gBACjB,WAAW,IAAI,IAAI,CAAC,KAAK,CAAC;YAC5B,CAAC,CACF,CAAC;YACF,IAAI,CAAC,WAAW,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;SAChD;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,56 @@
1
+ import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
2
+ interface SearchRelevancy {
3
+ includeScore?: boolean;
4
+ includeMatches?: boolean;
5
+ maxPatternLength?: number;
6
+ ignoreLocation?: boolean;
7
+ threshold?: number;
8
+ keys?: string[] | {
9
+ name: string;
10
+ weight: number;
11
+ }[];
12
+ }
13
+ interface SearchIndexPluginOptions {
14
+ maxLineLength?: number;
15
+ maxLineCount?: number;
16
+ keys?: string[];
17
+ relevancy?: SearchRelevancy;
18
+ }
19
+ interface Optimization {
20
+ content: string;
21
+ title: string;
22
+ maxLineCount?: number;
23
+ maxLineLength?: number;
24
+ }
25
+ /**
26
+ * There are three scenarios for the "keys":
27
+ *
28
+ * 1. No keys are specified in the plugin options. In this case, we'll use the fallback keys.
29
+ * 2. The keys are specified as an array of strings. In this case, we'll add the required keys to the array.
30
+ * 3. The keys are specified as an array of objects. In this case, we can assume "weighting" is being applied
31
+ * so we'll only return the keys that have been specified in the options.
32
+ *
33
+ * @param optionKeys array of keys specified in the plugin options
34
+ * @returns array of keys to be used in the search index
35
+ */
36
+ export declare function parseKeys(optionKeys?: any[]): any[];
37
+ /**
38
+ * Converts raw content string into an array of sentences suitable for inclusion
39
+ * in the search index
40
+ *
41
+ * @param options.content the raw content string
42
+ * @param options.title the title of the page (used for adding context to parse errors)
43
+ * @param options.maxLineLength the maximum length of a sentence (set this to match the
44
+ * "location" option in your Fuse.js configuration). Sentences longer than this value will be
45
+ * truncated.
46
+ * @param options.maxLineCount the maximum number of lines to include in the search index for
47
+ * each page. Pages with more lines than this value will be truncated.
48
+ * @returns array of sentence strings
49
+ */
50
+ export declare const optimizeContentForSearch: ({ content: rawContent, title, maxLineLength, maxLineCount }: Optimization) => Promise<string[]>;
51
+ /**
52
+ * Creates a search-data.json file that contains all the information
53
+ * from each page that is required to generate a search index.
54
+ */
55
+ declare const SearchIndexPlugin: PluginType<Page, SearchIndexPluginOptions>;
56
+ export default SearchIndexPlugin;