@graphql-markdown/core 1.6.4 → 1.7.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/dist/config.d.ts +32 -0
- package/dist/config.js +199 -0
- package/dist/diff.d.ts +2 -0
- package/dist/diff.js +41 -0
- package/dist/generator.d.ts +2 -0
- package/dist/generator.js +74 -0
- package/dist/graphql-config.d.ts +10 -0
- package/dist/graphql-config.js +97 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -0
- package/dist/printer.d.ts +2 -0
- package/dist/printer.js +44 -0
- package/dist/renderer.d.ts +20 -0
- package/dist/renderer.js +133 -0
- package/package.json +61 -11
- package/assets/sidebar.json +0 -8
- package/src/config.js +0 -194
- package/src/diff.js +0 -30
- package/src/generator.js +0 -99
- package/src/graphql-config.js +0 -61
- package/src/index.js +0 -6
- package/src/printer.js +0 -24
- package/src/renderer.js +0 -193
package/dist/renderer.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Renderer = void 0;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const graphql_1 = require("@graphql-markdown/graphql");
|
|
6
|
+
const utils_1 = require("@graphql-markdown/utils");
|
|
7
|
+
const logger_1 = require("@graphql-markdown/logger");
|
|
8
|
+
const SIDEBAR = "sidebar-schema.js";
|
|
9
|
+
const CATEGORY_YAML = "_category_.yml";
|
|
10
|
+
var SidebarPosition;
|
|
11
|
+
(function (SidebarPosition) {
|
|
12
|
+
SidebarPosition[SidebarPosition["FIRST"] = 1] = "FIRST";
|
|
13
|
+
SidebarPosition[SidebarPosition["LAST"] = 999] = "LAST";
|
|
14
|
+
})(SidebarPosition || (SidebarPosition = {}));
|
|
15
|
+
class Renderer {
|
|
16
|
+
group;
|
|
17
|
+
outputDir;
|
|
18
|
+
baseURL;
|
|
19
|
+
prettify;
|
|
20
|
+
options;
|
|
21
|
+
printer;
|
|
22
|
+
constructor(printer, outputDir, baseURL, group, prettify, docOptions) {
|
|
23
|
+
this.printer = printer;
|
|
24
|
+
this.group = group;
|
|
25
|
+
this.outputDir = outputDir;
|
|
26
|
+
this.baseURL = baseURL;
|
|
27
|
+
this.prettify = prettify;
|
|
28
|
+
this.options = docOptions;
|
|
29
|
+
}
|
|
30
|
+
async generateCategoryMetafile(category, dirPath, sidebarPosition = SidebarPosition.FIRST, styleClass) {
|
|
31
|
+
const filePath = (0, node_path_1.join)(dirPath, CATEGORY_YAML);
|
|
32
|
+
if (await (0, utils_1.fileExists)(filePath)) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
await (0, utils_1.ensureDir)(dirPath);
|
|
36
|
+
const label = (0, utils_1.startCase)(category);
|
|
37
|
+
const link = this.options && this.options.index !== true
|
|
38
|
+
? "null"
|
|
39
|
+
: `\n type: generated-index\n title: '${label} overview'`;
|
|
40
|
+
const className = typeof styleClass === "string" ? `className: ${styleClass}\n` : "";
|
|
41
|
+
await (0, utils_1.saveFile)(filePath, `label: ${label}\nposition: ${sidebarPosition}\n${className}link: ${link}\n`);
|
|
42
|
+
}
|
|
43
|
+
async generateCategoryMetafileType(type, name, rootTypeName) {
|
|
44
|
+
let dirPath = this.outputDir;
|
|
45
|
+
if (this.options &&
|
|
46
|
+
this.options.deprecated === "group" &&
|
|
47
|
+
(0, graphql_1.isDeprecated)(type)) {
|
|
48
|
+
dirPath = (0, node_path_1.join)(dirPath, (0, utils_1.slugify)("deprecated"));
|
|
49
|
+
await this.generateCategoryMetafile("deprecated", dirPath, SidebarPosition.LAST, "deprecated");
|
|
50
|
+
}
|
|
51
|
+
if (this.group &&
|
|
52
|
+
rootTypeName in this.group &&
|
|
53
|
+
name in this.group[rootTypeName]) {
|
|
54
|
+
dirPath = (0, node_path_1.join)(dirPath, (0, utils_1.slugify)(this.group[rootTypeName][name] ?? ""));
|
|
55
|
+
await this.generateCategoryMetafile(this.group[rootTypeName][name] ?? "", dirPath);
|
|
56
|
+
}
|
|
57
|
+
dirPath = (0, node_path_1.join)(dirPath, (0, utils_1.slugify)(rootTypeName));
|
|
58
|
+
await this.generateCategoryMetafile(rootTypeName, dirPath);
|
|
59
|
+
return dirPath;
|
|
60
|
+
}
|
|
61
|
+
async renderRootTypes(rootTypeName, type) {
|
|
62
|
+
if (typeof type !== "object" || type === null) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
return Promise.all(Object.keys(type)
|
|
66
|
+
.map(async (name) => {
|
|
67
|
+
const dirPath = await this.generateCategoryMetafileType(type[name], name, rootTypeName);
|
|
68
|
+
return this.renderTypeEntities(dirPath, name, type[name]);
|
|
69
|
+
})
|
|
70
|
+
.filter((res) => {
|
|
71
|
+
return typeof res !== "undefined";
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
async renderTypeEntities(dirPath, name, type) {
|
|
75
|
+
const PageRegex = /(?<category>[A-Za-z0-9-]+)[\\/]+(?<pageId>[A-Za-z0-9-]+).mdx$/;
|
|
76
|
+
const fileName = (0, utils_1.slugify)(name);
|
|
77
|
+
const filePath = (0, node_path_1.join)((0, node_path_1.normalize)(dirPath), `${fileName}.mdx`);
|
|
78
|
+
let content;
|
|
79
|
+
try {
|
|
80
|
+
content = this.printer.printType(fileName, type, this.options);
|
|
81
|
+
if (typeof content !== "string") {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
(0, logger_1.log)(`An error occurred while processing "${type}"`, logger_1.LogLevel.warn);
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
await (0, utils_1.saveFile)(filePath, content, this.prettify ? utils_1.prettifyMarkdown : undefined);
|
|
90
|
+
const pagePath = (0, node_path_1.relative)(this.outputDir, filePath);
|
|
91
|
+
const page = PageRegex.exec(pagePath);
|
|
92
|
+
if (!page?.groups) {
|
|
93
|
+
(0, logger_1.log)(`An error occurred while processing file ${filePath} for type "${type}"`, logger_1.LogLevel.warn);
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
const slug = utils_1.pathUrl.join(page.groups.category, page.groups.pageId);
|
|
97
|
+
return {
|
|
98
|
+
category: (0, utils_1.startCase)(page.groups.category),
|
|
99
|
+
slug: slug,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
async renderSidebar() {
|
|
103
|
+
const sidebar = {
|
|
104
|
+
schemaSidebar: [
|
|
105
|
+
{
|
|
106
|
+
type: "autogenerated",
|
|
107
|
+
dirName: this.baseURL,
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
};
|
|
111
|
+
const jsonSidebar = `
|
|
112
|
+
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
|
|
113
|
+
|
|
114
|
+
module.exports = ${JSON.stringify(sidebar, null, 2)};
|
|
115
|
+
`;
|
|
116
|
+
const filePath = (0, node_path_1.join)(this.outputDir, SIDEBAR);
|
|
117
|
+
await (0, utils_1.saveFile)(filePath, jsonSidebar, this.prettify ? utils_1.prettifyJavascript : undefined);
|
|
118
|
+
return filePath;
|
|
119
|
+
}
|
|
120
|
+
async renderHomepage(homepageLocation) {
|
|
121
|
+
const homePage = (0, node_path_1.basename)(homepageLocation);
|
|
122
|
+
const destLocation = (0, node_path_1.join)(this.outputDir, homePage);
|
|
123
|
+
const slug = utils_1.pathUrl.resolve("/", this.baseURL);
|
|
124
|
+
await (0, utils_1.copyFile)(homepageLocation, destLocation);
|
|
125
|
+
const template = await (0, utils_1.readFile)(destLocation);
|
|
126
|
+
const data = template
|
|
127
|
+
.toString()
|
|
128
|
+
.replace(/##baseURL##/gm, slug)
|
|
129
|
+
.replace(/##generated-date-time##/gm, new Date().toLocaleString());
|
|
130
|
+
await (0, utils_1.saveFile)(destLocation, data);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.Renderer = Renderer;
|
package/package.json
CHANGED
|
@@ -5,12 +5,15 @@
|
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/graphql-markdown/graphql-markdown/issues"
|
|
7
7
|
},
|
|
8
|
-
"version": "1.
|
|
8
|
+
"version": "1.7.0",
|
|
9
9
|
"license": "MIT",
|
|
10
|
-
"main": "src/index.js",
|
|
11
10
|
"repository": {
|
|
12
11
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/graphql-markdown/graphql-markdown.git"
|
|
12
|
+
"url": "git+https://github.com/graphql-markdown/graphql-markdown.git",
|
|
13
|
+
"directory": "packages/core"
|
|
14
|
+
},
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "Gregory Heitz"
|
|
14
17
|
},
|
|
15
18
|
"keywords": [
|
|
16
19
|
"graphql",
|
|
@@ -19,23 +22,59 @@
|
|
|
19
22
|
"markdown",
|
|
20
23
|
"graphql-markdown"
|
|
21
24
|
],
|
|
22
|
-
"
|
|
23
|
-
|
|
25
|
+
"main": "dist/index.js",
|
|
26
|
+
"types": "dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"default": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"default": {
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"default": "./dist/index.js"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"./*": {
|
|
43
|
+
"require": {
|
|
44
|
+
"types": "./dist/*.d.ts",
|
|
45
|
+
"default": "./dist/*.js"
|
|
46
|
+
},
|
|
47
|
+
"import": {
|
|
48
|
+
"types": "./dist/*.d.ts",
|
|
49
|
+
"default": "./dist/*.js"
|
|
50
|
+
},
|
|
51
|
+
"default": {
|
|
52
|
+
"types": "./dist/*.d.ts",
|
|
53
|
+
"default": "./dist/*.js"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"./package.json": "./package.json"
|
|
24
57
|
},
|
|
25
58
|
"scripts": {
|
|
26
59
|
"prepack": "pinst --disable",
|
|
27
60
|
"postpack": "pinst --enable",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
61
|
+
"stryker": "stryker run",
|
|
62
|
+
"clean": "rm -rf ./dist"
|
|
30
63
|
},
|
|
31
64
|
"dependencies": {
|
|
32
|
-
"@graphql-markdown/
|
|
65
|
+
"@graphql-markdown/graphql": "^1.0.0",
|
|
66
|
+
"@graphql-markdown/logger": "^1.0.0",
|
|
67
|
+
"@graphql-markdown/utils": "^1.6.0"
|
|
33
68
|
},
|
|
34
69
|
"peerDependencies": {
|
|
35
|
-
"@graphql-markdown/diff": "^1.0
|
|
36
|
-
"@graphql-markdown/
|
|
70
|
+
"@graphql-markdown/diff": "^1.1.0",
|
|
71
|
+
"@graphql-markdown/helpers": "^1.0.0",
|
|
72
|
+
"@graphql-markdown/printer-legacy": "^1.5.0",
|
|
37
73
|
"graphql-config": "^5.0.2"
|
|
38
74
|
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@graphql-markdown/types": "^1.0.0"
|
|
77
|
+
},
|
|
39
78
|
"peerDependenciesMeta": {
|
|
40
79
|
"@graphql-markdown/printer-legacy": {
|
|
41
80
|
"optional": true
|
|
@@ -43,6 +82,9 @@
|
|
|
43
82
|
"@graphql-markdown/diff": {
|
|
44
83
|
"optional": true
|
|
45
84
|
},
|
|
85
|
+
"@graphql-markdown/helpers": {
|
|
86
|
+
"optional": true
|
|
87
|
+
},
|
|
46
88
|
"graphql-config": {
|
|
47
89
|
"optional": true
|
|
48
90
|
}
|
|
@@ -54,6 +96,14 @@
|
|
|
54
96
|
"node": ">=16.14"
|
|
55
97
|
},
|
|
56
98
|
"publishConfig": {
|
|
99
|
+
"directory": "dist",
|
|
57
100
|
"access": "public"
|
|
58
|
-
}
|
|
101
|
+
},
|
|
102
|
+
"typescript": {
|
|
103
|
+
"definition": "dist/index.d.ts"
|
|
104
|
+
},
|
|
105
|
+
"files": [
|
|
106
|
+
"dist",
|
|
107
|
+
"assets"
|
|
108
|
+
]
|
|
59
109
|
}
|
package/assets/sidebar.json
DELETED
package/src/config.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
const { join } = require("path");
|
|
2
|
-
const { tmpdir } = require("os");
|
|
3
|
-
|
|
4
|
-
const {
|
|
5
|
-
object: { hasProperty },
|
|
6
|
-
} = require("@graphql-markdown/utils");
|
|
7
|
-
|
|
8
|
-
const { loadConfiguration } = require("./graphql-config");
|
|
9
|
-
|
|
10
|
-
const PACKAGE_NAME = "@graphql-markdown/docusaurus";
|
|
11
|
-
const ASSETS_LOCATION = join(__dirname, "../assets/");
|
|
12
|
-
|
|
13
|
-
const DEFAULT_OPTIONS = {
|
|
14
|
-
baseURL: "schema",
|
|
15
|
-
customDirective: undefined,
|
|
16
|
-
diffMethod: undefined,
|
|
17
|
-
docOptions: {
|
|
18
|
-
index: false,
|
|
19
|
-
pagination: true,
|
|
20
|
-
toc: true,
|
|
21
|
-
},
|
|
22
|
-
groupByDirective: undefined,
|
|
23
|
-
homepage: join(ASSETS_LOCATION, "generated.md"),
|
|
24
|
-
linkRoot: "/",
|
|
25
|
-
loaders: {},
|
|
26
|
-
pretty: false,
|
|
27
|
-
printer: "@graphql-markdown/printer-legacy",
|
|
28
|
-
printTypeOptions: {
|
|
29
|
-
codeSection: true,
|
|
30
|
-
deprecated: "default",
|
|
31
|
-
parentTypePrefix: true,
|
|
32
|
-
relatedTypeSection: true,
|
|
33
|
-
typeBadges: true,
|
|
34
|
-
},
|
|
35
|
-
rootPath: "./docs",
|
|
36
|
-
schema: "./schema.graphql",
|
|
37
|
-
tmpDir: join(tmpdir(), PACKAGE_NAME),
|
|
38
|
-
skipDocDirective: [],
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
function buildConfig(configFileOpts, cliOpts, id = undefined) {
|
|
42
|
-
if (typeof cliOpts === "undefined" || cliOpts === null) {
|
|
43
|
-
cliOpts = {};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const graphqlConfig = loadConfiguration(id);
|
|
47
|
-
const config = { ...DEFAULT_OPTIONS, ...graphqlConfig, ...configFileOpts };
|
|
48
|
-
|
|
49
|
-
const baseURL = cliOpts.base ?? config.baseURL;
|
|
50
|
-
const skipDocDirective = getSkipDocDirectives(cliOpts, config);
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
baseURL,
|
|
54
|
-
customDirective: getCustomDirectives(
|
|
55
|
-
config.customDirective,
|
|
56
|
-
skipDocDirective,
|
|
57
|
-
),
|
|
58
|
-
diffMethod: getDiffMethod(cliOpts.diff ?? config.diffMethod, cliOpts.force),
|
|
59
|
-
docOptions: getDocOptions(cliOpts, config.docOptions),
|
|
60
|
-
groupByDirective:
|
|
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),
|
|
66
|
-
prettify: cliOpts.pretty ?? config.pretty,
|
|
67
|
-
printer: config.printer,
|
|
68
|
-
printTypeOptions: gePrintTypeOptions(cliOpts, config.printTypeOptions),
|
|
69
|
-
schemaLocation: cliOpts.schema ?? config.schema,
|
|
70
|
-
skipDocDirective,
|
|
71
|
-
tmpDir: cliOpts.tmp ?? config.tmpDir,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function getCustomDirectives(customDirectiveOptions, skipDocDirective = []) {
|
|
76
|
-
if (
|
|
77
|
-
typeof customDirectiveOptions === "undefined" ||
|
|
78
|
-
(typeof customDirectiveOptions === "object" &&
|
|
79
|
-
Object.keys(customDirectiveOptions).length == 0)
|
|
80
|
-
) {
|
|
81
|
-
return undefined;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
for (const [name, option] of Object.entries(customDirectiveOptions)) {
|
|
85
|
-
if (skipDocDirective.includes(name)) {
|
|
86
|
-
delete customDirectiveOptions[name];
|
|
87
|
-
} else if (
|
|
88
|
-
(hasProperty(option, "descriptor") === false ||
|
|
89
|
-
typeof option.descriptor !== "function") &&
|
|
90
|
-
(hasProperty(option, "tag") === false || typeof option.tag !== "function")
|
|
91
|
-
) {
|
|
92
|
-
throw new Error(
|
|
93
|
-
`Wrong format for plugin custom directive "${name}".\nPlease refer to https://graphql-markdown.github.io/docs/advanced/custom-directive`,
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return Object.keys(customDirectiveOptions).length === 0
|
|
99
|
-
? undefined
|
|
100
|
-
: customDirectiveOptions;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function getDiffMethod(diff, force) {
|
|
104
|
-
return force ? "FORCE" : diff;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function getDocOptions(cliOpts, configOptions) {
|
|
108
|
-
return {
|
|
109
|
-
pagination: !cliOpts.noPagination && configOptions.pagination,
|
|
110
|
-
toc: !cliOpts.noToc && configOptions.toc,
|
|
111
|
-
index: cliOpts.index || configOptions.index,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function gePrintTypeOptions(cliOpts, configOptions) {
|
|
116
|
-
return {
|
|
117
|
-
codeSection: !cliOpts.noCode && configOptions.codeSection,
|
|
118
|
-
deprecated:
|
|
119
|
-
cliOpts.deprecated ??
|
|
120
|
-
configOptions.deprecated ??
|
|
121
|
-
DEFAULT_OPTIONS.printTypeOptions.deprecated,
|
|
122
|
-
parentTypePrefix: !cliOpts.noParentType && configOptions.parentTypePrefix,
|
|
123
|
-
relatedTypeSection:
|
|
124
|
-
!cliOpts.noRelatedType && configOptions.relatedTypeSection,
|
|
125
|
-
typeBadges: !cliOpts.noTypeBadges && configOptions.typeBadges,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function getSkipDocDirectives(cliOpts = {}, configFileOpts = {}) {
|
|
130
|
-
const directiveList = [].concat(
|
|
131
|
-
cliOpts.skip ?? [],
|
|
132
|
-
configFileOpts.skipDocDirective ?? [],
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
const skipDirectives = directiveList.map((option) =>
|
|
136
|
-
getSkipDocDirective(option),
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
if (
|
|
140
|
-
(hasProperty(configFileOpts, "printTypeOptions") === true &&
|
|
141
|
-
configFileOpts.printTypeOptions.deprecated === "skip") ||
|
|
142
|
-
(hasProperty(cliOpts, "deprecated") === true &&
|
|
143
|
-
cliOpts.deprecated === "skip")
|
|
144
|
-
) {
|
|
145
|
-
skipDirectives.push("deprecated");
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return skipDirectives;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function getSkipDocDirective(option) {
|
|
152
|
-
const OPTION_REGEX = /^@(?<directive>\w+)$/;
|
|
153
|
-
|
|
154
|
-
if (typeof option !== "string") {
|
|
155
|
-
throw new Error(`Invalid "${option}"`);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const parsedOption = OPTION_REGEX.exec(option);
|
|
159
|
-
|
|
160
|
-
if (typeof parsedOption === "undefined" || parsedOption == null) {
|
|
161
|
-
throw new Error(`Invalid "${option}"`);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return parsedOption.groups.directive;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function parseGroupByOption(groupOptions) {
|
|
168
|
-
const DEFAULT_GROUP = "Miscellaneous";
|
|
169
|
-
const OPTION_REGEX =
|
|
170
|
-
/^@(?<directive>\w+)\((?<field>\w+)(?:\|=(?<fallback>\w+))?\)/;
|
|
171
|
-
|
|
172
|
-
if (typeof groupOptions !== "string") {
|
|
173
|
-
return undefined;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const parsedOptions = OPTION_REGEX.exec(groupOptions);
|
|
177
|
-
|
|
178
|
-
if (typeof parsedOptions === "undefined" || parsedOptions == null) {
|
|
179
|
-
throw new Error(`Invalid "${groupOptions}"`);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const { directive, field, fallback = DEFAULT_GROUP } = parsedOptions.groups;
|
|
183
|
-
return { directive, field, fallback };
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
module.exports = {
|
|
187
|
-
ASSETS_LOCATION,
|
|
188
|
-
buildConfig,
|
|
189
|
-
DEFAULT_OPTIONS,
|
|
190
|
-
getCustomDirectives,
|
|
191
|
-
getSkipDocDirective,
|
|
192
|
-
getSkipDocDirectives,
|
|
193
|
-
parseGroupByOption,
|
|
194
|
-
};
|
package/src/diff.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
graphql: { getSchemaMap, loadSchema, getDocumentLoaders },
|
|
3
|
-
group: { getGroups },
|
|
4
|
-
directive: { getCustomDirectives },
|
|
5
|
-
} = require("@graphql-markdown/utils");
|
|
6
|
-
|
|
7
|
-
const { logger: Logger } = require("@graphql-markdown/utils");
|
|
8
|
-
const Renderer = require("./renderer");
|
|
9
|
-
const { hasChanges } = require("./diff");
|
|
10
|
-
const { getPrinter } = require("./printer");
|
|
11
|
-
|
|
12
|
-
const NS_PER_SEC = 1e9;
|
|
13
|
-
const SEC_DECIMALS = 3;
|
|
14
|
-
|
|
15
|
-
const generateDocFromSchema = async ({
|
|
16
|
-
baseURL,
|
|
17
|
-
schemaLocation,
|
|
18
|
-
outputDir,
|
|
19
|
-
linkRoot,
|
|
20
|
-
homepageLocation,
|
|
21
|
-
diffMethod,
|
|
22
|
-
tmpDir,
|
|
23
|
-
loaders: loadersList,
|
|
24
|
-
groupByDirective,
|
|
25
|
-
prettify,
|
|
26
|
-
docOptions,
|
|
27
|
-
printTypeOptions,
|
|
28
|
-
printer: printerModule,
|
|
29
|
-
skipDocDirective,
|
|
30
|
-
customDirective,
|
|
31
|
-
loggerModule,
|
|
32
|
-
}) => {
|
|
33
|
-
const start = process.hrtime.bigint();
|
|
34
|
-
|
|
35
|
-
const logger = Logger.setInstance(loggerModule);
|
|
36
|
-
|
|
37
|
-
const loaders = getDocumentLoaders(loadersList);
|
|
38
|
-
const schema = await loadSchema(schemaLocation, loaders);
|
|
39
|
-
|
|
40
|
-
const changed = await hasChanges(schema, tmpDir, diffMethod);
|
|
41
|
-
if (!changed) {
|
|
42
|
-
logger.info(`No changes detected in schema "${schemaLocation}".`);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const rootTypes = getSchemaMap(schema);
|
|
46
|
-
const customDirectives = getCustomDirectives(rootTypes, customDirective);
|
|
47
|
-
const groups = getGroups(rootTypes, groupByDirective);
|
|
48
|
-
const printer = getPrinter(
|
|
49
|
-
// module mandatory
|
|
50
|
-
printerModule,
|
|
51
|
-
|
|
52
|
-
// config mandatory
|
|
53
|
-
{
|
|
54
|
-
schema,
|
|
55
|
-
baseURL,
|
|
56
|
-
linkRoot,
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
// options
|
|
60
|
-
{
|
|
61
|
-
groups,
|
|
62
|
-
printTypeOptions,
|
|
63
|
-
skipDocDirective,
|
|
64
|
-
customDirectives,
|
|
65
|
-
},
|
|
66
|
-
);
|
|
67
|
-
const renderer = new Renderer(printer, outputDir, baseURL, groups, prettify, {
|
|
68
|
-
...docOptions,
|
|
69
|
-
deprecated: printTypeOptions.deprecated,
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
const pages = await Promise.all(
|
|
73
|
-
Object.keys(rootTypes).map((typeName) =>
|
|
74
|
-
renderer.renderRootTypes(typeName, rootTypes[typeName]),
|
|
75
|
-
),
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
await renderer.renderHomepage(homepageLocation);
|
|
79
|
-
|
|
80
|
-
const sidebarPath = await renderer.renderSidebar();
|
|
81
|
-
|
|
82
|
-
const duration = (
|
|
83
|
-
Number(process.hrtime.bigint() - start) / NS_PER_SEC
|
|
84
|
-
).toFixed(SEC_DECIMALS);
|
|
85
|
-
|
|
86
|
-
logger.success(
|
|
87
|
-
`Documentation successfully generated in "${outputDir}" with base URL "${baseURL}".`,
|
|
88
|
-
);
|
|
89
|
-
logger.info(
|
|
90
|
-
`${
|
|
91
|
-
pages.flat().length
|
|
92
|
-
} pages generated in ${duration}s from schema "${schemaLocation}".`,
|
|
93
|
-
);
|
|
94
|
-
logger.info(
|
|
95
|
-
`Remember to update your Docusaurus site's sidebars with "${sidebarPath}".`,
|
|
96
|
-
);
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
module.exports = { generateDocFromSchema };
|
package/src/graphql-config.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
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/index.js
DELETED
package/src/printer.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
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 };
|