@graphql-markdown/core 1.13.0 → 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
  };
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,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) {
@@ -94,13 +95,13 @@ const generateDocFromSchema = async ({ baseURL, customDirective, diffMethod, doc
94
95
  onlyDocDirectives,
95
96
  printTypeOptions,
96
97
  skipDocDirectives,
97
- });
98
+ }, mdxParser);
98
99
  const renderer = await (0, renderer_1.getRenderer)(printer, outputDir, baseURL, groups, prettify, {
99
100
  ...docOptions,
100
101
  deprecated: printTypeOptions?.deprecated,
101
102
  force,
102
103
  hierarchy: printTypeOptions?.hierarchy,
103
- });
104
+ }, hasMDXSupport);
104
105
  const pages = await Promise.all(Object.keys(rootTypes).map(async (name) => {
105
106
  const typeName = name;
106
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.13.0",
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.10.0",
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.5.0"
77
+ "@graphql-markdown/types": "^1.6.0"
78
78
  },
79
79
  "peerDependenciesMeta": {
80
80
  "@graphql-markdown/printer-legacy": {