@graphql-markdown/core 1.0.0
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/LICENSE +21 -0
- package/README.md +4 -0
- package/assets/generated.md +19 -0
- package/assets/sidebar.json +8 -0
- package/package.json +59 -0
- package/src/config.js +84 -0
- package/src/index.js +7 -0
- package/src/lib/generator.js +123 -0
- package/src/lib/group-info.js +73 -0
- package/src/lib/renderer.js +145 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Grégory Heitz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
# @graphql-markdown/core
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@graphql-markdown/core)
|
|
4
|
+
[](https://raw.githubusercontent.com/graphql-markdown/graphql-markdown/main/LICENSE)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: schema
|
|
3
|
+
slug: ##baseURL##
|
|
4
|
+
title: Schema Documentation
|
|
5
|
+
sidebar_position: 1
|
|
6
|
+
hide_table_of_contents: true
|
|
7
|
+
pagination_next: null
|
|
8
|
+
pagination_prev: null
|
|
9
|
+
sidebar_class_name: navbar__toggle
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
This documentation has been automatically generated from the GraphQL schema.
|
|
13
|
+
|
|
14
|
+
Use the docs in the sidebar to find out how to use the schema:
|
|
15
|
+
|
|
16
|
+
- **Allowed operations**: queries and mutations.
|
|
17
|
+
- **Schema-defined types**: scalars, objects, enums, interfaces, unions, and input objects.
|
|
18
|
+
|
|
19
|
+
<small><i>Generated on ##generated-date-time##.</i></small>
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@graphql-markdown/core",
|
|
3
|
+
"homepage": "https://graphql-markdown.github.io",
|
|
4
|
+
"description": "GraphQL-Markdown core package for generating Markdown documentation from a GraphQL schema.",
|
|
5
|
+
"bugs": {
|
|
6
|
+
"url": "https://github.com/graphql-markdown/graphql-markdown/issues"
|
|
7
|
+
},
|
|
8
|
+
"version": "1.0.0",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"main": "src/index.js",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/graphql-markdown/graphql-markdown.git"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"graphql",
|
|
17
|
+
"graphql-schema",
|
|
18
|
+
"documentation",
|
|
19
|
+
"markdown",
|
|
20
|
+
"graphql-markdown"
|
|
21
|
+
],
|
|
22
|
+
"author": {
|
|
23
|
+
"name": "Gregory Heitz"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"prepack": "pinst --disable",
|
|
27
|
+
"postpack": "pinst --enable",
|
|
28
|
+
"test": "jest",
|
|
29
|
+
"stryker": "stryker run"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@graphql-markdown/utils": "^1.0.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@graphql-markdown/printer-legacy": "^1.0.0",
|
|
36
|
+
"@graphql-markdown/diff": "^1.0.0",
|
|
37
|
+
"prettier": "^2.5"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"@graphql-markdown/printer-legacy": {
|
|
41
|
+
"optional": true
|
|
42
|
+
},
|
|
43
|
+
"@graphql-markdown/diff": {
|
|
44
|
+
"optional": true
|
|
45
|
+
},
|
|
46
|
+
"prettier": {
|
|
47
|
+
"optional": true
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"directories": {
|
|
51
|
+
"test": "tests"
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=16.14"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/config.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const { join } = require("path");
|
|
2
|
+
const { tmpdir } = require("os");
|
|
3
|
+
|
|
4
|
+
const { parseGroupByOption } = require("./lib/group-info");
|
|
5
|
+
|
|
6
|
+
const PACKAGE_NAME = "@graphql-markdown/docusaurus";
|
|
7
|
+
const ASSETS_LOCATION = join(__dirname, "../assets/");
|
|
8
|
+
|
|
9
|
+
const DEFAULT_OPTIONS = {
|
|
10
|
+
schema: "./schema.graphql",
|
|
11
|
+
rootPath: "./docs",
|
|
12
|
+
baseURL: "schema",
|
|
13
|
+
linkRoot: "/",
|
|
14
|
+
homepage: join(ASSETS_LOCATION, "generated.md"),
|
|
15
|
+
diffMethod: undefined,
|
|
16
|
+
tmpDir: join(tmpdir(), PACKAGE_NAME),
|
|
17
|
+
loaders: {},
|
|
18
|
+
pretty: false,
|
|
19
|
+
printer: "@graphql-markdown/printer-legacy",
|
|
20
|
+
docOptions: {
|
|
21
|
+
pagination: true,
|
|
22
|
+
toc: true,
|
|
23
|
+
index: false,
|
|
24
|
+
},
|
|
25
|
+
printTypeOptions: {
|
|
26
|
+
parentTypePrefix: true,
|
|
27
|
+
relatedTypeSection: true,
|
|
28
|
+
typeBadges: true,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function buildConfig(configFileOpts, cliOpts) {
|
|
33
|
+
let config = DEFAULT_OPTIONS;
|
|
34
|
+
|
|
35
|
+
if (typeof configFileOpts != "undefined" && configFileOpts != null) {
|
|
36
|
+
config = { ...DEFAULT_OPTIONS, ...configFileOpts };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (typeof cliOpts == "undefined" || cliOpts == null) {
|
|
40
|
+
cliOpts = {};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const baseURL = cliOpts.base ?? config.baseURL;
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
baseURL,
|
|
47
|
+
schemaLocation: cliOpts.schema ?? config.schema,
|
|
48
|
+
outputDir: join(cliOpts.root ?? config.rootPath, baseURL),
|
|
49
|
+
linkRoot: cliOpts.link ?? config.linkRoot,
|
|
50
|
+
homepageLocation: cliOpts.homepage ?? config.homepage,
|
|
51
|
+
diffMethod: getDiffMethod(cliOpts.diff ?? config.diffMethod, cliOpts.force),
|
|
52
|
+
tmpDir: cliOpts.tmp ?? config.tmpDir,
|
|
53
|
+
loaders: config.loaders,
|
|
54
|
+
groupByDirective:
|
|
55
|
+
parseGroupByOption(cliOpts.groupByDirective) || config.groupByDirective,
|
|
56
|
+
prettify: cliOpts.pretty ?? config.pretty,
|
|
57
|
+
docOptions: getDocOptions(cliOpts, config.docOptions),
|
|
58
|
+
printTypeOptions: gePrintTypeOptions(cliOpts, config.printTypeOptions),
|
|
59
|
+
printer: config.printer,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function getDiffMethod(diff, force) {
|
|
64
|
+
return force ? "FORCE" : diff;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function getDocOptions(cliOpts, configOptions) {
|
|
68
|
+
return {
|
|
69
|
+
pagination: !cliOpts.noPagination && configOptions.pagination,
|
|
70
|
+
toc: !cliOpts.noToc && configOptions.toc,
|
|
71
|
+
index: cliOpts.index || configOptions.index,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function gePrintTypeOptions(cliOpts, configOptions) {
|
|
76
|
+
return {
|
|
77
|
+
parentTypePrefix: !cliOpts.noParentType && configOptions.parentTypePrefix,
|
|
78
|
+
relatedTypeSection:
|
|
79
|
+
!cliOpts.noRelatedType && configOptions.relatedTypeSection,
|
|
80
|
+
typeBadges: !cliOpts.noTypeBadges && configOptions.typeBadges,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
module.exports = { buildConfig, DEFAULT_OPTIONS, ASSETS_LOCATION };
|
package/src/index.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
const { getSchemaMap, loadSchema, getDocumentLoaders } =
|
|
2
|
+
require("@graphql-markdown/utils").graphql;
|
|
3
|
+
const { getGroups } = require("./group-info");
|
|
4
|
+
const Renderer = require("./renderer");
|
|
5
|
+
|
|
6
|
+
const time = process.hrtime();
|
|
7
|
+
|
|
8
|
+
const hasChanges = async (
|
|
9
|
+
schema,
|
|
10
|
+
tmpDir,
|
|
11
|
+
diffMethod,
|
|
12
|
+
diffModule = "@graphql-markdown/diff",
|
|
13
|
+
) => {
|
|
14
|
+
if (typeof diffMethod == "undefined" || diffMethod == null) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const { checkSchemaChanges } = require(diffModule);
|
|
20
|
+
return await checkSchemaChanges(schema, tmpDir, diffMethod);
|
|
21
|
+
} catch (e) {
|
|
22
|
+
console.warn(
|
|
23
|
+
`Cannot find module '${diffModule}' from @graphql-markdown/core!`,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return true;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const getPrinter = (
|
|
31
|
+
schema,
|
|
32
|
+
baseURL,
|
|
33
|
+
linkRoot,
|
|
34
|
+
groups,
|
|
35
|
+
printTypeOptions,
|
|
36
|
+
printerModule,
|
|
37
|
+
) => {
|
|
38
|
+
if (typeof printerModule != "string") {
|
|
39
|
+
throw new Error(
|
|
40
|
+
"Invalid printer module name in printTypeOptions settings.",
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
const Printer = require(printerModule);
|
|
46
|
+
return new Printer(schema, baseURL, linkRoot, {
|
|
47
|
+
groups,
|
|
48
|
+
printTypeOptions,
|
|
49
|
+
});
|
|
50
|
+
} catch (e) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
`Cannot find module '${printerModule}' from @graphql-markdown/core in printTypeOptions settings.`,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const generateDocFromSchema = async ({
|
|
58
|
+
baseURL,
|
|
59
|
+
schemaLocation,
|
|
60
|
+
outputDir,
|
|
61
|
+
linkRoot,
|
|
62
|
+
homepageLocation,
|
|
63
|
+
diffMethod,
|
|
64
|
+
tmpDir,
|
|
65
|
+
loaders,
|
|
66
|
+
groupByDirective,
|
|
67
|
+
prettify,
|
|
68
|
+
docOptions,
|
|
69
|
+
printTypeOptions,
|
|
70
|
+
printer: printerModule,
|
|
71
|
+
}) => {
|
|
72
|
+
const schema = await loadSchema(schemaLocation, getDocumentLoaders(loaders));
|
|
73
|
+
|
|
74
|
+
const changed = await hasChanges(schema, tmpDir, diffMethod);
|
|
75
|
+
if (!changed) {
|
|
76
|
+
console.info(`No changes detected in schema "${schemaLocation}".`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const rootTypes = getSchemaMap(schema);
|
|
80
|
+
const groups = new getGroups(rootTypes, groupByDirective);
|
|
81
|
+
const printer = getPrinter(
|
|
82
|
+
schema,
|
|
83
|
+
baseURL,
|
|
84
|
+
linkRoot,
|
|
85
|
+
groups,
|
|
86
|
+
printTypeOptions,
|
|
87
|
+
printerModule,
|
|
88
|
+
);
|
|
89
|
+
const renderer = new Renderer(
|
|
90
|
+
printer,
|
|
91
|
+
outputDir,
|
|
92
|
+
baseURL,
|
|
93
|
+
groups,
|
|
94
|
+
prettify,
|
|
95
|
+
docOptions,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const pages = await Promise.all(
|
|
99
|
+
Object.keys(rootTypes).map((typeName) =>
|
|
100
|
+
renderer.renderRootTypes(typeName, rootTypes[typeName]),
|
|
101
|
+
),
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
await renderer.renderHomepage(homepageLocation);
|
|
105
|
+
|
|
106
|
+
const sidebarPath = await renderer.renderSidebar();
|
|
107
|
+
|
|
108
|
+
const [sec, msec] = process.hrtime(time);
|
|
109
|
+
const duration = (sec + msec / 1e9).toFixed(3);
|
|
110
|
+
console.info(
|
|
111
|
+
`Documentation successfully generated in "${outputDir}" with base URL "${baseURL}".`,
|
|
112
|
+
);
|
|
113
|
+
console.log(
|
|
114
|
+
`${
|
|
115
|
+
pages.flat().length
|
|
116
|
+
} pages generated in ${duration}s from schema "${schemaLocation}".`,
|
|
117
|
+
);
|
|
118
|
+
console.info(
|
|
119
|
+
`Remember to update your Docusaurus site's sidebars with "${sidebarPath}".`,
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
module.exports = { getPrinter, hasChanges, generateDocFromSchema };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const {
|
|
2
|
+
array: { convertArrayToObject },
|
|
3
|
+
} = require("@graphql-markdown/utils").scalars;
|
|
4
|
+
|
|
5
|
+
const DEFAULT_GROUP = "Miscellaneous";
|
|
6
|
+
const OPTION_REGEX =
|
|
7
|
+
/^@(?<directive>\w+)\((?<field>\w+)(?:\|=(?<fallback>\w+))?\)/;
|
|
8
|
+
|
|
9
|
+
function parseGroupByOption(groupOptions) {
|
|
10
|
+
if (typeof groupOptions !== "string") {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const parsedOptions = OPTION_REGEX.exec(groupOptions);
|
|
15
|
+
|
|
16
|
+
if (typeof parsedOptions == "undefined" || parsedOptions == null) {
|
|
17
|
+
throw new Error(`Invalid "${groupOptions}"`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const { directive, field, fallback = DEFAULT_GROUP } = parsedOptions.groups;
|
|
21
|
+
return { directive, field, fallback };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getGroups(rootTypes, groupByDirective) {
|
|
25
|
+
let groups = {};
|
|
26
|
+
|
|
27
|
+
if (typeof groupByDirective == "undefined" || groupByDirective == null) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
Object.keys(rootTypes).forEach((typeName) => {
|
|
32
|
+
let rootType = rootTypes[typeName];
|
|
33
|
+
if (typeof rootType != "undefined" && rootType != null) {
|
|
34
|
+
if (Array.isArray(rootType)) {
|
|
35
|
+
rootType = convertArrayToObject(rootType);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
Object.keys(rootType).forEach((type) => {
|
|
39
|
+
groups[type] = getGroupName(rootType[type], groupByDirective);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return groups;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function getGroupName(type, groupByDirective) {
|
|
48
|
+
let group = groupByDirective.fallback; // default value is fallback, and it will be only overridden if a group is found
|
|
49
|
+
|
|
50
|
+
if (typeof type.astNode == "undefined" || type.astNode == null) {
|
|
51
|
+
return group;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const allDirectives = type.astNode.directives;
|
|
55
|
+
|
|
56
|
+
if (!Array.isArray(allDirectives)) {
|
|
57
|
+
return group;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
for (const directive of allDirectives) {
|
|
61
|
+
if (directive.name.value !== groupByDirective.directive) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const field = directive.arguments.find(
|
|
65
|
+
({ name }) => name.value === groupByDirective.field,
|
|
66
|
+
);
|
|
67
|
+
return field.value.value;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return group;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = { getGroupName, getGroups, parseGroupByOption };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
const path = require("path");
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
array: { convertArrayToObject },
|
|
5
|
+
object: { hasProperty },
|
|
6
|
+
string: { toSlug, startCase },
|
|
7
|
+
url: { pathUrl },
|
|
8
|
+
} = require("@graphql-markdown/utils").scalars;
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
prettier: { prettifyJavascript, prettifyMarkdown },
|
|
12
|
+
fs: { saveFile, ensureDir, copyFile, readFile, fileExists },
|
|
13
|
+
} = require("@graphql-markdown/utils").helpers;
|
|
14
|
+
|
|
15
|
+
const { ASSETS_LOCATION } = require("../config");
|
|
16
|
+
const { schemaSidebar } = require(`${ASSETS_LOCATION}/sidebar.json`);
|
|
17
|
+
|
|
18
|
+
const SIDEBAR = "sidebar-schema.js";
|
|
19
|
+
const HOMEPAGE_ID = "schema";
|
|
20
|
+
const CATEGORY_YAML = "_category_.yml";
|
|
21
|
+
|
|
22
|
+
module.exports = class Renderer {
|
|
23
|
+
constructor(printer, outputDir, baseURL, group, prettify, docOptions) {
|
|
24
|
+
this.group = group;
|
|
25
|
+
this.outputDir = outputDir;
|
|
26
|
+
this.baseURL = baseURL;
|
|
27
|
+
this.printer = printer;
|
|
28
|
+
this.prettify = prettify;
|
|
29
|
+
this.options = docOptions;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async generateCategoryMetafile(category, dirPath) {
|
|
33
|
+
const filePath = path.join(dirPath, CATEGORY_YAML);
|
|
34
|
+
|
|
35
|
+
if (await fileExists(filePath)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
await ensureDir(dirPath);
|
|
40
|
+
|
|
41
|
+
const label = startCase(category);
|
|
42
|
+
const link =
|
|
43
|
+
typeof this.options === "undefined" || !this.options.index
|
|
44
|
+
? "null"
|
|
45
|
+
: `\n type: generated-index\n title: '${label} overview'\n`;
|
|
46
|
+
|
|
47
|
+
await saveFile(filePath, `label: ${label}\nlink: ${link}\n`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async renderRootTypes(rootTypeName, type) {
|
|
51
|
+
if (typeof type === "undefined" || type === null) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (Array.isArray(type)) {
|
|
56
|
+
type = convertArrayToObject(type);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return Promise.all(
|
|
60
|
+
Object.keys(type).map(async (name) => {
|
|
61
|
+
let dirPath = this.outputDir;
|
|
62
|
+
|
|
63
|
+
if (hasProperty(this.group, name)) {
|
|
64
|
+
dirPath = path.join(dirPath, toSlug(this.group[name]));
|
|
65
|
+
await this.generateCategoryMetafile(this.group[name], dirPath);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
dirPath = path.join(dirPath, toSlug(rootTypeName));
|
|
69
|
+
await this.generateCategoryMetafile(rootTypeName, dirPath);
|
|
70
|
+
|
|
71
|
+
return this.renderTypeEntities(dirPath, name, type[name]);
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async renderTypeEntities(dirPath, name, type) {
|
|
77
|
+
if (typeof type === "undefined" || type === null) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const fileName = toSlug(name);
|
|
82
|
+
const filePath = path.join(path.normalize(dirPath), `${fileName}.mdx`);
|
|
83
|
+
|
|
84
|
+
const content = this.printer.printType(fileName, type, this.options);
|
|
85
|
+
await saveFile(
|
|
86
|
+
filePath,
|
|
87
|
+
this.prettify ? prettifyMarkdown(content) : content,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const pagePath = path.relative(this.outputDir, filePath);
|
|
91
|
+
const page = pagePath.match(
|
|
92
|
+
/(?<category>[A-Za-z0-9-]+)[\\/]+(?<pageId>[A-Za-z0-9-]+).mdx?$/,
|
|
93
|
+
);
|
|
94
|
+
const slug = pathUrl.join(page.groups.category, page.groups.pageId);
|
|
95
|
+
|
|
96
|
+
return { category: startCase(page.groups.category), slug: slug };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async renderSidebar() {
|
|
100
|
+
const sidebar = {
|
|
101
|
+
schemaSidebar: schemaSidebar.map((entry) => {
|
|
102
|
+
switch (entry.type) {
|
|
103
|
+
case "doc":
|
|
104
|
+
entry.id = pathUrl.join(this.baseURL, HOMEPAGE_ID);
|
|
105
|
+
break;
|
|
106
|
+
case "autogenerated":
|
|
107
|
+
entry.dirName = this.baseURL;
|
|
108
|
+
break;
|
|
109
|
+
default: //do nothing
|
|
110
|
+
}
|
|
111
|
+
return entry;
|
|
112
|
+
}),
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const jsonSidebar = `
|
|
116
|
+
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
|
|
117
|
+
|
|
118
|
+
module.exports = ${JSON.stringify(sidebar, null, 2)};
|
|
119
|
+
`;
|
|
120
|
+
|
|
121
|
+
const filePath = path.join(this.outputDir, SIDEBAR);
|
|
122
|
+
await saveFile(
|
|
123
|
+
filePath,
|
|
124
|
+
this.prettify ? prettifyJavascript(jsonSidebar) : jsonSidebar,
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
return path.relative("./", filePath);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async renderHomepage(homepageLocation) {
|
|
131
|
+
const homePage = path.basename(homepageLocation);
|
|
132
|
+
const destLocation = path.join(this.outputDir, homePage);
|
|
133
|
+
const slug = pathUrl.resolve("/", this.baseURL);
|
|
134
|
+
|
|
135
|
+
await copyFile(homepageLocation, destLocation);
|
|
136
|
+
|
|
137
|
+
const template = await readFile(destLocation);
|
|
138
|
+
|
|
139
|
+
const data = template
|
|
140
|
+
.toString()
|
|
141
|
+
.replace(/##baseURL##/gm, slug)
|
|
142
|
+
.replace(/##generated-date-time##/gm, new Date().toLocaleString());
|
|
143
|
+
await saveFile(destLocation, data);
|
|
144
|
+
}
|
|
145
|
+
};
|