@graphql-markdown/core 1.1.7 → 1.2.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/package.json +4 -4
- package/src/config.js +40 -6
- package/src/generator.js +6 -9
- package/src/renderer.js +50 -13
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.2.1",
|
|
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.2.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@graphql-markdown/printer-legacy": "^1.1
|
|
36
|
-
"@graphql-markdown/diff": "^1.0.
|
|
35
|
+
"@graphql-markdown/printer-legacy": "^1.2.1",
|
|
36
|
+
"@graphql-markdown/diff": "^1.0.7",
|
|
37
37
|
"prettier": "^2.8"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
package/src/config.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
const { join } = require("path");
|
|
2
2
|
const { tmpdir } = require("os");
|
|
3
3
|
|
|
4
|
+
const {
|
|
5
|
+
object: { hasProperty },
|
|
6
|
+
} = require("@graphql-markdown/utils");
|
|
7
|
+
|
|
4
8
|
const { parseGroupByOption } = require("./group-info");
|
|
5
9
|
|
|
6
10
|
const PACKAGE_NAME = "@graphql-markdown/docusaurus";
|
|
@@ -26,8 +30,9 @@ const DEFAULT_OPTIONS = {
|
|
|
26
30
|
parentTypePrefix: true,
|
|
27
31
|
relatedTypeSection: true,
|
|
28
32
|
typeBadges: true,
|
|
33
|
+
deprecated: "default",
|
|
29
34
|
},
|
|
30
|
-
skipDocDirective:
|
|
35
|
+
skipDocDirective: [],
|
|
31
36
|
};
|
|
32
37
|
|
|
33
38
|
function buildConfig(configFileOpts, cliOpts) {
|
|
@@ -58,9 +63,7 @@ function buildConfig(configFileOpts, cliOpts) {
|
|
|
58
63
|
docOptions: getDocOptions(cliOpts, config.docOptions),
|
|
59
64
|
printTypeOptions: gePrintTypeOptions(cliOpts, config.printTypeOptions),
|
|
60
65
|
printer: config.printer,
|
|
61
|
-
skipDocDirective:
|
|
62
|
-
cliOpts.skip ?? config.skipDocDirective,
|
|
63
|
-
),
|
|
66
|
+
skipDocDirective: getSkipDocDirectives(cliOpts, config),
|
|
64
67
|
};
|
|
65
68
|
}
|
|
66
69
|
|
|
@@ -82,14 +85,39 @@ function gePrintTypeOptions(cliOpts, configOptions) {
|
|
|
82
85
|
relatedTypeSection:
|
|
83
86
|
!cliOpts.noRelatedType && configOptions.relatedTypeSection,
|
|
84
87
|
typeBadges: !cliOpts.noTypeBadges && configOptions.typeBadges,
|
|
88
|
+
deprecated:
|
|
89
|
+
cliOpts.deprecated ??
|
|
90
|
+
configOptions.deprecated ??
|
|
91
|
+
DEFAULT_OPTIONS.printTypeOptions.deprecated,
|
|
85
92
|
};
|
|
86
93
|
}
|
|
87
94
|
|
|
95
|
+
function getSkipDocDirectives(cliOpts = {}, configFileOpts = {}) {
|
|
96
|
+
const directiveList = [].concat(
|
|
97
|
+
cliOpts.skip ?? [],
|
|
98
|
+
configFileOpts.skipDocDirective ?? [],
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const skipDirectives = directiveList.map((option) =>
|
|
102
|
+
getSkipDocDirective(option),
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
if (
|
|
106
|
+
(hasProperty(configFileOpts, "printTypeOptions") &&
|
|
107
|
+
configFileOpts.printTypeOptions.deprecated === "skip") ||
|
|
108
|
+
(hasProperty(cliOpts, "deprecated") && cliOpts.deprecated === "skip")
|
|
109
|
+
) {
|
|
110
|
+
skipDirectives.push("deprecated");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return skipDirectives;
|
|
114
|
+
}
|
|
115
|
+
|
|
88
116
|
function getSkipDocDirective(option) {
|
|
89
117
|
const OPTION_REGEX = /^@(?<directive>\w+)$/;
|
|
90
118
|
|
|
91
119
|
if (typeof option !== "string") {
|
|
92
|
-
|
|
120
|
+
throw new Error(`Invalid "${option}"`);
|
|
93
121
|
}
|
|
94
122
|
|
|
95
123
|
const parsedOption = OPTION_REGEX.exec(option);
|
|
@@ -101,4 +129,10 @@ function getSkipDocDirective(option) {
|
|
|
101
129
|
return parsedOption.groups.directive;
|
|
102
130
|
}
|
|
103
131
|
|
|
104
|
-
module.exports = {
|
|
132
|
+
module.exports = {
|
|
133
|
+
buildConfig,
|
|
134
|
+
getSkipDocDirectives,
|
|
135
|
+
getSkipDocDirective,
|
|
136
|
+
DEFAULT_OPTIONS,
|
|
137
|
+
ASSETS_LOCATION,
|
|
138
|
+
};
|
package/src/generator.js
CHANGED
|
@@ -5,6 +5,7 @@ const { getGroups } = require("./group-info");
|
|
|
5
5
|
const Renderer = require("./renderer");
|
|
6
6
|
|
|
7
7
|
const NS_PER_SEC = 1e9;
|
|
8
|
+
const SEC_DECIMALS = 3;
|
|
8
9
|
|
|
9
10
|
const hasChanges = async (
|
|
10
11
|
schema,
|
|
@@ -104,14 +105,10 @@ const generateDocFromSchema = async ({
|
|
|
104
105
|
printerModule,
|
|
105
106
|
skipDocDirective,
|
|
106
107
|
);
|
|
107
|
-
const renderer = new Renderer(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
groups,
|
|
112
|
-
prettify,
|
|
113
|
-
docOptions,
|
|
114
|
-
);
|
|
108
|
+
const renderer = new Renderer(printer, outputDir, baseURL, groups, prettify, {
|
|
109
|
+
...docOptions,
|
|
110
|
+
deprecated: printTypeOptions.deprecated,
|
|
111
|
+
});
|
|
115
112
|
|
|
116
113
|
const pages = await Promise.all(
|
|
117
114
|
Object.keys(rootTypes).map((typeName) =>
|
|
@@ -125,7 +122,7 @@ const generateDocFromSchema = async ({
|
|
|
125
122
|
|
|
126
123
|
const duration = (
|
|
127
124
|
Number(process.hrtime.bigint() - start) / NS_PER_SEC
|
|
128
|
-
).toFixed(
|
|
125
|
+
).toFixed(SEC_DECIMALS);
|
|
129
126
|
|
|
130
127
|
console.info(
|
|
131
128
|
`Documentation successfully generated in "${outputDir}" with base URL "${baseURL}".`,
|
package/src/renderer.js
CHANGED
|
@@ -6,6 +6,7 @@ const {
|
|
|
6
6
|
url: { pathUrl },
|
|
7
7
|
prettier: { prettifyJavascript, prettifyMarkdown },
|
|
8
8
|
fs: { saveFile, ensureDir, copyFile, readFile, fileExists },
|
|
9
|
+
graphql: { isDeprecated },
|
|
9
10
|
} = require("@graphql-markdown/utils");
|
|
10
11
|
|
|
11
12
|
const { ASSETS_LOCATION } = require("./config");
|
|
@@ -14,6 +15,10 @@ const { schemaSidebar } = require(`${ASSETS_LOCATION}/sidebar.json`);
|
|
|
14
15
|
const SIDEBAR = "sidebar-schema.js";
|
|
15
16
|
const HOMEPAGE_ID = "schema";
|
|
16
17
|
const CATEGORY_YAML = "_category_.yml";
|
|
18
|
+
const SIDEBAR_POSITION = {
|
|
19
|
+
FIRST: 1,
|
|
20
|
+
LAST: 999,
|
|
21
|
+
};
|
|
17
22
|
|
|
18
23
|
module.exports = class Renderer {
|
|
19
24
|
constructor(printer, outputDir, baseURL, group, prettify, docOptions) {
|
|
@@ -25,7 +30,12 @@ module.exports = class Renderer {
|
|
|
25
30
|
this.options = docOptions;
|
|
26
31
|
}
|
|
27
32
|
|
|
28
|
-
async generateCategoryMetafile(
|
|
33
|
+
async generateCategoryMetafile(
|
|
34
|
+
category,
|
|
35
|
+
dirPath,
|
|
36
|
+
sidebarPosition = SIDEBAR_POSITION.FIRST,
|
|
37
|
+
styleClass = undefined,
|
|
38
|
+
) {
|
|
29
39
|
const filePath = path.join(dirPath, CATEGORY_YAML);
|
|
30
40
|
|
|
31
41
|
if (await fileExists(filePath)) {
|
|
@@ -38,9 +48,41 @@ module.exports = class Renderer {
|
|
|
38
48
|
const link =
|
|
39
49
|
typeof this.options === "undefined" || !this.options.index
|
|
40
50
|
? "null"
|
|
41
|
-
: `\n type: generated-index\n title: '${label} overview'
|
|
51
|
+
: `\n type: generated-index\n title: '${label} overview'`;
|
|
52
|
+
const className =
|
|
53
|
+
typeof styleClass === "string" ? `className: ${styleClass}\n` : "";
|
|
54
|
+
await saveFile(
|
|
55
|
+
filePath,
|
|
56
|
+
`label: ${label}\nposition: ${sidebarPosition}\n${className}link: ${link}\n`,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async generateCategoryMetafileType(type, name, rootTypeName) {
|
|
61
|
+
let dirPath = this.outputDir;
|
|
62
|
+
|
|
63
|
+
if (
|
|
64
|
+
hasProperty(this.options, "deprecated") &&
|
|
65
|
+
this.options.deprecated === "group" &&
|
|
66
|
+
isDeprecated(type)
|
|
67
|
+
) {
|
|
68
|
+
dirPath = path.join(dirPath, toSlug("deprecated"));
|
|
69
|
+
await this.generateCategoryMetafile(
|
|
70
|
+
"deprecated",
|
|
71
|
+
dirPath,
|
|
72
|
+
SIDEBAR_POSITION.LAST,
|
|
73
|
+
"deprecated",
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (hasProperty(this.group, name)) {
|
|
78
|
+
dirPath = path.join(dirPath, toSlug(this.group[name]));
|
|
79
|
+
await this.generateCategoryMetafile(this.group[name], dirPath);
|
|
80
|
+
}
|
|
42
81
|
|
|
43
|
-
|
|
82
|
+
dirPath = path.join(dirPath, toSlug(rootTypeName));
|
|
83
|
+
await this.generateCategoryMetafile(rootTypeName, dirPath);
|
|
84
|
+
|
|
85
|
+
return dirPath;
|
|
44
86
|
}
|
|
45
87
|
|
|
46
88
|
async renderRootTypes(rootTypeName, type) {
|
|
@@ -51,15 +93,11 @@ module.exports = class Renderer {
|
|
|
51
93
|
return Promise.all(
|
|
52
94
|
Object.keys(type)
|
|
53
95
|
.map(async (name) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
dirPath = path.join(dirPath, toSlug(rootTypeName));
|
|
62
|
-
await this.generateCategoryMetafile(rootTypeName, dirPath);
|
|
96
|
+
const dirPath = await this.generateCategoryMetafileType(
|
|
97
|
+
type[name],
|
|
98
|
+
name,
|
|
99
|
+
rootTypeName,
|
|
100
|
+
);
|
|
63
101
|
|
|
64
102
|
return this.renderTypeEntities(dirPath, name, type[name]);
|
|
65
103
|
})
|
|
@@ -79,7 +117,6 @@ module.exports = class Renderer {
|
|
|
79
117
|
}
|
|
80
118
|
} catch (error) {
|
|
81
119
|
console.log(`An error occurred while processing "${type}"`);
|
|
82
|
-
console.debug(error);
|
|
83
120
|
return undefined;
|
|
84
121
|
}
|
|
85
122
|
|