@graphql-markdown/core 1.2.2 → 1.3.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/package.json +4 -4
- package/src/config.js +23 -4
- package/src/generator.js +1 -1
- package/src/index.js +0 -1
- package/src/renderer.js +9 -3
- package/src/group-info.js +0 -65
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.3.0",
|
|
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.
|
|
32
|
+
"@graphql-markdown/utils": "^1.3.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@graphql-markdown/printer-legacy": "^1.2.
|
|
36
|
-
"@graphql-markdown/diff": "^1.0.
|
|
35
|
+
"@graphql-markdown/printer-legacy": "^1.2.3",
|
|
36
|
+
"@graphql-markdown/diff": "^1.0.9",
|
|
37
37
|
"prettier": "^2.8"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
package/src/config.js
CHANGED
|
@@ -5,8 +5,6 @@ const {
|
|
|
5
5
|
object: { hasProperty },
|
|
6
6
|
} = require("@graphql-markdown/utils");
|
|
7
7
|
|
|
8
|
-
const { parseGroupByOption } = require("./group-info");
|
|
9
|
-
|
|
10
8
|
const PACKAGE_NAME = "@graphql-markdown/docusaurus";
|
|
11
9
|
const ASSETS_LOCATION = join(__dirname, "../assets/");
|
|
12
10
|
|
|
@@ -103,9 +101,10 @@ function getSkipDocDirectives(cliOpts = {}, configFileOpts = {}) {
|
|
|
103
101
|
);
|
|
104
102
|
|
|
105
103
|
if (
|
|
106
|
-
(hasProperty(configFileOpts, "printTypeOptions") &&
|
|
104
|
+
(hasProperty(configFileOpts, "printTypeOptions") === true &&
|
|
107
105
|
configFileOpts.printTypeOptions.deprecated === "skip") ||
|
|
108
|
-
(hasProperty(cliOpts, "deprecated")
|
|
106
|
+
(hasProperty(cliOpts, "deprecated") === true &&
|
|
107
|
+
cliOpts.deprecated === "skip")
|
|
109
108
|
) {
|
|
110
109
|
skipDirectives.push("deprecated");
|
|
111
110
|
}
|
|
@@ -129,10 +128,30 @@ function getSkipDocDirective(option) {
|
|
|
129
128
|
return parsedOption.groups.directive;
|
|
130
129
|
}
|
|
131
130
|
|
|
131
|
+
function parseGroupByOption(groupOptions) {
|
|
132
|
+
const DEFAULT_GROUP = "Miscellaneous";
|
|
133
|
+
const OPTION_REGEX =
|
|
134
|
+
/^@(?<directive>\w+)\((?<field>\w+)(?:\|=(?<fallback>\w+))?\)/;
|
|
135
|
+
|
|
136
|
+
if (typeof groupOptions !== "string") {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const parsedOptions = OPTION_REGEX.exec(groupOptions);
|
|
141
|
+
|
|
142
|
+
if (typeof parsedOptions === "undefined" || parsedOptions == null) {
|
|
143
|
+
throw new Error(`Invalid "${groupOptions}"`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const { directive, field, fallback = DEFAULT_GROUP } = parsedOptions.groups;
|
|
147
|
+
return { directive, field, fallback };
|
|
148
|
+
}
|
|
149
|
+
|
|
132
150
|
module.exports = {
|
|
133
151
|
buildConfig,
|
|
134
152
|
getSkipDocDirectives,
|
|
135
153
|
getSkipDocDirective,
|
|
154
|
+
parseGroupByOption,
|
|
136
155
|
DEFAULT_OPTIONS,
|
|
137
156
|
ASSETS_LOCATION,
|
|
138
157
|
};
|
package/src/generator.js
CHANGED
package/src/index.js
CHANGED
package/src/renderer.js
CHANGED
|
@@ -74,9 +74,15 @@ module.exports = class Renderer {
|
|
|
74
74
|
);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
if (
|
|
78
|
+
hasProperty(this.group, rootTypeName) &&
|
|
79
|
+
hasProperty(this.group[rootTypeName], name)
|
|
80
|
+
) {
|
|
81
|
+
dirPath = path.join(dirPath, toSlug(this.group[rootTypeName][name]));
|
|
82
|
+
await this.generateCategoryMetafile(
|
|
83
|
+
this.group[rootTypeName][name],
|
|
84
|
+
dirPath,
|
|
85
|
+
);
|
|
80
86
|
}
|
|
81
87
|
|
|
82
88
|
dirPath = path.join(dirPath, toSlug(rootTypeName));
|
package/src/group-info.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
const DEFAULT_GROUP = "Miscellaneous";
|
|
2
|
-
const OPTION_REGEX =
|
|
3
|
-
/^@(?<directive>\w+)\((?<field>\w+)(?:\|=(?<fallback>\w+))?\)/;
|
|
4
|
-
|
|
5
|
-
function parseGroupByOption(groupOptions) {
|
|
6
|
-
if (typeof groupOptions !== "string") {
|
|
7
|
-
return undefined;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const parsedOptions = OPTION_REGEX.exec(groupOptions);
|
|
11
|
-
|
|
12
|
-
if (typeof parsedOptions === "undefined" || parsedOptions == null) {
|
|
13
|
-
throw new Error(`Invalid "${groupOptions}"`);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const { directive, field, fallback = DEFAULT_GROUP } = parsedOptions.groups;
|
|
17
|
-
return { directive, field, fallback };
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function getGroups(rootTypes, groupByDirective) {
|
|
21
|
-
let groups = {};
|
|
22
|
-
|
|
23
|
-
if (typeof groupByDirective === "undefined" || groupByDirective == null) {
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
Object.keys(rootTypes).forEach((typeName) => {
|
|
28
|
-
let rootType = rootTypes[typeName];
|
|
29
|
-
if (typeof rootType != "undefined" && rootType != null) {
|
|
30
|
-
Object.keys(rootType).forEach((type) => {
|
|
31
|
-
groups[type] = getGroupName(rootType[type], groupByDirective);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
return groups;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function getGroupName(type, groupByDirective) {
|
|
40
|
-
let group = groupByDirective.fallback; // default value is fallback, and it will be only overridden if a group is found
|
|
41
|
-
|
|
42
|
-
if (typeof type.astNode === "undefined" || type.astNode == null) {
|
|
43
|
-
return group;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const allDirectives = type.astNode.directives;
|
|
47
|
-
|
|
48
|
-
if (!Array.isArray(allDirectives)) {
|
|
49
|
-
return group;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
for (const directive of allDirectives) {
|
|
53
|
-
if (directive.name.value !== groupByDirective.directive) {
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
const field = directive.arguments.find(
|
|
57
|
-
({ name }) => name.value === groupByDirective.field,
|
|
58
|
-
);
|
|
59
|
-
return field.value.value;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return group;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
module.exports = { getGroupName, getGroups, parseGroupByOption };
|