@graphql-markdown/core 1.1.6 → 1.1.7
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/package.json +7 -4
- package/src/generator.js +26 -13
- package/src/group-info.js +0 -8
- package/src/renderer.js +13 -20
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.1.
|
|
8
|
+
"version": "1.1.7",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"main": "src/index.js",
|
|
11
11
|
"repository": {
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"stryker": "stryker run"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@graphql-markdown/utils": "^1.1.
|
|
32
|
+
"@graphql-markdown/utils": "^1.1.4"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@graphql-markdown/printer-legacy": "^1.1.
|
|
36
|
-
"@graphql-markdown/diff": "^1.0.
|
|
35
|
+
"@graphql-markdown/printer-legacy": "^1.1.7",
|
|
36
|
+
"@graphql-markdown/diff": "^1.0.6",
|
|
37
37
|
"prettier": "^2.8"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
@@ -47,6 +47,9 @@
|
|
|
47
47
|
"optional": true
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@graphql-markdown/printer-legacy": "^1.1.3"
|
|
52
|
+
},
|
|
50
53
|
"directories": {
|
|
51
54
|
"test": "tests"
|
|
52
55
|
},
|
package/src/generator.js
CHANGED
|
@@ -4,7 +4,7 @@ const {
|
|
|
4
4
|
const { getGroups } = require("./group-info");
|
|
5
5
|
const Renderer = require("./renderer");
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const NS_PER_SEC = 1e9;
|
|
8
8
|
|
|
9
9
|
const hasChanges = async (
|
|
10
10
|
schema,
|
|
@@ -12,7 +12,12 @@ const hasChanges = async (
|
|
|
12
12
|
diffMethod,
|
|
13
13
|
diffModule = "@graphql-markdown/diff",
|
|
14
14
|
) => {
|
|
15
|
-
if (
|
|
15
|
+
if (
|
|
16
|
+
typeof diffMethod === "undefined" ||
|
|
17
|
+
diffMethod == null ||
|
|
18
|
+
typeof diffModule === "undefined" ||
|
|
19
|
+
diffModule == null
|
|
20
|
+
) {
|
|
16
21
|
return true;
|
|
17
22
|
}
|
|
18
23
|
|
|
@@ -37,24 +42,29 @@ const getPrinter = (
|
|
|
37
42
|
printerModule,
|
|
38
43
|
skipDocDirective,
|
|
39
44
|
) => {
|
|
45
|
+
let Printer = undefined;
|
|
46
|
+
|
|
40
47
|
if (typeof printerModule !== "string") {
|
|
41
48
|
throw new Error(
|
|
42
|
-
|
|
49
|
+
'Invalid printer module name in "printTypeOptions" settings.',
|
|
43
50
|
);
|
|
44
51
|
}
|
|
45
52
|
|
|
46
53
|
try {
|
|
47
|
-
|
|
48
|
-
return new Printer(schema, baseURL, linkRoot, {
|
|
49
|
-
groups,
|
|
50
|
-
printTypeOptions,
|
|
51
|
-
skipDocDirective,
|
|
52
|
-
});
|
|
54
|
+
Printer = require(printerModule);
|
|
53
55
|
} catch (error) {
|
|
54
56
|
throw new Error(
|
|
55
|
-
`Cannot find module '${printerModule}'
|
|
57
|
+
`Cannot find module '${printerModule}' for @graphql-markdown/core in "printTypeOptions" settings.`,
|
|
56
58
|
);
|
|
57
59
|
}
|
|
60
|
+
|
|
61
|
+
Printer.init(schema, baseURL, linkRoot, {
|
|
62
|
+
groups,
|
|
63
|
+
printTypeOptions,
|
|
64
|
+
skipDocDirective,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return Printer;
|
|
58
68
|
};
|
|
59
69
|
|
|
60
70
|
const generateDocFromSchema = async ({
|
|
@@ -73,6 +83,8 @@ const generateDocFromSchema = async ({
|
|
|
73
83
|
printer: printerModule,
|
|
74
84
|
skipDocDirective,
|
|
75
85
|
}) => {
|
|
86
|
+
const start = process.hrtime.bigint();
|
|
87
|
+
|
|
76
88
|
const loaders = getDocumentLoaders(loadersList);
|
|
77
89
|
const schema = await loadSchema(schemaLocation, loaders);
|
|
78
90
|
|
|
@@ -99,7 +111,6 @@ const generateDocFromSchema = async ({
|
|
|
99
111
|
groups,
|
|
100
112
|
prettify,
|
|
101
113
|
docOptions,
|
|
102
|
-
skipDocDirective,
|
|
103
114
|
);
|
|
104
115
|
|
|
105
116
|
const pages = await Promise.all(
|
|
@@ -112,8 +123,10 @@ const generateDocFromSchema = async ({
|
|
|
112
123
|
|
|
113
124
|
const sidebarPath = await renderer.renderSidebar();
|
|
114
125
|
|
|
115
|
-
const
|
|
116
|
-
|
|
126
|
+
const duration = (
|
|
127
|
+
Number(process.hrtime.bigint() - start) / NS_PER_SEC
|
|
128
|
+
).toFixed(3);
|
|
129
|
+
|
|
117
130
|
console.info(
|
|
118
131
|
`Documentation successfully generated in "${outputDir}" with base URL "${baseURL}".`,
|
|
119
132
|
);
|
package/src/group-info.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
const {
|
|
2
|
-
array: { convertArrayToObject },
|
|
3
|
-
} = require("@graphql-markdown/utils");
|
|
4
|
-
|
|
5
1
|
const DEFAULT_GROUP = "Miscellaneous";
|
|
6
2
|
const OPTION_REGEX =
|
|
7
3
|
/^@(?<directive>\w+)\((?<field>\w+)(?:\|=(?<fallback>\w+))?\)/;
|
|
@@ -31,10 +27,6 @@ function getGroups(rootTypes, groupByDirective) {
|
|
|
31
27
|
Object.keys(rootTypes).forEach((typeName) => {
|
|
32
28
|
let rootType = rootTypes[typeName];
|
|
33
29
|
if (typeof rootType != "undefined" && rootType != null) {
|
|
34
|
-
if (Array.isArray(rootType)) {
|
|
35
|
-
rootType = convertArrayToObject(rootType);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
30
|
Object.keys(rootType).forEach((type) => {
|
|
39
31
|
groups[type] = getGroupName(rootType[type], groupByDirective);
|
|
40
32
|
});
|
package/src/renderer.js
CHANGED
|
@@ -4,7 +4,6 @@ const {
|
|
|
4
4
|
object: { hasProperty },
|
|
5
5
|
string: { toSlug, startCase },
|
|
6
6
|
url: { pathUrl },
|
|
7
|
-
graphql: { hasDirective },
|
|
8
7
|
prettier: { prettifyJavascript, prettifyMarkdown },
|
|
9
8
|
fs: { saveFile, ensureDir, copyFile, readFile, fileExists },
|
|
10
9
|
} = require("@graphql-markdown/utils");
|
|
@@ -17,22 +16,13 @@ const HOMEPAGE_ID = "schema";
|
|
|
17
16
|
const CATEGORY_YAML = "_category_.yml";
|
|
18
17
|
|
|
19
18
|
module.exports = class Renderer {
|
|
20
|
-
constructor(
|
|
21
|
-
printer,
|
|
22
|
-
outputDir,
|
|
23
|
-
baseURL,
|
|
24
|
-
group,
|
|
25
|
-
prettify,
|
|
26
|
-
docOptions,
|
|
27
|
-
skipDocDirective,
|
|
28
|
-
) {
|
|
19
|
+
constructor(printer, outputDir, baseURL, group, prettify, docOptions) {
|
|
29
20
|
this.group = group;
|
|
30
21
|
this.outputDir = outputDir;
|
|
31
22
|
this.baseURL = baseURL;
|
|
32
23
|
this.printer = printer;
|
|
33
24
|
this.prettify = prettify;
|
|
34
25
|
this.options = docOptions;
|
|
35
|
-
this.skipDocDirective = skipDocDirective;
|
|
36
26
|
}
|
|
37
27
|
|
|
38
28
|
async generateCategoryMetafile(category, dirPath) {
|
|
@@ -78,18 +68,21 @@ module.exports = class Renderer {
|
|
|
78
68
|
}
|
|
79
69
|
|
|
80
70
|
async renderTypeEntities(dirPath, name, type) {
|
|
81
|
-
if (
|
|
82
|
-
typeof type === "undefined" ||
|
|
83
|
-
type === null ||
|
|
84
|
-
hasDirective(type, this.skipDocDirective)
|
|
85
|
-
) {
|
|
86
|
-
return undefined;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
71
|
const fileName = toSlug(name);
|
|
90
72
|
const filePath = path.join(path.normalize(dirPath), `${fileName}.mdx`);
|
|
91
73
|
|
|
92
|
-
|
|
74
|
+
let content;
|
|
75
|
+
try {
|
|
76
|
+
content = this.printer.printType(fileName, type, this.options);
|
|
77
|
+
if (typeof content === "undefined") {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.log(`An error occurred while processing "${type}"`);
|
|
82
|
+
console.debug(error);
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
|
|
93
86
|
await saveFile(
|
|
94
87
|
filePath,
|
|
95
88
|
this.prettify ? prettifyMarkdown(content) : content,
|