@jpmorganchase/mosaic-plugins 0.1.0-beta.10

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 (49) hide show
  1. package/dist/$AliasPlugin.d.ts +10 -0
  2. package/dist/$AliasPlugin.js +55 -0
  3. package/dist/$AliasPlugin.js.map +1 -0
  4. package/dist/$CodeModPlugin.d.ts +7 -0
  5. package/dist/$CodeModPlugin.js +24 -0
  6. package/dist/$CodeModPlugin.js.map +1 -0
  7. package/dist/$RefPlugin.d.ts +31 -0
  8. package/dist/$RefPlugin.js +119 -0
  9. package/dist/$RefPlugin.js.map +1 -0
  10. package/dist/$TagPlugin.d.ts +28 -0
  11. package/dist/$TagPlugin.js +65 -0
  12. package/dist/$TagPlugin.js.map +1 -0
  13. package/dist/BreadcrumbsPlugin.d.ts +17 -0
  14. package/dist/BreadcrumbsPlugin.js +35 -0
  15. package/dist/BreadcrumbsPlugin.js.map +1 -0
  16. package/dist/LazyPagePlugin.d.ts +14 -0
  17. package/dist/LazyPagePlugin.js +63 -0
  18. package/dist/LazyPagePlugin.js.map +1 -0
  19. package/dist/LocalFolderSavePlugin.d.ts +6 -0
  20. package/dist/LocalFolderSavePlugin.js +21 -0
  21. package/dist/LocalFolderSavePlugin.js.map +1 -0
  22. package/dist/NextPrevPagePlugin.d.ts +22 -0
  23. package/dist/NextPrevPagePlugin.js +50 -0
  24. package/dist/NextPrevPagePlugin.js.map +1 -0
  25. package/dist/PagesWithoutFileExtPlugin.d.ts +9 -0
  26. package/dist/PagesWithoutFileExtPlugin.js +29 -0
  27. package/dist/PagesWithoutFileExtPlugin.js.map +1 -0
  28. package/dist/ReadingTimePlugin.d.ts +10 -0
  29. package/dist/ReadingTimePlugin.js +23 -0
  30. package/dist/ReadingTimePlugin.js.map +1 -0
  31. package/dist/SearchIndexPlugin.d.ts +12 -0
  32. package/dist/SearchIndexPlugin.js +80 -0
  33. package/dist/SearchIndexPlugin.js.map +1 -0
  34. package/dist/SharedConfigPlugin.d.ts +13 -0
  35. package/dist/SharedConfigPlugin.js +34 -0
  36. package/dist/SharedConfigPlugin.js.map +1 -0
  37. package/dist/SidebarPlugin.d.ts +25 -0
  38. package/dist/SidebarPlugin.js +95 -0
  39. package/dist/SidebarPlugin.js.map +1 -0
  40. package/dist/SiteMapPlugin.d.ts +6 -0
  41. package/dist/SiteMapPlugin.js +27 -0
  42. package/dist/SiteMapPlugin.js.map +1 -0
  43. package/dist/TableOfContentsPlugin.d.ts +20 -0
  44. package/dist/TableOfContentsPlugin.js +34 -0
  45. package/dist/TableOfContentsPlugin.js.map +1 -0
  46. package/dist/utils/normaliseRefs.d.ts +1 -0
  47. package/dist/utils/normaliseRefs.js +66 -0
  48. package/dist/utils/normaliseRefs.js.map +1 -0
  49. package/package.json +54 -0
@@ -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;
@@ -0,0 +1,29 @@
1
+ import { escapeRegExp } from 'lodash-es';
2
+ import path from 'path';
3
+ function createPageTest(ignorePages, pageExtensions) {
4
+ const extTest = new RegExp(`${pageExtensions.map(escapeRegExp).join('|')}$`);
5
+ const ignoreTest = new RegExp(`${ignorePages.map(escapeRegExp).join('|')}$`);
6
+ return file => !ignoreTest.test(file) && extTest.test(file) && !path.basename(file).startsWith('.');
7
+ }
8
+ /**
9
+ * Plugin that creates aliases without the file extension for every page emitted by the source.
10
+ * This allows pages to be retrieved from the filesystem without specifying `.mdx` (or whatever file extension is specified in `options.stripExt`).
11
+ * The plugin also modifies the `route` to point to the shorter alias. Friendly fullPaths are the shortest possible paths that
12
+ * will point to the page (see `Page` docs)
13
+ */
14
+ const PagesWithoutFileExtPlugin = {
15
+ async $afterSource(pages, { config, ignorePages, pageExtensions }) {
16
+ const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
17
+ const pageTest = new RegExp(`${pageExtensions.map(escapeRegExp).join('|')}$`);
18
+ for (const page of pages) {
19
+ if (!isNonHiddenPage(page.fullPath)) {
20
+ continue;
21
+ }
22
+ page.route = page.route.replace(pageTest, '');
23
+ config.setAliases(page.fullPath, [page.route]);
24
+ }
25
+ return pages;
26
+ }
27
+ };
28
+ export default PagesWithoutFileExtPlugin;
29
+ //# sourceMappingURL=PagesWithoutFileExtPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PagesWithoutFileExtPlugin.js","sourceRoot":"","sources":["../src/PagesWithoutFileExtPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,SAAS,cAAc,CAAC,WAAW,EAAE,cAAc;IACjD,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,GAAG,cAAc,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7E,MAAM,UAAU,GAAG,IAAI,MAAM,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7E,OAAO,IAAI,CAAC,EAAE,CACZ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,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,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;gBACnC,SAAS;aACV;YACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YAC9C,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;SAChD;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC;AAEF,eAAe,yBAAyB,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,GAAG,MAAM,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACjD,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,12 @@
1
+ import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
2
+ interface SearchIndexPluginOptions {
3
+ maxLineLength?: number;
4
+ maxLineCount?: number;
5
+ keys?: string[];
6
+ }
7
+ /**
8
+ * Creates a search-data.json file that contains all the information from a page that is required
9
+ * to generate a search index
10
+ */
11
+ declare const SearchIndexPlugin: PluginType<Page, SearchIndexPluginOptions>;
12
+ export default SearchIndexPlugin;
@@ -0,0 +1,80 @@
1
+ import { unified } from 'unified';
2
+ import markdown from 'remark-parse';
3
+ import remarkMdx from 'remark-mdx';
4
+ import { visit } from 'unist-util-visit';
5
+ /**
6
+ * Converts raw content string into an array of sentences suitable for inclusion
7
+ * in the search index
8
+ *
9
+ * @param options.content the raw content string
10
+ * @param options.title the title of the page (used for adding context to parse errors)
11
+ * @param options.maxLineLength the maximum length of a sentence (set this to match the
12
+ * "location" option in your Fuse.js configuration). Sentences longer than this value will be
13
+ * truncated.
14
+ * @param options.maxLineCount the maximum number of lines to include in the search index for
15
+ * each page. Pages with more lines than this value will be truncated.
16
+ * @returns array of sentence strings
17
+ */
18
+ const optimizeContentForSearch = async ({ content, title, maxLineLength, maxLineCount }) => {
19
+ if (!content || content.length < 1)
20
+ return [content];
21
+ const processor = unified().use(markdown).use(remarkMdx);
22
+ let tree;
23
+ try {
24
+ tree = await processor.parse(content);
25
+ }
26
+ catch (err) {
27
+ console.error(`Search Index Plugin failed to parse content for ${title}`, err.reason);
28
+ return [];
29
+ }
30
+ const sentences = [];
31
+ visit(tree, (node) => node.type === 'text' || node.type === 'code', (node) => {
32
+ if (maxLineLength) {
33
+ sentences.push(node.value.slice(0, maxLineLength));
34
+ }
35
+ else {
36
+ sentences.push(node.value);
37
+ }
38
+ });
39
+ if (maxLineLength) {
40
+ return sentences.slice(0, maxLineCount);
41
+ }
42
+ return sentences;
43
+ };
44
+ /**
45
+ * Creates a search-data.json file that contains all the information from a page that is required
46
+ * to generate a search index
47
+ */
48
+ const SearchIndexPlugin = {
49
+ async afterUpdate(mutableFilesystem, { sharedFilesystem, serialiser, ignorePages }, { maxLineLength, maxLineCount, keys }) {
50
+ const pages = await Promise.all((await mutableFilesystem.promises.glob('**', {
51
+ onlyFiles: true,
52
+ ignore: ignorePages.map(ignore => `**/${ignore}`),
53
+ cwd: '/'
54
+ })).map(async (pagePath) => {
55
+ const deserialisedPage = await serialiser.deserialise(pagePath, await mutableFilesystem.promises.readFile(pagePath));
56
+ return deserialisedPage;
57
+ }));
58
+ const searchData = await Promise.all(pages.map(async (page) => {
59
+ const content = await optimizeContentForSearch({
60
+ content: page.content || '',
61
+ title: page.title || '',
62
+ maxLineLength,
63
+ maxLineCount
64
+ });
65
+ const defaultResults = {
66
+ title: page.title,
67
+ content,
68
+ route: page.route
69
+ };
70
+ if (keys && keys.length > 0) {
71
+ const extendedResults = keys.reduce((acc, key) => ({ ...acc, [key]: page[key] }), {});
72
+ return { ...defaultResults, ...extendedResults };
73
+ }
74
+ return defaultResults;
75
+ }));
76
+ await sharedFilesystem.promises.writeFile('/search-data.json', JSON.stringify(searchData));
77
+ }
78
+ };
79
+ export default SearchIndexPlugin;
80
+ //# sourceMappingURL=SearchIndexPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SearchIndexPlugin.js","sourceRoot":"","sources":["../src/SearchIndexPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,QAAQ,MAAM,cAAc,CAAC;AACpC,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAqBzC;;;;;;;;;;;;GAYG;AACH,MAAM,wBAAwB,GAAG,KAAK,EAAE,EACtC,OAAO,EACP,KAAK,EACL,aAAa,EACb,YAAY,EACC,EAAE,EAAE;IACjB,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACrD,MAAM,SAAS,GAAG,OAAO,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACzD,IAAI,IAAI,CAAC;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1
+ import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
2
+ interface SharedConfigPluginPage extends Page {
3
+ sharedConfig?: string;
4
+ }
5
+ interface SharedConfigPluginOptions {
6
+ filename: string;
7
+ }
8
+ /**
9
+ * Plugin that crawls the page hierarchy to find the closest `sharedConfig` from any parent index's page metadata.
10
+ * It then exports a JSON file (name: `options.filename`) into each directory with the merged config for that level
11
+ */
12
+ declare const SharedConfigPlugin: PluginType<SharedConfigPluginPage, SharedConfigPluginOptions>;
13
+ export default SharedConfigPlugin;
@@ -0,0 +1,34 @@
1
+ import { flatten } from 'lodash-es';
2
+ import path from 'path';
3
+ function createFileGlob(url, pageExtensions) {
4
+ if (pageExtensions.length === 1) {
5
+ return `${url}${pageExtensions[0]}`;
6
+ }
7
+ return `${url}{${pageExtensions.join(',')}}`;
8
+ }
9
+ /**
10
+ * Plugin that crawls the page hierarchy to find the closest `sharedConfig` from any parent index's page metadata.
11
+ * It then exports a JSON file (name: `options.filename`) into each directory with the merged config for that level
12
+ */
13
+ const SharedConfigPlugin = {
14
+ async $beforeSend(mutableFilesystem, { config, serialiser, ignorePages, pageExtensions }, options) {
15
+ const pagePaths = await mutableFilesystem.promises.glob(createFileGlob('**/index', pageExtensions), {
16
+ ignore: [options.filename, ...flatten(ignorePages.map(ignore => [ignore, `**/${ignore}`]))],
17
+ cwd: '/'
18
+ });
19
+ for (const pagePath of pagePaths) {
20
+ const sharedConfigFile = path.join(path.dirname(String(pagePath)), options.filename);
21
+ const page = await serialiser.deserialise(String(pagePath), await mutableFilesystem.promises.readFile(String(pagePath)));
22
+ if (page.sharedConfig) {
23
+ config.setRef(sharedConfigFile, ['config', '$ref'], `${String(pagePath)}#/sharedConfig`);
24
+ await mutableFilesystem.promises.writeFile(sharedConfigFile, '{}');
25
+ }
26
+ else {
27
+ const baseDir = path.resolve(path.dirname(String(pagePath)), '../');
28
+ config.setAliases(path.join(baseDir, options.filename), [sharedConfigFile]);
29
+ }
30
+ }
31
+ }
32
+ };
33
+ export default SharedConfigPlugin;
34
+ //# sourceMappingURL=SharedConfigPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SharedConfigPlugin.js","sourceRoot":"","sources":["../src/SharedConfigPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,SAAS,cAAc,CAAC,GAAG,EAAE,cAAc;IACzC,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE;QAC/B,OAAO,GAAG,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;KACrC;IACD,OAAO,GAAG,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAC/C,CAAC;AAUD;;;GAGG;AACH,MAAM,kBAAkB,GAAkE;IACxF,KAAK,CAAC,WAAW,CACf,iBAAiB,EACjB,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,EACnD,OAAO;QAEP,MAAM,SAAS,GAAG,MAAM,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CACrD,cAAc,CAAC,UAAU,EAAE,cAAc,CAAC,EAC1C;YACE,MAAM,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;YAC3F,GAAG,EAAE,GAAG;SACT,CACF,CAAC;QAEF,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;YAChC,MAAM,gBAAgB,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;YAErF,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,WAAW,CACvC,MAAM,CAAC,QAAQ,CAAC,EAChB,MAAM,iBAAiB,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAC5D,CAAC;YACF,IAAI,IAAI,CAAC,YAAY,EAAE;gBACrB,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;gBACzF,MAAM,iBAAiB,CAAC,QAAQ,CAAC,SAAS,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;aACpE;iBAAM;gBACL,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;gBAEpE,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;aAC7E;SACF;IACH,CAAC;CACF,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { Plugin as PluginType } from '@jpmorganchase/mosaic-types';
2
+ import { Page } from '@jpmorganchase/mosaic-types';
3
+ interface SidebarPluginConfigData {
4
+ dirs: string[];
5
+ refs: {
6
+ [key: string]: {
7
+ $$path: (number | string)[];
8
+ $$value: string;
9
+ }[];
10
+ };
11
+ }
12
+ interface SidebarPluginPage extends Page {
13
+ sidebar?: {
14
+ label?: string;
15
+ };
16
+ }
17
+ interface SidebarPluginOptions {
18
+ filename: string;
19
+ }
20
+ /**
21
+ * Sorts the pages in a folder by priority and then exports a JSON file (name: `options.filename`) with the
22
+ * sidebar tree from that directory downwards and adds sidebar data into frontmatter for each page.
23
+ */
24
+ declare const SidebarPlugin: PluginType<SidebarPluginPage, SidebarPluginOptions, SidebarPluginConfigData>;
25
+ export default SidebarPlugin;
@@ -0,0 +1,95 @@
1
+ import path from 'path';
2
+ function createFileGlob(patterns, pageExtensions) {
3
+ if (Array.isArray(patterns)) {
4
+ return patterns.map(pattern => createFileGlob(pattern, pageExtensions));
5
+ }
6
+ if (pageExtensions.length === 1) {
7
+ return `${patterns}${pageExtensions[0]}`;
8
+ }
9
+ return `${patterns}{${pageExtensions.join(',')}}`;
10
+ }
11
+ function isSubfolderIndex(page, dirName) {
12
+ return page.fullPath.split('/').length === String(dirName).split('/').length + 2;
13
+ }
14
+ function sortFn(pageA, pageB, dirName) {
15
+ // Always pin /index to the front
16
+ const route = `${dirName}/index`;
17
+ if (pageA.route === route) {
18
+ return -1;
19
+ }
20
+ if (pageB.route === route) {
21
+ return 1;
22
+ }
23
+ return ((pageB.sidebar && pageB.sidebar.priority ? pageB.sidebar.priority : -1) -
24
+ (pageA.sidebar && pageA.sidebar.priority ? pageA.sidebar.priority : -1));
25
+ }
26
+ function filterFn(page) {
27
+ return !(page.sidebar && page.sidebar.exclude);
28
+ }
29
+ /**
30
+ * Sorts the pages in a folder by priority and then exports a JSON file (name: `options.filename`) with the
31
+ * sidebar tree from that directory downwards and adds sidebar data into frontmatter for each page.
32
+ */
33
+ const SidebarPlugin = {
34
+ async $beforeSend(mutableFilesystem, { config, serialiser, ignorePages, pageExtensions }, options) {
35
+ function setPageRefs(sidebarFilePath, page, i) {
36
+ config.setRef(sidebarFilePath, ['pages', `${i}`, 'id', '$ref'], `${page.fullPath}#/route`);
37
+ const label = page.sidebar && page.sidebar.label
38
+ ? `${page.fullPath}#/sidebar/label`
39
+ : `${page.fullPath}#/title`;
40
+ config.setRef(sidebarFilePath, ['pages', `${i}`, 'name', '$ref'], label);
41
+ config.setRef(sidebarFilePath, ['pages', `${i}`, 'data', 'link', '$ref'], `${page.fullPath}#/route`);
42
+ }
43
+ async function setChildPageRefs(page, dirName, i, sidebarFilePath) {
44
+ if (isSubfolderIndex(page, dirName)) {
45
+ const childDirName = path.posix.dirname(page.fullPath);
46
+ const childNodeSidebarPath = path.posix.join(childDirName, options.filename);
47
+ const childPages = (await Promise.all((await mutableFilesystem.promises.glob(createFileGlob(['*', '*/index'], pageExtensions), {
48
+ onlyFiles: true,
49
+ cwd: String(childDirName),
50
+ ignore: ignorePages.map(ignore => `**/${ignore}`)
51
+ })).map(async (pagePath) => {
52
+ const deserialisedPage = await serialiser.deserialise(pagePath, await mutableFilesystem.promises.readFile(pagePath));
53
+ return deserialisedPage;
54
+ }))).filter(filterPage => filterFn(filterPage));
55
+ if (childPages.length > 1) {
56
+ for (let j = 1; j < childPages.length; j++) {
57
+ config.setRef(sidebarFilePath, ['pages', `${i}`, 'childNodes', `${j - 1}`, '$ref'], `${childNodeSidebarPath}#/pages/${j}`);
58
+ }
59
+ }
60
+ }
61
+ }
62
+ function addSidebarDataToFrontmatter(page, dirName) {
63
+ const dirNameLevels = String(dirName)
64
+ .split('/')
65
+ .filter(level => level);
66
+ const sidebarRootDir = path.posix.join('/', ...dirNameLevels.slice(0, dirNameLevels.length < 3 ? dirNameLevels.length : 3), '/');
67
+ config.setRef(String(page.fullPath), ['sidebarData', '$ref'], path.posix.join(String(sidebarRootDir), options.filename, '#', 'pages'));
68
+ }
69
+ const dirs = await mutableFilesystem.promises.glob('**', {
70
+ onlyDirectories: true,
71
+ cwd: '/'
72
+ });
73
+ for (const dirName of dirs) {
74
+ const sidebarFilePath = path.posix.join(String(dirName), options.filename);
75
+ const pages = (await Promise.all((await mutableFilesystem.promises.glob(createFileGlob(['*', '*/index'], pageExtensions), {
76
+ onlyFiles: true,
77
+ cwd: String(dirName),
78
+ ignore: ignorePages.map(ignore => `**/${ignore}`)
79
+ })).map(async (pagePath) => {
80
+ const deserialisedPage = await serialiser.deserialise(pagePath, await mutableFilesystem.promises.readFile(pagePath));
81
+ return deserialisedPage;
82
+ })))
83
+ .filter(page => filterFn(page))
84
+ .sort((pageA, pageB) => sortFn(pageA, pageB, dirName));
85
+ for (let i = 0; i < pages.length; i++) {
86
+ setPageRefs(sidebarFilePath, pages[i], i);
87
+ setChildPageRefs(pages[i], dirName, i, sidebarFilePath);
88
+ addSidebarDataToFrontmatter(pages[i], dirName);
89
+ }
90
+ await mutableFilesystem.promises.writeFile(sidebarFilePath, '[]');
91
+ }
92
+ }
93
+ };
94
+ export default SidebarPlugin;
95
+ //# sourceMappingURL=SidebarPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SidebarPlugin.js","sourceRoot":"","sources":["../src/SidebarPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB,SAAS,cAAc,CAAC,QAAQ,EAAE,cAAc;IAC9C,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAC3B,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC;KACzE;IACD,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE;QAC/B,OAAO,GAAG,QAAQ,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;KAC1C;IACD,OAAO,GAAG,QAAQ,IAAI,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AACpD,CAAC;AACD,SAAS,gBAAgB,CAAC,IAAI,EAAE,OAAO;IACrC,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AACnF,CAAC;AAED,SAAS,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO;IACnC,iCAAiC;IAEjC,MAAM,KAAK,GAAG,GAAG,OAAO,QAAQ,CAAC;IACjC,IAAI,KAAK,CAAC,KAAK,KAAK,KAAK,EAAE;QACzB,OAAO,CAAC,CAAC,CAAC;KACX;IACD,IAAI,KAAK,CAAC,KAAK,KAAK,KAAK,E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,EAAE,IAAI,CAAC,CAAC;SACnE;IACH,CAAC;CACF,CAAC;AACJ,eAAe,aAAa,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
2
+ interface SiteMapPluginConfigData {
3
+ sitemaps: Array<string[]>;
4
+ }
5
+ declare const SiteMapPlugin: PluginType<Page, unknown, SiteMapPluginConfigData, SiteMapPluginConfigData>;
6
+ export default SiteMapPlugin;
@@ -0,0 +1,27 @@
1
+ const SiteMapPlugin = {
2
+ // Merge together all of the individual sitemaps from each source
3
+ async afterUpdate(_, { sharedFilesystem, globalConfig }) {
4
+ if (!Array.isArray(globalConfig.data.sitemaps)) {
5
+ return;
6
+ }
7
+ const urls = globalConfig.data.sitemaps.map(items => items
8
+ .map(item => `\t<url>\n\t\t<loc>${String(item)}</loc>\n\t\t<changefreq>weekly</changefreq>\n\t\t<priority>0.5</priority>\n\t</url>`)
9
+ .join('\n'));
10
+ const urlSet = `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n ${urls}\n\n</urlset>`;
11
+ await sharedFilesystem.promises.writeFile('/sitemap.xml', urlSet);
12
+ },
13
+ // Store a sitemap for just this source
14
+ async $beforeSend(mutableFilesystem, { config, ignorePages }) {
15
+ config.setData({
16
+ sitemaps: [
17
+ (await mutableFilesystem.promises.glob('**', {
18
+ onlyFiles: true,
19
+ ignore: ignorePages.map(ignore => `**/${ignore}`),
20
+ cwd: '/'
21
+ }))
22
+ ]
23
+ });
24
+ }
25
+ };
26
+ export default SiteMapPlugin;
27
+ //# sourceMappingURL=SiteMapPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SiteMapPlugin.js","sourceRoot":"","sources":["../src/SiteMapPlugin.ts"],"names":[],"mappings":"AAMA,MAAM,aAAa,GAAgF;IACjG,iEAAiE;IACjE,KAAK,CAAC,WAAW,CAAC,CAAC,EAAE,EAAE,gBAAgB,EAAE,YAAY,EAAE;QACrD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;YAC9C,OAAO;SACR;QAED,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAClD,KAAK;aACF,GAAG,CACF,IAAI,CAAC,EAAE,CACL,qBAAqB,MAAM,CACzB,IAAI,CACL,qFAAqF,CACzF;aACA,IAAI,CAAC,IAAI,CAAC,CACd,CAAC;QAEF,MAAM,MAAM,GAAG,kEAAkE,IAAI,eAAe,CAAC;QACrG,MAAM,gBAAgB,CAAC,QAAQ,CAAC,SAAS,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;IACpE,CAAC;IACD,uCAAuC;IACvC,KAAK,CAAC,WAAW,CAAC,iBAAiB,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE;QAC1D,MAAM,CAAC,OAAO,CAAC;YACb,QAAQ,EAAE;gBACR,CAAC,MAAM,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE;oBAC3C,SAAS,EAAE,IAAI;oBACf,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,MAAM,EAAE,CAAC;oBACjD,GAAG,EAAE,GAAG;iBACT,CAAC,CAAkB;aACrB;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
2
+ import type { Heading as MarkdownHeading } from 'mdast';
3
+ declare type TOCItem = {
4
+ level: number;
5
+ id: string;
6
+ text: string;
7
+ };
8
+ interface TableOfContentsPluginPage extends Page {
9
+ tableOfContents?: TOCItem[];
10
+ }
11
+ declare type Rank = MarkdownHeading['depth'];
12
+ interface TableOfContentsPluginOptions {
13
+ minRank: Rank;
14
+ maxRank: Rank;
15
+ }
16
+ /**
17
+ * Calculates table of contents from page headings
18
+ */
19
+ declare const TableOfContentsPlugin: PluginType<TableOfContentsPluginPage, TableOfContentsPluginOptions>;
20
+ export default TableOfContentsPlugin;
@@ -0,0 +1,34 @@
1
+ import Slugger from 'github-slugger';
2
+ import remarkParse from 'remark-parse';
3
+ import { unified } from 'unified';
4
+ import remarkStringify from 'remark-stringify';
5
+ import remarkHeadings from '@vcarl/remark-headings';
6
+ /**
7
+ * Calculates table of contents from page headings
8
+ */
9
+ const TableOfContentsPlugin = {
10
+ async $afterSource(pages, _, { minRank, maxRank }) {
11
+ const processor = unified().use(remarkParse).use(remarkStringify).use(remarkHeadings);
12
+ for (const page of pages) {
13
+ const slugger = new Slugger();
14
+ if (page.content) {
15
+ const vfile = await processor.process(page.content);
16
+ const headings = vfile.data.headings;
17
+ const items = headings
18
+ .filter(heading => heading.depth >= minRank && heading.depth <= maxRank)
19
+ .map(validHeading => {
20
+ const text = validHeading.value.trim();
21
+ return {
22
+ level: validHeading.depth,
23
+ id: slugger.slug(text),
24
+ text
25
+ };
26
+ });
27
+ page.tableOfContents = items;
28
+ }
29
+ }
30
+ return pages;
31
+ }
32
+ };
33
+ export default TableOfContentsPlugin;
34
+ //# sourceMappingURL=TableOfContentsPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableOfContentsPlugin.js","sourceRoot":"","sources":["../src/TableOfContentsPlugin.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAC/C,OAAO,cAAc,MAAM,wBAAwB,CAAC;AAcpD;;GAEG;AACH,MAAM,qBAAqB,GAAwE;IACjG,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE;QAC/C,MAAM,SAAS,GAAG,OAAO,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QACtF,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;YAC9B,IAAI,IAAI,CAAC,OAAO,EAAE;gBAChB,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBACpD,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,QAA8C,CAAC;gBAC3E,MAAM,KAAK,GAAc,QAAQ;qBAC9B,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,IAAI,OAAO,IAAI,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC;qBACvE,GAAG,CAAC,YAAY,CAAC,EAAE;oBAClB,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;oBACvC,OAAO;wBACL,KAAK,EAAE,YAAY,CAAC,KAAK;wBACzB,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;wBACtB,IAAI;qBACL,CAAC;gBACJ,CAAC,CAAC,CAAC;gBACL,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;aAC9B;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
@@ -0,0 +1 @@
1
+ export default function normaliseRefs(filepath: any, refs: any, filesystem: any, pageExtensions: any, ignorePages: any): Promise<{}>;
@@ -0,0 +1,66 @@
1
+ import path from 'path';
2
+ import glob from 'fast-glob';
3
+ import { set } from 'lodash-es';
4
+ function createFileGlob(url, pageExtensions) {
5
+ if (pageExtensions.length === 1) {
6
+ return `${url}${pageExtensions[0]}`;
7
+ }
8
+ return `${url}{${pageExtensions.join(',')}}`;
9
+ }
10
+ export default async function normaliseRefs(filepath, refs, filesystem, pageExtensions, ignorePages) {
11
+ const configWithoutGlobs = {};
12
+ for (let i = 0; i < refs.length; i++) {
13
+ const ref = refs[i];
14
+ const [url, fragment = ''] = ref.$$value.split('#');
15
+ if (!url) {
16
+ continue;
17
+ }
18
+ const fullUrl = path.resolve(path.dirname(filepath), url);
19
+ if (!glob.isDynamicPattern(url)) {
20
+ if (!(await filesystem.promises.exists(fullUrl))) {
21
+ throw new Error(`A \`$ref\` for '${filepath}' pointed to page '${fullUrl}' - which could not be found.`);
22
+ }
23
+ const refRealPath = await filesystem.promises.realpath(fullUrl
24
+ //path.resolve(path.dirname(filepath), url)
25
+ );
26
+ const stat = await filesystem.promises.stat(refRealPath);
27
+ // Turn directory refs into full index paths
28
+ // TODO: But DO we want to do this?
29
+ if (stat.isDirectory()) {
30
+ // && !/\/index(\.\w{1,4})?$/.test(url)) {
31
+ set(configWithoutGlobs, ref.$$path.slice(0, -1), {
32
+ $ref: `${await filesystem.promises.realpath(path.join(refRealPath, 'index'))}#${fragment}`
33
+ });
34
+ }
35
+ else {
36
+ set(configWithoutGlobs, ref.$$path.slice(0, -1), {
37
+ $ref: `${refRealPath}#${fragment}`
38
+ });
39
+ }
40
+ continue;
41
+ }
42
+ try {
43
+ let globResolvedRefs =
44
+ // If the pattern doesn't have an explicit file extension - then we'll make it just return pages
45
+ await filesystem.promises.glob(!/\/[^/]+\.\w{2,4}$/.test(url) ? createFileGlob(url, pageExtensions) : url, {
46
+ ignore: [filepath, ...ignorePages.map(ignore => `**/${ignore}`)],
47
+ cwd: path.dirname(filepath),
48
+ absolute: true
49
+ });
50
+ // Use a set so we de-dupe any symlinks that point to the same page
51
+ const resolvedRefs = new Set();
52
+ for (const value of globResolvedRefs) {
53
+ const refRealPath = await filesystem.promises.realpath(path.resolve(filepath, value));
54
+ if (refRealPath !== (await filesystem.promises.realpath(filepath))) {
55
+ resolvedRefs.add(`${refRealPath}#${fragment}`);
56
+ }
57
+ }
58
+ set(configWithoutGlobs, ref.$$path.slice(0, -1), Array.from(resolvedRefs).map($ref => ({ $ref })));
59
+ }
60
+ catch (e) {
61
+ throw e;
62
+ }
63
+ }
64
+ return configWithoutGlobs;
65
+ }
66
+ //# sourceMappingURL=normaliseRefs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normaliseRefs.js","sourceRoot":"","sources":["../../src/utils/normaliseRefs.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEhC,SAAS,cAAc,CAAC,GAAG,EAAE,cAAc;IACzC,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE;QAC/B,OAAO,GAAG,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;KACrC;IACD,OAAO,GAAG,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAC/C,CAAC;AAED,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,aAAa,CACzC,QAAQ,EACR,IAAI,EACJ,UAAU,EACV,cAAc,EACd,WAAW;IAEX,MAAM,kBAAkB,GAAG,EAAE,CAAC;IAE9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACpC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,MAAM,CAAC,GAAG,EAAE,QAAQ,GAAG,EAAE,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAEpD,IAAI,CAAC,GAAG,EAAE;YACR,SAAS;SACV;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,CAAC;QAE1D,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAA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,MAAM,CAAC,EAAE,CAAC,MAAM,MAAM,EAAE,CAAC,CAAC;gBAChE,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;gBAC3B,QAAQ,EAAE,IAAI;aACf,CACF,CAAC;YAEJ,mEAAmE;YACnE,MAAM,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;YAE/B,KAAK,MAAM,KAAK,IAAI,gBAAgB,EAAE;gBACpC,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;gBACtF,IAAI,WAAW,KAAK,CAAC,MAAM,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,EAAE;oBAClE,YAAY,CAAC,GAAG,CAAC,GAAG,WAAW,IAAI,QAAQ,EAAE,CAAC,CAAC;iBAChD;aACF;YAED,GAAG,CACD,kBAAkB,EAClB,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EACvB,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CACjD,CAAC;SACH;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,CAAC;SACT;KACF;IAED,OAAO,kBAAkB,CAAC;AAC5B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@jpmorganchase/mosaic-plugins",
3
+ "version": "0.1.0-beta.10",
4
+ "author": "",
5
+ "description": "Mosaic plugins for core file system",
6
+ "license": "Apache-2.0",
7
+ "type": "module",
8
+ "exports": {
9
+ "./*": {
10
+ "types": "./dist/*.d.ts",
11
+ "import": "./dist/*.js",
12
+ "node": "./dist/*.js"
13
+ }
14
+ },
15
+ "engines": {
16
+ "node": ">= 16.0.0"
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "clean": "rm -fr dist",
24
+ "lint": "eslint --ignore-pattern \"**/__tests__/**\""
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git@github.com:jpmorganchase/mosaic.git"
29
+ },
30
+ "devDependencies": {
31
+ "@types/fs-extra": "^9.0.13"
32
+ },
33
+ "dependencies": {
34
+ "@apidevtools/json-schema-ref-parser": "^9.0.9",
35
+ "@jpmorganchase/mosaic-serialisers": "^0.1.0-beta.10",
36
+ "@jpmorganchase/mosaic-source-git-repo": "^0.1.0-beta.10",
37
+ "@jpmorganchase/mosaic-source-local-folder": "^0.1.0-beta.10",
38
+ "@jpmorganchase/mosaic-types": "^0.1.0-beta.10",
39
+ "@types/github-slugger": "^1.3.0",
40
+ "@vcarl/remark-headings": "^0.1.0",
41
+ "fs-extra": "^10.1.0",
42
+ "github-slugger": "^1.4.0",
43
+ "lodash-es": "^4.17.21",
44
+ "memfs": "^3.4.12",
45
+ "reading-time": "^1.5.0",
46
+ "remark-mdx": "^2.1.5",
47
+ "remark-parse": "^10.0.1",
48
+ "remark-stringify": "^10.0.2",
49
+ "rxjs": "^7.5.5",
50
+ "unified": "^10.1.2",
51
+ "unist-util-visit": "^4.1.1",
52
+ "uuid": "^7.0.3"
53
+ }
54
+ }