@jpmorganchase/mosaic-plugins 0.1.0-beta.3 → 0.1.0-beta.4
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/CHANGELOG.md +8 -0
- package/dist/$AliasPlugin.js +75 -0
- package/dist/$AliasPlugin.js.map +1 -0
- package/dist/$CodeModPlugin.js +42 -0
- package/dist/$CodeModPlugin.js.map +1 -0
- package/dist/$RefPlugin.js +146 -0
- package/dist/$RefPlugin.js.map +1 -0
- package/dist/$TagPlugin.js +90 -0
- package/dist/$TagPlugin.js.map +1 -0
- package/dist/BreadcrumbsPlugin.js +48 -0
- package/dist/BreadcrumbsPlugin.js.map +1 -0
- package/dist/LazyPagePlugin.js +95 -0
- package/dist/LazyPagePlugin.js.map +1 -0
- package/dist/NextPrevPagePlugin.js +59 -0
- package/dist/NextPrevPagePlugin.js.map +1 -0
- package/dist/PagesWithoutFileExtPlugin.js +47 -0
- package/dist/PagesWithoutFileExtPlugin.js.map +1 -0
- package/dist/ReadingTimePlugin.mjs +119 -0
- package/dist/ReadingTimePlugin.mjs.map +1 -0
- package/dist/SharedConfigPlugin.js +50 -0
- package/dist/SharedConfigPlugin.js.map +1 -0
- package/dist/SidebarPlugin.js +109 -0
- package/dist/SidebarPlugin.js.map +1 -0
- package/dist/SiteMapPlugin.js +44 -0
- package/dist/SiteMapPlugin.js.map +1 -0
- package/dist/TableOfContentsPlugin.mjs +140 -0
- package/dist/TableOfContentsPlugin.mjs.map +1 -0
- package/dist/utils/normaliseRefs.js +83 -0
- package/dist/utils/normaliseRefs.js.map +1 -0
- package/package.json +6 -3
- package/.turbo/turbo-build.log +0 -14
- package/src/$AliasPlugin.ts +0 -62
- package/src/$CodeModPlugin.ts +0 -34
- package/src/$RefPlugin.ts +0 -200
- package/src/$TagPlugin.ts +0 -99
- package/src/BreadcrumbsPlugin.ts +0 -43
- package/src/LazyPagePlugin.ts +0 -101
- package/src/NextPrevPagePlugin.ts +0 -80
- package/src/PagesWithoutFileExtPlugin.ts +0 -38
- package/src/ReadingTimePlugin.mjs.ts +0 -32
- package/src/SharedConfigPlugin.ts +0 -49
- package/src/SidebarPlugin.ts +0 -154
- package/src/SiteMapPlugin.ts +0 -44
- package/src/TableOfContentsPlugin.mjs.ts +0 -52
- package/src/utils/normaliseRefs.ts +0 -85
- package/tsconfig.json +0 -21
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type Page from '@jpmorganchase/mosaic-types/dist/Page';
|
|
2
|
-
import type PluginType from '@jpmorganchase/mosaic-types/dist/Plugin';
|
|
3
|
-
import { escapeRegExp } from 'lodash';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Plugin that creates aliases without the file extension for every page emitted by the source.
|
|
8
|
-
* This allows pages to be retrieved from the filesystem without specifying `.mdx` (or whatever file extension is specified in `options.stripExt`).
|
|
9
|
-
* The plugin also modifies the `route` to point to the shorter alias. Friendly fullPaths are the shortest possible paths that
|
|
10
|
-
* will point to the page (see `Page` docs)
|
|
11
|
-
*/
|
|
12
|
-
const PagesWithoutFileExtPlugin: PluginType<
|
|
13
|
-
{}
|
|
14
|
-
> = {
|
|
15
|
-
async $afterSource(pages: Page[], { config, ignorePages, pageExtensions }) {
|
|
16
|
-
const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
|
|
17
|
-
const pageTest = new RegExp(`${pageExtensions.map(escapeRegExp).join('|')}$`);
|
|
18
|
-
|
|
19
|
-
for (const page of pages) {
|
|
20
|
-
if (!isNonHiddenPage(page.fullPath)) {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
page.route = page.route.replace(pageTest, '');
|
|
24
|
-
config.setAliases(page.fullPath, [page.route]);
|
|
25
|
-
}
|
|
26
|
-
return pages;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export default PagesWithoutFileExtPlugin;
|
|
31
|
-
|
|
32
|
-
function createPageTest(ignorePages, pageExtensions) {
|
|
33
|
-
const extTest = new RegExp(`${pageExtensions.map(escapeRegExp).join('|')}$`);
|
|
34
|
-
const ignoreTest = new RegExp(`${ignorePages.map(escapeRegExp).join('|')}$`);
|
|
35
|
-
return file => {
|
|
36
|
-
return !ignoreTest.test(file) && extTest.test(file) && !path.basename(file).startsWith('.');
|
|
37
|
-
};
|
|
38
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type PluginType from '@jpmorganchase/mosaic-types/dist/Plugin';
|
|
2
|
-
import type Page from '@jpmorganchase/mosaic-types/dist/Page';
|
|
3
|
-
import getReadingTime from 'reading-time';
|
|
4
|
-
import { unified } from 'unified';
|
|
5
|
-
import { visit } from 'unist-util-visit';
|
|
6
|
-
import markdown from 'remark-parse';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Calculates reading time for pages and adds to frontmatter
|
|
10
|
-
*/
|
|
11
|
-
const ReadingTimePlugin: PluginType<{}> = {
|
|
12
|
-
async $afterSource(pages: Page[]) {
|
|
13
|
-
const processor = unified().use(markdown);
|
|
14
|
-
for (const page of pages) {
|
|
15
|
-
const tree = await processor.parse(page.content);
|
|
16
|
-
let textContent = '';
|
|
17
|
-
|
|
18
|
-
visit(
|
|
19
|
-
tree,
|
|
20
|
-
node => node.type === 'text' || node.type === 'code',
|
|
21
|
-
node => {
|
|
22
|
-
textContent += node.value;
|
|
23
|
-
}
|
|
24
|
-
);
|
|
25
|
-
page.readingTime = getReadingTime(textContent);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return pages;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export default ReadingTimePlugin;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type PluginType from '@jpmorganchase/mosaic-types/dist/Plugin';
|
|
2
|
-
import flatten from 'lodash/flatten';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Plugin that crawls the page hierarchy to find the closest `sharedConfig` from any parent index's page metadata.
|
|
7
|
-
* It then exports a JSON file (name: `options.filename`) into each directory with the merged config for that level
|
|
8
|
-
*/
|
|
9
|
-
const SharedConfigPlugin: PluginType<{}, { filename: string }> = {
|
|
10
|
-
async $beforeSend(
|
|
11
|
-
mutableFilesystem,
|
|
12
|
-
{ config, serialiser, ignorePages, pageExtensions },
|
|
13
|
-
options
|
|
14
|
-
) {
|
|
15
|
-
const pagePaths = await mutableFilesystem.promises.glob(
|
|
16
|
-
createFileGlob('**/index,/index', pageExtensions),
|
|
17
|
-
{
|
|
18
|
-
ignore: [options.filename, ...flatten(ignorePages.map(ignore => [ignore, `**/${ignore}`]))],
|
|
19
|
-
cwd: '/'
|
|
20
|
-
}
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
for (const pagePath of pagePaths) {
|
|
24
|
-
const sharedConfigFile = path.join(path.dirname(String(pagePath)), options.filename);
|
|
25
|
-
|
|
26
|
-
const page = await serialiser.deserialise(
|
|
27
|
-
String(pagePath),
|
|
28
|
-
await mutableFilesystem.promises.readFile(String(pagePath))
|
|
29
|
-
);
|
|
30
|
-
if (page.sharedConfig) {
|
|
31
|
-
config.setRef(sharedConfigFile, ['config', '$ref'], `${String(pagePath)}#/sharedConfig`);
|
|
32
|
-
await mutableFilesystem.promises.writeFile(sharedConfigFile, '{}');
|
|
33
|
-
} else {
|
|
34
|
-
const baseDir = path.resolve(path.dirname(String(pagePath)), '../');
|
|
35
|
-
|
|
36
|
-
config.setAliases(path.join(baseDir, options.filename), [sharedConfigFile]);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export default SharedConfigPlugin;
|
|
43
|
-
|
|
44
|
-
function createFileGlob(url, pageExtensions) {
|
|
45
|
-
if (pageExtensions.length === 1) {
|
|
46
|
-
return `${url}${pageExtensions[0]}`;
|
|
47
|
-
}
|
|
48
|
-
return `${url}{${pageExtensions.join(',')}}`;
|
|
49
|
-
}
|
package/src/SidebarPlugin.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import type PluginType from '@jpmorganchase/mosaic-types/dist/Plugin';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Sorts the pages in a folder by priority and then exports a JSON file (name: `options.filename`) with the
|
|
6
|
-
* sidebar tree from that directory downwards and adds sidebar data into frontmatter for each page.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const SidebarPlugin: PluginType<
|
|
10
|
-
{
|
|
11
|
-
dirs: string[];
|
|
12
|
-
refs: { [key: string]: { $$path: (number | string)[]; $$value: string }[] };
|
|
13
|
-
},
|
|
14
|
-
{ filename: string }
|
|
15
|
-
> = {
|
|
16
|
-
async $beforeSend(
|
|
17
|
-
mutableFilesystem,
|
|
18
|
-
{ config, serialiser, ignorePages, pageExtensions },
|
|
19
|
-
options
|
|
20
|
-
) {
|
|
21
|
-
const dirs = await mutableFilesystem.promises.glob('**', {
|
|
22
|
-
onlyDirectories: true,
|
|
23
|
-
cwd: '/'
|
|
24
|
-
});
|
|
25
|
-
for (const dirName of dirs) {
|
|
26
|
-
const sidebarFilePath = path.posix.join(String(dirName), options.filename);
|
|
27
|
-
const pages = (
|
|
28
|
-
await Promise.all(
|
|
29
|
-
((await mutableFilesystem.promises.glob(
|
|
30
|
-
createFileGlob(['*', '*/index'], pageExtensions),
|
|
31
|
-
{
|
|
32
|
-
onlyFiles: true,
|
|
33
|
-
cwd: String(dirName),
|
|
34
|
-
ignore: ignorePages.map(ignore => `**/${ignore}`)
|
|
35
|
-
}
|
|
36
|
-
)) as string[]).map(async pagePath => {
|
|
37
|
-
return await serialiser.deserialise(
|
|
38
|
-
pagePath,
|
|
39
|
-
await mutableFilesystem.promises.readFile(pagePath)
|
|
40
|
-
);
|
|
41
|
-
})
|
|
42
|
-
)
|
|
43
|
-
)
|
|
44
|
-
.filter(page => filterFn(page))
|
|
45
|
-
.sort((pageA, pageB) => sortFn(pageA, pageB, dirName));
|
|
46
|
-
|
|
47
|
-
for (let i = 0; i < pages.length; i++) {
|
|
48
|
-
setPageRefs(sidebarFilePath, pages[i], i);
|
|
49
|
-
setChildPageRefs(pages[i], dirName, i, sidebarFilePath);
|
|
50
|
-
addSidebarDataToFrontmatter(pages[i], dirName);
|
|
51
|
-
}
|
|
52
|
-
await mutableFilesystem.promises.writeFile(sidebarFilePath, '[]');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function setPageRefs(sidebarFilePath, page, i) {
|
|
56
|
-
config.setRef(sidebarFilePath, ['pages', `${i}`, 'id', '$ref'], `${page.fullPath}#/route`);
|
|
57
|
-
page.sidebar && page.sidebar.label
|
|
58
|
-
? config.setRef(
|
|
59
|
-
sidebarFilePath,
|
|
60
|
-
['pages', `${i}`, 'name', '$ref'],
|
|
61
|
-
`${page.fullPath}#/sidebar/label`
|
|
62
|
-
)
|
|
63
|
-
: config.setRef(
|
|
64
|
-
sidebarFilePath,
|
|
65
|
-
['pages', `${i}`, 'name', '$ref'],
|
|
66
|
-
`${page.fullPath}#/title`
|
|
67
|
-
);
|
|
68
|
-
config.setRef(
|
|
69
|
-
sidebarFilePath,
|
|
70
|
-
['pages', `${i}`, 'data', 'link', '$ref'],
|
|
71
|
-
`${page.fullPath}#/route`
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async function setChildPageRefs(page, dirName, i, sidebarFilePath) {
|
|
76
|
-
if (isSubfolderIndex(page, dirName)) {
|
|
77
|
-
const childDirName = path.posix.dirname(page.fullPath);
|
|
78
|
-
const childNodeSidebarPath = path.posix.join(childDirName, options.filename);
|
|
79
|
-
const childPages = (
|
|
80
|
-
await Promise.all(
|
|
81
|
-
((await mutableFilesystem.promises.glob(
|
|
82
|
-
createFileGlob(['*', '*/index'], pageExtensions),
|
|
83
|
-
{
|
|
84
|
-
onlyFiles: true,
|
|
85
|
-
cwd: String(childDirName),
|
|
86
|
-
ignore: ignorePages.map(ignore => `**/${ignore}`)
|
|
87
|
-
}
|
|
88
|
-
)) as string[]).map(async pagePath => {
|
|
89
|
-
return await serialiser.deserialise(
|
|
90
|
-
pagePath,
|
|
91
|
-
await mutableFilesystem.promises.readFile(pagePath)
|
|
92
|
-
);
|
|
93
|
-
})
|
|
94
|
-
)
|
|
95
|
-
).filter(page => filterFn(page));
|
|
96
|
-
if (childPages.length > 1) {
|
|
97
|
-
for (let j = 1; j < childPages.length; j++) {
|
|
98
|
-
config.setRef(
|
|
99
|
-
sidebarFilePath,
|
|
100
|
-
['pages', `${i}`, 'childNodes', `${j - 1}`, '$ref'],
|
|
101
|
-
`${childNodeSidebarPath}#/pages/${j}`
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function addSidebarDataToFrontmatter(page, dirName) {
|
|
109
|
-
const dirNameLevels = String(dirName)
|
|
110
|
-
.split('/')
|
|
111
|
-
.filter(level => level);
|
|
112
|
-
const sidebarRootDir =
|
|
113
|
-
`/` + dirNameLevels.slice(0, dirNameLevels.length < 3 ? dirNameLevels.length : 3).join(`/`);
|
|
114
|
-
config.setRef(
|
|
115
|
-
String(page.fullPath),
|
|
116
|
-
['sidebarData', '$ref'],
|
|
117
|
-
path.posix.join(String(sidebarRootDir), options.filename, '#', 'pages')
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
export default SidebarPlugin;
|
|
123
|
-
|
|
124
|
-
function createFileGlob(patterns, pageExtensions) {
|
|
125
|
-
if (Array.isArray(patterns)) {
|
|
126
|
-
return patterns.map(pattern => createFileGlob(pattern, pageExtensions));
|
|
127
|
-
}
|
|
128
|
-
if (pageExtensions.length === 1) {
|
|
129
|
-
return `${patterns}${pageExtensions[0]}`;
|
|
130
|
-
}
|
|
131
|
-
return `${patterns}{${pageExtensions.join(',')}}`;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function isSubfolderIndex(page, dirName) {
|
|
135
|
-
return page.fullPath.split('/').length == String(dirName).split('/').length + 2;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function sortFn(pageA, pageB, dirName) {
|
|
139
|
-
// Always pin /index to the front
|
|
140
|
-
if (pageA.route === dirName + '/index') {
|
|
141
|
-
return -1;
|
|
142
|
-
}
|
|
143
|
-
if (pageB.route === dirName + '/index') {
|
|
144
|
-
return 1;
|
|
145
|
-
}
|
|
146
|
-
return (
|
|
147
|
-
(pageB.sidebar && pageB.sidebar.priority ? pageB.sidebar.priority : -1) -
|
|
148
|
-
(pageA.sidebar && pageA.sidebar.priority ? pageA.sidebar.priority : -1)
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function filterFn(page) {
|
|
153
|
-
return !(page.sidebar && page.sidebar.exclude);
|
|
154
|
-
}
|
package/src/SiteMapPlugin.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type PluginType from '@jpmorganchase/mosaic-types/dist/Plugin';
|
|
2
|
-
|
|
3
|
-
const SiteMapPlugin: PluginType<
|
|
4
|
-
{ sitemaps: string[][] },
|
|
5
|
-
{}
|
|
6
|
-
> = {
|
|
7
|
-
// Merge together all of the individual sitemaps from each source
|
|
8
|
-
async afterUpdate(mutableFilesystem, { sharedFilesystem, globalConfig }) {
|
|
9
|
-
if (!Array.isArray(globalConfig.data.sitemaps)) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
await sharedFilesystem.promises.writeFile(
|
|
13
|
-
'/sitemap.xml',
|
|
14
|
-
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n' +
|
|
15
|
-
globalConfig.data.sitemaps
|
|
16
|
-
.map(items =>
|
|
17
|
-
items
|
|
18
|
-
.map(
|
|
19
|
-
item =>
|
|
20
|
-
`\t<url>\n\t\t<loc>${String(
|
|
21
|
-
item
|
|
22
|
-
)}</loc>\n\t\t<changefreq>weekly</changefreq>\n\t\t<priority>0.5</priority>\n\t</url>`
|
|
23
|
-
)
|
|
24
|
-
.join('\n')
|
|
25
|
-
)
|
|
26
|
-
.join('') +
|
|
27
|
-
'\n</urlset>'
|
|
28
|
-
);
|
|
29
|
-
},
|
|
30
|
-
// Store a sitemap for just this source
|
|
31
|
-
async $beforeSend(mutableFilesystem, { config, ignorePages }, options) {
|
|
32
|
-
config.setData({
|
|
33
|
-
sitemaps: [
|
|
34
|
-
(await mutableFilesystem.promises.glob('**', {
|
|
35
|
-
onlyFiles: true,
|
|
36
|
-
ignore: ignorePages.map(ignore => `**/${ignore}`),
|
|
37
|
-
cwd: '/'
|
|
38
|
-
})) as string[]
|
|
39
|
-
]
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export default SiteMapPlugin;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type PluginType from '@jpmorganchase/mosaic-types/dist/Plugin';
|
|
2
|
-
import type Page from '@jpmorganchase/mosaic-types/dist/Page';
|
|
3
|
-
import { visit } from 'unist-util-visit';
|
|
4
|
-
import markdown from 'remark-parse';
|
|
5
|
-
import { unified } from 'unified';
|
|
6
|
-
import Slugger from 'github-slugger';
|
|
7
|
-
import { toString } from 'hast-util-to-string';
|
|
8
|
-
|
|
9
|
-
type TOCItem = { level: number; id: string; text: string };
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Calculates table of contents from page headings
|
|
13
|
-
*/
|
|
14
|
-
const TableOfContentsPlugin: PluginType<{}, { minRank: 2; maxRank: 4 }> = {
|
|
15
|
-
async $afterSource(pages: Page[], {}, { minRank, maxRank }) {
|
|
16
|
-
const processor = unified().use(markdown);
|
|
17
|
-
const slugger = new Slugger();
|
|
18
|
-
for (const page of pages) {
|
|
19
|
-
const tree = await processor.parse(page.content);
|
|
20
|
-
const items: TOCItem[] = [];
|
|
21
|
-
visit(
|
|
22
|
-
tree,
|
|
23
|
-
node => test(node),
|
|
24
|
-
node => {
|
|
25
|
-
const text = toString(node).trim();
|
|
26
|
-
items.push({
|
|
27
|
-
level: node.depth,
|
|
28
|
-
id: slugger.slug(text),
|
|
29
|
-
text: text
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
);
|
|
33
|
-
page.tableOfContents = items;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return pages;
|
|
37
|
-
|
|
38
|
-
function test(node) {
|
|
39
|
-
return node.type === 'heading' && isHeadingInRange(node);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function isHeadingInRange(node) {
|
|
43
|
-
const depth = node.depth;
|
|
44
|
-
if (depth < minRank || depth > maxRank) {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export default TableOfContentsPlugin;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
|
|
3
|
-
import glob from 'fast-glob';
|
|
4
|
-
import set from 'lodash/set';
|
|
5
|
-
|
|
6
|
-
function createFileGlob(url, pageExtensions) {
|
|
7
|
-
if (pageExtensions.length === 1) {
|
|
8
|
-
return `${url}${pageExtensions[0]}`;
|
|
9
|
-
}
|
|
10
|
-
return `${url}{${pageExtensions.join(',')}}`;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export default async function normaliseRefs(filepath, refs, filesystem, pageExtensions, ignorePages) {
|
|
14
|
-
const configWithoutGlobs = {};
|
|
15
|
-
|
|
16
|
-
for (let i = 0; i < refs.length; i++) {
|
|
17
|
-
const ref = refs[i];
|
|
18
|
-
const [url, fragment = ''] = ref.$$value.split('#');
|
|
19
|
-
|
|
20
|
-
if (!url) {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const fullUrl = path.resolve(path.dirname(filepath), url);
|
|
25
|
-
|
|
26
|
-
if (!glob.isDynamicPattern(url)) {
|
|
27
|
-
if (!(await filesystem.promises.exists(fullUrl))) {
|
|
28
|
-
throw new Error(
|
|
29
|
-
`A \`$ref\` for '${filepath}' pointed to page '${fullUrl}' - which could not be found.`
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
const refRealPath = await filesystem.promises.realpath(
|
|
33
|
-
fullUrl
|
|
34
|
-
//path.resolve(path.dirname(filepath), url)
|
|
35
|
-
);
|
|
36
|
-
const stat = await filesystem.promises.stat(refRealPath);
|
|
37
|
-
// Turn directory refs into full index paths
|
|
38
|
-
// TODO: But DO we want to do this?
|
|
39
|
-
if (stat.isDirectory()) {
|
|
40
|
-
// && !/\/index(\.\w{1,4})?$/.test(url)) {
|
|
41
|
-
set(configWithoutGlobs, ref.$$path.slice(0, -1), {
|
|
42
|
-
$ref: `${await filesystem.promises.realpath(path.join(refRealPath, 'index'))}#${fragment}`
|
|
43
|
-
});
|
|
44
|
-
} else {
|
|
45
|
-
set(configWithoutGlobs, ref.$$path.slice(0, -1), {
|
|
46
|
-
$ref: `${refRealPath}#${fragment}`
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
let globResolvedRefs =
|
|
54
|
-
// If the pattern doesn't have an explicit file extension - then we'll make it just return pages
|
|
55
|
-
await filesystem.promises.glob(
|
|
56
|
-
!/\/[^/]+\.\w{2,4}$/.test(url) ? createFileGlob(url, pageExtensions) : url,
|
|
57
|
-
{
|
|
58
|
-
ignore: [filepath, ...ignorePages.map(ignore => `**/${ignore}`)],
|
|
59
|
-
cwd: path.dirname(filepath),
|
|
60
|
-
absolute: true
|
|
61
|
-
}
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
// Use a set so we de-dupe any symlinks that point to the same page
|
|
65
|
-
const resolvedRefs = new Set();
|
|
66
|
-
|
|
67
|
-
for (const value of globResolvedRefs) {
|
|
68
|
-
const refRealPath = await filesystem.promises.realpath(path.resolve(filepath, value));
|
|
69
|
-
if (refRealPath !== (await filesystem.promises.realpath(filepath))) {
|
|
70
|
-
resolvedRefs.add(`${refRealPath}#${fragment}`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
set(
|
|
75
|
-
configWithoutGlobs,
|
|
76
|
-
ref.$$path.slice(0, -1),
|
|
77
|
-
Array.from(resolvedRefs).map($ref => ({ $ref }))
|
|
78
|
-
);
|
|
79
|
-
} catch (e) {
|
|
80
|
-
throw e;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return configWithoutGlobs;
|
|
85
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "commonjs",
|
|
4
|
-
"allowJs": true,
|
|
5
|
-
"target": "es2015",
|
|
6
|
-
"esModuleInterop": true,
|
|
7
|
-
"moduleResolution": "NodeNext",
|
|
8
|
-
"outDir": "dist",
|
|
9
|
-
"skipLibCheck": true,
|
|
10
|
-
"sourceMap": true,
|
|
11
|
-
"rootDir": "./src"
|
|
12
|
-
},
|
|
13
|
-
"include": ["src/**/*"],
|
|
14
|
-
"exclude": [
|
|
15
|
-
"node_modules",
|
|
16
|
-
"src/**/__tests__/**/*",
|
|
17
|
-
"src/__tests__/**/*",
|
|
18
|
-
"src/**/*.mjs.*",
|
|
19
|
-
"**/dist/**/*"
|
|
20
|
-
]
|
|
21
|
-
}
|