@graphql-markdown/core 1.0.1 → 1.1.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
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.1.1",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"main": "src/index.js",
|
|
11
11
|
"repository": {
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"stryker": "stryker run"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@graphql-markdown/utils": "^1.0
|
|
32
|
+
"@graphql-markdown/utils": "^1.1.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@graphql-markdown/printer-legacy": "^1.
|
|
36
|
-
"@graphql-markdown/diff": "^1.0.
|
|
37
|
-
"prettier": "^2.
|
|
35
|
+
"@graphql-markdown/printer-legacy": "^1.1.1",
|
|
36
|
+
"@graphql-markdown/diff": "^1.0.2",
|
|
37
|
+
"prettier": "^2.8"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@graphql-markdown/printer-legacy": {
|
package/src/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { join } = require("path");
|
|
2
2
|
const { tmpdir } = require("os");
|
|
3
3
|
|
|
4
|
-
const { parseGroupByOption } = require("./
|
|
4
|
+
const { parseGroupByOption } = require("./group-info");
|
|
5
5
|
|
|
6
6
|
const PACKAGE_NAME = "@graphql-markdown/docusaurus";
|
|
7
7
|
const ASSETS_LOCATION = join(__dirname, "../assets/");
|
|
@@ -27,6 +27,7 @@ const DEFAULT_OPTIONS = {
|
|
|
27
27
|
relatedTypeSection: true,
|
|
28
28
|
typeBadges: true,
|
|
29
29
|
},
|
|
30
|
+
skipDocDirective: undefined,
|
|
30
31
|
};
|
|
31
32
|
|
|
32
33
|
function buildConfig(configFileOpts, cliOpts) {
|
|
@@ -57,6 +58,9 @@ function buildConfig(configFileOpts, cliOpts) {
|
|
|
57
58
|
docOptions: getDocOptions(cliOpts, config.docOptions),
|
|
58
59
|
printTypeOptions: gePrintTypeOptions(cliOpts, config.printTypeOptions),
|
|
59
60
|
printer: config.printer,
|
|
61
|
+
skipDocDirective: getSkipDocDirective(
|
|
62
|
+
cliOpts.skip ?? config.skipDocDirective,
|
|
63
|
+
),
|
|
60
64
|
};
|
|
61
65
|
}
|
|
62
66
|
|
|
@@ -81,4 +85,20 @@ function gePrintTypeOptions(cliOpts, configOptions) {
|
|
|
81
85
|
};
|
|
82
86
|
}
|
|
83
87
|
|
|
88
|
+
function getSkipDocDirective(option) {
|
|
89
|
+
const OPTION_REGEX = /^@(?<directive>\w+)$/;
|
|
90
|
+
|
|
91
|
+
if (typeof option !== "string") {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const parsedOption = OPTION_REGEX.exec(option);
|
|
96
|
+
|
|
97
|
+
if (typeof parsedOption === "undefined" || parsedOption == null) {
|
|
98
|
+
throw new Error(`Invalid "${option}"`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return parsedOption.groups.directive;
|
|
102
|
+
}
|
|
103
|
+
|
|
84
104
|
module.exports = { buildConfig, DEFAULT_OPTIONS, ASSETS_LOCATION };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
const {
|
|
2
|
-
|
|
1
|
+
const {
|
|
2
|
+
graphql: { getSchemaMap, loadSchema, getDocumentLoaders },
|
|
3
|
+
} = require("@graphql-markdown/utils");
|
|
3
4
|
const { getGroups } = require("./group-info");
|
|
4
5
|
const Renderer = require("./renderer");
|
|
5
6
|
|
|
@@ -34,6 +35,7 @@ const getPrinter = (
|
|
|
34
35
|
groups,
|
|
35
36
|
printTypeOptions,
|
|
36
37
|
printerModule,
|
|
38
|
+
skipDocDirective,
|
|
37
39
|
) => {
|
|
38
40
|
if (typeof printerModule !== "string") {
|
|
39
41
|
throw new Error(
|
|
@@ -46,6 +48,7 @@ const getPrinter = (
|
|
|
46
48
|
return new Printer(schema, baseURL, linkRoot, {
|
|
47
49
|
groups,
|
|
48
50
|
printTypeOptions,
|
|
51
|
+
skipDocDirective,
|
|
49
52
|
});
|
|
50
53
|
} catch (error) {
|
|
51
54
|
throw new Error(
|
|
@@ -68,6 +71,7 @@ const generateDocFromSchema = async ({
|
|
|
68
71
|
docOptions,
|
|
69
72
|
printTypeOptions,
|
|
70
73
|
printer: printerModule,
|
|
74
|
+
skipDocDirective,
|
|
71
75
|
}) => {
|
|
72
76
|
const loaders = getDocumentLoaders(loadersList);
|
|
73
77
|
const schema = await loadSchema(schemaLocation, loaders);
|
|
@@ -86,6 +90,7 @@ const generateDocFromSchema = async ({
|
|
|
86
90
|
groups,
|
|
87
91
|
printTypeOptions,
|
|
88
92
|
printerModule,
|
|
93
|
+
skipDocDirective,
|
|
89
94
|
);
|
|
90
95
|
const renderer = new Renderer(
|
|
91
96
|
printer,
|
|
@@ -94,6 +99,7 @@ const generateDocFromSchema = async ({
|
|
|
94
99
|
groups,
|
|
95
100
|
prettify,
|
|
96
101
|
docOptions,
|
|
102
|
+
skipDocDirective,
|
|
97
103
|
);
|
|
98
104
|
|
|
99
105
|
const pages = await Promise.all(
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* istanbul ignore file */
|
|
2
2
|
|
|
3
3
|
module.exports = {
|
|
4
|
-
generateDocFromSchema: require("./
|
|
5
|
-
groupInfo: require("./
|
|
4
|
+
generateDocFromSchema: require("./generator").generateDocFromSchema,
|
|
5
|
+
groupInfo: require("./group-info"),
|
|
6
6
|
config: require("./config"),
|
|
7
7
|
};
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
const path = require("path");
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
|
-
array: { convertArrayToObject },
|
|
5
4
|
object: { hasProperty },
|
|
6
5
|
string: { toSlug, startCase },
|
|
7
6
|
url: { pathUrl },
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const {
|
|
7
|
+
graphql: { hasDirective },
|
|
11
8
|
prettier: { prettifyJavascript, prettifyMarkdown },
|
|
12
9
|
fs: { saveFile, ensureDir, copyFile, readFile, fileExists },
|
|
13
|
-
} = require("@graphql-markdown/utils")
|
|
10
|
+
} = require("@graphql-markdown/utils");
|
|
14
11
|
|
|
15
|
-
const { ASSETS_LOCATION } = require("
|
|
12
|
+
const { ASSETS_LOCATION } = require("./config");
|
|
16
13
|
const { schemaSidebar } = require(`${ASSETS_LOCATION}/sidebar.json`);
|
|
17
14
|
|
|
18
15
|
const SIDEBAR = "sidebar-schema.js";
|
|
@@ -20,13 +17,22 @@ const HOMEPAGE_ID = "schema";
|
|
|
20
17
|
const CATEGORY_YAML = "_category_.yml";
|
|
21
18
|
|
|
22
19
|
module.exports = class Renderer {
|
|
23
|
-
constructor(
|
|
20
|
+
constructor(
|
|
21
|
+
printer,
|
|
22
|
+
outputDir,
|
|
23
|
+
baseURL,
|
|
24
|
+
group,
|
|
25
|
+
prettify,
|
|
26
|
+
docOptions,
|
|
27
|
+
skipDocDirective,
|
|
28
|
+
) {
|
|
24
29
|
this.group = group;
|
|
25
30
|
this.outputDir = outputDir;
|
|
26
31
|
this.baseURL = baseURL;
|
|
27
32
|
this.printer = printer;
|
|
28
33
|
this.prettify = prettify;
|
|
29
34
|
this.options = docOptions;
|
|
35
|
+
this.skipDocDirective = skipDocDirective;
|
|
30
36
|
}
|
|
31
37
|
|
|
32
38
|
async generateCategoryMetafile(category, dirPath) {
|
|
@@ -48,33 +54,35 @@ module.exports = class Renderer {
|
|
|
48
54
|
}
|
|
49
55
|
|
|
50
56
|
async renderRootTypes(rootTypeName, type) {
|
|
51
|
-
if (typeof type
|
|
57
|
+
if (typeof type !== "object" || type === null) {
|
|
52
58
|
return undefined;
|
|
53
59
|
}
|
|
54
60
|
|
|
55
|
-
if (Array.isArray(type)) {
|
|
56
|
-
type = convertArrayToObject(type);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
61
|
return Promise.all(
|
|
60
|
-
Object.keys(type)
|
|
61
|
-
|
|
62
|
+
Object.keys(type)
|
|
63
|
+
.map(async (name) => {
|
|
64
|
+
let dirPath = this.outputDir;
|
|
62
65
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
if (hasProperty(this.group, name)) {
|
|
67
|
+
dirPath = path.join(dirPath, toSlug(this.group[name]));
|
|
68
|
+
await this.generateCategoryMetafile(this.group[name], dirPath);
|
|
69
|
+
}
|
|
67
70
|
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
dirPath = path.join(dirPath, toSlug(rootTypeName));
|
|
72
|
+
await this.generateCategoryMetafile(rootTypeName, dirPath);
|
|
70
73
|
|
|
71
|
-
|
|
72
|
-
|
|
74
|
+
return this.renderTypeEntities(dirPath, name, type[name]);
|
|
75
|
+
})
|
|
76
|
+
.filter((res) => typeof res !== "undefined"),
|
|
73
77
|
);
|
|
74
78
|
}
|
|
75
79
|
|
|
76
80
|
async renderTypeEntities(dirPath, name, type) {
|
|
77
|
-
if (
|
|
81
|
+
if (
|
|
82
|
+
typeof type === "undefined" ||
|
|
83
|
+
type === null ||
|
|
84
|
+
hasDirective(type, this.skipDocDirective)
|
|
85
|
+
) {
|
|
78
86
|
return undefined;
|
|
79
87
|
}
|
|
80
88
|
|