@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/config.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CliOptions, ConfigDocOptions, ConfigOptions, ConfigPrintTypeOptions, CustomDirective, DirectiveName, GroupByDirectiveOptions, LoaderOption, Maybe, Options, TypeDiffMethod } from "@graphql-markdown/types";
|
|
2
|
+
export declare enum DiffMethod {
|
|
3
|
+
NONE = "NONE",
|
|
4
|
+
FORCE = "FORCE"
|
|
5
|
+
}
|
|
6
|
+
export declare enum DeprecatedOption {
|
|
7
|
+
DEFAULT = "default",
|
|
8
|
+
GROUP = "group",
|
|
9
|
+
SKIP = "skip"
|
|
10
|
+
}
|
|
11
|
+
export declare const DOCS_URL: "https://graphql-markdown.github.io/docs";
|
|
12
|
+
export declare const PACKAGE_NAME: "@graphql-markdown/docusaurus";
|
|
13
|
+
export declare const ASSET_HOMEPAGE_LOCATION: string;
|
|
14
|
+
export declare const DEFAULT_OPTIONS: Required<Omit<ConfigOptions, "customDirective" | "groupByDirective" | "loaders" | "metatags">> & {
|
|
15
|
+
customDirective: Maybe<CustomDirective>;
|
|
16
|
+
groupByDirective: Maybe<GroupByDirectiveOptions>;
|
|
17
|
+
loaders: Maybe<LoaderOption>;
|
|
18
|
+
metatags: Maybe<Record<string, string>>[];
|
|
19
|
+
};
|
|
20
|
+
export declare const getDocDirective: (name: Maybe<DirectiveName>) => DirectiveName;
|
|
21
|
+
export declare const getOnlyDocDirectives: (cliOpts: Maybe<CliOptions>, configFileOpts: Maybe<Pick<ConfigOptions, "onlyDocDirective">>) => DirectiveName[];
|
|
22
|
+
export declare const getSkipDocDirectives: (cliOpts: Maybe<CliOptions>, configFileOpts: Maybe<Pick<ConfigOptions, "printTypeOptions" | "skipDocDirective">>) => DirectiveName[];
|
|
23
|
+
export declare const getVisibilityDirectives: (cliOpts: Maybe<CliOptions>, configFileOpts: Maybe<Pick<ConfigOptions, "onlyDocDirective" | "printTypeOptions" | "skipDocDirective">>) => {
|
|
24
|
+
onlyDocDirective: DirectiveName[];
|
|
25
|
+
skipDocDirective: DirectiveName[];
|
|
26
|
+
};
|
|
27
|
+
export declare const getCustomDirectives: (customDirectiveOptions: Maybe<CustomDirective>, skipDocDirective?: Maybe<DirectiveName[]>) => Maybe<CustomDirective>;
|
|
28
|
+
export declare const getDiffMethod: (diff: TypeDiffMethod, force?: boolean) => TypeDiffMethod;
|
|
29
|
+
export declare const getDocOptions: (cliOpts: Maybe<CliOptions>, configOptions: Maybe<ConfigDocOptions>) => Required<ConfigDocOptions>;
|
|
30
|
+
export declare const getPrintTypeOptions: (cliOpts: Maybe<CliOptions>, configOptions: Maybe<ConfigPrintTypeOptions>) => Required<ConfigPrintTypeOptions>;
|
|
31
|
+
export declare const parseGroupByOption: (groupOptions: unknown) => Maybe<GroupByDirectiveOptions>;
|
|
32
|
+
export declare const buildConfig: (configFileOpts: Maybe<ConfigOptions>, cliOpts: Maybe<CliOptions>, id?: Maybe<string>) => Promise<Options>;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildConfig = exports.parseGroupByOption = exports.getPrintTypeOptions = exports.getDocOptions = exports.getDiffMethod = exports.getCustomDirectives = exports.getVisibilityDirectives = exports.getSkipDocDirectives = exports.getOnlyDocDirectives = exports.getDocDirective = exports.DEFAULT_OPTIONS = exports.ASSET_HOMEPAGE_LOCATION = exports.PACKAGE_NAME = exports.DOCS_URL = exports.DeprecatedOption = exports.DiffMethod = void 0;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const node_os_1 = require("node:os");
|
|
6
|
+
const graphql_config_1 = require("./graphql-config");
|
|
7
|
+
var DiffMethod;
|
|
8
|
+
(function (DiffMethod) {
|
|
9
|
+
DiffMethod["NONE"] = "NONE";
|
|
10
|
+
DiffMethod["FORCE"] = "FORCE";
|
|
11
|
+
})(DiffMethod || (exports.DiffMethod = DiffMethod = {}));
|
|
12
|
+
var DeprecatedOption;
|
|
13
|
+
(function (DeprecatedOption) {
|
|
14
|
+
DeprecatedOption["DEFAULT"] = "default";
|
|
15
|
+
DeprecatedOption["GROUP"] = "group";
|
|
16
|
+
DeprecatedOption["SKIP"] = "skip";
|
|
17
|
+
})(DeprecatedOption || (exports.DeprecatedOption = DeprecatedOption = {}));
|
|
18
|
+
exports.DOCS_URL = "https://graphql-markdown.github.io/docs";
|
|
19
|
+
exports.PACKAGE_NAME = "@graphql-markdown/docusaurus";
|
|
20
|
+
exports.ASSET_HOMEPAGE_LOCATION = (0, node_path_1.join)(__dirname, "..", "assets", "generated.md");
|
|
21
|
+
exports.DEFAULT_OPTIONS = {
|
|
22
|
+
id: "default",
|
|
23
|
+
baseURL: "schema",
|
|
24
|
+
customDirective: undefined,
|
|
25
|
+
diffMethod: DiffMethod.NONE,
|
|
26
|
+
docOptions: {
|
|
27
|
+
index: false,
|
|
28
|
+
pagination: true,
|
|
29
|
+
toc: true,
|
|
30
|
+
},
|
|
31
|
+
groupByDirective: undefined,
|
|
32
|
+
homepage: exports.ASSET_HOMEPAGE_LOCATION,
|
|
33
|
+
linkRoot: "/",
|
|
34
|
+
loaders: undefined,
|
|
35
|
+
metatags: [],
|
|
36
|
+
pretty: false,
|
|
37
|
+
printer: "@graphql-markdown/printer-legacy",
|
|
38
|
+
printTypeOptions: {
|
|
39
|
+
codeSection: true,
|
|
40
|
+
deprecated: DeprecatedOption.DEFAULT,
|
|
41
|
+
parentTypePrefix: true,
|
|
42
|
+
relatedTypeSection: true,
|
|
43
|
+
typeBadges: true,
|
|
44
|
+
},
|
|
45
|
+
rootPath: "./docs",
|
|
46
|
+
schema: "./schema.graphql",
|
|
47
|
+
tmpDir: (0, node_path_1.join)((0, node_os_1.tmpdir)(), exports.PACKAGE_NAME),
|
|
48
|
+
skipDocDirective: [],
|
|
49
|
+
onlyDocDirective: [],
|
|
50
|
+
};
|
|
51
|
+
const getDocDirective = (name) => {
|
|
52
|
+
const OPTION_REGEX = /^@(?<directive>\w+)$/;
|
|
53
|
+
if (typeof name !== "string" || !OPTION_REGEX.test(name)) {
|
|
54
|
+
throw new Error(`Invalid "${name}"`);
|
|
55
|
+
}
|
|
56
|
+
const { groups: { directive }, } = OPTION_REGEX.exec(name);
|
|
57
|
+
return directive;
|
|
58
|
+
};
|
|
59
|
+
exports.getDocDirective = getDocDirective;
|
|
60
|
+
const getOnlyDocDirectives = (cliOpts, configFileOpts) => {
|
|
61
|
+
const directiveList = [].concat((cliOpts?.only ?? []), (configFileOpts?.onlyDocDirective ?? []));
|
|
62
|
+
const onlyDirectives = directiveList.map((directiveName) => {
|
|
63
|
+
return (0, exports.getDocDirective)(directiveName);
|
|
64
|
+
});
|
|
65
|
+
return onlyDirectives;
|
|
66
|
+
};
|
|
67
|
+
exports.getOnlyDocDirectives = getOnlyDocDirectives;
|
|
68
|
+
const getSkipDocDirectives = (cliOpts, configFileOpts) => {
|
|
69
|
+
const directiveList = [].concat((cliOpts?.skip ?? []), (configFileOpts?.skipDocDirective ?? []));
|
|
70
|
+
const skipDirectives = directiveList.map((directiveName) => {
|
|
71
|
+
return (0, exports.getDocDirective)(directiveName);
|
|
72
|
+
});
|
|
73
|
+
if ((configFileOpts &&
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
75
|
+
configFileOpts.printTypeOptions?.deprecated === DeprecatedOption.SKIP) ||
|
|
76
|
+
(cliOpts && cliOpts.deprecated === DeprecatedOption.SKIP)) {
|
|
77
|
+
skipDirectives.push("deprecated");
|
|
78
|
+
}
|
|
79
|
+
return skipDirectives;
|
|
80
|
+
};
|
|
81
|
+
exports.getSkipDocDirectives = getSkipDocDirectives;
|
|
82
|
+
const getVisibilityDirectives = (cliOpts, configFileOpts) => {
|
|
83
|
+
const skipDocDirective = (0, exports.getSkipDocDirectives)(cliOpts, configFileOpts);
|
|
84
|
+
const onlyDocDirective = (0, exports.getOnlyDocDirectives)(cliOpts, configFileOpts);
|
|
85
|
+
if (onlyDocDirective.some((directiveName) => {
|
|
86
|
+
return skipDocDirective.includes(directiveName);
|
|
87
|
+
})) {
|
|
88
|
+
throw new Error("The same directive cannot be declared in 'onlyDocDirective' and 'skipDocDirective'.");
|
|
89
|
+
}
|
|
90
|
+
return { onlyDocDirective, skipDocDirective };
|
|
91
|
+
};
|
|
92
|
+
exports.getVisibilityDirectives = getVisibilityDirectives;
|
|
93
|
+
const getCustomDirectives = (customDirectiveOptions, skipDocDirective) => {
|
|
94
|
+
if (!customDirectiveOptions ||
|
|
95
|
+
Object.keys(customDirectiveOptions).length === 0) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
for (const [name, option] of Object.entries(customDirectiveOptions)) {
|
|
99
|
+
if (Array.isArray(skipDocDirective) &&
|
|
100
|
+
skipDocDirective.includes(name)) {
|
|
101
|
+
delete customDirectiveOptions[name];
|
|
102
|
+
}
|
|
103
|
+
else if (("descriptor" in option && typeof option.descriptor !== "function") ||
|
|
104
|
+
("tag" in option && typeof option.tag !== "function") ||
|
|
105
|
+
!("tag" in option || "descriptor" in option)) {
|
|
106
|
+
throw new Error(`Wrong format for plugin custom directive "${name}".\nPlease refer to ${exports.DOCS_URL}/advanced/custom-directive`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return Object.keys(customDirectiveOptions).length === 0
|
|
110
|
+
? undefined
|
|
111
|
+
: customDirectiveOptions;
|
|
112
|
+
};
|
|
113
|
+
exports.getCustomDirectives = getCustomDirectives;
|
|
114
|
+
const getDiffMethod = (diff, force = false) => {
|
|
115
|
+
return force
|
|
116
|
+
? DiffMethod.FORCE
|
|
117
|
+
: diff.toLocaleUpperCase();
|
|
118
|
+
};
|
|
119
|
+
exports.getDiffMethod = getDiffMethod;
|
|
120
|
+
const getDocOptions = (cliOpts, configOptions) => {
|
|
121
|
+
return {
|
|
122
|
+
pagination: (!cliOpts?.noPagination && configOptions?.pagination) ??
|
|
123
|
+
exports.DEFAULT_OPTIONS.docOptions.pagination,
|
|
124
|
+
toc: (!cliOpts?.noToc && configOptions?.toc) ??
|
|
125
|
+
exports.DEFAULT_OPTIONS.docOptions.toc,
|
|
126
|
+
index:
|
|
127
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
128
|
+
(cliOpts?.index || configOptions?.index) ??
|
|
129
|
+
exports.DEFAULT_OPTIONS.docOptions.index,
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
exports.getDocOptions = getDocOptions;
|
|
133
|
+
const getPrintTypeOptions = (cliOpts, configOptions) => {
|
|
134
|
+
return {
|
|
135
|
+
codeSection: (!cliOpts?.noCode && configOptions?.codeSection) ??
|
|
136
|
+
exports.DEFAULT_OPTIONS.printTypeOptions.codeSection,
|
|
137
|
+
deprecated: (cliOpts?.deprecated ??
|
|
138
|
+
configOptions?.deprecated ??
|
|
139
|
+
exports.DEFAULT_OPTIONS.printTypeOptions.deprecated).toLocaleLowerCase(),
|
|
140
|
+
parentTypePrefix: (!cliOpts?.noParentType && configOptions?.parentTypePrefix) ??
|
|
141
|
+
exports.DEFAULT_OPTIONS.printTypeOptions.parentTypePrefix,
|
|
142
|
+
relatedTypeSection: (!cliOpts?.noRelatedType && configOptions?.relatedTypeSection) ??
|
|
143
|
+
exports.DEFAULT_OPTIONS.printTypeOptions.relatedTypeSection,
|
|
144
|
+
typeBadges: (!cliOpts?.noTypeBadges && configOptions?.typeBadges) ??
|
|
145
|
+
exports.DEFAULT_OPTIONS.printTypeOptions.typeBadges,
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
exports.getPrintTypeOptions = getPrintTypeOptions;
|
|
149
|
+
const parseGroupByOption = (groupOptions) => {
|
|
150
|
+
const DEFAULT_GROUP = "Miscellaneous";
|
|
151
|
+
const OPTION_REGEX = /^@(?<directive>\w+)\((?<field>\w+)(?:\|=(?<fallback>\w+))?\)/;
|
|
152
|
+
if (typeof groupOptions !== "string") {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
const parsedOptions = OPTION_REGEX.exec(groupOptions);
|
|
156
|
+
if (typeof parsedOptions === "undefined" || parsedOptions === null) {
|
|
157
|
+
throw new Error(`Invalid "${groupOptions}"`);
|
|
158
|
+
}
|
|
159
|
+
if (!("groups" in parsedOptions)) {
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
const { directive, field, fallback = DEFAULT_GROUP, } = parsedOptions.groups;
|
|
163
|
+
return { directive, field, fallback };
|
|
164
|
+
};
|
|
165
|
+
exports.parseGroupByOption = parseGroupByOption;
|
|
166
|
+
const buildConfig = async (configFileOpts, cliOpts, id = "default") => {
|
|
167
|
+
if (!cliOpts) {
|
|
168
|
+
cliOpts = {};
|
|
169
|
+
}
|
|
170
|
+
const graphqlConfig = await (0, graphql_config_1.loadConfiguration)(id);
|
|
171
|
+
const config = {
|
|
172
|
+
...exports.DEFAULT_OPTIONS,
|
|
173
|
+
...graphqlConfig,
|
|
174
|
+
...configFileOpts,
|
|
175
|
+
};
|
|
176
|
+
const baseURL = cliOpts.base ?? config.baseURL;
|
|
177
|
+
const { onlyDocDirective, skipDocDirective } = (0, exports.getVisibilityDirectives)(cliOpts, config);
|
|
178
|
+
return {
|
|
179
|
+
baseURL,
|
|
180
|
+
customDirective: (0, exports.getCustomDirectives)(config.customDirective, skipDocDirective),
|
|
181
|
+
diffMethod: (0, exports.getDiffMethod)(cliOpts.diff ?? config.diffMethod, cliOpts.force),
|
|
182
|
+
docOptions: (0, exports.getDocOptions)(cliOpts, config.docOptions),
|
|
183
|
+
groupByDirective: (0, exports.parseGroupByOption)(cliOpts.groupByDirective) ?? config.groupByDirective,
|
|
184
|
+
homepageLocation: cliOpts.homepage ?? config.homepage ?? exports.DEFAULT_OPTIONS.homepage,
|
|
185
|
+
id: id ?? exports.DEFAULT_OPTIONS.id,
|
|
186
|
+
linkRoot: cliOpts.link ?? config.linkRoot ?? exports.DEFAULT_OPTIONS.linkRoot,
|
|
187
|
+
loaders: config.loaders,
|
|
188
|
+
metatags: config.metatags ?? exports.DEFAULT_OPTIONS.metatags,
|
|
189
|
+
onlyDocDirective,
|
|
190
|
+
outputDir: (0, node_path_1.join)(cliOpts.root ?? config.rootPath, baseURL),
|
|
191
|
+
prettify: cliOpts.pretty ?? config.pretty ?? exports.DEFAULT_OPTIONS.pretty,
|
|
192
|
+
printer: (config.printer ?? exports.DEFAULT_OPTIONS.printer),
|
|
193
|
+
printTypeOptions: (0, exports.getPrintTypeOptions)(cliOpts, config.printTypeOptions),
|
|
194
|
+
schemaLocation: cliOpts.schema ?? config.schema ?? exports.DEFAULT_OPTIONS.schema,
|
|
195
|
+
skipDocDirective,
|
|
196
|
+
tmpDir: cliOpts.tmp ?? config.tmpDir ?? exports.DEFAULT_OPTIONS.tmpDir,
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
exports.buildConfig = buildConfig;
|
package/dist/diff.d.ts
ADDED
package/dist/diff.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.hasChanges = void 0;
|
|
27
|
+
const logger_1 = require("@graphql-markdown/logger");
|
|
28
|
+
const hasChanges = async (schema, tmpDir, diffMethod, diffModule = "@graphql-markdown/diff") => {
|
|
29
|
+
if (typeof diffMethod !== "string" || typeof diffModule !== "string") {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const { checkSchemaChanges, } = await Promise.resolve(`${diffModule}`).then(s => __importStar(require(s)));
|
|
34
|
+
return await checkSchemaChanges(schema, tmpDir, diffMethod);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
(0, logger_1.log)(`Cannot find module '${diffModule}' from @graphql-markdown/core!`, logger_1.LogLevel.warn);
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.hasChanges = hasChanges;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { GeneratorOptions } from "@graphql-markdown/types";
|
|
2
|
+
export declare const generateDocFromSchema: ({ baseURL, customDirective, diffMethod, docOptions, groupByDirective, homepageLocation, linkRoot, loaders: loadersList, loggerModule, metatags, onlyDocDirective, outputDir, prettify, printer: printerModule, printTypeOptions, schemaLocation, skipDocDirective, tmpDir, }: GeneratorOptions) => Promise<void>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateDocFromSchema = void 0;
|
|
4
|
+
const logger_1 = require("@graphql-markdown/logger");
|
|
5
|
+
const graphql_1 = require("@graphql-markdown/graphql");
|
|
6
|
+
const renderer_1 = require("./renderer");
|
|
7
|
+
const diff_1 = require("./diff");
|
|
8
|
+
const printer_1 = require("./printer");
|
|
9
|
+
const config_1 = require("./config");
|
|
10
|
+
const NS_PER_SEC = 1e9;
|
|
11
|
+
const SEC_DECIMALS = 3;
|
|
12
|
+
const generateDocFromSchema = async ({ baseURL, customDirective, diffMethod, docOptions, groupByDirective, homepageLocation, linkRoot, loaders: loadersList, loggerModule, metatags, onlyDocDirective, outputDir, prettify, printer: printerModule, printTypeOptions, schemaLocation, skipDocDirective, tmpDir, }) => {
|
|
13
|
+
const start = process.hrtime.bigint();
|
|
14
|
+
(0, logger_1.Logger)(loggerModule);
|
|
15
|
+
const loaders = await (0, graphql_1.getDocumentLoaders)(loadersList);
|
|
16
|
+
if (!loaders) {
|
|
17
|
+
(0, logger_1.log)(`An error occurred while loading GraphQL loader.\nCheck your dependencies and configuration.`, "error");
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const schema = await (0, graphql_1.loadSchema)(schemaLocation, loaders);
|
|
21
|
+
if (diffMethod !== config_1.DiffMethod.NONE) {
|
|
22
|
+
const changed = await (0, diff_1.hasChanges)(schema, tmpDir, diffMethod);
|
|
23
|
+
if (!changed) {
|
|
24
|
+
(0, logger_1.log)(`No changes detected in schema "${String(schemaLocation)}".`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const [onlyDocDirectives, skipDocDirectives] = [
|
|
28
|
+
onlyDocDirective,
|
|
29
|
+
skipDocDirective,
|
|
30
|
+
].map((directiveList) => {
|
|
31
|
+
return directiveList
|
|
32
|
+
.map((name) => {
|
|
33
|
+
return schema.getDirective(name);
|
|
34
|
+
})
|
|
35
|
+
.filter((directive) => {
|
|
36
|
+
return typeof directive !== "undefined";
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
const rootTypes = (0, graphql_1.getSchemaMap)(schema);
|
|
40
|
+
const customDirectives = (0, graphql_1.getCustomDirectives)(rootTypes, customDirective);
|
|
41
|
+
const groups = (0, graphql_1.getGroups)(rootTypes, groupByDirective);
|
|
42
|
+
const printer = await (0, printer_1.getPrinter)(
|
|
43
|
+
// module mandatory
|
|
44
|
+
printerModule,
|
|
45
|
+
// config mandatory
|
|
46
|
+
{
|
|
47
|
+
baseURL,
|
|
48
|
+
linkRoot,
|
|
49
|
+
schema,
|
|
50
|
+
},
|
|
51
|
+
// options
|
|
52
|
+
{
|
|
53
|
+
customDirectives,
|
|
54
|
+
groups,
|
|
55
|
+
onlyDocDirectives,
|
|
56
|
+
printTypeOptions,
|
|
57
|
+
skipDocDirectives,
|
|
58
|
+
metatags,
|
|
59
|
+
});
|
|
60
|
+
const renderer = new renderer_1.Renderer(printer, outputDir, baseURL, groups, prettify, {
|
|
61
|
+
...docOptions,
|
|
62
|
+
deprecated: printTypeOptions.deprecated,
|
|
63
|
+
});
|
|
64
|
+
const pages = await Promise.all(Object.keys(rootTypes).map(async (typeName) => {
|
|
65
|
+
return renderer.renderRootTypes(typeName, rootTypes[typeName]);
|
|
66
|
+
}));
|
|
67
|
+
await renderer.renderHomepage(homepageLocation);
|
|
68
|
+
const sidebarPath = await renderer.renderSidebar();
|
|
69
|
+
const duration = (Number(process.hrtime.bigint() - start) / NS_PER_SEC).toFixed(SEC_DECIMALS);
|
|
70
|
+
(0, logger_1.log)(`Documentation successfully generated in "${outputDir}" with base URL "${baseURL}".`, "success");
|
|
71
|
+
(0, logger_1.log)(`${pages.flat().length} pages generated in ${duration}s from schema "${String(schemaLocation)}".`);
|
|
72
|
+
(0, logger_1.log)(`Remember to update your Docusaurus site's sidebars with "${sidebarPath}".`);
|
|
73
|
+
};
|
|
74
|
+
exports.generateDocFromSchema = generateDocFromSchema;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ExtensionProjectConfig, GraphQLExtensionDeclaration, LoaderOption, Maybe, PackageOptionsConfig } from "@graphql-markdown/types";
|
|
2
|
+
export declare const EXTENSION_NAME: "graphql-markdown";
|
|
3
|
+
export declare const graphQLConfigExtension: GraphQLExtensionDeclaration;
|
|
4
|
+
interface ThrowOptions {
|
|
5
|
+
throwOnMissing: boolean;
|
|
6
|
+
throwOnEmpty: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const setLoaderOptions: (loaders: LoaderOption, options: PackageOptionsConfig) => LoaderOption;
|
|
9
|
+
export declare const loadConfiguration: (id: Maybe<string>, options?: Maybe<PackageOptionsConfig>, { throwOnMissing, throwOnEmpty }?: ThrowOptions) => Promise<Maybe<Readonly<ExtensionProjectConfig>>>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.loadConfiguration = exports.setLoaderOptions = exports.graphQLConfigExtension = exports.EXTENSION_NAME = void 0;
|
|
27
|
+
const logger_1 = require("@graphql-markdown/logger");
|
|
28
|
+
exports.EXTENSION_NAME = "graphql-markdown";
|
|
29
|
+
const graphQLConfigExtension = () => {
|
|
30
|
+
return { name: exports.EXTENSION_NAME };
|
|
31
|
+
};
|
|
32
|
+
exports.graphQLConfigExtension = graphQLConfigExtension;
|
|
33
|
+
const setLoaderOptions = (loaders, options) => {
|
|
34
|
+
for (const loader in loaders) {
|
|
35
|
+
if (typeof loaders[loader] === "string") {
|
|
36
|
+
loaders[loader] = {
|
|
37
|
+
module: loaders[loader],
|
|
38
|
+
options,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
loaders[loader].options = {
|
|
43
|
+
...options,
|
|
44
|
+
...loaders[loader].options,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return loaders;
|
|
49
|
+
};
|
|
50
|
+
exports.setLoaderOptions = setLoaderOptions;
|
|
51
|
+
const loadConfiguration = async (id, options, { throwOnMissing, throwOnEmpty } = {
|
|
52
|
+
throwOnMissing: false,
|
|
53
|
+
throwOnEmpty: false,
|
|
54
|
+
}) => {
|
|
55
|
+
let graphQLConfig;
|
|
56
|
+
if (typeof id !== "string") {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
graphQLConfig = await Promise.resolve().then(() => __importStar(require("graphql-config")));
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
(0, logger_1.log)("Cannot find module 'graphql-config'!");
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
const config = await graphQLConfig.loadConfig({
|
|
67
|
+
...options,
|
|
68
|
+
extensions: [exports.graphQLConfigExtension],
|
|
69
|
+
throwOnMissing,
|
|
70
|
+
throwOnEmpty,
|
|
71
|
+
});
|
|
72
|
+
if (!config) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const projectConfig = config
|
|
77
|
+
.getProject(id)
|
|
78
|
+
.extension(exports.EXTENSION_NAME);
|
|
79
|
+
if (Array.isArray(projectConfig.schema)) {
|
|
80
|
+
const schema = projectConfig.schema[0];
|
|
81
|
+
if (typeof schema === "string") {
|
|
82
|
+
projectConfig.schema = schema;
|
|
83
|
+
}
|
|
84
|
+
if (typeof projectConfig.schema === "object") {
|
|
85
|
+
projectConfig.schema = Object.keys(schema)[0];
|
|
86
|
+
if (typeof projectConfig.loaders !== "undefined") {
|
|
87
|
+
projectConfig.loaders = (0, exports.setLoaderOptions)(projectConfig.loaders, Object.values(schema)[0]);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return projectConfig;
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
exports.loadConfiguration = loadConfiguration;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* istanbul ignore file */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.buildConfig = exports.generateDocFromSchema = void 0;
|
|
5
|
+
var generator_1 = require("./generator");
|
|
6
|
+
Object.defineProperty(exports, "generateDocFromSchema", { enumerable: true, get: function () { return generator_1.generateDocFromSchema; } });
|
|
7
|
+
var config_1 = require("./config");
|
|
8
|
+
Object.defineProperty(exports, "buildConfig", { enumerable: true, get: function () { return config_1.buildConfig; } });
|
package/dist/printer.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getPrinter = void 0;
|
|
27
|
+
const getPrinter = async (printerModule, config, options) => {
|
|
28
|
+
if (typeof printerModule !== "string") {
|
|
29
|
+
throw new Error("Invalid printer module name.");
|
|
30
|
+
}
|
|
31
|
+
if (!config) {
|
|
32
|
+
throw new Error("Invalid printer config.");
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const { Printer } = await Promise.resolve(`${printerModule}`).then(s => __importStar(require(s)));
|
|
36
|
+
const { schema, baseURL, linkRoot } = config;
|
|
37
|
+
Printer.init(schema, baseURL, linkRoot, { ...options });
|
|
38
|
+
return Printer;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
throw new Error(`Cannot find module '${printerModule}'.`);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
exports.getPrinter = getPrinter;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Category, ConfigDocOptions, Maybe, Printer, SchemaEntitiesGroupMap, SchemaEntity, TypeDeprecatedOption } from "@graphql-markdown/types";
|
|
2
|
+
export declare class Renderer {
|
|
3
|
+
group: Maybe<SchemaEntitiesGroupMap>;
|
|
4
|
+
outputDir: string;
|
|
5
|
+
baseURL: string;
|
|
6
|
+
prettify: boolean;
|
|
7
|
+
options: Maybe<ConfigDocOptions & {
|
|
8
|
+
deprecated: TypeDeprecatedOption;
|
|
9
|
+
}>;
|
|
10
|
+
private readonly printer;
|
|
11
|
+
constructor(printer: Printer, outputDir: string, baseURL: string, group: Maybe<SchemaEntitiesGroupMap>, prettify: boolean, docOptions: Maybe<ConfigDocOptions & {
|
|
12
|
+
deprecated: TypeDeprecatedOption;
|
|
13
|
+
}>);
|
|
14
|
+
generateCategoryMetafile(category: string, dirPath: string, sidebarPosition?: number, styleClass?: string): Promise<void>;
|
|
15
|
+
generateCategoryMetafileType(type: unknown, name: string, rootTypeName: SchemaEntity): Promise<string>;
|
|
16
|
+
renderRootTypes(rootTypeName: SchemaEntity, type: unknown): Promise<Maybe<Maybe<Category>[]>>;
|
|
17
|
+
renderTypeEntities(dirPath: string, name: string, type: unknown): Promise<Maybe<Category>>;
|
|
18
|
+
renderSidebar(): Promise<string>;
|
|
19
|
+
renderHomepage(homepageLocation: string): Promise<void>;
|
|
20
|
+
}
|