@graphql-markdown/core 1.13.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/config.d.ts CHANGED
@@ -1,13 +1,22 @@
1
1
  import type { CliOptions, ConfigDocOptions, ConfigOptions, ConfigPrintTypeOptions, CustomDirective, DeprecatedCliOptions, DeprecatedConfigDocOptions, DeprecatedConfigPrintTypeOptions, DirectiveName, GroupByDirectiveOptions, Maybe, Options, TypeDiffMethod, TypeHierarchyObjectType, TypeHierarchyType, TypeHierarchyValueType } from "@graphql-markdown/types";
2
+ /**
3
+ * @public
4
+ */
2
5
  export declare enum TypeHierarchy {
3
6
  API = "api",
4
7
  ENTITY = "entity",
5
8
  FLAT = "flat"
6
9
  }
10
+ /**
11
+ * @public
12
+ */
7
13
  export declare enum DiffMethod {
8
14
  NONE = "NONE",
9
15
  FORCE = "FORCE"
10
16
  }
17
+ /**
18
+ * @public
19
+ */
11
20
  export declare enum DeprecatedOption {
12
21
  DEFAULT = "default",
13
22
  GROUP = "group",
@@ -19,7 +28,7 @@ export declare const ASSET_HOMEPAGE_LOCATION: string;
19
28
  export declare const DEFAULT_HIERARCHY: {
20
29
  api: {};
21
30
  };
22
- export declare const DEFAULT_OPTIONS: Readonly<Pick<ConfigOptions, "customDirective" | "groupByDirective" | "loaders"> & Required<Omit<ConfigOptions, "customDirective" | "groupByDirective" | "loaders" | "printTypeOptions">>> & {
31
+ export declare const DEFAULT_OPTIONS: Readonly<Pick<ConfigOptions, "customDirective" | "groupByDirective" | "loaders"> & Required<Omit<ConfigOptions, "customDirective" | "groupByDirective" | "loaders" | "mdxParser" | "printTypeOptions">>> & {
23
32
  printTypeOptions: Required<Omit<ConfigPrintTypeOptions, "hierarchy">> & {
24
33
  hierarchy: Required<Pick<TypeHierarchyObjectType, TypeHierarchy.API>>;
25
34
  };
package/dist/config.js CHANGED
@@ -4,17 +4,26 @@ exports.buildConfig = exports.parseGroupByOption = exports.getPrintTypeOptions =
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
+ /**
8
+ * @public
9
+ */
7
10
  var TypeHierarchy;
8
11
  (function (TypeHierarchy) {
9
12
  TypeHierarchy["API"] = "api";
10
13
  TypeHierarchy["ENTITY"] = "entity";
11
14
  TypeHierarchy["FLAT"] = "flat";
12
15
  })(TypeHierarchy || (exports.TypeHierarchy = TypeHierarchy = {}));
16
+ /**
17
+ * @public
18
+ */
13
19
  var DiffMethod;
14
20
  (function (DiffMethod) {
15
21
  DiffMethod["NONE"] = "NONE";
16
22
  DiffMethod["FORCE"] = "FORCE";
17
23
  })(DiffMethod || (exports.DiffMethod = DiffMethod = {}));
24
+ /**
25
+ * @public
26
+ */
18
27
  var DeprecatedOption;
19
28
  (function (DeprecatedOption) {
20
29
  DeprecatedOption["DEFAULT"] = "default";
@@ -242,6 +251,7 @@ const buildConfig = async (configFileOpts, cliOpts, id = "default") => {
242
251
  id: id ?? exports.DEFAULT_OPTIONS.id,
243
252
  linkRoot: cliOpts.link ?? config.linkRoot ?? exports.DEFAULT_OPTIONS.linkRoot,
244
253
  loaders: config.loaders,
254
+ mdxParser: cliOpts.mdxParser ?? config.mdxParser,
245
255
  metatags: config.metatags ?? exports.DEFAULT_OPTIONS.metatags,
246
256
  onlyDocDirective,
247
257
  outputDir: (0, node_path_1.join)(cliOpts.root ?? config.rootPath, baseURL),
@@ -1,2 +1,2 @@
1
1
  import type { GeneratorOptions } from "@graphql-markdown/types";
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>;
2
+ export declare const generateDocFromSchema: ({ baseURL, customDirective, diffMethod, docOptions, force, groupByDirective, homepageLocation, linkRoot, loaders: loadersList, loggerModule, mdxParser, metatags, onlyDocDirective, outputDir, prettify, printer: printerModule, printTypeOptions, schemaLocation, skipDocDirective, tmpDir, }: GeneratorOptions) => Promise<void>;
package/dist/generator.js CHANGED
@@ -43,7 +43,7 @@ const printer_1 = require("./printer");
43
43
  const renderer_1 = require("./renderer");
44
44
  const NS_PER_SEC = 1e9;
45
45
  const SEC_DECIMALS = 3;
46
- const generateDocFromSchema = async ({ baseURL, customDirective, diffMethod, docOptions, force, groupByDirective, homepageLocation, linkRoot, loaders: loadersList, loggerModule, metatags, onlyDocDirective, outputDir, prettify, printer: printerModule, printTypeOptions, schemaLocation, skipDocDirective, tmpDir, }) => {
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
48
  await (0, logger_1.default)(loggerModule);
49
49
  const loaders = await (0, graphql_1.getDocumentLoaders)(loadersList);
@@ -73,6 +73,12 @@ const generateDocFromSchema = async ({ baseURL, customDirective, diffMethod, doc
73
73
  const rootTypes = (0, graphql_1.getSchemaMap)(schema);
74
74
  const customDirectives = (0, graphql_1.getCustomDirectives)(rootTypes, customDirective);
75
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
+ }));
76
82
  const printer = await (0, printer_1.getPrinter)(
77
83
  // module mandatory
78
84
  printerModule,
@@ -94,13 +100,13 @@ const generateDocFromSchema = async ({ baseURL, customDirective, diffMethod, doc
94
100
  onlyDocDirectives,
95
101
  printTypeOptions,
96
102
  skipDocDirectives,
97
- });
103
+ }, mdxModule);
98
104
  const renderer = await (0, renderer_1.getRenderer)(printer, outputDir, baseURL, groups, prettify, {
99
105
  ...docOptions,
100
106
  deprecated: printTypeOptions?.deprecated,
101
107
  force,
102
108
  hierarchy: printTypeOptions?.hierarchy,
103
- });
109
+ }, mdxModule);
104
110
  const pages = await Promise.all(Object.keys(rootTypes).map(async (name) => {
105
111
  const typeName = name;
106
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>) => Promise<Printer>;
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) => {
44
44
  try {
45
45
  const { Printer } = await Promise.resolve(`${printerModule}`).then(s => __importStar(require(s)));
46
46
  const { schema, baseURL, linkRoot } = config;
47
- Printer.init(schema, baseURL, linkRoot, { ...options });
47
+ await Printer.init(schema, baseURL, linkRoot, { ...options }, mdxModule);
48
48
  return Printer;
49
49
  }
50
50
  catch {
@@ -1,21 +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>;
16
+ mdxModule: unknown;
17
+ mdxModuleIndexFileSupport: boolean;
10
18
  private readonly printer;
11
- constructor(printer: Printer, outputDir: string, baseURL: string, group: Maybe<SchemaEntitiesGroupMap>, prettify: boolean, docOptions: Maybe<RendererDocOptions>);
12
- generateCategoryMetafile(category: string, dirPath: string, sidebarPosition?: number, styleClass?: string, options?: {
13
- collapsible: boolean;
14
- collapsed: boolean;
15
- }): 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>;
16
22
  generateCategoryMetafileType(type: unknown, name: string, rootTypeName: SchemaEntity): Promise<string>;
17
23
  renderRootTypes(rootTypeName: SchemaEntity, type: unknown): Promise<Maybe<Maybe<Category>[]>>;
18
24
  renderTypeEntities(dirPath: string, name: string, type: unknown): Promise<Maybe<Category>>;
19
25
  renderHomepage(homepageLocation: string): Promise<void>;
20
26
  }
21
- export declare const getRenderer: (printer: Printer, outputDir: string, baseURL: string, group: Maybe<SchemaEntitiesGroupMap>, prettify: boolean, docOptions: Maybe<RendererDocOptions>) => Promise<InstanceType<typeof Renderer>>;
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
- const CATEGORY_YAML = "_category_.yml";
11
- const CATEGORY_STYLE_CLASS = "graphql-markdown-api-section";
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,33 +38,32 @@ class Renderer {
35
38
  baseURL;
36
39
  prettify;
37
40
  options;
41
+ mdxModule;
42
+ mdxModuleIndexFileSupport;
38
43
  printer;
39
- constructor(printer, outputDir, baseURL, group, prettify, docOptions) {
44
+ constructor(printer, outputDir, baseURL, group, prettify, docOptions, mdxModule) {
40
45
  this.printer = printer;
41
46
  this.group = group;
42
47
  this.outputDir = outputDir;
43
48
  this.baseURL = baseURL;
44
49
  this.prettify = prettify;
45
50
  this.options = docOptions;
51
+ this.mdxModule = mdxModule;
52
+ this.mdxModuleIndexFileSupport = this.hasMDXIndexFileSupport(mdxModule);
46
53
  }
47
- async generateCategoryMetafile(category, dirPath, sidebarPosition, styleClass, options = {
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 = {
48
61
  collapsible: true,
49
62
  collapsed: true,
50
63
  }) {
51
- const filePath = (0, node_path_1.join)(dirPath, CATEGORY_YAML);
52
- if (await (0, utils_1.fileExists)(filePath)) {
53
- return;
64
+ if (this.mdxModuleIndexFileSupport) {
65
+ await this.mdxModule.generateIndexMetafile(dirPath, category, { ...options, index: this.options?.index });
54
66
  }
55
- await (0, utils_1.ensureDir)(dirPath);
56
- const label = (0, utils_1.startCase)(category);
57
- const link = this.options && this.options.index !== true
58
- ? "null"
59
- : `\n type: generated-index\n title: '${label} overview'`;
60
- const className = typeof styleClass === "string" ? `className: ${styleClass}\n` : "";
61
- const position = typeof sidebarPosition === "number"
62
- ? sidebarPosition
63
- : SidebarPosition.FIRST;
64
- await (0, utils_1.saveFile)(filePath, `label: ${label}\nposition: ${position}\n${className}link: ${link}\ncollapsible: ${options.collapsible}\ncollapsed: ${options.collapsed}\n`);
65
67
  }
66
68
  async generateCategoryMetafileType(type, name, rootTypeName) {
67
69
  let dirPath = this.outputDir;
@@ -74,20 +76,28 @@ class Renderer {
74
76
  if (useApiGroup) {
75
77
  const typeCat = (0, exports.getApiGroupFolder)(type, useApiGroup);
76
78
  dirPath = (0, node_path_1.join)(dirPath, (0, utils_1.slugify)(typeCat));
77
- await this.generateCategoryMetafile(typeCat, dirPath, undefined, CATEGORY_STYLE_CLASS, { collapsible: false, collapsed: false });
79
+ await this.generateIndexMetafile(dirPath, typeCat, {
80
+ collapsible: false,
81
+ collapsed: false,
82
+ styleClass: CATEGORY_STYLE_CLASS.API,
83
+ });
78
84
  }
79
85
  if (this.options?.deprecated === "group" && (0, graphql_1.isDeprecated)(type)) {
80
86
  dirPath = (0, node_path_1.join)(dirPath, (0, utils_1.slugify)(DEPRECATED));
81
- await this.generateCategoryMetafile(DEPRECATED, dirPath, SidebarPosition.LAST, DEPRECATED);
87
+ await this.generateIndexMetafile(dirPath, DEPRECATED, {
88
+ sidebarPosition: SidebarPosition.LAST,
89
+ styleClass: CATEGORY_STYLE_CLASS.DEPRECATED,
90
+ });
82
91
  }
83
92
  if (this.group &&
84
93
  rootTypeName in this.group &&
85
94
  name in this.group[rootTypeName]) {
86
- dirPath = (0, node_path_1.join)(dirPath, (0, utils_1.slugify)(this.group[rootTypeName][name] ?? ""));
87
- await this.generateCategoryMetafile(this.group[rootTypeName][name] ?? "", dirPath);
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);
88
98
  }
89
99
  dirPath = (0, node_path_1.join)(dirPath, (0, utils_1.slugify)(rootTypeName));
90
- await this.generateCategoryMetafile(rootTypeName, dirPath);
100
+ await this.generateIndexMetafile(dirPath, rootTypeName);
91
101
  return dirPath;
92
102
  }
93
103
  async renderRootTypes(rootTypeName, type) {
@@ -108,10 +118,11 @@ class Renderer {
108
118
  }));
109
119
  }
110
120
  async renderTypeEntities(dirPath, name, type) {
111
- const PageRegex = /(?<category>[A-Za-z0-9-]+)[\\/]+(?<pageId>[A-Za-z0-9-]+).mdx$/;
112
- const PageRegexFlat = /(?<pageId>[A-Za-z0-9-]+).mdx$/;
121
+ const PageRegex = /(?<category>[A-Za-z0-9-]+)[\\/]+(?<pageId>[A-Za-z0-9-]+).mdx?$/;
122
+ const PageRegexFlat = /(?<pageId>[A-Za-z0-9-]+).mdx?$/;
123
+ const extension = this.mdxModule ? "mdx" : "md";
113
124
  const fileName = (0, utils_1.slugify)(name);
114
- const filePath = (0, node_path_1.join)((0, node_path_1.normalize)(dirPath), `${fileName}.mdx`);
125
+ const filePath = (0, node_path_1.join)((0, node_path_1.normalize)(dirPath), `${fileName}.${extension}`);
115
126
  let content;
116
127
  try {
117
128
  content = this.printer.printType(fileName, type, this.options);
@@ -156,8 +167,8 @@ class Renderer {
156
167
  }
157
168
  }
158
169
  exports.Renderer = Renderer;
159
- const getRenderer = async (printer, outputDir, baseURL, group, prettify, docOptions) => {
170
+ const getRenderer = async (printer, outputDir, baseURL, group, prettify, docOptions, mdxModule) => {
160
171
  await (0, utils_1.ensureDir)(outputDir, { forceEmpty: docOptions?.force });
161
- return new Renderer(printer, outputDir, baseURL, group, prettify, docOptions);
172
+ return new Renderer(printer, outputDir, baseURL, group, prettify, docOptions, mdxModule);
162
173
  };
163
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.13.0",
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.5",
66
+ "@graphql-markdown/graphql": "^1.1.6",
67
67
  "@graphql-markdown/logger": "^1.0.5",
68
- "@graphql-markdown/utils": "^1.7.1"
68
+ "@graphql-markdown/utils": "^1.8.0"
69
69
  },
70
70
  "peerDependencies": {
71
- "@graphql-markdown/diff": "^1.1.9",
72
- "@graphql-markdown/helpers": "^1.0.8",
73
- "@graphql-markdown/printer-legacy": "^1.10.0",
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.5.0"
77
+ "@graphql-markdown/types": "^1.7.0"
78
78
  },
79
79
  "peerDependenciesMeta": {
80
80
  "@graphql-markdown/printer-legacy": {