@graphql-markdown/docusaurus 1.14.0 → 1.15.1
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/README.md +2 -20
- package/package.json +7 -146
- package/src/index.js +4 -3
- package/assets/generated.md +0 -19
- package/assets/sidebar.json +0 -8
- package/src/config.js +0 -83
- package/src/const/mdx.js +0 -7
- package/src/const/strings.js +0 -30
- package/src/lib/diff.js +0 -79
- package/src/lib/generator.js +0 -78
- package/src/lib/graphql.js +0 -372
- package/src/lib/group-info.js +0 -76
- package/src/lib/printer.js +0 -581
- package/src/lib/renderer.js +0 -150
- package/src/utils/helpers/fs.js +0 -33
- package/src/utils/helpers/prettier.js +0 -29
- package/src/utils/scalars/array.js +0 -18
- package/src/utils/scalars/object.js +0 -16
- package/src/utils/scalars/string.js +0 -86
- package/src/utils/scalars/url.js +0 -8
package/README.md
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
<h1 align="center">GraphQL documentation generator for Docusaurus</h1>
|
|
1
|
+
# @graphql-markdown/docusaurus
|
|
4
2
|
|
|
5
3
|
[](https://www.npmjs.com/package/@graphql-markdown/docusaurus)
|
|
6
4
|
[](https://raw.githubusercontent.com/graphql-markdown/graphql-markdown/main/LICENSE)
|
|
7
|
-
[](https://plant.treeware.earth/graphql-markdown/graphql-markdown)
|
|
8
|
-
[](https://coveralls.io/github/graphql-markdown/graphql-markdown?branch=main)
|
|
9
|
-
[](https://dashboard.stryker-mutator.io/reports/github.com/graphql-markdown/graphql-markdown/main)
|
|
10
|
-
[](https://sonarcloud.io/project/overview?id=graphql-markdown_graphql-markdown)
|
|
11
|
-
[](https://snyk.io/advisor/npm-package/@graphql-markdown/docusaurus)
|
|
12
|
-
[](http://commitizen.github.io/cz-cli/)
|
|
13
5
|
|
|
14
|
-
|
|
6
|
+
**Docusaurus** [docs feature](https://docusaurus.io/docs/docs-introduction) plugin for generating **Markdown documentation** from a **GraphQL schema**.
|
|
15
7
|
|
|
16
8
|
## Installation
|
|
17
9
|
|
|
@@ -53,13 +45,3 @@ See [documentation troubleshooting](https://graphql-markdown.github.io/docs/trou
|
|
|
53
45
|
GraphQL-Markdown packages are 100% free and open-source, under the [MIT license](https://github.com/graphql-markdown/graphql-markdown/blob/main/LICENSE).
|
|
54
46
|
|
|
55
47
|
This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/graphql-markdown/graphql-markdown) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.
|
|
56
|
-
|
|
57
|
-
## Contributions
|
|
58
|
-
|
|
59
|
-
[Contributions](https://github.com/graphql-markdown/graphql-markdown/blob/main/CONTRIBUTING.md), issues and feature requests are very welcome. If you are using this package and fixed a bug for yourself, please consider submitting a PR!
|
|
60
|
-
|
|
61
|
-
<a href="https://github.com/graphql-markdown/graphql-markdown/graphs/contributors">
|
|
62
|
-
<img src="https://contrib.rocks/image?repo=graphql-markdown/graphql-markdown" />
|
|
63
|
-
</a>
|
|
64
|
-
|
|
65
|
-
Made with [contributors-img](https://contrib.rocks).
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/graphql-markdown/graphql-markdown/issues"
|
|
7
7
|
},
|
|
8
|
-
"version": "1.
|
|
8
|
+
"version": "1.15.1",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"main": "src/index.js",
|
|
11
11
|
"repository": {
|
|
@@ -24,83 +24,15 @@
|
|
|
24
24
|
"author": {
|
|
25
25
|
"name": "Gregory Heitz"
|
|
26
26
|
},
|
|
27
|
-
"contributors": [
|
|
28
|
-
{
|
|
29
|
-
"name": "jocrau"
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
"name": "mimo84"
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
"name": "coder2034"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"name": "lauzierj"
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
"name": "jineshshah36"
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
"name": "GuiHash"
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
"name": "davidyaha"
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
"name": "jlndk"
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
"name": "elias-pap"
|
|
54
|
-
}
|
|
55
|
-
],
|
|
56
27
|
"scripts": {
|
|
57
|
-
"prettier": "prettier \"{src,tests,assets}/**/*.{js,json,md}\"",
|
|
58
|
-
"lint": "eslint \"{src,tests,assets}/**/*.js\"",
|
|
59
|
-
"test": "jest",
|
|
60
|
-
"test:unit": "jest --projects tests/unit",
|
|
61
|
-
"test:integration": "jest --projects tests/integration",
|
|
62
|
-
"test:smoke": "earthly +smoke-test",
|
|
63
|
-
"test:coverage": "sh ./scripts/coverage.sh",
|
|
64
|
-
"test:mutation": "stryker run --reporters progress,html",
|
|
65
|
-
"prepare": "husky install",
|
|
66
28
|
"prepack": "pinst --disable",
|
|
67
29
|
"postpack": "pinst --enable",
|
|
68
|
-
"
|
|
30
|
+
"test": "jest",
|
|
31
|
+
"stryker": "stryker run"
|
|
69
32
|
},
|
|
70
33
|
"dependencies": {
|
|
71
|
-
"@graphql-
|
|
72
|
-
"@graphql-
|
|
73
|
-
"@graphql-tools/load": "^7.7.4"
|
|
74
|
-
},
|
|
75
|
-
"peerDependencies": {
|
|
76
|
-
"graphql": "^14.0 || ^15.0 || ^16.0",
|
|
77
|
-
"prettier": "^2.5"
|
|
78
|
-
},
|
|
79
|
-
"peerDependenciesMeta": {
|
|
80
|
-
"prettier": {
|
|
81
|
-
"optional": true
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
"devDependencies": {
|
|
85
|
-
"@stryker-mutator/core": "6.2.2",
|
|
86
|
-
"@stryker-mutator/jest-runner": "6.2.2",
|
|
87
|
-
"commitizen": "4.2.5",
|
|
88
|
-
"cz-emoji": "1.3.1",
|
|
89
|
-
"diff": "5.1.0",
|
|
90
|
-
"directory-tree": "3.3.1",
|
|
91
|
-
"eslint": "8.24.0",
|
|
92
|
-
"eslint-config-prettier": "8.5.0",
|
|
93
|
-
"eslint-plugin-jest": "27.1.0",
|
|
94
|
-
"eslint-plugin-node": "11.1.0",
|
|
95
|
-
"eslint-plugin-prettier": "4.2.1",
|
|
96
|
-
"graphql": "16.6.0",
|
|
97
|
-
"husky": "8.0.1",
|
|
98
|
-
"jest": "29.1.2",
|
|
99
|
-
"jest-file-snapshot": "0.5.0",
|
|
100
|
-
"lodash.filter": "4.6.0",
|
|
101
|
-
"mock-fs": "5.1.4",
|
|
102
|
-
"pinst": "3.0.0",
|
|
103
|
-
"prettier": "2.7.1"
|
|
34
|
+
"@graphql-markdown/core": "^1.0.1",
|
|
35
|
+
"@graphql-markdown/printer-legacy": "^1.0.1"
|
|
104
36
|
},
|
|
105
37
|
"directories": {
|
|
106
38
|
"test": "tests"
|
|
@@ -108,78 +40,7 @@
|
|
|
108
40
|
"engines": {
|
|
109
41
|
"node": ">=16.14"
|
|
110
42
|
},
|
|
111
|
-
"
|
|
112
|
-
"
|
|
113
|
-
"path": "./node_modules/cz-emoji"
|
|
114
|
-
},
|
|
115
|
-
"cz-emoji": {
|
|
116
|
-
"skipQuestions": [
|
|
117
|
-
"scope",
|
|
118
|
-
"issues",
|
|
119
|
-
"breaking"
|
|
120
|
-
],
|
|
121
|
-
"types": [
|
|
122
|
-
{
|
|
123
|
-
"emoji": "✨",
|
|
124
|
-
"code": ":sparkles:",
|
|
125
|
-
"description": "Add a new feature.",
|
|
126
|
-
"name": "feat"
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
"emoji": "🐛",
|
|
130
|
-
"code": ":bug:",
|
|
131
|
-
"description": "Fix a bug.",
|
|
132
|
-
"name": "fix"
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
"emoji": "📦️",
|
|
136
|
-
"code": ":package:",
|
|
137
|
-
"description": "Update dependencies.",
|
|
138
|
-
"name": "build"
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
"emoji": "🔧",
|
|
142
|
-
"code": ":wrench:",
|
|
143
|
-
"description": "Update configuration files.",
|
|
144
|
-
"name": "conf"
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
"emoji": "♻️",
|
|
148
|
-
"code": ":recycle:",
|
|
149
|
-
"description": "Refactor code.",
|
|
150
|
-
"name": "refactor"
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
"emoji": "🧪",
|
|
154
|
-
"code": ":test_tube:",
|
|
155
|
-
"description": "Update tests.",
|
|
156
|
-
"name": "test"
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
"emoji": "👷",
|
|
160
|
-
"code": ":construction_worker:",
|
|
161
|
-
"description": "Update CI.",
|
|
162
|
-
"name": "ci"
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
"emoji": "📝",
|
|
166
|
-
"code": ":memo:",
|
|
167
|
-
"description": "Update documentation.",
|
|
168
|
-
"name": "docs"
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
"emoji": "🔖",
|
|
172
|
-
"code": ":bookmark:",
|
|
173
|
-
"description": "Add a tag / release.",
|
|
174
|
-
"name": "tag"
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
"emoji": "🧑💻",
|
|
178
|
-
"code": ":technologist:",
|
|
179
|
-
"description": "Other changes.",
|
|
180
|
-
"name": "other"
|
|
181
|
-
}
|
|
182
|
-
]
|
|
183
|
-
}
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
184
45
|
}
|
|
185
46
|
}
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/* istanbul ignore file */
|
|
2
|
-
const {
|
|
3
|
-
const generateDocFromSchema = require("./lib/generator");
|
|
2
|
+
const { generateDocFromSchema, config } = require("@graphql-markdown/core");
|
|
4
3
|
|
|
5
4
|
const NAME = "docusaurus-graphql-doc-generator";
|
|
6
5
|
const COMMAND = "graphql-to-doc";
|
|
@@ -44,7 +43,9 @@ module.exports = function pluginGraphQLDocGenerator(_, configOptions) {
|
|
|
44
43
|
)
|
|
45
44
|
.option("--pretty", "Prettify generated files")
|
|
46
45
|
.action(async (cliOptions) => {
|
|
47
|
-
await generateDocFromSchema(
|
|
46
|
+
await generateDocFromSchema(
|
|
47
|
+
config.buildConfig(configOptions, cliOptions),
|
|
48
|
+
);
|
|
48
49
|
});
|
|
49
50
|
},
|
|
50
51
|
};
|
package/assets/generated.md
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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/assets/sidebar.json
DELETED
package/src/config.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
const { join } = require("path");
|
|
2
|
-
const { tmpdir } = require("os");
|
|
3
|
-
|
|
4
|
-
const { parseGroupByOption } = require("./lib/group-info");
|
|
5
|
-
const { COMPARE_METHOD } = require("./lib/diff");
|
|
6
|
-
|
|
7
|
-
const PACKAGE_NAME = "@graphql-markdown/docusaurus";
|
|
8
|
-
const ASSETS_LOCATION = join(__dirname, "../assets/");
|
|
9
|
-
|
|
10
|
-
const DEFAULT_OPTIONS = {
|
|
11
|
-
schema: "./schema.graphql",
|
|
12
|
-
rootPath: "./docs",
|
|
13
|
-
baseURL: "schema",
|
|
14
|
-
linkRoot: "/",
|
|
15
|
-
homepage: join(ASSETS_LOCATION, "generated.md"),
|
|
16
|
-
diffMethod: COMPARE_METHOD.DIFF,
|
|
17
|
-
tmpDir: join(tmpdir(), PACKAGE_NAME),
|
|
18
|
-
loaders: {},
|
|
19
|
-
pretty: false,
|
|
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
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function getDiffMethod(diff, force) {
|
|
63
|
-
return force ? COMPARE_METHOD.FORCE : diff;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function getDocOptions(cliOpts, configOptions) {
|
|
67
|
-
return {
|
|
68
|
-
pagination: !cliOpts.noPagination && configOptions.pagination,
|
|
69
|
-
toc: !cliOpts.noToc && configOptions.toc,
|
|
70
|
-
index: cliOpts.index || configOptions.index,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function gePrintTypeOptions(cliOpts, configOptions) {
|
|
75
|
-
return {
|
|
76
|
-
parentTypePrefix: !cliOpts.noParentType && configOptions.parentTypePrefix,
|
|
77
|
-
relatedTypeSection:
|
|
78
|
-
!cliOpts.noRelatedType && configOptions.relatedTypeSection,
|
|
79
|
-
typeBadges: !cliOpts.noTypeBadges && configOptions.typeBadges,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
module.exports = { buildConfig, DEFAULT_OPTIONS, ASSETS_LOCATION };
|
package/src/const/mdx.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
module.exports = `
|
|
2
|
-
export const Bullet = () => <><span style={{ fontWeight: 'normal', fontSize: '.5em', color: 'var(--ifm-color-secondary-darkest)' }}> ● </span></>
|
|
3
|
-
|
|
4
|
-
export const SpecifiedBy = (props) => <>Specification<a className="link" style={{ fontSize:'1.5em', paddingLeft:'4px' }} target="_blank" href={props.url} title={'Specified by ' + props.url}>⎘</a></>
|
|
5
|
-
|
|
6
|
-
export const Badge = (props) => <><span class={'badge badge--' + props.class}>{props.text}</span></>
|
|
7
|
-
`;
|
package/src/const/strings.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const ROOT_TYPE_LOCALE = {
|
|
2
|
-
QUERY: { singular: "query", plural: "queries" },
|
|
3
|
-
MUTATION: { singular: "mutation", plural: "mutations" },
|
|
4
|
-
SUBSCRIPTION: { singular: "subscription", plural: "subscriptions" },
|
|
5
|
-
TYPE: { singular: "object", plural: "objects" },
|
|
6
|
-
INTERFACE: { singular: "interface", plural: "interfaces" },
|
|
7
|
-
DIRECTIVE: { singular: "directive", plural: "directives" },
|
|
8
|
-
SCALAR: { singular: "scalar", plural: "scalars" },
|
|
9
|
-
ENUM: { singular: "enum", plural: "enums" },
|
|
10
|
-
OPERATION: { singular: "operation", plural: "operations" },
|
|
11
|
-
UNION: { singular: "union", plural: "unions" },
|
|
12
|
-
INPUT: { singular: "input", plural: "inputs" },
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const HEADER_SECTION_LEVEL = "###";
|
|
16
|
-
const HEADER_SECTION_SUB_LEVEL = "####";
|
|
17
|
-
const HEADER_SECTION_ITEM_LEVEL = "#####";
|
|
18
|
-
const NO_DESCRIPTION_TEXT = "No description";
|
|
19
|
-
const MARKDOWN_EOL = "\n";
|
|
20
|
-
const MARKDOWN_EOP = "\n\n";
|
|
21
|
-
|
|
22
|
-
module.exports = {
|
|
23
|
-
ROOT_TYPE_LOCALE,
|
|
24
|
-
HEADER_SECTION_LEVEL,
|
|
25
|
-
HEADER_SECTION_SUB_LEVEL,
|
|
26
|
-
HEADER_SECTION_ITEM_LEVEL,
|
|
27
|
-
NO_DESCRIPTION_TEXT,
|
|
28
|
-
MARKDOWN_EOL,
|
|
29
|
-
MARKDOWN_EOP,
|
|
30
|
-
};
|
package/src/lib/diff.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
const path = require("path");
|
|
2
|
-
const crypto = require("crypto");
|
|
3
|
-
|
|
4
|
-
const { fileExists, readFile, saveFile } = require("../utils/helpers/fs");
|
|
5
|
-
|
|
6
|
-
const { loadSchema, getDocumentLoaders, printSchema } = require("./graphql");
|
|
7
|
-
const { diff } = require("@graphql-inspector/core");
|
|
8
|
-
|
|
9
|
-
const SCHEMA_HASH_FILE = ".schema";
|
|
10
|
-
const SCHEMA_REF = "schema.graphql";
|
|
11
|
-
const COMPARE_METHOD = {
|
|
12
|
-
DIFF: "SCHEMA-DIFF",
|
|
13
|
-
HASH: "SCHEMA-HASH",
|
|
14
|
-
FORCE: "FORCE",
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const defaultLoaders = {
|
|
18
|
-
GraphQLFileLoader: "@graphql-tools/graphql-file-loader",
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
function getSchemaHash(schema) {
|
|
22
|
-
let printedSchema = printSchema(schema, { commentDescriptions: true });
|
|
23
|
-
let sum = crypto.createHash("sha256").update(printedSchema);
|
|
24
|
-
return sum.digest("hex");
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async function getDiff(schemaNew, schemaOld) {
|
|
28
|
-
const schemaRef = await loadSchema(schemaOld, {
|
|
29
|
-
loaders: getDocumentLoaders(defaultLoaders).loaders,
|
|
30
|
-
});
|
|
31
|
-
return diff(schemaRef, schemaNew);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async function checkSchemaChanges(
|
|
35
|
-
schema,
|
|
36
|
-
outputDir,
|
|
37
|
-
method = COMPARE_METHOD.DIFF,
|
|
38
|
-
) {
|
|
39
|
-
const hashFile = path.join(outputDir, SCHEMA_HASH_FILE);
|
|
40
|
-
const hashSchema = getSchemaHash(schema);
|
|
41
|
-
const schemaRef = path.join(outputDir, SCHEMA_REF);
|
|
42
|
-
|
|
43
|
-
if (method === COMPARE_METHOD.DIFF) {
|
|
44
|
-
if (await fileExists(schemaRef)) {
|
|
45
|
-
const schemaDiff = await getDiff(schema, schemaRef);
|
|
46
|
-
return schemaDiff.length > 0;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (method === COMPARE_METHOD.HASH) {
|
|
51
|
-
if (await fileExists(hashFile)) {
|
|
52
|
-
const hash = await readFile(hashFile);
|
|
53
|
-
return hashSchema != hash;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async function saveSchemaFile(schema, outputDir) {
|
|
61
|
-
const schemaFile = path.join(outputDir, SCHEMA_REF);
|
|
62
|
-
const schemaPrint = printSchema(schema);
|
|
63
|
-
await saveFile(schemaFile, schemaPrint);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async function saveSchemaHash(schema, outputDir) {
|
|
67
|
-
const hashFile = path.join(outputDir, SCHEMA_HASH_FILE);
|
|
68
|
-
const hashSchema = getSchemaHash(schema);
|
|
69
|
-
await saveFile(hashFile, hashSchema);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
module.exports = {
|
|
73
|
-
checkSchemaChanges,
|
|
74
|
-
saveSchemaHash,
|
|
75
|
-
saveSchemaFile,
|
|
76
|
-
COMPARE_METHOD,
|
|
77
|
-
SCHEMA_HASH_FILE,
|
|
78
|
-
SCHEMA_REF,
|
|
79
|
-
};
|
package/src/lib/generator.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
const { getSchemaMap, loadSchema, getDocumentLoaders } = require("./graphql");
|
|
2
|
-
const { getGroups } = require("./group-info");
|
|
3
|
-
const Renderer = require("./renderer");
|
|
4
|
-
const Printer = require("./printer");
|
|
5
|
-
const {
|
|
6
|
-
checkSchemaChanges,
|
|
7
|
-
saveSchemaHash,
|
|
8
|
-
saveSchemaFile,
|
|
9
|
-
} = require("./diff");
|
|
10
|
-
|
|
11
|
-
const time = process.hrtime();
|
|
12
|
-
|
|
13
|
-
module.exports = async function generateDocFromSchema({
|
|
14
|
-
baseURL,
|
|
15
|
-
schemaLocation,
|
|
16
|
-
outputDir,
|
|
17
|
-
linkRoot,
|
|
18
|
-
homepageLocation,
|
|
19
|
-
diffMethod,
|
|
20
|
-
tmpDir,
|
|
21
|
-
loaders,
|
|
22
|
-
groupByDirective,
|
|
23
|
-
prettify,
|
|
24
|
-
docOptions,
|
|
25
|
-
printTypeOptions,
|
|
26
|
-
}) {
|
|
27
|
-
const { loaders: documentLoaders, loaderOptions } =
|
|
28
|
-
getDocumentLoaders(loaders);
|
|
29
|
-
const schema = await loadSchema(schemaLocation, {
|
|
30
|
-
loaders: documentLoaders,
|
|
31
|
-
...loaderOptions,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const hasChanged = await checkSchemaChanges(schema, tmpDir, diffMethod);
|
|
35
|
-
|
|
36
|
-
if (hasChanged) {
|
|
37
|
-
const rootTypes = getSchemaMap(schema);
|
|
38
|
-
const groups = new getGroups(rootTypes, groupByDirective);
|
|
39
|
-
const renderer = new Renderer(
|
|
40
|
-
new Printer(schema, baseURL, linkRoot, {
|
|
41
|
-
groups,
|
|
42
|
-
printTypeOptions,
|
|
43
|
-
}),
|
|
44
|
-
outputDir,
|
|
45
|
-
baseURL,
|
|
46
|
-
groups,
|
|
47
|
-
prettify,
|
|
48
|
-
docOptions,
|
|
49
|
-
);
|
|
50
|
-
const pages = await Promise.all(
|
|
51
|
-
Object.keys(rootTypes).map((typeName) =>
|
|
52
|
-
renderer.renderRootTypes(typeName, rootTypes[typeName]),
|
|
53
|
-
),
|
|
54
|
-
);
|
|
55
|
-
await renderer.renderHomepage(homepageLocation);
|
|
56
|
-
const sidebarPath = await renderer.renderSidebar();
|
|
57
|
-
|
|
58
|
-
const [sec, msec] = process.hrtime(time);
|
|
59
|
-
const duration = (sec + msec / 1e9).toFixed(3);
|
|
60
|
-
console.info(
|
|
61
|
-
`Documentation successfully generated in "${outputDir}" with base URL "${baseURL}".`,
|
|
62
|
-
);
|
|
63
|
-
console.log(
|
|
64
|
-
`${
|
|
65
|
-
pages.flat().length
|
|
66
|
-
} pages generated in ${duration}s from schema "${schemaLocation}".`,
|
|
67
|
-
);
|
|
68
|
-
console.info(
|
|
69
|
-
`Remember to update your Docusaurus site's sidebars with "${sidebarPath}".`,
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
// create references for checkSchemaChanges
|
|
73
|
-
await saveSchemaHash(schema, tmpDir);
|
|
74
|
-
await saveSchemaFile(schema, tmpDir);
|
|
75
|
-
} else {
|
|
76
|
-
console.info(`No changes detected in schema "${schemaLocation}".`);
|
|
77
|
-
}
|
|
78
|
-
};
|