@graphql-markdown/core 1.5.0 → 1.6.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 +6 -9
- package/src/config.js +7 -8
- package/src/graphql-config.js +61 -0
- package/src/renderer.js +4 -2
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.6.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.5.
|
|
32
|
+
"@graphql-markdown/utils": "^1.5.1"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@graphql-markdown/
|
|
36
|
-
"@graphql-markdown/
|
|
37
|
-
"
|
|
35
|
+
"@graphql-markdown/diff": "^1.0.14",
|
|
36
|
+
"@graphql-markdown/printer-legacy": "^1.4.1",
|
|
37
|
+
"graphql-config": "^5.0.2"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@graphql-markdown/printer-legacy": {
|
|
@@ -43,13 +43,10 @@
|
|
|
43
43
|
"@graphql-markdown/diff": {
|
|
44
44
|
"optional": true
|
|
45
45
|
},
|
|
46
|
-
"
|
|
46
|
+
"graphql-config": {
|
|
47
47
|
"optional": true
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
|
-
"devDependencies": {
|
|
51
|
-
"@graphql-markdown/printer-legacy": "^1.1.3"
|
|
52
|
-
},
|
|
53
50
|
"directories": {
|
|
54
51
|
"test": "tests"
|
|
55
52
|
},
|
package/src/config.js
CHANGED
|
@@ -5,6 +5,8 @@ const {
|
|
|
5
5
|
object: { hasProperty },
|
|
6
6
|
} = require("@graphql-markdown/utils");
|
|
7
7
|
|
|
8
|
+
const { loadConfiguration } = require("./graphql-config");
|
|
9
|
+
|
|
8
10
|
const PACKAGE_NAME = "@graphql-markdown/docusaurus";
|
|
9
11
|
const ASSETS_LOCATION = join(__dirname, "../assets/");
|
|
10
12
|
|
|
@@ -35,17 +37,14 @@ const DEFAULT_OPTIONS = {
|
|
|
35
37
|
skipDocDirective: [],
|
|
36
38
|
};
|
|
37
39
|
|
|
38
|
-
function buildConfig(configFileOpts, cliOpts) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (typeof configFileOpts !== "undefined" && configFileOpts != null) {
|
|
42
|
-
config = { ...DEFAULT_OPTIONS, ...configFileOpts };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (typeof cliOpts === "undefined" || cliOpts == null) {
|
|
40
|
+
function buildConfig(configFileOpts, cliOpts, id = undefined) {
|
|
41
|
+
if (typeof cliOpts === "undefined" || cliOpts === null) {
|
|
46
42
|
cliOpts = {};
|
|
47
43
|
}
|
|
48
44
|
|
|
45
|
+
const graphqlConfig = loadConfiguration(id);
|
|
46
|
+
const config = { ...DEFAULT_OPTIONS, ...graphqlConfig, ...configFileOpts };
|
|
47
|
+
|
|
49
48
|
const baseURL = cliOpts.base ?? config.baseURL;
|
|
50
49
|
const skipDocDirective = getSkipDocDirectives(cliOpts, config);
|
|
51
50
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const logger = require("@graphql-markdown/utils").logger.getInstance();
|
|
2
|
+
|
|
3
|
+
const EXTENSION_NAME = "graphql-markdown";
|
|
4
|
+
|
|
5
|
+
const loadConfiguration = (
|
|
6
|
+
id = undefined,
|
|
7
|
+
options = undefined,
|
|
8
|
+
{ throwOnMissing, throwOnEmpty } = {
|
|
9
|
+
throwOnMissing: false,
|
|
10
|
+
throwOnEmpty: false,
|
|
11
|
+
},
|
|
12
|
+
) => {
|
|
13
|
+
let GraphQLConfig;
|
|
14
|
+
try {
|
|
15
|
+
// eslint-disable-next-line node/no-missing-require
|
|
16
|
+
GraphQLConfig = require("graphql-config");
|
|
17
|
+
} catch (error) {
|
|
18
|
+
logger.log("Cannot find module 'graphql-config'!");
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const config = GraphQLConfig.loadConfigSync({
|
|
23
|
+
...options,
|
|
24
|
+
extensions: [() => ({ name: EXTENSION_NAME })],
|
|
25
|
+
throwOnMissing,
|
|
26
|
+
throwOnEmpty,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const projectConfig = config.getProject(id).extension(EXTENSION_NAME);
|
|
31
|
+
|
|
32
|
+
if (typeof projectConfig?.schema !== "string") {
|
|
33
|
+
const schema = projectConfig?.schema[0];
|
|
34
|
+
if (typeof schema === "string") {
|
|
35
|
+
projectConfig.schema = schema;
|
|
36
|
+
} else {
|
|
37
|
+
projectConfig.schema = Object.keys(schema)[0];
|
|
38
|
+
projectConfig.loaders = setLoaderOptions(
|
|
39
|
+
projectConfig.loaders,
|
|
40
|
+
Object.values(schema)[0],
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return projectConfig;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const setLoaderOptions = (loaders, options) => {
|
|
51
|
+
for (const loader in loaders) {
|
|
52
|
+
if (typeof loaders[loader] === "string") {
|
|
53
|
+
loaders[loader] = { module: loaders[loader], options };
|
|
54
|
+
} else {
|
|
55
|
+
loaders[loader].options = { ...options, ...loaders[loader].options };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return loaders;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
module.exports = { loadConfiguration, EXTENSION_NAME };
|
package/src/renderer.js
CHANGED
|
@@ -130,7 +130,8 @@ module.exports = class Renderer {
|
|
|
130
130
|
|
|
131
131
|
await saveFile(
|
|
132
132
|
filePath,
|
|
133
|
-
|
|
133
|
+
content,
|
|
134
|
+
this.prettify ? prettifyMarkdown : undefined,
|
|
134
135
|
);
|
|
135
136
|
|
|
136
137
|
const pagePath = path.relative(this.outputDir, filePath);
|
|
@@ -167,7 +168,8 @@ module.exports = ${JSON.stringify(sidebar, null, 2)};
|
|
|
167
168
|
const filePath = path.join(this.outputDir, SIDEBAR);
|
|
168
169
|
await saveFile(
|
|
169
170
|
filePath,
|
|
170
|
-
|
|
171
|
+
jsonSidebar,
|
|
172
|
+
this.prettify ? prettifyJavascript : undefined,
|
|
171
173
|
);
|
|
172
174
|
|
|
173
175
|
return path.relative("./", filePath);
|