@graphql-markdown/core 1.12.2 → 1.14.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
  };
@@ -33,16 +42,10 @@ export declare const getVisibilityDirectives: (cliOpts: Maybe<CliOptions>, confi
33
42
  };
34
43
  export declare const getCustomDirectives: (customDirectiveOptions: Maybe<CustomDirective>, skipDocDirective?: Maybe<DirectiveName[]>) => Maybe<CustomDirective>;
35
44
  export declare const getDiffMethod: (diff: TypeDiffMethod, force?: boolean) => TypeDiffMethod;
36
- export declare const parseDeprecatedDocOptions: (cliOpts: Maybe<DeprecatedCliOptions>, configOptions: Maybe<DeprecatedConfigDocOptions>) => Partial<{
37
- pagination_next: null;
38
- pagination_prev: null;
39
- hide_table_of_contents: boolean;
40
- }>;
41
- export declare const getDocOptions: (cliOpts?: Maybe<CliOptions & DeprecatedCliOptions>, configOptions?: Maybe<ConfigDocOptions & DeprecatedConfigDocOptions>) => Required<ConfigDocOptions>;
45
+ export declare const parseDeprecatedDocOptions: (_cliOpts: Maybe<Omit<DeprecatedCliOptions, "never">>, _configOptions: Maybe<Omit<DeprecatedConfigDocOptions, "never">>) => Record<string, never>;
46
+ export declare const getDocOptions: (cliOpts?: Maybe<CliOptions & Omit<DeprecatedCliOptions, "never">>, configOptions?: Maybe<ConfigDocOptions & Omit<DeprecatedConfigDocOptions, "never">>) => Required<ConfigDocOptions>;
42
47
  export declare const getTypeHierarchyOption: (cliOption?: Maybe<TypeHierarchyValueType>, configOption?: Maybe<TypeHierarchyType>) => Maybe<TypeHierarchyObjectType>;
43
- export declare const parseDeprecatedPrintTypeOptions: (cliOpts: Maybe<DeprecatedCliOptions>, configOptions: Maybe<DeprecatedConfigPrintTypeOptions>) => Partial<{
44
- hierarchy: TypeHierarchyType;
45
- }>;
46
- export declare const getPrintTypeOptions: (cliOpts: Maybe<CliOptions & DeprecatedCliOptions>, configOptions: Maybe<ConfigPrintTypeOptions & DeprecatedConfigPrintTypeOptions>) => Required<ConfigPrintTypeOptions>;
48
+ export declare const parseDeprecatedPrintTypeOptions: (_cliOpts: Maybe<Omit<DeprecatedCliOptions, "never">>, _configOptions: Maybe<Omit<DeprecatedConfigPrintTypeOptions, "never">>) => Record<string, never>;
49
+ export declare const getPrintTypeOptions: (cliOpts: Maybe<CliOptions & Omit<DeprecatedCliOptions, "never">>, configOptions: Maybe<ConfigPrintTypeOptions & Omit<DeprecatedConfigPrintTypeOptions, "never">>) => Required<ConfigPrintTypeOptions>;
47
50
  export declare const parseGroupByOption: (groupOptions: unknown) => Maybe<GroupByDirectiveOptions>;
48
51
  export declare const buildConfig: (configFileOpts: Maybe<ConfigOptions>, cliOpts?: Maybe<CliOptions>, id?: Maybe<string>) => Promise<Options>;
package/dist/config.js CHANGED
@@ -4,18 +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
- const logger_1 = require("@graphql-markdown/logger");
7
+ /**
8
+ * @public
9
+ */
8
10
  var TypeHierarchy;
9
11
  (function (TypeHierarchy) {
10
12
  TypeHierarchy["API"] = "api";
11
13
  TypeHierarchy["ENTITY"] = "entity";
12
14
  TypeHierarchy["FLAT"] = "flat";
13
15
  })(TypeHierarchy || (exports.TypeHierarchy = TypeHierarchy = {}));
16
+ /**
17
+ * @public
18
+ */
14
19
  var DiffMethod;
15
20
  (function (DiffMethod) {
16
21
  DiffMethod["NONE"] = "NONE";
17
22
  DiffMethod["FORCE"] = "FORCE";
18
23
  })(DiffMethod || (exports.DiffMethod = DiffMethod = {}));
24
+ /**
25
+ * @public
26
+ */
19
27
  var DeprecatedOption;
20
28
  (function (DeprecatedOption) {
21
29
  DeprecatedOption["DEFAULT"] = "default";
@@ -126,38 +134,23 @@ const getDiffMethod = (diff, force = false) => {
126
134
  : diff.toLocaleUpperCase();
127
135
  };
128
136
  exports.getDiffMethod = getDiffMethod;
129
- const parseDeprecatedDocOptions = (cliOpts, configOptions) => {
130
- // deprecated, replaced by frontMatter
131
- let pagination;
132
- if ((typeof cliOpts?.noPagination !== "undefined" && cliOpts.noPagination) ||
133
- (typeof configOptions?.pagination !== "undefined" &&
134
- !configOptions.pagination)) {
135
- pagination = { pagination_next: null, pagination_prev: null };
136
- (0, logger_1.log)("Doc option `pagination` is deprecated. Use `frontMatter: { pagination_next: null, pagination_prev: null }` instead.", "warn");
137
- }
138
- // deprecated, replaced by frontMatter
139
- let toc;
140
- if (typeof cliOpts?.noToc !== "undefined" ||
141
- typeof configOptions?.toc !== "undefined") {
142
- toc = {
143
- hide_table_of_contents: cliOpts?.noToc === true || configOptions?.toc === false,
144
- };
145
- (0, logger_1.log)("Doc option `toc` is deprecated. Use `frontMatter: { hide_table_of_contents: true | false }` instead.", "warn");
146
- }
147
- return { ...pagination, ...toc };
137
+ const parseDeprecatedDocOptions = (_cliOpts, _configOptions) => {
138
+ return {};
148
139
  };
149
140
  exports.parseDeprecatedDocOptions = parseDeprecatedDocOptions;
150
141
  const getDocOptions = (cliOpts, configOptions) => {
151
142
  const deprecated = (0, exports.parseDeprecatedDocOptions)(cliOpts, configOptions);
143
+ const index = typeof cliOpts?.index === "boolean"
144
+ ? cliOpts.index
145
+ : typeof configOptions?.index === "boolean"
146
+ ? configOptions.index
147
+ : exports.DEFAULT_OPTIONS.docOptions.index;
152
148
  return {
153
149
  frontMatter: {
154
150
  ...deprecated,
155
151
  ...configOptions?.frontMatter,
156
152
  },
157
- index:
158
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
159
- (cliOpts?.index || configOptions?.index) ??
160
- exports.DEFAULT_OPTIONS.docOptions.index,
153
+ index,
161
154
  };
162
155
  };
163
156
  exports.getDocOptions = getDocOptions;
@@ -192,27 +185,8 @@ const getTypeHierarchyOption = (cliOption, configOption) => {
192
185
  return cliHierarchy ?? configHierarchy ?? exports.DEFAULT_HIERARCHY;
193
186
  };
194
187
  exports.getTypeHierarchyOption = getTypeHierarchyOption;
195
- const parseDeprecatedPrintTypeOptions = (cliOpts, configOptions) => {
196
- // deprecated, replaced by hierarchy
197
- let option;
198
- if (typeof cliOpts?.noApiGroup !== "undefined" && cliOpts.noApiGroup) {
199
- option = { hierarchy: TypeHierarchy.ENTITY };
200
- (0, logger_1.log)("Type option `noApiGroup` is deprecated. Use `hierarchy: 'entity'` instead.", "warn");
201
- }
202
- else if (typeof configOptions?.useApiGroup !== "undefined") {
203
- if (typeof configOptions.useApiGroup === "object") {
204
- option = {
205
- hierarchy: { [TypeHierarchy.API]: { ...configOptions.useApiGroup } },
206
- };
207
- }
208
- else {
209
- option = configOptions.useApiGroup
210
- ? { hierarchy: TypeHierarchy.API }
211
- : { hierarchy: TypeHierarchy.ENTITY };
212
- }
213
- (0, logger_1.log)("Type option `useApiGroup` is deprecated. Use `hierarchy: 'api'` instead.", "warn");
214
- }
215
- return { ...option };
188
+ const parseDeprecatedPrintTypeOptions = (_cliOpts, _configOptions) => {
189
+ return {};
216
190
  };
217
191
  exports.parseDeprecatedPrintTypeOptions = parseDeprecatedPrintTypeOptions;
218
192
  const getPrintTypeOptions = (cliOpts, configOptions) => {
@@ -277,6 +251,7 @@ const buildConfig = async (configFileOpts, cliOpts, id = "default") => {
277
251
  id: id ?? exports.DEFAULT_OPTIONS.id,
278
252
  linkRoot: cliOpts.link ?? config.linkRoot ?? exports.DEFAULT_OPTIONS.linkRoot,
279
253
  loaders: config.loaders,
254
+ mdxParser: cliOpts.mdxParser ?? config.mdxParser,
280
255
  metatags: config.metatags ?? exports.DEFAULT_OPTIONS.metatags,
281
256
  onlyDocDirective,
282
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,8 +43,9 @@ 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
+ const hasMDXSupport = mdxParser ? true : false;
48
49
  await (0, logger_1.default)(loggerModule);
49
50
  const loaders = await (0, graphql_1.getDocumentLoaders)(loadersList);
50
51
  if (!loaders) {
@@ -86,17 +87,21 @@ const generateDocFromSchema = async ({ baseURL, customDirective, diffMethod, doc
86
87
  {
87
88
  customDirectives,
88
89
  groups,
90
+ meta: {
91
+ generatorFrameworkName: docOptions?.generatorFrameworkName,
92
+ generatorFrameworkVersion: docOptions?.generatorFrameworkVersion,
93
+ },
94
+ metatags,
89
95
  onlyDocDirectives,
90
96
  printTypeOptions,
91
97
  skipDocDirectives,
92
- metatags,
93
- });
98
+ }, mdxParser);
94
99
  const renderer = await (0, renderer_1.getRenderer)(printer, outputDir, baseURL, groups, prettify, {
95
100
  ...docOptions,
96
101
  deprecated: printTypeOptions?.deprecated,
97
102
  force,
98
103
  hierarchy: printTypeOptions?.hierarchy,
99
- });
104
+ }, hasMDXSupport);
100
105
  const pages = await Promise.all(Object.keys(rootTypes).map(async (name) => {
101
106
  const typeName = name;
102
107
  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>, mdxParser?: PackageName) => 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, mdxParser) => {
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 }, mdxParser);
48
48
  return Printer;
49
49
  }
50
50
  catch {
@@ -7,8 +7,9 @@ export declare class Renderer {
7
7
  baseURL: string;
8
8
  prettify: boolean;
9
9
  options: Maybe<RendererDocOptions>;
10
+ hasMDXSupport: boolean;
10
11
  private readonly printer;
11
- constructor(printer: Printer, outputDir: string, baseURL: string, group: Maybe<SchemaEntitiesGroupMap>, prettify: boolean, docOptions: Maybe<RendererDocOptions>);
12
+ constructor(printer: Printer, outputDir: string, baseURL: string, group: Maybe<SchemaEntitiesGroupMap>, prettify: boolean, docOptions: Maybe<RendererDocOptions>, mdx?: boolean);
12
13
  generateCategoryMetafile(category: string, dirPath: string, sidebarPosition?: number, styleClass?: string, options?: {
13
14
  collapsible: boolean;
14
15
  collapsed: boolean;
@@ -18,4 +19,4 @@ export declare class Renderer {
18
19
  renderTypeEntities(dirPath: string, name: string, type: unknown): Promise<Maybe<Category>>;
19
20
  renderHomepage(homepageLocation: string): Promise<void>;
20
21
  }
21
- export declare const getRenderer: (printer: Printer, outputDir: string, baseURL: string, group: Maybe<SchemaEntitiesGroupMap>, prettify: boolean, docOptions: Maybe<RendererDocOptions>) => Promise<InstanceType<typeof Renderer>>;
22
+ export declare const getRenderer: (printer: Printer, outputDir: string, baseURL: string, group: Maybe<SchemaEntitiesGroupMap>, prettify: boolean, docOptions: Maybe<RendererDocOptions>, mdx?: boolean) => Promise<InstanceType<typeof Renderer>>;
package/dist/renderer.js CHANGED
@@ -35,14 +35,16 @@ class Renderer {
35
35
  baseURL;
36
36
  prettify;
37
37
  options;
38
+ hasMDXSupport;
38
39
  printer;
39
- constructor(printer, outputDir, baseURL, group, prettify, docOptions) {
40
+ constructor(printer, outputDir, baseURL, group, prettify, docOptions, mdx = false) {
40
41
  this.printer = printer;
41
42
  this.group = group;
42
43
  this.outputDir = outputDir;
43
44
  this.baseURL = baseURL;
44
45
  this.prettify = prettify;
45
46
  this.options = docOptions;
47
+ this.hasMDXSupport = mdx;
46
48
  }
47
49
  async generateCategoryMetafile(category, dirPath, sidebarPosition, styleClass, options = {
48
50
  collapsible: true,
@@ -108,10 +110,11 @@ class Renderer {
108
110
  }));
109
111
  }
110
112
  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$/;
113
+ const PageRegex = /(?<category>[A-Za-z0-9-]+)[\\/]+(?<pageId>[A-Za-z0-9-]+).mdx?$/;
114
+ const PageRegexFlat = /(?<pageId>[A-Za-z0-9-]+).mdx?$/;
115
+ const extension = this.hasMDXSupport ? "mdx" : "md";
113
116
  const fileName = (0, utils_1.slugify)(name);
114
- const filePath = (0, node_path_1.join)((0, node_path_1.normalize)(dirPath), `${fileName}.mdx`);
117
+ const filePath = (0, node_path_1.join)((0, node_path_1.normalize)(dirPath), `${fileName}.${extension}`);
115
118
  let content;
116
119
  try {
117
120
  content = this.printer.printType(fileName, type, this.options);
@@ -156,8 +159,8 @@ class Renderer {
156
159
  }
157
160
  }
158
161
  exports.Renderer = Renderer;
159
- const getRenderer = async (printer, outputDir, baseURL, group, prettify, docOptions) => {
162
+ const getRenderer = async (printer, outputDir, baseURL, group, prettify, docOptions, mdx = false) => {
160
163
  await (0, utils_1.ensureDir)(outputDir, { forceEmpty: docOptions?.force });
161
- return new Renderer(printer, outputDir, baseURL, group, prettify, docOptions);
164
+ return new Renderer(printer, outputDir, baseURL, group, prettify, docOptions, mdx);
162
165
  };
163
166
  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.12.2",
8
+ "version": "1.14.0",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
@@ -70,11 +70,11 @@
70
70
  "peerDependencies": {
71
71
  "@graphql-markdown/diff": "^1.1.9",
72
72
  "@graphql-markdown/helpers": "^1.0.8",
73
- "@graphql-markdown/printer-legacy": "^1.9.1",
73
+ "@graphql-markdown/printer-legacy": "^1.11.0",
74
74
  "graphql-config": "^5.1.0"
75
75
  },
76
76
  "devDependencies": {
77
- "@graphql-markdown/types": "^1.4.2"
77
+ "@graphql-markdown/types": "^1.6.0"
78
78
  },
79
79
  "peerDependenciesMeta": {
80
80
  "@graphql-markdown/printer-legacy": {