@graphql-markdown/core 1.11.0 → 1.12.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 +17 -4
- package/dist/config.js +76 -10
- package/dist/diff.js +1 -1
- package/dist/generator.d.ts +1 -1
- package/dist/generator.js +8 -6
- package/dist/graphql-config.js +2 -2
- package/dist/printer.js +1 -1
- package/dist/renderer.d.ts +4 -1
- package/dist/renderer.js +52 -12
- package/package.json +9 -9
package/dist/config.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type { CliOptions, ConfigDocOptions, ConfigOptions, ConfigPrintTypeOptions, CustomDirective, DeprecatedCliOptions, DeprecatedConfigDocOptions, DirectiveName, GroupByDirectiveOptions, Maybe, Options, TypeDiffMethod } from "@graphql-markdown/types";
|
|
1
|
+
import type { CliOptions, ConfigDocOptions, ConfigOptions, ConfigPrintTypeOptions, CustomDirective, DeprecatedCliOptions, DeprecatedConfigDocOptions, DeprecatedConfigPrintTypeOptions, DirectiveName, GroupByDirectiveOptions, Maybe, Options, TypeDiffMethod, TypeHierarchyObjectType, TypeHierarchyType, TypeHierarchyValueType } from "@graphql-markdown/types";
|
|
2
|
+
export declare enum TypeHierarchy {
|
|
3
|
+
API = "api",
|
|
4
|
+
ENTITY = "entity",
|
|
5
|
+
FLAT = "flat"
|
|
6
|
+
}
|
|
2
7
|
export declare enum DiffMethod {
|
|
3
8
|
NONE = "NONE",
|
|
4
9
|
FORCE = "FORCE"
|
|
@@ -11,7 +16,11 @@ export declare enum DeprecatedOption {
|
|
|
11
16
|
export declare const DOCS_URL: "https://graphql-markdown.dev/docs";
|
|
12
17
|
export declare const PACKAGE_NAME: "@graphql-markdown/docusaurus";
|
|
13
18
|
export declare const ASSET_HOMEPAGE_LOCATION: string;
|
|
14
|
-
export declare const DEFAULT_OPTIONS: Readonly<Pick<ConfigOptions, "customDirective" | "groupByDirective" | "loaders"> & Required<Omit<ConfigOptions, "customDirective" | "groupByDirective" | "loaders"
|
|
19
|
+
export declare const DEFAULT_OPTIONS: Readonly<Pick<ConfigOptions, "customDirective" | "groupByDirective" | "loaders"> & Required<Omit<ConfigOptions, "customDirective" | "groupByDirective" | "loaders" | "printTypeOptions">>> & {
|
|
20
|
+
printTypeOptions: Required<Omit<ConfigPrintTypeOptions, "hierarchy">> & {
|
|
21
|
+
hierarchy: Required<Pick<TypeHierarchyObjectType, TypeHierarchy.API>>;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
15
24
|
export declare const getDocDirective: (name: Maybe<DirectiveName>) => DirectiveName;
|
|
16
25
|
export declare const getOnlyDocDirectives: (cliOpts: Maybe<CliOptions>, configFileOpts: Maybe<Pick<ConfigOptions, "onlyDocDirective">>) => DirectiveName[];
|
|
17
26
|
export declare const getSkipDocDirectives: (cliOpts: Maybe<CliOptions>, configFileOpts: Maybe<Pick<ConfigOptions, "printTypeOptions" | "skipDocDirective">>) => DirectiveName[];
|
|
@@ -27,6 +36,10 @@ export declare const parseDeprecatedDocOptions: (cliOpts: Maybe<DeprecatedCliOpt
|
|
|
27
36
|
hide_table_of_contents: boolean;
|
|
28
37
|
}>;
|
|
29
38
|
export declare const getDocOptions: (cliOpts?: Maybe<CliOptions & DeprecatedCliOptions>, configOptions?: Maybe<ConfigDocOptions & DeprecatedConfigDocOptions>) => Required<ConfigDocOptions>;
|
|
30
|
-
export declare const
|
|
39
|
+
export declare const getTypeHierarchyOption: (cliOption?: Maybe<TypeHierarchyValueType>, configOption?: Maybe<TypeHierarchyType>) => Maybe<TypeHierarchyObjectType>;
|
|
40
|
+
export declare const parseDeprecatedPrintTypeOptions: (cliOpts: Maybe<DeprecatedCliOptions>, configOptions: Maybe<DeprecatedConfigPrintTypeOptions>) => Partial<{
|
|
41
|
+
hierarchy: TypeHierarchyType;
|
|
42
|
+
}>;
|
|
43
|
+
export declare const getPrintTypeOptions: (cliOpts: Maybe<CliOptions & DeprecatedCliOptions>, configOptions: Maybe<ConfigPrintTypeOptions & DeprecatedConfigPrintTypeOptions>) => Required<ConfigPrintTypeOptions>;
|
|
31
44
|
export declare const parseGroupByOption: (groupOptions: unknown) => Maybe<GroupByDirectiveOptions>;
|
|
32
|
-
export declare const buildConfig: (configFileOpts: Maybe<ConfigOptions>, cliOpts
|
|
45
|
+
export declare const buildConfig: (configFileOpts: Maybe<ConfigOptions>, cliOpts?: Maybe<CliOptions>, id?: Maybe<string>) => Promise<Options>;
|
package/dist/config.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildConfig = exports.parseGroupByOption = exports.getPrintTypeOptions = exports.getDocOptions = exports.parseDeprecatedDocOptions = 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;
|
|
3
|
+
exports.buildConfig = exports.parseGroupByOption = exports.getPrintTypeOptions = exports.parseDeprecatedPrintTypeOptions = exports.getTypeHierarchyOption = exports.getDocOptions = exports.parseDeprecatedDocOptions = 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 = exports.TypeHierarchy = void 0;
|
|
4
4
|
const node_path_1 = require("node:path");
|
|
5
5
|
const node_os_1 = require("node:os");
|
|
6
6
|
const graphql_config_1 = require("./graphql-config");
|
|
7
7
|
const logger_1 = require("@graphql-markdown/logger");
|
|
8
|
+
var TypeHierarchy;
|
|
9
|
+
(function (TypeHierarchy) {
|
|
10
|
+
TypeHierarchy["API"] = "api";
|
|
11
|
+
TypeHierarchy["ENTITY"] = "entity";
|
|
12
|
+
TypeHierarchy["FLAT"] = "flat";
|
|
13
|
+
})(TypeHierarchy || (exports.TypeHierarchy = TypeHierarchy = {}));
|
|
8
14
|
var DiffMethod;
|
|
9
15
|
(function (DiffMethod) {
|
|
10
16
|
DiffMethod["NONE"] = "NONE";
|
|
@@ -25,9 +31,10 @@ exports.DEFAULT_OPTIONS = {
|
|
|
25
31
|
customDirective: undefined,
|
|
26
32
|
diffMethod: DiffMethod.NONE,
|
|
27
33
|
docOptions: {
|
|
28
|
-
index: false,
|
|
29
34
|
frontMatter: {},
|
|
35
|
+
index: false,
|
|
30
36
|
},
|
|
37
|
+
force: false,
|
|
31
38
|
groupByDirective: undefined,
|
|
32
39
|
homepage: exports.ASSET_HOMEPAGE_LOCATION,
|
|
33
40
|
linkRoot: "/",
|
|
@@ -42,7 +49,7 @@ exports.DEFAULT_OPTIONS = {
|
|
|
42
49
|
parentTypePrefix: true,
|
|
43
50
|
relatedTypeSection: true,
|
|
44
51
|
typeBadges: true,
|
|
45
|
-
|
|
52
|
+
hierarchy: { [TypeHierarchy.API]: {} },
|
|
46
53
|
},
|
|
47
54
|
rootPath: "./docs",
|
|
48
55
|
schema: "./schema.graphql",
|
|
@@ -143,19 +150,77 @@ exports.parseDeprecatedDocOptions = parseDeprecatedDocOptions;
|
|
|
143
150
|
const getDocOptions = (cliOpts, configOptions) => {
|
|
144
151
|
const deprecated = (0, exports.parseDeprecatedDocOptions)(cliOpts, configOptions);
|
|
145
152
|
return {
|
|
146
|
-
index:
|
|
147
|
-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
148
|
-
(cliOpts?.index || configOptions?.index) ??
|
|
149
|
-
exports.DEFAULT_OPTIONS.docOptions.index,
|
|
150
153
|
frontMatter: {
|
|
151
154
|
...deprecated,
|
|
152
155
|
...configOptions?.frontMatter,
|
|
153
156
|
},
|
|
157
|
+
index:
|
|
158
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
159
|
+
(cliOpts?.index || configOptions?.index) ??
|
|
160
|
+
exports.DEFAULT_OPTIONS.docOptions.index,
|
|
154
161
|
};
|
|
155
162
|
};
|
|
156
163
|
exports.getDocOptions = getDocOptions;
|
|
164
|
+
const getTypeHierarchyOption = (cliOption, configOption) => {
|
|
165
|
+
const parseValue = (config) => {
|
|
166
|
+
if (typeof config === "string") {
|
|
167
|
+
switch (true) {
|
|
168
|
+
case new RegExp(`^${TypeHierarchy.ENTITY}$`, "i").test(config):
|
|
169
|
+
return { [TypeHierarchy.ENTITY]: {} };
|
|
170
|
+
case new RegExp(`^${TypeHierarchy.FLAT}$`, "i").test(config):
|
|
171
|
+
return { [TypeHierarchy.FLAT]: {} };
|
|
172
|
+
case new RegExp(`^${TypeHierarchy.API}$`, "i").test(config):
|
|
173
|
+
return { [TypeHierarchy.API]: {} };
|
|
174
|
+
default:
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return config;
|
|
179
|
+
};
|
|
180
|
+
const toStringHierarchy = (hierarchy) => {
|
|
181
|
+
return hierarchy && Object.keys(hierarchy)[0];
|
|
182
|
+
};
|
|
183
|
+
const cliHierarchy = parseValue(cliOption);
|
|
184
|
+
const configHierarchy = parseValue(configOption);
|
|
185
|
+
if (cliHierarchy && configHierarchy) {
|
|
186
|
+
const strCliHierarchy = toStringHierarchy(cliHierarchy);
|
|
187
|
+
const strConfigHierarchy = toStringHierarchy(configHierarchy);
|
|
188
|
+
if (strCliHierarchy !== strConfigHierarchy) {
|
|
189
|
+
throw new Error(`Hierarchy option mismatch in CLI flag '${strCliHierarchy}' and config '${strConfigHierarchy}'`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return (cliHierarchy ??
|
|
193
|
+
configHierarchy ??
|
|
194
|
+
exports.DEFAULT_OPTIONS.printTypeOptions.hierarchy);
|
|
195
|
+
};
|
|
196
|
+
exports.getTypeHierarchyOption = getTypeHierarchyOption;
|
|
197
|
+
const parseDeprecatedPrintTypeOptions = (cliOpts, configOptions) => {
|
|
198
|
+
// deprecated, replaced by hierarchy
|
|
199
|
+
let option;
|
|
200
|
+
if (typeof cliOpts?.noApiGroup !== "undefined" && cliOpts.noApiGroup) {
|
|
201
|
+
option = { hierarchy: TypeHierarchy.ENTITY };
|
|
202
|
+
(0, logger_1.log)("Type option `noApiGroup` is deprecated. Use `hierarchy: 'entity'` instead.", "warn");
|
|
203
|
+
}
|
|
204
|
+
else if (typeof configOptions?.useApiGroup !== "undefined") {
|
|
205
|
+
if (typeof configOptions.useApiGroup === "object") {
|
|
206
|
+
option = {
|
|
207
|
+
hierarchy: { [TypeHierarchy.API]: { ...configOptions.useApiGroup } },
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
option = configOptions.useApiGroup
|
|
212
|
+
? { hierarchy: TypeHierarchy.API }
|
|
213
|
+
: { hierarchy: TypeHierarchy.ENTITY };
|
|
214
|
+
}
|
|
215
|
+
(0, logger_1.log)("Type option `useApiGroup` is deprecated. Use `hierarchy: 'api'` instead.", "warn");
|
|
216
|
+
}
|
|
217
|
+
return { ...option };
|
|
218
|
+
};
|
|
219
|
+
exports.parseDeprecatedPrintTypeOptions = parseDeprecatedPrintTypeOptions;
|
|
157
220
|
const getPrintTypeOptions = (cliOpts, configOptions) => {
|
|
221
|
+
const deprecated = (0, exports.parseDeprecatedPrintTypeOptions)(cliOpts, configOptions);
|
|
158
222
|
return {
|
|
223
|
+
...deprecated,
|
|
159
224
|
codeSection: (!cliOpts?.noCode && configOptions?.codeSection) ??
|
|
160
225
|
exports.DEFAULT_OPTIONS.printTypeOptions.codeSection,
|
|
161
226
|
deprecated: (cliOpts?.deprecated ??
|
|
@@ -169,8 +234,7 @@ const getPrintTypeOptions = (cliOpts, configOptions) => {
|
|
|
169
234
|
exports.DEFAULT_OPTIONS.printTypeOptions.relatedTypeSection,
|
|
170
235
|
typeBadges: (!cliOpts?.noTypeBadges && configOptions?.typeBadges) ??
|
|
171
236
|
exports.DEFAULT_OPTIONS.printTypeOptions.typeBadges,
|
|
172
|
-
|
|
173
|
-
exports.DEFAULT_OPTIONS.printTypeOptions.useApiGroup,
|
|
237
|
+
hierarchy: (0, exports.getTypeHierarchyOption)(cliOpts?.hierarchy, configOptions?.hierarchy),
|
|
174
238
|
};
|
|
175
239
|
};
|
|
176
240
|
exports.getPrintTypeOptions = getPrintTypeOptions;
|
|
@@ -203,11 +267,13 @@ const buildConfig = async (configFileOpts, cliOpts, id = "default") => {
|
|
|
203
267
|
};
|
|
204
268
|
const baseURL = cliOpts.base ?? config.baseURL;
|
|
205
269
|
const { onlyDocDirective, skipDocDirective } = (0, exports.getVisibilityDirectives)(cliOpts, config);
|
|
270
|
+
const force = cliOpts.force ?? config.force ?? exports.DEFAULT_OPTIONS.force;
|
|
206
271
|
return {
|
|
207
272
|
baseURL,
|
|
208
273
|
customDirective: (0, exports.getCustomDirectives)(config.customDirective, skipDocDirective),
|
|
209
|
-
diffMethod: (0, exports.getDiffMethod)(cliOpts.diff ?? config.diffMethod,
|
|
274
|
+
diffMethod: (0, exports.getDiffMethod)(cliOpts.diff ?? config.diffMethod, force),
|
|
210
275
|
docOptions: (0, exports.getDocOptions)(cliOpts, config.docOptions),
|
|
276
|
+
force,
|
|
211
277
|
groupByDirective: (0, exports.parseGroupByOption)(cliOpts.groupByDirective) ?? config.groupByDirective,
|
|
212
278
|
homepageLocation: cliOpts.homepage ?? config.homepage ?? exports.DEFAULT_OPTIONS.homepage,
|
|
213
279
|
id: id ?? exports.DEFAULT_OPTIONS.id,
|
package/dist/diff.js
CHANGED
|
@@ -33,7 +33,7 @@ const hasChanges = async (schema, tmpDir, diffMethod, diffModule = "@graphql-mar
|
|
|
33
33
|
const { checkSchemaChanges, } = await Promise.resolve(`${diffModule}`).then(s => __importStar(require(s)));
|
|
34
34
|
return await checkSchemaChanges(schema, tmpDir, diffMethod);
|
|
35
35
|
}
|
|
36
|
-
catch
|
|
36
|
+
catch {
|
|
37
37
|
(0, logger_1.log)(`Cannot find module '${diffModule}' from @graphql-markdown/core!`, logger_1.LogLevel.warn);
|
|
38
38
|
return true;
|
|
39
39
|
}
|
package/dist/generator.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
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>;
|
|
2
|
+
export declare const generateDocFromSchema: ({ baseURL, customDirective, diffMethod, docOptions, force, groupByDirective, homepageLocation, linkRoot, loaders: loadersList, loggerModule, metatags, onlyDocDirective, outputDir, prettify, printer: printerModule, printTypeOptions, schemaLocation, skipDocDirective, tmpDir, }: GeneratorOptions) => Promise<void>;
|
package/dist/generator.js
CHANGED
|
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateDocFromSchema = void 0;
|
|
4
4
|
const logger_1 = require("@graphql-markdown/logger");
|
|
5
5
|
const graphql_1 = require("@graphql-markdown/graphql");
|
|
6
|
-
const
|
|
6
|
+
const config_1 = require("./config");
|
|
7
7
|
const diff_1 = require("./diff");
|
|
8
8
|
const printer_1 = require("./printer");
|
|
9
|
-
const
|
|
9
|
+
const renderer_1 = require("./renderer");
|
|
10
10
|
const NS_PER_SEC = 1e9;
|
|
11
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, }) => {
|
|
12
|
+
const generateDocFromSchema = async ({ baseURL, customDirective, diffMethod, docOptions, force, groupByDirective, homepageLocation, linkRoot, loaders: loadersList, loggerModule, metatags, onlyDocDirective, outputDir, prettify, printer: printerModule, printTypeOptions, schemaLocation, skipDocDirective, tmpDir, }) => {
|
|
13
13
|
const start = process.hrtime.bigint();
|
|
14
14
|
(0, logger_1.Logger)(loggerModule);
|
|
15
15
|
const loaders = await (0, graphql_1.getDocumentLoaders)(loadersList);
|
|
@@ -57,12 +57,14 @@ const generateDocFromSchema = async ({ baseURL, customDirective, diffMethod, doc
|
|
|
57
57
|
skipDocDirectives,
|
|
58
58
|
metatags,
|
|
59
59
|
});
|
|
60
|
-
const renderer =
|
|
60
|
+
const renderer = await (0, renderer_1.getRenderer)(printer, outputDir, baseURL, groups, prettify, {
|
|
61
61
|
...docOptions,
|
|
62
62
|
deprecated: printTypeOptions?.deprecated,
|
|
63
|
-
|
|
63
|
+
force,
|
|
64
|
+
hierarchy: printTypeOptions?.hierarchy,
|
|
64
65
|
});
|
|
65
|
-
const pages = await Promise.all(Object.keys(rootTypes).map(async (
|
|
66
|
+
const pages = await Promise.all(Object.keys(rootTypes).map(async (name) => {
|
|
67
|
+
const typeName = name;
|
|
66
68
|
return renderer.renderRootTypes(typeName, rootTypes[typeName]);
|
|
67
69
|
}));
|
|
68
70
|
await renderer.renderHomepage(homepageLocation);
|
package/dist/graphql-config.js
CHANGED
|
@@ -59,7 +59,7 @@ const loadConfiguration = async (id, options, { throwOnMissing, throwOnEmpty } =
|
|
|
59
59
|
try {
|
|
60
60
|
graphQLConfig = await Promise.resolve().then(() => __importStar(require("graphql-config")));
|
|
61
61
|
}
|
|
62
|
-
catch
|
|
62
|
+
catch {
|
|
63
63
|
(0, logger_1.log)("Cannot find module 'graphql-config'!");
|
|
64
64
|
return undefined;
|
|
65
65
|
}
|
|
@@ -90,7 +90,7 @@ const loadConfiguration = async (id, options, { throwOnMissing, throwOnEmpty } =
|
|
|
90
90
|
}
|
|
91
91
|
return projectConfig;
|
|
92
92
|
}
|
|
93
|
-
catch
|
|
93
|
+
catch {
|
|
94
94
|
return undefined;
|
|
95
95
|
}
|
|
96
96
|
};
|
package/dist/printer.js
CHANGED
package/dist/renderer.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { Category, Maybe, Printer, RendererDocOptions, SchemaEntitiesGroupMap, SchemaEntity } from "@graphql-markdown/types";
|
|
1
|
+
import type { ApiGroupOverrideType, Category, Maybe, Printer, RendererDocOptions, SchemaEntitiesGroupMap, SchemaEntity } from "@graphql-markdown/types";
|
|
2
|
+
export declare const API_GROUPS: Required<ApiGroupOverrideType>;
|
|
3
|
+
export declare const getApiGroupFolder: (type: unknown, groups?: Maybe<ApiGroupOverrideType | boolean>) => string;
|
|
2
4
|
export declare class Renderer {
|
|
3
5
|
group: Maybe<SchemaEntitiesGroupMap>;
|
|
4
6
|
outputDir: string;
|
|
@@ -16,3 +18,4 @@ export declare class Renderer {
|
|
|
16
18
|
renderTypeEntities(dirPath: string, name: string, type: unknown): Promise<Maybe<Category>>;
|
|
17
19
|
renderHomepage(homepageLocation: string): Promise<void>;
|
|
18
20
|
}
|
|
21
|
+
export declare const getRenderer: (printer: Printer, outputDir: string, baseURL: string, group: Maybe<SchemaEntitiesGroupMap>, prettify: boolean, docOptions: Maybe<RendererDocOptions>) => Promise<InstanceType<typeof Renderer>>;
|
package/dist/renderer.js
CHANGED
|
@@ -1,16 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Renderer = void 0;
|
|
3
|
+
exports.getRenderer = exports.Renderer = exports.getApiGroupFolder = exports.API_GROUPS = void 0;
|
|
4
4
|
const node_path_1 = require("node:path");
|
|
5
5
|
const graphql_1 = require("@graphql-markdown/graphql");
|
|
6
6
|
const utils_1 = require("@graphql-markdown/utils");
|
|
7
7
|
const logger_1 = require("@graphql-markdown/logger");
|
|
8
|
+
const config_1 = require("./config");
|
|
9
|
+
const DEPRECATED = "deprecated";
|
|
8
10
|
const CATEGORY_YAML = "_category_.yml";
|
|
11
|
+
const CATEGORY_STYLE_CLASS = "graphql-markdown-api-section";
|
|
9
12
|
var SidebarPosition;
|
|
10
13
|
(function (SidebarPosition) {
|
|
11
14
|
SidebarPosition[SidebarPosition["FIRST"] = 1] = "FIRST";
|
|
12
15
|
SidebarPosition[SidebarPosition["LAST"] = 999] = "LAST";
|
|
13
16
|
})(SidebarPosition || (SidebarPosition = {}));
|
|
17
|
+
exports.API_GROUPS = {
|
|
18
|
+
operations: "operations",
|
|
19
|
+
types: "types",
|
|
20
|
+
};
|
|
21
|
+
const getApiGroupFolder = (type, groups) => {
|
|
22
|
+
let folderNames = exports.API_GROUPS;
|
|
23
|
+
if (groups && typeof groups === "object") {
|
|
24
|
+
folderNames = { ...exports.API_GROUPS, ...groups };
|
|
25
|
+
}
|
|
26
|
+
return (0, graphql_1.isApiType)(type) ? folderNames.operations : folderNames.types;
|
|
27
|
+
};
|
|
28
|
+
exports.getApiGroupFolder = getApiGroupFolder;
|
|
29
|
+
const isHierarchy = (options, hierarchy) => {
|
|
30
|
+
return (options?.hierarchy?.[hierarchy] && true);
|
|
31
|
+
};
|
|
14
32
|
class Renderer {
|
|
15
33
|
group;
|
|
16
34
|
outputDir;
|
|
@@ -47,14 +65,20 @@ class Renderer {
|
|
|
47
65
|
}
|
|
48
66
|
async generateCategoryMetafileType(type, name, rootTypeName) {
|
|
49
67
|
let dirPath = this.outputDir;
|
|
50
|
-
if (this.options
|
|
51
|
-
|
|
68
|
+
if (isHierarchy(this.options, config_1.TypeHierarchy.FLAT)) {
|
|
69
|
+
return dirPath;
|
|
70
|
+
}
|
|
71
|
+
const useApiGroup = isHierarchy(this.options, config_1.TypeHierarchy.API)
|
|
72
|
+
? this.options.hierarchy[config_1.TypeHierarchy.API]
|
|
73
|
+
: !this.options?.hierarchy;
|
|
74
|
+
if (useApiGroup) {
|
|
75
|
+
const typeCat = (0, exports.getApiGroupFolder)(type, useApiGroup);
|
|
52
76
|
dirPath = (0, node_path_1.join)(dirPath, (0, utils_1.slugify)(typeCat));
|
|
53
|
-
await this.generateCategoryMetafile(typeCat, dirPath, undefined,
|
|
77
|
+
await this.generateCategoryMetafile(typeCat, dirPath, undefined, CATEGORY_STYLE_CLASS, { collapsible: false, collapsed: false });
|
|
54
78
|
}
|
|
55
79
|
if (this.options?.deprecated === "group" && (0, graphql_1.isDeprecated)(type)) {
|
|
56
|
-
dirPath = (0, node_path_1.join)(dirPath, (0, utils_1.slugify)(
|
|
57
|
-
await this.generateCategoryMetafile(
|
|
80
|
+
dirPath = (0, node_path_1.join)(dirPath, (0, utils_1.slugify)(DEPRECATED));
|
|
81
|
+
await this.generateCategoryMetafile(DEPRECATED, dirPath, SidebarPosition.LAST, DEPRECATED);
|
|
58
82
|
}
|
|
59
83
|
if (this.group &&
|
|
60
84
|
rootTypeName in this.group &&
|
|
@@ -70,9 +94,13 @@ class Renderer {
|
|
|
70
94
|
if (typeof type !== "object" || type === null) {
|
|
71
95
|
return undefined;
|
|
72
96
|
}
|
|
97
|
+
const isFlat = isHierarchy(this.options, config_1.TypeHierarchy.FLAT);
|
|
73
98
|
return Promise.all(Object.keys(type)
|
|
74
99
|
.map(async (name) => {
|
|
75
|
-
|
|
100
|
+
let dirPath = this.outputDir;
|
|
101
|
+
if (!isFlat) {
|
|
102
|
+
dirPath = await this.generateCategoryMetafileType(type[name], name, rootTypeName);
|
|
103
|
+
}
|
|
76
104
|
return this.renderTypeEntities(dirPath, name, type[name]);
|
|
77
105
|
})
|
|
78
106
|
.filter((res) => {
|
|
@@ -81,6 +109,7 @@ class Renderer {
|
|
|
81
109
|
}
|
|
82
110
|
async renderTypeEntities(dirPath, name, type) {
|
|
83
111
|
const PageRegex = /(?<category>[A-Za-z0-9-]+)[\\/]+(?<pageId>[A-Za-z0-9-]+).mdx$/;
|
|
112
|
+
const PageRegexFlat = /(?<pageId>[A-Za-z0-9-]+).mdx$/;
|
|
84
113
|
const fileName = (0, utils_1.slugify)(name);
|
|
85
114
|
const filePath = (0, node_path_1.join)((0, node_path_1.normalize)(dirPath), `${fileName}.mdx`);
|
|
86
115
|
let content;
|
|
@@ -90,21 +119,27 @@ class Renderer {
|
|
|
90
119
|
return undefined;
|
|
91
120
|
}
|
|
92
121
|
}
|
|
93
|
-
catch
|
|
122
|
+
catch {
|
|
94
123
|
(0, logger_1.log)(`An error occurred while processing "${type}"`, logger_1.LogLevel.warn);
|
|
95
124
|
return undefined;
|
|
96
125
|
}
|
|
97
126
|
await (0, utils_1.saveFile)(filePath, content, this.prettify ? utils_1.prettifyMarkdown : undefined);
|
|
98
127
|
const pagePath = (0, node_path_1.relative)(this.outputDir, filePath);
|
|
99
|
-
const
|
|
128
|
+
const isFlat = isHierarchy(this.options, config_1.TypeHierarchy.FLAT);
|
|
129
|
+
const page = isFlat
|
|
130
|
+
? PageRegexFlat.exec(pagePath)
|
|
131
|
+
: PageRegex.exec(pagePath);
|
|
100
132
|
if (!page?.groups) {
|
|
101
133
|
(0, logger_1.log)(`An error occurred while processing file ${filePath} for type "${type}"`, logger_1.LogLevel.warn);
|
|
102
134
|
return undefined;
|
|
103
135
|
}
|
|
104
|
-
const slug =
|
|
136
|
+
const slug = isFlat
|
|
137
|
+
? page.groups.pageId
|
|
138
|
+
: utils_1.pathUrl.join(page.groups.category, page.groups.pageId);
|
|
139
|
+
const category = isFlat ? "schema" : (0, utils_1.startCase)(page.groups.category);
|
|
105
140
|
return {
|
|
106
|
-
category
|
|
107
|
-
slug
|
|
141
|
+
category,
|
|
142
|
+
slug,
|
|
108
143
|
};
|
|
109
144
|
}
|
|
110
145
|
async renderHomepage(homepageLocation) {
|
|
@@ -121,3 +156,8 @@ class Renderer {
|
|
|
121
156
|
}
|
|
122
157
|
}
|
|
123
158
|
exports.Renderer = Renderer;
|
|
159
|
+
const getRenderer = async (printer, outputDir, baseURL, group, prettify, docOptions) => {
|
|
160
|
+
await (0, utils_1.ensureDir)(outputDir, { forceEmpty: docOptions?.force });
|
|
161
|
+
return new Renderer(printer, outputDir, baseURL, group, prettify, docOptions);
|
|
162
|
+
};
|
|
163
|
+
exports.getRenderer = getRenderer;
|
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.12.0",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -63,18 +63,18 @@
|
|
|
63
63
|
"docs": "typedoc"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@graphql-markdown/graphql": "^1.1.
|
|
67
|
-
"@graphql-markdown/logger": "^1.0.
|
|
68
|
-
"@graphql-markdown/utils": "^1.
|
|
66
|
+
"@graphql-markdown/graphql": "^1.1.4",
|
|
67
|
+
"@graphql-markdown/logger": "^1.0.4",
|
|
68
|
+
"@graphql-markdown/utils": "^1.7.0"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"@graphql-markdown/diff": "^1.1.
|
|
72
|
-
"@graphql-markdown/helpers": "^1.0.
|
|
73
|
-
"@graphql-markdown/printer-legacy": "^1.
|
|
74
|
-
"graphql-config": "^5.0
|
|
71
|
+
"@graphql-markdown/diff": "^1.1.8",
|
|
72
|
+
"@graphql-markdown/helpers": "^1.0.7",
|
|
73
|
+
"@graphql-markdown/printer-legacy": "^1.9.0",
|
|
74
|
+
"graphql-config": "^5.1.0"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@graphql-markdown/types": "^1.
|
|
77
|
+
"@graphql-markdown/types": "^1.4.0"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|
|
80
80
|
"@graphql-markdown/printer-legacy": {
|