@graphql-markdown/core 1.4.1 → 1.5.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 +32 -30
- package/src/diff.js +30 -0
- package/src/generator.js +12 -55
- package/src/printer.js +24 -0
- package/src/renderer.js +3 -1
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.5.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.5.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@graphql-markdown/printer-legacy": "^1.
|
|
36
|
-
"@graphql-markdown/diff": "^1.0.
|
|
35
|
+
"@graphql-markdown/printer-legacy": "^1.4.0",
|
|
36
|
+
"@graphql-markdown/diff": "^1.0.12",
|
|
37
37
|
"prettier": "^2.8"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
package/src/config.js
CHANGED
|
@@ -9,29 +9,30 @@ const PACKAGE_NAME = "@graphql-markdown/docusaurus";
|
|
|
9
9
|
const ASSETS_LOCATION = join(__dirname, "../assets/");
|
|
10
10
|
|
|
11
11
|
const DEFAULT_OPTIONS = {
|
|
12
|
-
schema: "./schema.graphql",
|
|
13
|
-
rootPath: "./docs",
|
|
14
12
|
baseURL: "schema",
|
|
15
|
-
|
|
16
|
-
homepage: join(ASSETS_LOCATION, "generated.md"),
|
|
13
|
+
customDirective: undefined,
|
|
17
14
|
diffMethod: undefined,
|
|
18
|
-
tmpDir: join(tmpdir(), PACKAGE_NAME),
|
|
19
|
-
loaders: {},
|
|
20
|
-
pretty: false,
|
|
21
|
-
printer: "@graphql-markdown/printer-legacy",
|
|
22
15
|
docOptions: {
|
|
16
|
+
index: false,
|
|
23
17
|
pagination: true,
|
|
24
18
|
toc: true,
|
|
25
|
-
index: false,
|
|
26
19
|
},
|
|
20
|
+
groupByDirective: undefined,
|
|
21
|
+
homepage: join(ASSETS_LOCATION, "generated.md"),
|
|
22
|
+
linkRoot: "/",
|
|
23
|
+
loaders: {},
|
|
24
|
+
pretty: false,
|
|
25
|
+
printer: "@graphql-markdown/printer-legacy",
|
|
27
26
|
printTypeOptions: {
|
|
27
|
+
deprecated: "default",
|
|
28
28
|
parentTypePrefix: true,
|
|
29
29
|
relatedTypeSection: true,
|
|
30
30
|
typeBadges: true,
|
|
31
|
-
deprecated: "default",
|
|
32
31
|
},
|
|
32
|
+
rootPath: "./docs",
|
|
33
|
+
schema: "./schema.graphql",
|
|
34
|
+
tmpDir: join(tmpdir(), PACKAGE_NAME),
|
|
33
35
|
skipDocDirective: [],
|
|
34
|
-
customDirective: undefined,
|
|
35
36
|
};
|
|
36
37
|
|
|
37
38
|
function buildConfig(configFileOpts, cliOpts) {
|
|
@@ -50,24 +51,24 @@ function buildConfig(configFileOpts, cliOpts) {
|
|
|
50
51
|
|
|
51
52
|
return {
|
|
52
53
|
baseURL,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
customDirective: getCustomDirectives(
|
|
55
|
+
config.customDirective,
|
|
56
|
+
skipDocDirective,
|
|
57
|
+
),
|
|
57
58
|
diffMethod: getDiffMethod(cliOpts.diff ?? config.diffMethod, cliOpts.force),
|
|
58
|
-
|
|
59
|
-
loaders: config.loaders,
|
|
59
|
+
docOptions: getDocOptions(cliOpts, config.docOptions),
|
|
60
60
|
groupByDirective:
|
|
61
61
|
parseGroupByOption(cliOpts.groupByDirective) || config.groupByDirective,
|
|
62
|
+
homepageLocation: cliOpts.homepage ?? config.homepage,
|
|
63
|
+
linkRoot: cliOpts.link ?? config.linkRoot,
|
|
64
|
+
loaders: config.loaders,
|
|
65
|
+
outputDir: join(cliOpts.root ?? config.rootPath, baseURL),
|
|
62
66
|
prettify: cliOpts.pretty ?? config.pretty,
|
|
63
|
-
docOptions: getDocOptions(cliOpts, config.docOptions),
|
|
64
|
-
printTypeOptions: gePrintTypeOptions(cliOpts, config.printTypeOptions),
|
|
65
67
|
printer: config.printer,
|
|
68
|
+
printTypeOptions: gePrintTypeOptions(cliOpts, config.printTypeOptions),
|
|
69
|
+
schemaLocation: cliOpts.schema ?? config.schema,
|
|
66
70
|
skipDocDirective,
|
|
67
|
-
|
|
68
|
-
config.customDirective,
|
|
69
|
-
skipDocDirective,
|
|
70
|
-
),
|
|
71
|
+
tmpDir: cliOpts.tmp ?? config.tmpDir,
|
|
71
72
|
};
|
|
72
73
|
}
|
|
73
74
|
|
|
@@ -84,11 +85,12 @@ function getCustomDirectives(customDirectiveOptions, skipDocDirective = []) {
|
|
|
84
85
|
if (skipDocDirective.includes(name)) {
|
|
85
86
|
delete customDirectiveOptions[name];
|
|
86
87
|
} else if (
|
|
87
|
-
hasProperty(option, "descriptor") === false ||
|
|
88
|
-
|
|
88
|
+
(hasProperty(option, "descriptor") === false ||
|
|
89
|
+
typeof option.descriptor !== "function") &&
|
|
90
|
+
(hasProperty(option, "tag") === false || typeof option.tag !== "function")
|
|
89
91
|
) {
|
|
90
92
|
throw new Error(
|
|
91
|
-
`Wrong format for plugin custom directive "${name}"
|
|
93
|
+
`Wrong format for plugin custom directive "${name}".\nPlease refer to https://graphql-markdown.github.io/docs/advanced/custom-directive`,
|
|
92
94
|
);
|
|
93
95
|
}
|
|
94
96
|
}
|
|
@@ -181,11 +183,11 @@ function parseGroupByOption(groupOptions) {
|
|
|
181
183
|
}
|
|
182
184
|
|
|
183
185
|
module.exports = {
|
|
186
|
+
ASSETS_LOCATION,
|
|
184
187
|
buildConfig,
|
|
185
|
-
|
|
188
|
+
DEFAULT_OPTIONS,
|
|
189
|
+
getCustomDirectives,
|
|
186
190
|
getSkipDocDirective,
|
|
191
|
+
getSkipDocDirectives,
|
|
187
192
|
parseGroupByOption,
|
|
188
|
-
getCustomDirectives,
|
|
189
|
-
DEFAULT_OPTIONS,
|
|
190
|
-
ASSETS_LOCATION,
|
|
191
193
|
};
|
package/src/diff.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const logger = require("@graphql-markdown/utils").logger.getInstance();
|
|
2
|
+
|
|
3
|
+
const hasChanges = async (
|
|
4
|
+
schema,
|
|
5
|
+
tmpDir,
|
|
6
|
+
diffMethod,
|
|
7
|
+
diffModule = "@graphql-markdown/diff",
|
|
8
|
+
) => {
|
|
9
|
+
if (
|
|
10
|
+
typeof diffMethod === "undefined" ||
|
|
11
|
+
diffMethod == null ||
|
|
12
|
+
typeof diffModule === "undefined" ||
|
|
13
|
+
diffModule == null
|
|
14
|
+
) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const { checkSchemaChanges } = require(diffModule);
|
|
20
|
+
return await checkSchemaChanges(schema, tmpDir, diffMethod);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
logger.warn(
|
|
23
|
+
`Cannot find module '${diffModule}' from @graphql-markdown/core!`,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return true;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
module.exports = { hasChanges };
|
package/src/generator.js
CHANGED
|
@@ -3,61 +3,15 @@ const {
|
|
|
3
3
|
group: { getGroups },
|
|
4
4
|
directive: { getCustomDirectives },
|
|
5
5
|
} = require("@graphql-markdown/utils");
|
|
6
|
+
|
|
7
|
+
const { logger: Logger } = require("@graphql-markdown/utils");
|
|
6
8
|
const Renderer = require("./renderer");
|
|
9
|
+
const { hasChanges } = require("./diff");
|
|
10
|
+
const { getPrinter } = require("./printer");
|
|
7
11
|
|
|
8
12
|
const NS_PER_SEC = 1e9;
|
|
9
13
|
const SEC_DECIMALS = 3;
|
|
10
14
|
|
|
11
|
-
const hasChanges = async (
|
|
12
|
-
schema,
|
|
13
|
-
tmpDir,
|
|
14
|
-
diffMethod,
|
|
15
|
-
diffModule = "@graphql-markdown/diff",
|
|
16
|
-
) => {
|
|
17
|
-
if (
|
|
18
|
-
typeof diffMethod === "undefined" ||
|
|
19
|
-
diffMethod == null ||
|
|
20
|
-
typeof diffModule === "undefined" ||
|
|
21
|
-
diffModule == null
|
|
22
|
-
) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
const { checkSchemaChanges } = require(diffModule);
|
|
28
|
-
return await checkSchemaChanges(schema, tmpDir, diffMethod);
|
|
29
|
-
} catch (error) {
|
|
30
|
-
console.warn(
|
|
31
|
-
`Cannot find module '${diffModule}' from @graphql-markdown/core!`,
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return true;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const getPrinter = (printerModule, config, options) => {
|
|
39
|
-
let Printer = undefined;
|
|
40
|
-
|
|
41
|
-
if (typeof printerModule !== "string") {
|
|
42
|
-
throw new Error(
|
|
43
|
-
'Invalid printer module name in "printTypeOptions" settings.',
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
Printer = require(printerModule);
|
|
49
|
-
} catch (error) {
|
|
50
|
-
throw new Error(
|
|
51
|
-
`Cannot find module '${printerModule}' for @graphql-markdown/core in "printTypeOptions" settings.`,
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const { schema, baseURL, linkRoot } = config;
|
|
56
|
-
Printer.init(schema, baseURL, linkRoot, { ...options });
|
|
57
|
-
|
|
58
|
-
return Printer;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
15
|
const generateDocFromSchema = async ({
|
|
62
16
|
baseURL,
|
|
63
17
|
schemaLocation,
|
|
@@ -74,15 +28,18 @@ const generateDocFromSchema = async ({
|
|
|
74
28
|
printer: printerModule,
|
|
75
29
|
skipDocDirective,
|
|
76
30
|
customDirective,
|
|
31
|
+
loggerModule,
|
|
77
32
|
}) => {
|
|
78
33
|
const start = process.hrtime.bigint();
|
|
79
34
|
|
|
35
|
+
const logger = Logger.setInstance(loggerModule);
|
|
36
|
+
|
|
80
37
|
const loaders = getDocumentLoaders(loadersList);
|
|
81
38
|
const schema = await loadSchema(schemaLocation, loaders);
|
|
82
39
|
|
|
83
40
|
const changed = await hasChanges(schema, tmpDir, diffMethod);
|
|
84
41
|
if (!changed) {
|
|
85
|
-
|
|
42
|
+
logger.info(`No changes detected in schema "${schemaLocation}".`);
|
|
86
43
|
}
|
|
87
44
|
|
|
88
45
|
const rootTypes = getSchemaMap(schema);
|
|
@@ -126,17 +83,17 @@ const generateDocFromSchema = async ({
|
|
|
126
83
|
Number(process.hrtime.bigint() - start) / NS_PER_SEC
|
|
127
84
|
).toFixed(SEC_DECIMALS);
|
|
128
85
|
|
|
129
|
-
|
|
86
|
+
logger.success(
|
|
130
87
|
`Documentation successfully generated in "${outputDir}" with base URL "${baseURL}".`,
|
|
131
88
|
);
|
|
132
|
-
|
|
89
|
+
logger.info(
|
|
133
90
|
`${
|
|
134
91
|
pages.flat().length
|
|
135
92
|
} pages generated in ${duration}s from schema "${schemaLocation}".`,
|
|
136
93
|
);
|
|
137
|
-
|
|
94
|
+
logger.info(
|
|
138
95
|
`Remember to update your Docusaurus site's sidebars with "${sidebarPath}".`,
|
|
139
96
|
);
|
|
140
97
|
};
|
|
141
98
|
|
|
142
|
-
module.exports = {
|
|
99
|
+
module.exports = { generateDocFromSchema };
|
package/src/printer.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const getPrinter = (printerModule, config, options) => {
|
|
2
|
+
let Printer = undefined;
|
|
3
|
+
|
|
4
|
+
if (typeof printerModule !== "string") {
|
|
5
|
+
throw new Error(
|
|
6
|
+
'Invalid printer module name in "printTypeOptions" settings.',
|
|
7
|
+
);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
Printer = require(printerModule);
|
|
12
|
+
} catch (error) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
`Cannot find module '${printerModule}' for @graphql-markdown/core in "printTypeOptions" settings.`,
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const { schema, baseURL, linkRoot } = config;
|
|
19
|
+
Printer.init(schema, baseURL, linkRoot, { ...options });
|
|
20
|
+
|
|
21
|
+
return Printer;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
module.exports = { getPrinter };
|
package/src/renderer.js
CHANGED
|
@@ -9,6 +9,8 @@ const {
|
|
|
9
9
|
graphql: { isDeprecated },
|
|
10
10
|
} = require("@graphql-markdown/utils");
|
|
11
11
|
|
|
12
|
+
const logger = require("@graphql-markdown/utils").logger.getInstance();
|
|
13
|
+
|
|
12
14
|
const { ASSETS_LOCATION } = require("./config");
|
|
13
15
|
const { schemaSidebar } = require(`${ASSETS_LOCATION}/sidebar.json`);
|
|
14
16
|
|
|
@@ -122,7 +124,7 @@ module.exports = class Renderer {
|
|
|
122
124
|
return undefined;
|
|
123
125
|
}
|
|
124
126
|
} catch (error) {
|
|
125
|
-
|
|
127
|
+
logger.warn(`An error occurred while processing "${type}"`);
|
|
126
128
|
return undefined;
|
|
127
129
|
}
|
|
128
130
|
|