@graphql-markdown/core 1.0.0 → 1.1.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
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.0",
|
|
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.0.1"
|
|
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.0",
|
|
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,16 +27,17 @@ 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) {
|
|
33
34
|
let config = DEFAULT_OPTIONS;
|
|
34
35
|
|
|
35
|
-
if (typeof configFileOpts
|
|
36
|
+
if (typeof configFileOpts !== "undefined" && configFileOpts != null) {
|
|
36
37
|
config = { ...DEFAULT_OPTIONS, ...configFileOpts };
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
if (typeof cliOpts
|
|
40
|
+
if (typeof cliOpts === "undefined" || cliOpts == null) {
|
|
40
41
|
cliOpts = {};
|
|
41
42
|
}
|
|
42
43
|
|
|
@@ -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 };
|
|
@@ -11,14 +11,14 @@ const hasChanges = async (
|
|
|
11
11
|
diffMethod,
|
|
12
12
|
diffModule = "@graphql-markdown/diff",
|
|
13
13
|
) => {
|
|
14
|
-
if (typeof diffMethod
|
|
14
|
+
if (typeof diffMethod === "undefined" || diffMethod == null) {
|
|
15
15
|
return true;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
try {
|
|
19
19
|
const { checkSchemaChanges } = require(diffModule);
|
|
20
20
|
return await checkSchemaChanges(schema, tmpDir, diffMethod);
|
|
21
|
-
} catch (
|
|
21
|
+
} catch (error) {
|
|
22
22
|
console.warn(
|
|
23
23
|
`Cannot find module '${diffModule}' from @graphql-markdown/core!`,
|
|
24
24
|
);
|
|
@@ -34,8 +34,9 @@ const getPrinter = (
|
|
|
34
34
|
groups,
|
|
35
35
|
printTypeOptions,
|
|
36
36
|
printerModule,
|
|
37
|
+
skipDocDirective,
|
|
37
38
|
) => {
|
|
38
|
-
if (typeof printerModule
|
|
39
|
+
if (typeof printerModule !== "string") {
|
|
39
40
|
throw new Error(
|
|
40
41
|
"Invalid printer module name in printTypeOptions settings.",
|
|
41
42
|
);
|
|
@@ -46,8 +47,9 @@ const getPrinter = (
|
|
|
46
47
|
return new Printer(schema, baseURL, linkRoot, {
|
|
47
48
|
groups,
|
|
48
49
|
printTypeOptions,
|
|
50
|
+
skipDocDirective,
|
|
49
51
|
});
|
|
50
|
-
} catch (
|
|
52
|
+
} catch (error) {
|
|
51
53
|
throw new Error(
|
|
52
54
|
`Cannot find module '${printerModule}' from @graphql-markdown/core in printTypeOptions settings.`,
|
|
53
55
|
);
|
|
@@ -62,14 +64,16 @@ const generateDocFromSchema = async ({
|
|
|
62
64
|
homepageLocation,
|
|
63
65
|
diffMethod,
|
|
64
66
|
tmpDir,
|
|
65
|
-
loaders,
|
|
67
|
+
loaders: loadersList,
|
|
66
68
|
groupByDirective,
|
|
67
69
|
prettify,
|
|
68
70
|
docOptions,
|
|
69
71
|
printTypeOptions,
|
|
70
72
|
printer: printerModule,
|
|
73
|
+
skipDocDirective,
|
|
71
74
|
}) => {
|
|
72
|
-
const
|
|
75
|
+
const loaders = getDocumentLoaders(loadersList);
|
|
76
|
+
const schema = await loadSchema(schemaLocation, loaders);
|
|
73
77
|
|
|
74
78
|
const changed = await hasChanges(schema, tmpDir, diffMethod);
|
|
75
79
|
if (!changed) {
|
|
@@ -85,6 +89,7 @@ const generateDocFromSchema = async ({
|
|
|
85
89
|
groups,
|
|
86
90
|
printTypeOptions,
|
|
87
91
|
printerModule,
|
|
92
|
+
skipDocDirective,
|
|
88
93
|
);
|
|
89
94
|
const renderer = new Renderer(
|
|
90
95
|
printer,
|
|
@@ -93,6 +98,7 @@ const generateDocFromSchema = async ({
|
|
|
93
98
|
groups,
|
|
94
99
|
prettify,
|
|
95
100
|
docOptions,
|
|
101
|
+
skipDocDirective,
|
|
96
102
|
);
|
|
97
103
|
|
|
98
104
|
const pages = await Promise.all(
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
const {
|
|
2
|
-
array: { convertArrayToObject },
|
|
3
|
-
} = require("@graphql-markdown/utils").scalars;
|
|
1
|
+
const { convertArrayToObject } = require("@graphql-markdown/utils").array;
|
|
4
2
|
|
|
5
3
|
const DEFAULT_GROUP = "Miscellaneous";
|
|
6
4
|
const OPTION_REGEX =
|
|
@@ -13,7 +11,7 @@ function parseGroupByOption(groupOptions) {
|
|
|
13
11
|
|
|
14
12
|
const parsedOptions = OPTION_REGEX.exec(groupOptions);
|
|
15
13
|
|
|
16
|
-
if (typeof parsedOptions
|
|
14
|
+
if (typeof parsedOptions === "undefined" || parsedOptions == null) {
|
|
17
15
|
throw new Error(`Invalid "${groupOptions}"`);
|
|
18
16
|
}
|
|
19
17
|
|
|
@@ -24,7 +22,7 @@ function parseGroupByOption(groupOptions) {
|
|
|
24
22
|
function getGroups(rootTypes, groupByDirective) {
|
|
25
23
|
let groups = {};
|
|
26
24
|
|
|
27
|
-
if (typeof groupByDirective
|
|
25
|
+
if (typeof groupByDirective === "undefined" || groupByDirective == null) {
|
|
28
26
|
return undefined;
|
|
29
27
|
}
|
|
30
28
|
|
|
@@ -47,7 +45,7 @@ function getGroups(rootTypes, groupByDirective) {
|
|
|
47
45
|
function getGroupName(type, groupByDirective) {
|
|
48
46
|
let group = groupByDirective.fallback; // default value is fallback, and it will be only overridden if a group is found
|
|
49
47
|
|
|
50
|
-
if (typeof type.astNode
|
|
48
|
+
if (typeof type.astNode === "undefined" || type.astNode == null) {
|
|
51
49
|
return group;
|
|
52
50
|
}
|
|
53
51
|
|
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
|
|