@graphql-markdown/core 1.14.0 → 1.15.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/generator.js +8 -3
- package/dist/printer.d.ts +1 -1
- package/dist/printer.js +2 -2
- package/dist/renderer.d.ts +13 -8
- package/dist/renderer.js +35 -27
- package/package.json +7 -7
package/dist/generator.js
CHANGED
|
@@ -45,7 +45,6 @@ const NS_PER_SEC = 1e9;
|
|
|
45
45
|
const SEC_DECIMALS = 3;
|
|
46
46
|
const generateDocFromSchema = async ({ baseURL, customDirective, diffMethod, docOptions, force, groupByDirective, homepageLocation, linkRoot, loaders: loadersList, loggerModule, mdxParser, metatags, onlyDocDirective, outputDir, prettify, printer: printerModule, printTypeOptions, schemaLocation, skipDocDirective, tmpDir, }) => {
|
|
47
47
|
const start = process.hrtime.bigint();
|
|
48
|
-
const hasMDXSupport = mdxParser ? true : false;
|
|
49
48
|
await (0, logger_1.default)(loggerModule);
|
|
50
49
|
const loaders = await (0, graphql_1.getDocumentLoaders)(loadersList);
|
|
51
50
|
if (!loaders) {
|
|
@@ -74,6 +73,12 @@ const generateDocFromSchema = async ({ baseURL, customDirective, diffMethod, doc
|
|
|
74
73
|
const rootTypes = (0, graphql_1.getSchemaMap)(schema);
|
|
75
74
|
const customDirectives = (0, graphql_1.getCustomDirectives)(rootTypes, customDirective);
|
|
76
75
|
const groups = (0, graphql_1.getGroups)(rootTypes, groupByDirective);
|
|
76
|
+
const mdxModule = await (!mdxParser
|
|
77
|
+
? undefined
|
|
78
|
+
: Promise.resolve(`${mdxParser}`).then(s => __importStar(require(s))).catch(() => {
|
|
79
|
+
(0, logger_1.log)(`An error occurred while loading MDX formatter "${mdxParser}"`, logger_1.LogLevel.warn);
|
|
80
|
+
return undefined;
|
|
81
|
+
}));
|
|
77
82
|
const printer = await (0, printer_1.getPrinter)(
|
|
78
83
|
// module mandatory
|
|
79
84
|
printerModule,
|
|
@@ -95,13 +100,13 @@ const generateDocFromSchema = async ({ baseURL, customDirective, diffMethod, doc
|
|
|
95
100
|
onlyDocDirectives,
|
|
96
101
|
printTypeOptions,
|
|
97
102
|
skipDocDirectives,
|
|
98
|
-
},
|
|
103
|
+
}, mdxModule);
|
|
99
104
|
const renderer = await (0, renderer_1.getRenderer)(printer, outputDir, baseURL, groups, prettify, {
|
|
100
105
|
...docOptions,
|
|
101
106
|
deprecated: printTypeOptions?.deprecated,
|
|
102
107
|
force,
|
|
103
108
|
hierarchy: printTypeOptions?.hierarchy,
|
|
104
|
-
},
|
|
109
|
+
}, mdxModule);
|
|
105
110
|
const pages = await Promise.all(Object.keys(rootTypes).map(async (name) => {
|
|
106
111
|
const typeName = name;
|
|
107
112
|
return renderer.renderRootTypes(typeName, rootTypes[typeName]);
|
package/dist/printer.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Maybe, PackageName, Printer, PrinterConfig, PrinterOptions } from "@graphql-markdown/types";
|
|
2
|
-
export declare const getPrinter: (printerModule?: Maybe<PackageName>, config?: Maybe<PrinterConfig>, options?: Maybe<PrinterOptions>,
|
|
2
|
+
export declare const getPrinter: (printerModule?: Maybe<PackageName>, config?: Maybe<PrinterConfig>, options?: Maybe<PrinterOptions>, mdxModule?: unknown) => Promise<Printer>;
|
package/dist/printer.js
CHANGED
|
@@ -34,7 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.getPrinter = void 0;
|
|
37
|
-
const getPrinter = async (printerModule, config, options,
|
|
37
|
+
const getPrinter = async (printerModule, config, options, mdxModule) => {
|
|
38
38
|
if (typeof printerModule !== "string") {
|
|
39
39
|
throw new Error("Invalid printer module name.");
|
|
40
40
|
}
|
|
@@ -44,7 +44,7 @@ const getPrinter = async (printerModule, config, options, mdxParser) => {
|
|
|
44
44
|
try {
|
|
45
45
|
const { Printer } = await Promise.resolve(`${printerModule}`).then(s => __importStar(require(s)));
|
|
46
46
|
const { schema, baseURL, linkRoot } = config;
|
|
47
|
-
await Printer.init(schema, baseURL, linkRoot, { ...options },
|
|
47
|
+
await Printer.init(schema, baseURL, linkRoot, { ...options }, mdxModule);
|
|
48
48
|
return Printer;
|
|
49
49
|
}
|
|
50
50
|
catch {
|
package/dist/renderer.d.ts
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
|
-
import type { ApiGroupOverrideType, Category, Maybe, Printer, RendererDocOptions, SchemaEntitiesGroupMap, SchemaEntity } from "@graphql-markdown/types";
|
|
1
|
+
import type { ApiGroupOverrideType, Category, Maybe, MDXSupportType, Printer, RendererDocOptions, SchemaEntitiesGroupMap, SchemaEntity } from "@graphql-markdown/types";
|
|
2
2
|
export declare const API_GROUPS: Required<ApiGroupOverrideType>;
|
|
3
3
|
export declare const getApiGroupFolder: (type: unknown, groups?: Maybe<ApiGroupOverrideType | boolean>) => string;
|
|
4
|
+
export interface CategoryMetafileOptions {
|
|
5
|
+
collapsible?: boolean;
|
|
6
|
+
collapsed?: boolean;
|
|
7
|
+
sidebarPosition?: number;
|
|
8
|
+
styleClass?: string;
|
|
9
|
+
}
|
|
4
10
|
export declare class Renderer {
|
|
5
11
|
group: Maybe<SchemaEntitiesGroupMap>;
|
|
6
12
|
outputDir: string;
|
|
7
13
|
baseURL: string;
|
|
8
14
|
prettify: boolean;
|
|
9
15
|
options: Maybe<RendererDocOptions>;
|
|
10
|
-
|
|
16
|
+
mdxModule: unknown;
|
|
17
|
+
mdxModuleIndexFileSupport: boolean;
|
|
11
18
|
private readonly printer;
|
|
12
|
-
constructor(printer: Printer, outputDir: string, baseURL: string, group: Maybe<SchemaEntitiesGroupMap>, prettify: boolean, docOptions: Maybe<RendererDocOptions>,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
collapsed: boolean;
|
|
16
|
-
}): Promise<void>;
|
|
19
|
+
constructor(printer: Printer, outputDir: string, baseURL: string, group: Maybe<SchemaEntitiesGroupMap>, prettify: boolean, docOptions: Maybe<RendererDocOptions>, mdxModule?: unknown);
|
|
20
|
+
hasMDXIndexFileSupport(module?: unknown): module is Partial<MDXSupportType> & Pick<MDXSupportType, "generateIndexMetafile">;
|
|
21
|
+
generateIndexMetafile(dirPath: string, category: string, options?: CategoryMetafileOptions): Promise<void>;
|
|
17
22
|
generateCategoryMetafileType(type: unknown, name: string, rootTypeName: SchemaEntity): Promise<string>;
|
|
18
23
|
renderRootTypes(rootTypeName: SchemaEntity, type: unknown): Promise<Maybe<Maybe<Category>[]>>;
|
|
19
24
|
renderTypeEntities(dirPath: string, name: string, type: unknown): Promise<Maybe<Category>>;
|
|
20
25
|
renderHomepage(homepageLocation: string): Promise<void>;
|
|
21
26
|
}
|
|
22
|
-
export declare const getRenderer: (printer: Printer, outputDir: string, baseURL: string, group: Maybe<SchemaEntitiesGroupMap>, prettify: boolean, docOptions: Maybe<RendererDocOptions>,
|
|
27
|
+
export declare const getRenderer: (printer: Printer, outputDir: string, baseURL: string, group: Maybe<SchemaEntitiesGroupMap>, prettify: boolean, docOptions: Maybe<RendererDocOptions>, mdxModule?: unknown) => Promise<InstanceType<typeof Renderer>>;
|
package/dist/renderer.js
CHANGED
|
@@ -7,8 +7,11 @@ const utils_1 = require("@graphql-markdown/utils");
|
|
|
7
7
|
const logger_1 = require("@graphql-markdown/logger");
|
|
8
8
|
const config_1 = require("./config");
|
|
9
9
|
const DEPRECATED = "deprecated";
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
var CATEGORY_STYLE_CLASS;
|
|
11
|
+
(function (CATEGORY_STYLE_CLASS) {
|
|
12
|
+
CATEGORY_STYLE_CLASS["API"] = "graphql-markdown-api-section";
|
|
13
|
+
CATEGORY_STYLE_CLASS["DEPRECATED"] = "graphql-markdown-deprecated-section";
|
|
14
|
+
})(CATEGORY_STYLE_CLASS || (CATEGORY_STYLE_CLASS = {}));
|
|
12
15
|
var SidebarPosition;
|
|
13
16
|
(function (SidebarPosition) {
|
|
14
17
|
SidebarPosition[SidebarPosition["FIRST"] = 1] = "FIRST";
|
|
@@ -35,35 +38,32 @@ class Renderer {
|
|
|
35
38
|
baseURL;
|
|
36
39
|
prettify;
|
|
37
40
|
options;
|
|
38
|
-
|
|
41
|
+
mdxModule;
|
|
42
|
+
mdxModuleIndexFileSupport;
|
|
39
43
|
printer;
|
|
40
|
-
constructor(printer, outputDir, baseURL, group, prettify, docOptions,
|
|
44
|
+
constructor(printer, outputDir, baseURL, group, prettify, docOptions, mdxModule) {
|
|
41
45
|
this.printer = printer;
|
|
42
46
|
this.group = group;
|
|
43
47
|
this.outputDir = outputDir;
|
|
44
48
|
this.baseURL = baseURL;
|
|
45
49
|
this.prettify = prettify;
|
|
46
50
|
this.options = docOptions;
|
|
47
|
-
this.
|
|
51
|
+
this.mdxModule = mdxModule;
|
|
52
|
+
this.mdxModuleIndexFileSupport = this.hasMDXIndexFileSupport(mdxModule);
|
|
48
53
|
}
|
|
49
|
-
|
|
54
|
+
hasMDXIndexFileSupport(module = this.mdxModule) {
|
|
55
|
+
return !!(module &&
|
|
56
|
+
typeof module === "object" &&
|
|
57
|
+
"generateIndexMetafile" in module &&
|
|
58
|
+
typeof module.generateIndexMetafile === "function");
|
|
59
|
+
}
|
|
60
|
+
async generateIndexMetafile(dirPath, category, options = {
|
|
50
61
|
collapsible: true,
|
|
51
62
|
collapsed: true,
|
|
52
63
|
}) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return;
|
|
64
|
+
if (this.mdxModuleIndexFileSupport) {
|
|
65
|
+
await this.mdxModule.generateIndexMetafile(dirPath, category, { ...options, index: this.options?.index });
|
|
56
66
|
}
|
|
57
|
-
await (0, utils_1.ensureDir)(dirPath);
|
|
58
|
-
const label = (0, utils_1.startCase)(category);
|
|
59
|
-
const link = this.options && this.options.index !== true
|
|
60
|
-
? "null"
|
|
61
|
-
: `\n type: generated-index\n title: '${label} overview'`;
|
|
62
|
-
const className = typeof styleClass === "string" ? `className: ${styleClass}\n` : "";
|
|
63
|
-
const position = typeof sidebarPosition === "number"
|
|
64
|
-
? sidebarPosition
|
|
65
|
-
: SidebarPosition.FIRST;
|
|
66
|
-
await (0, utils_1.saveFile)(filePath, `label: ${label}\nposition: ${position}\n${className}link: ${link}\ncollapsible: ${options.collapsible}\ncollapsed: ${options.collapsed}\n`);
|
|
67
67
|
}
|
|
68
68
|
async generateCategoryMetafileType(type, name, rootTypeName) {
|
|
69
69
|
let dirPath = this.outputDir;
|
|
@@ -76,20 +76,28 @@ class Renderer {
|
|
|
76
76
|
if (useApiGroup) {
|
|
77
77
|
const typeCat = (0, exports.getApiGroupFolder)(type, useApiGroup);
|
|
78
78
|
dirPath = (0, node_path_1.join)(dirPath, (0, utils_1.slugify)(typeCat));
|
|
79
|
-
await this.
|
|
79
|
+
await this.generateIndexMetafile(dirPath, typeCat, {
|
|
80
|
+
collapsible: false,
|
|
81
|
+
collapsed: false,
|
|
82
|
+
styleClass: CATEGORY_STYLE_CLASS.API,
|
|
83
|
+
});
|
|
80
84
|
}
|
|
81
85
|
if (this.options?.deprecated === "group" && (0, graphql_1.isDeprecated)(type)) {
|
|
82
86
|
dirPath = (0, node_path_1.join)(dirPath, (0, utils_1.slugify)(DEPRECATED));
|
|
83
|
-
await this.
|
|
87
|
+
await this.generateIndexMetafile(dirPath, DEPRECATED, {
|
|
88
|
+
sidebarPosition: SidebarPosition.LAST,
|
|
89
|
+
styleClass: CATEGORY_STYLE_CLASS.DEPRECATED,
|
|
90
|
+
});
|
|
84
91
|
}
|
|
85
92
|
if (this.group &&
|
|
86
93
|
rootTypeName in this.group &&
|
|
87
94
|
name in this.group[rootTypeName]) {
|
|
88
|
-
|
|
89
|
-
|
|
95
|
+
const rootGroup = this.group[rootTypeName][name] ?? "";
|
|
96
|
+
dirPath = (0, node_path_1.join)(dirPath, (0, utils_1.slugify)(rootGroup));
|
|
97
|
+
await this.generateIndexMetafile(dirPath, rootGroup);
|
|
90
98
|
}
|
|
91
99
|
dirPath = (0, node_path_1.join)(dirPath, (0, utils_1.slugify)(rootTypeName));
|
|
92
|
-
await this.
|
|
100
|
+
await this.generateIndexMetafile(dirPath, rootTypeName);
|
|
93
101
|
return dirPath;
|
|
94
102
|
}
|
|
95
103
|
async renderRootTypes(rootTypeName, type) {
|
|
@@ -112,7 +120,7 @@ class Renderer {
|
|
|
112
120
|
async renderTypeEntities(dirPath, name, type) {
|
|
113
121
|
const PageRegex = /(?<category>[A-Za-z0-9-]+)[\\/]+(?<pageId>[A-Za-z0-9-]+).mdx?$/;
|
|
114
122
|
const PageRegexFlat = /(?<pageId>[A-Za-z0-9-]+).mdx?$/;
|
|
115
|
-
const extension = this.
|
|
123
|
+
const extension = this.mdxModule ? "mdx" : "md";
|
|
116
124
|
const fileName = (0, utils_1.slugify)(name);
|
|
117
125
|
const filePath = (0, node_path_1.join)((0, node_path_1.normalize)(dirPath), `${fileName}.${extension}`);
|
|
118
126
|
let content;
|
|
@@ -159,8 +167,8 @@ class Renderer {
|
|
|
159
167
|
}
|
|
160
168
|
}
|
|
161
169
|
exports.Renderer = Renderer;
|
|
162
|
-
const getRenderer = async (printer, outputDir, baseURL, group, prettify, docOptions,
|
|
170
|
+
const getRenderer = async (printer, outputDir, baseURL, group, prettify, docOptions, mdxModule) => {
|
|
163
171
|
await (0, utils_1.ensureDir)(outputDir, { forceEmpty: docOptions?.force });
|
|
164
|
-
return new Renderer(printer, outputDir, baseURL, group, prettify, docOptions,
|
|
172
|
+
return new Renderer(printer, outputDir, baseURL, group, prettify, docOptions, mdxModule);
|
|
165
173
|
};
|
|
166
174
|
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.15.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.
|
|
66
|
+
"@graphql-markdown/graphql": "^1.1.6",
|
|
67
67
|
"@graphql-markdown/logger": "^1.0.5",
|
|
68
|
-
"@graphql-markdown/utils": "^1.
|
|
68
|
+
"@graphql-markdown/utils": "^1.8.0"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"@graphql-markdown/diff": "^1.1.
|
|
72
|
-
"@graphql-markdown/helpers": "^1.0.
|
|
73
|
-
"@graphql-markdown/printer-legacy": "^1.
|
|
71
|
+
"@graphql-markdown/diff": "^1.1.10",
|
|
72
|
+
"@graphql-markdown/helpers": "^1.0.9",
|
|
73
|
+
"@graphql-markdown/printer-legacy": "^1.12.0",
|
|
74
74
|
"graphql-config": "^5.1.0"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@graphql-markdown/types": "^1.
|
|
77
|
+
"@graphql-markdown/types": "^1.7.0"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|
|
80
80
|
"@graphql-markdown/printer-legacy": {
|