@graphql-markdown/core 1.7.0-next.0 → 1.7.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
@@ -11,16 +11,22 @@ export declare enum DeprecatedOption {
11
11
  export declare const DOCS_URL: "https://graphql-markdown.github.io/docs";
12
12
  export declare const PACKAGE_NAME: "@graphql-markdown/docusaurus";
13
13
  export declare const ASSET_HOMEPAGE_LOCATION: string;
14
- export declare const DEFAULT_OPTIONS: Required<Omit<ConfigOptions, "customDirective" | "groupByDirective" | "loaders">> & {
15
- groupByDirective: Maybe<GroupByDirectiveOptions>;
14
+ export declare const DEFAULT_OPTIONS: Required<Omit<ConfigOptions, "customDirective" | "groupByDirective" | "loaders" | "metatags">> & {
16
15
  customDirective: Maybe<CustomDirective>;
16
+ groupByDirective: Maybe<GroupByDirectiveOptions>;
17
17
  loaders: Maybe<LoaderOption>;
18
+ metatags: Maybe<Record<string, string>>[];
19
+ };
20
+ export declare const getDocDirective: (name: Maybe<DirectiveName>) => DirectiveName;
21
+ export declare const getOnlyDocDirectives: (cliOpts: Maybe<CliOptions>, configFileOpts: Maybe<Pick<ConfigOptions, "onlyDocDirective">>) => DirectiveName[];
22
+ export declare const getSkipDocDirectives: (cliOpts: Maybe<CliOptions>, configFileOpts: Maybe<Pick<ConfigOptions, "printTypeOptions" | "skipDocDirective">>) => DirectiveName[];
23
+ export declare const getVisibilityDirectives: (cliOpts: Maybe<CliOptions>, configFileOpts: Maybe<Pick<ConfigOptions, "onlyDocDirective" | "printTypeOptions" | "skipDocDirective">>) => {
24
+ onlyDocDirective: DirectiveName[];
25
+ skipDocDirective: DirectiveName[];
18
26
  };
19
- export declare function buildConfig(configFileOpts: Maybe<ConfigOptions>, cliOpts: Maybe<CliOptions>, id?: Maybe<string>): Promise<Options>;
20
- export declare function getCustomDirectives(customDirectiveOptions: Maybe<CustomDirective>, skipDocDirective?: Maybe<DirectiveName[]>): Maybe<CustomDirective>;
21
- export declare function getDiffMethod(diff: TypeDiffMethod, force?: boolean): TypeDiffMethod;
22
- export declare function getDocOptions(cliOpts: Maybe<CliOptions>, configOptions: Maybe<ConfigDocOptions>): Required<ConfigDocOptions>;
23
- export declare function getPrintTypeOptions(cliOpts: Maybe<CliOptions>, configOptions: Maybe<ConfigPrintTypeOptions>): Required<ConfigPrintTypeOptions>;
24
- export declare function getSkipDocDirectives(cliOpts: Maybe<CliOptions>, configFileOpts: Maybe<Pick<ConfigOptions, "printTypeOptions" | "skipDocDirective">>): DirectiveName[];
25
- export declare function getSkipDocDirective(name: Maybe<DirectiveName>): DirectiveName;
26
- export declare function parseGroupByOption(groupOptions: unknown): Maybe<GroupByDirectiveOptions>;
27
+ export declare const getCustomDirectives: (customDirectiveOptions: Maybe<CustomDirective>, skipDocDirective?: Maybe<DirectiveName[]>) => Maybe<CustomDirective>;
28
+ export declare const getDiffMethod: (diff: TypeDiffMethod, force?: boolean) => TypeDiffMethod;
29
+ export declare const getDocOptions: (cliOpts: Maybe<CliOptions>, configOptions: Maybe<ConfigDocOptions>) => Required<ConfigDocOptions>;
30
+ export declare const getPrintTypeOptions: (cliOpts: Maybe<CliOptions>, configOptions: Maybe<ConfigPrintTypeOptions>) => Required<ConfigPrintTypeOptions>;
31
+ export declare const parseGroupByOption: (groupOptions: unknown) => Maybe<GroupByDirectiveOptions>;
32
+ export declare const buildConfig: (configFileOpts: Maybe<ConfigOptions>, cliOpts: Maybe<CliOptions>, id?: Maybe<string>) => Promise<Options>;
package/dist/config.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseGroupByOption = exports.getSkipDocDirective = exports.getSkipDocDirectives = exports.getPrintTypeOptions = exports.getDocOptions = exports.getDiffMethod = exports.getCustomDirectives = exports.buildConfig = 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.getDocOptions = 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;
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");
@@ -32,6 +32,7 @@ exports.DEFAULT_OPTIONS = {
32
32
  homepage: exports.ASSET_HOMEPAGE_LOCATION,
33
33
  linkRoot: "/",
34
34
  loaders: undefined,
35
+ metatags: [],
35
36
  pretty: false,
36
37
  printer: "@graphql-markdown/printer-legacy",
37
38
  printTypeOptions: {
@@ -45,42 +46,52 @@ exports.DEFAULT_OPTIONS = {
45
46
  schema: "./schema.graphql",
46
47
  tmpDir: (0, node_path_1.join)((0, node_os_1.tmpdir)(), exports.PACKAGE_NAME),
47
48
  skipDocDirective: [],
49
+ onlyDocDirective: [],
48
50
  };
49
- async function buildConfig(configFileOpts, cliOpts, id = "default") {
50
- if (!cliOpts) {
51
- cliOpts = {};
51
+ const getDocDirective = (name) => {
52
+ const OPTION_REGEX = /^@(?<directive>\w+)$/;
53
+ if (typeof name !== "string" || !OPTION_REGEX.test(name)) {
54
+ throw new Error(`Invalid "${name}"`);
52
55
  }
53
- const graphqlConfig = await (0, graphql_config_1.loadConfiguration)(id);
54
- const config = {
55
- ...exports.DEFAULT_OPTIONS,
56
- ...graphqlConfig,
57
- ...configFileOpts,
58
- };
59
- const baseURL = cliOpts.base ?? config.baseURL;
60
- const skipDocDirective = getSkipDocDirectives(cliOpts, config);
61
- return {
62
- baseURL,
63
- customDirective: getCustomDirectives(config.customDirective, skipDocDirective),
64
- diffMethod: getDiffMethod(cliOpts.diff ?? config.diffMethod, cliOpts.force),
65
- docOptions: getDocOptions(cliOpts, config.docOptions),
66
- groupByDirective: parseGroupByOption(cliOpts.groupByDirective) ?? config.groupByDirective,
67
- homepageLocation: cliOpts.homepage ?? config.homepage ?? exports.DEFAULT_OPTIONS.homepage,
68
- id: id ?? exports.DEFAULT_OPTIONS.id,
69
- linkRoot: cliOpts.link ?? config.linkRoot ?? exports.DEFAULT_OPTIONS.linkRoot,
70
- loaders: config.loaders,
71
- outputDir: (0, node_path_1.join)(cliOpts.root ?? config.rootPath, baseURL),
72
- prettify: cliOpts.pretty ?? config.pretty ?? exports.DEFAULT_OPTIONS.pretty,
73
- printer: (config.printer ?? exports.DEFAULT_OPTIONS.printer),
74
- printTypeOptions: getPrintTypeOptions(cliOpts, config.printTypeOptions),
75
- schemaLocation: cliOpts.schema ?? config.schema ?? exports.DEFAULT_OPTIONS.schema,
76
- skipDocDirective,
77
- tmpDir: cliOpts.tmp ?? config.tmpDir ?? exports.DEFAULT_OPTIONS.tmpDir,
78
- };
79
- }
80
- exports.buildConfig = buildConfig;
81
- function getCustomDirectives(customDirectiveOptions, skipDocDirective) {
82
- if (typeof customDirectiveOptions === "undefined" ||
83
- customDirectiveOptions === null ||
56
+ const { groups: { directive }, } = OPTION_REGEX.exec(name);
57
+ return directive;
58
+ };
59
+ exports.getDocDirective = getDocDirective;
60
+ const getOnlyDocDirectives = (cliOpts, configFileOpts) => {
61
+ const directiveList = [].concat((cliOpts?.only ?? []), (configFileOpts?.onlyDocDirective ?? []));
62
+ const onlyDirectives = directiveList.map((directiveName) => {
63
+ return (0, exports.getDocDirective)(directiveName);
64
+ });
65
+ return onlyDirectives;
66
+ };
67
+ exports.getOnlyDocDirectives = getOnlyDocDirectives;
68
+ const getSkipDocDirectives = (cliOpts, configFileOpts) => {
69
+ const directiveList = [].concat((cliOpts?.skip ?? []), (configFileOpts?.skipDocDirective ?? []));
70
+ const skipDirectives = directiveList.map((directiveName) => {
71
+ return (0, exports.getDocDirective)(directiveName);
72
+ });
73
+ if ((configFileOpts &&
74
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
75
+ configFileOpts.printTypeOptions?.deprecated === DeprecatedOption.SKIP) ||
76
+ (cliOpts && cliOpts.deprecated === DeprecatedOption.SKIP)) {
77
+ skipDirectives.push("deprecated");
78
+ }
79
+ return skipDirectives;
80
+ };
81
+ exports.getSkipDocDirectives = getSkipDocDirectives;
82
+ const getVisibilityDirectives = (cliOpts, configFileOpts) => {
83
+ const skipDocDirective = (0, exports.getSkipDocDirectives)(cliOpts, configFileOpts);
84
+ const onlyDocDirective = (0, exports.getOnlyDocDirectives)(cliOpts, configFileOpts);
85
+ if (onlyDocDirective.some((directiveName) => {
86
+ return skipDocDirective.includes(directiveName);
87
+ })) {
88
+ throw new Error("The same directive cannot be declared in 'onlyDocDirective' and 'skipDocDirective'.");
89
+ }
90
+ return { onlyDocDirective, skipDocDirective };
91
+ };
92
+ exports.getVisibilityDirectives = getVisibilityDirectives;
93
+ const getCustomDirectives = (customDirectiveOptions, skipDocDirective) => {
94
+ if (!customDirectiveOptions ||
84
95
  Object.keys(customDirectiveOptions).length === 0) {
85
96
  return undefined;
86
97
  }
@@ -98,26 +109,28 @@ function getCustomDirectives(customDirectiveOptions, skipDocDirective) {
98
109
  return Object.keys(customDirectiveOptions).length === 0
99
110
  ? undefined
100
111
  : customDirectiveOptions;
101
- }
112
+ };
102
113
  exports.getCustomDirectives = getCustomDirectives;
103
- function getDiffMethod(diff, force = false) {
114
+ const getDiffMethod = (diff, force = false) => {
104
115
  return force
105
116
  ? DiffMethod.FORCE
106
117
  : diff.toLocaleUpperCase();
107
- }
118
+ };
108
119
  exports.getDiffMethod = getDiffMethod;
109
- function getDocOptions(cliOpts, configOptions) {
120
+ const getDocOptions = (cliOpts, configOptions) => {
110
121
  return {
111
122
  pagination: (!cliOpts?.noPagination && configOptions?.pagination) ??
112
123
  exports.DEFAULT_OPTIONS.docOptions.pagination,
113
124
  toc: (!cliOpts?.noToc && configOptions?.toc) ??
114
125
  exports.DEFAULT_OPTIONS.docOptions.toc,
115
- index: (cliOpts?.index || configOptions?.index) ??
126
+ index:
127
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
128
+ (cliOpts?.index || configOptions?.index) ??
116
129
  exports.DEFAULT_OPTIONS.docOptions.index,
117
130
  };
118
- }
131
+ };
119
132
  exports.getDocOptions = getDocOptions;
120
- function getPrintTypeOptions(cliOpts, configOptions) {
133
+ const getPrintTypeOptions = (cliOpts, configOptions) => {
121
134
  return {
122
135
  codeSection: (!cliOpts?.noCode && configOptions?.codeSection) ??
123
136
  exports.DEFAULT_OPTIONS.printTypeOptions.codeSection,
@@ -131,36 +144,16 @@ function getPrintTypeOptions(cliOpts, configOptions) {
131
144
  typeBadges: (!cliOpts?.noTypeBadges && configOptions?.typeBadges) ??
132
145
  exports.DEFAULT_OPTIONS.printTypeOptions.typeBadges,
133
146
  };
134
- }
147
+ };
135
148
  exports.getPrintTypeOptions = getPrintTypeOptions;
136
- function getSkipDocDirectives(cliOpts, configFileOpts) {
137
- const directiveList = [].concat((cliOpts?.skip ?? []), (configFileOpts?.skipDocDirective ?? []));
138
- const skipDirectives = directiveList.map((option) => getSkipDocDirective(option));
139
- if ((configFileOpts &&
140
- configFileOpts.printTypeOptions?.deprecated === DeprecatedOption.SKIP) ||
141
- (cliOpts && cliOpts.deprecated === DeprecatedOption.SKIP)) {
142
- skipDirectives.push("deprecated");
143
- }
144
- return skipDirectives;
145
- }
146
- exports.getSkipDocDirectives = getSkipDocDirectives;
147
- function getSkipDocDirective(name) {
148
- const OPTION_REGEX = /^@(?<directive>\w+)$/;
149
- if (typeof name !== "string" || !OPTION_REGEX.test(name)) {
150
- throw new Error(`Invalid "${name}"`);
151
- }
152
- const { groups: { directive }, } = OPTION_REGEX.exec(name);
153
- return directive;
154
- }
155
- exports.getSkipDocDirective = getSkipDocDirective;
156
- function parseGroupByOption(groupOptions) {
149
+ const parseGroupByOption = (groupOptions) => {
157
150
  const DEFAULT_GROUP = "Miscellaneous";
158
151
  const OPTION_REGEX = /^@(?<directive>\w+)\((?<field>\w+)(?:\|=(?<fallback>\w+))?\)/;
159
152
  if (typeof groupOptions !== "string") {
160
153
  return undefined;
161
154
  }
162
155
  const parsedOptions = OPTION_REGEX.exec(groupOptions);
163
- if (typeof parsedOptions === "undefined" || parsedOptions == null) {
156
+ if (typeof parsedOptions === "undefined" || parsedOptions === null) {
164
157
  throw new Error(`Invalid "${groupOptions}"`);
165
158
  }
166
159
  if (!("groups" in parsedOptions)) {
@@ -168,5 +161,39 @@ function parseGroupByOption(groupOptions) {
168
161
  }
169
162
  const { directive, field, fallback = DEFAULT_GROUP, } = parsedOptions.groups;
170
163
  return { directive, field, fallback };
171
- }
164
+ };
172
165
  exports.parseGroupByOption = parseGroupByOption;
166
+ const buildConfig = async (configFileOpts, cliOpts, id = "default") => {
167
+ if (!cliOpts) {
168
+ cliOpts = {};
169
+ }
170
+ const graphqlConfig = await (0, graphql_config_1.loadConfiguration)(id);
171
+ const config = {
172
+ ...exports.DEFAULT_OPTIONS,
173
+ ...graphqlConfig,
174
+ ...configFileOpts,
175
+ };
176
+ const baseURL = cliOpts.base ?? config.baseURL;
177
+ const { onlyDocDirective, skipDocDirective } = (0, exports.getVisibilityDirectives)(cliOpts, config);
178
+ return {
179
+ baseURL,
180
+ customDirective: (0, exports.getCustomDirectives)(config.customDirective, skipDocDirective),
181
+ diffMethod: (0, exports.getDiffMethod)(cliOpts.diff ?? config.diffMethod, cliOpts.force),
182
+ docOptions: (0, exports.getDocOptions)(cliOpts, config.docOptions),
183
+ groupByDirective: (0, exports.parseGroupByOption)(cliOpts.groupByDirective) ?? config.groupByDirective,
184
+ homepageLocation: cliOpts.homepage ?? config.homepage ?? exports.DEFAULT_OPTIONS.homepage,
185
+ id: id ?? exports.DEFAULT_OPTIONS.id,
186
+ linkRoot: cliOpts.link ?? config.linkRoot ?? exports.DEFAULT_OPTIONS.linkRoot,
187
+ loaders: config.loaders,
188
+ metatags: config.metatags ?? exports.DEFAULT_OPTIONS.metatags,
189
+ onlyDocDirective,
190
+ outputDir: (0, node_path_1.join)(cliOpts.root ?? config.rootPath, baseURL),
191
+ prettify: cliOpts.pretty ?? config.pretty ?? exports.DEFAULT_OPTIONS.pretty,
192
+ printer: (config.printer ?? exports.DEFAULT_OPTIONS.printer),
193
+ printTypeOptions: (0, exports.getPrintTypeOptions)(cliOpts, config.printTypeOptions),
194
+ schemaLocation: cliOpts.schema ?? config.schema ?? exports.DEFAULT_OPTIONS.schema,
195
+ skipDocDirective,
196
+ tmpDir: cliOpts.tmp ?? config.tmpDir ?? exports.DEFAULT_OPTIONS.tmpDir,
197
+ };
198
+ };
199
+ exports.buildConfig = buildConfig;
package/dist/diff.js CHANGED
@@ -25,7 +25,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.hasChanges = void 0;
27
27
  const logger_1 = require("@graphql-markdown/logger");
28
- const logger = (0, logger_1.Logger)();
29
28
  const hasChanges = async (schema, tmpDir, diffMethod, diffModule = "@graphql-markdown/diff") => {
30
29
  if (typeof diffMethod !== "string" || typeof diffModule !== "string") {
31
30
  return true;
@@ -35,7 +34,7 @@ const hasChanges = async (schema, tmpDir, diffMethod, diffModule = "@graphql-mar
35
34
  return await checkSchemaChanges(schema, tmpDir, diffMethod);
36
35
  }
37
36
  catch (error) {
38
- logger.warn(`Cannot find module '${diffModule}' from @graphql-markdown/core!`);
37
+ (0, logger_1.log)(`Cannot find module '${diffModule}' from @graphql-markdown/core!`, logger_1.LogLevel.warn);
39
38
  return true;
40
39
  }
41
40
  };
@@ -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, outputDir, prettify, printer: printerModule, printTypeOptions, schemaLocation, skipDocDirective, tmpDir, }: GeneratorOptions) => Promise<void>;
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>;
package/dist/generator.js CHANGED
@@ -9,21 +9,33 @@ const printer_1 = require("./printer");
9
9
  const config_1 = require("./config");
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, outputDir, prettify, printer: printerModule, printTypeOptions, schemaLocation, skipDocDirective, tmpDir, }) => {
12
+ const generateDocFromSchema = async ({ baseURL, customDirective, diffMethod, docOptions, groupByDirective, homepageLocation, linkRoot, loaders: loadersList, loggerModule, metatags, onlyDocDirective, outputDir, prettify, printer: printerModule, printTypeOptions, schemaLocation, skipDocDirective, tmpDir, }) => {
13
13
  const start = process.hrtime.bigint();
14
- const logger = (0, logger_1.Logger)(loggerModule);
14
+ (0, logger_1.Logger)(loggerModule);
15
15
  const loaders = await (0, graphql_1.getDocumentLoaders)(loadersList);
16
16
  if (!loaders) {
17
- logger.error(`An error occurred while loading GraphQL loader.\nCheck your dependencies and configuration.`);
17
+ (0, logger_1.log)(`An error occurred while loading GraphQL loader.\nCheck your dependencies and configuration.`, "error");
18
18
  return;
19
19
  }
20
20
  const schema = await (0, graphql_1.loadSchema)(schemaLocation, loaders);
21
21
  if (diffMethod !== config_1.DiffMethod.NONE) {
22
22
  const changed = await (0, diff_1.hasChanges)(schema, tmpDir, diffMethod);
23
23
  if (!changed) {
24
- logger.info(`No changes detected in schema "${String(schemaLocation)}".`);
24
+ (0, logger_1.log)(`No changes detected in schema "${String(schemaLocation)}".`);
25
25
  }
26
26
  }
27
+ const [onlyDocDirectives, skipDocDirectives] = [
28
+ onlyDocDirective,
29
+ skipDocDirective,
30
+ ].map((directiveList) => {
31
+ return directiveList
32
+ .map((name) => {
33
+ return schema.getDirective(name);
34
+ })
35
+ .filter((directive) => {
36
+ return typeof directive !== "undefined";
37
+ });
38
+ });
27
39
  const rootTypes = (0, graphql_1.getSchemaMap)(schema);
28
40
  const customDirectives = (0, graphql_1.getCustomDirectives)(rootTypes, customDirective);
29
41
  const groups = (0, graphql_1.getGroups)(rootTypes, groupByDirective);
@@ -40,19 +52,23 @@ const generateDocFromSchema = async ({ baseURL, customDirective, diffMethod, doc
40
52
  {
41
53
  customDirectives,
42
54
  groups,
55
+ onlyDocDirectives,
43
56
  printTypeOptions,
44
- skipDocDirective,
57
+ skipDocDirectives,
58
+ metatags,
45
59
  });
46
60
  const renderer = new renderer_1.Renderer(printer, outputDir, baseURL, groups, prettify, {
47
61
  ...docOptions,
48
62
  deprecated: printTypeOptions.deprecated,
49
63
  });
50
- const pages = await Promise.all(Object.keys(rootTypes).map(async (typeName) => renderer.renderRootTypes(typeName, rootTypes[typeName])));
64
+ const pages = await Promise.all(Object.keys(rootTypes).map(async (typeName) => {
65
+ return renderer.renderRootTypes(typeName, rootTypes[typeName]);
66
+ }));
51
67
  await renderer.renderHomepage(homepageLocation);
52
68
  const sidebarPath = await renderer.renderSidebar();
53
69
  const duration = (Number(process.hrtime.bigint() - start) / NS_PER_SEC).toFixed(SEC_DECIMALS);
54
- logger.success(`Documentation successfully generated in "${outputDir}" with base URL "${baseURL}".`);
55
- logger.info(`${pages.flat().length} pages generated in ${duration}s from schema "${String(schemaLocation)}".`);
56
- logger.info(`Remember to update your Docusaurus site's sidebars with "${sidebarPath}".`);
70
+ (0, logger_1.log)(`Documentation successfully generated in "${outputDir}" with base URL "${baseURL}".`, "success");
71
+ (0, logger_1.log)(`${pages.flat().length} pages generated in ${duration}s from schema "${String(schemaLocation)}".`);
72
+ (0, logger_1.log)(`Remember to update your Docusaurus site's sidebars with "${sidebarPath}".`);
57
73
  };
58
74
  exports.generateDocFromSchema = generateDocFromSchema;
@@ -1,16 +1,10 @@
1
- import type { ConfigOptions, GraphQLProjectConfig, LoaderOption, Maybe, PackageOptionsConfig } from "@graphql-markdown/types";
1
+ import type { ExtensionProjectConfig, GraphQLExtensionDeclaration, LoaderOption, Maybe, PackageOptionsConfig } from "@graphql-markdown/types";
2
2
  export declare const EXTENSION_NAME: "graphql-markdown";
3
- export declare const GraphQLConfigExtension: () => {
4
- readonly name: "graphql-markdown";
5
- };
6
- type ThrowOptions = {
3
+ export declare const graphQLConfigExtension: GraphQLExtensionDeclaration;
4
+ interface ThrowOptions {
7
5
  throwOnMissing: boolean;
8
6
  throwOnEmpty: boolean;
9
- };
10
- type Writeable<T> = {
11
- -readonly [P in keyof T]: T[P];
12
- };
13
- export type ExtensionProjectConfig = Omit<ConfigOptions, "schema"> & Writeable<GraphQLProjectConfig>;
7
+ }
14
8
  export declare const setLoaderOptions: (loaders: LoaderOption, options: PackageOptionsConfig) => LoaderOption;
15
9
  export declare const loadConfiguration: (id: Maybe<string>, options?: Maybe<PackageOptionsConfig>, { throwOnMissing, throwOnEmpty }?: ThrowOptions) => Promise<Maybe<Readonly<ExtensionProjectConfig>>>;
16
10
  export {};
@@ -23,12 +23,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.loadConfiguration = exports.setLoaderOptions = exports.GraphQLConfigExtension = exports.EXTENSION_NAME = void 0;
26
+ exports.loadConfiguration = exports.setLoaderOptions = exports.graphQLConfigExtension = exports.EXTENSION_NAME = void 0;
27
27
  const logger_1 = require("@graphql-markdown/logger");
28
- const logger = (0, logger_1.Logger)();
29
28
  exports.EXTENSION_NAME = "graphql-markdown";
30
- const GraphQLConfigExtension = () => ({ name: exports.EXTENSION_NAME });
31
- exports.GraphQLConfigExtension = GraphQLConfigExtension;
29
+ const graphQLConfigExtension = () => {
30
+ return { name: exports.EXTENSION_NAME };
31
+ };
32
+ exports.graphQLConfigExtension = graphQLConfigExtension;
32
33
  const setLoaderOptions = (loaders, options) => {
33
34
  for (const loader in loaders) {
34
35
  if (typeof loaders[loader] === "string") {
@@ -51,20 +52,20 @@ const loadConfiguration = async (id, options, { throwOnMissing, throwOnEmpty } =
51
52
  throwOnMissing: false,
52
53
  throwOnEmpty: false,
53
54
  }) => {
54
- let GraphQLConfig;
55
+ let graphQLConfig;
55
56
  if (typeof id !== "string") {
56
57
  return undefined;
57
58
  }
58
59
  try {
59
- GraphQLConfig = await Promise.resolve().then(() => __importStar(require("graphql-config")));
60
+ graphQLConfig = await Promise.resolve().then(() => __importStar(require("graphql-config")));
60
61
  }
61
62
  catch (error) {
62
- logger.log("Cannot find module 'graphql-config'!");
63
+ (0, logger_1.log)("Cannot find module 'graphql-config'!");
63
64
  return undefined;
64
65
  }
65
- const config = await GraphQLConfig.loadConfig({
66
+ const config = await graphQLConfig.loadConfig({
66
67
  ...options,
67
- extensions: [exports.GraphQLConfigExtension],
68
+ extensions: [exports.graphQLConfigExtension],
68
69
  throwOnMissing,
69
70
  throwOnEmpty,
70
71
  });
package/dist/printer.js CHANGED
@@ -26,10 +26,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.getPrinter = void 0;
27
27
  const getPrinter = async (printerModule, config, options) => {
28
28
  if (typeof printerModule !== "string") {
29
- throw new Error('Invalid printer module name in "printTypeOptions" settings.');
29
+ throw new Error("Invalid printer module name.");
30
30
  }
31
31
  if (!config) {
32
- throw new Error('Invalid printer config in "printTypeOptions" settings.');
32
+ throw new Error("Invalid printer config.");
33
33
  }
34
34
  try {
35
35
  const { Printer } = await Promise.resolve(`${printerModule}`).then(s => __importStar(require(s)));
@@ -38,7 +38,7 @@ const getPrinter = async (printerModule, config, options) => {
38
38
  return Printer;
39
39
  }
40
40
  catch (error) {
41
- throw new Error(`Cannot find module '${printerModule}' defined in "printTypeOptions" settings.`);
41
+ throw new Error(`Cannot find module '${printerModule}'.`);
42
42
  }
43
43
  };
44
44
  exports.getPrinter = getPrinter;
@@ -1,6 +1,5 @@
1
1
  import type { Category, ConfigDocOptions, Maybe, Printer, SchemaEntitiesGroupMap, SchemaEntity, TypeDeprecatedOption } from "@graphql-markdown/types";
2
2
  export declare class Renderer {
3
- private printer;
4
3
  group: Maybe<SchemaEntitiesGroupMap>;
5
4
  outputDir: string;
6
5
  baseURL: string;
@@ -8,6 +7,7 @@ export declare class Renderer {
8
7
  options: Maybe<ConfigDocOptions & {
9
8
  deprecated: TypeDeprecatedOption;
10
9
  }>;
10
+ private readonly printer;
11
11
  constructor(printer: Printer, outputDir: string, baseURL: string, group: Maybe<SchemaEntitiesGroupMap>, prettify: boolean, docOptions: Maybe<ConfigDocOptions & {
12
12
  deprecated: TypeDeprecatedOption;
13
13
  }>);
package/dist/renderer.js CHANGED
@@ -5,21 +5,20 @@ 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 logger = (0, logger_1.Logger)();
9
8
  const SIDEBAR = "sidebar-schema.js";
10
9
  const CATEGORY_YAML = "_category_.yml";
11
- var SIDEBAR_POSITION;
12
- (function (SIDEBAR_POSITION) {
13
- SIDEBAR_POSITION[SIDEBAR_POSITION["FIRST"] = 1] = "FIRST";
14
- SIDEBAR_POSITION[SIDEBAR_POSITION["LAST"] = 999] = "LAST";
15
- })(SIDEBAR_POSITION || (SIDEBAR_POSITION = {}));
10
+ var SidebarPosition;
11
+ (function (SidebarPosition) {
12
+ SidebarPosition[SidebarPosition["FIRST"] = 1] = "FIRST";
13
+ SidebarPosition[SidebarPosition["LAST"] = 999] = "LAST";
14
+ })(SidebarPosition || (SidebarPosition = {}));
16
15
  class Renderer {
17
- printer;
18
16
  group;
19
17
  outputDir;
20
18
  baseURL;
21
19
  prettify;
22
20
  options;
21
+ printer;
23
22
  constructor(printer, outputDir, baseURL, group, prettify, docOptions) {
24
23
  this.printer = printer;
25
24
  this.group = group;
@@ -28,7 +27,7 @@ class Renderer {
28
27
  this.prettify = prettify;
29
28
  this.options = docOptions;
30
29
  }
31
- async generateCategoryMetafile(category, dirPath, sidebarPosition = SIDEBAR_POSITION.FIRST, styleClass) {
30
+ async generateCategoryMetafile(category, dirPath, sidebarPosition = SidebarPosition.FIRST, styleClass) {
32
31
  const filePath = (0, node_path_1.join)(dirPath, CATEGORY_YAML);
33
32
  if (await (0, utils_1.fileExists)(filePath)) {
34
33
  return;
@@ -47,7 +46,7 @@ class Renderer {
47
46
  this.options.deprecated === "group" &&
48
47
  (0, graphql_1.isDeprecated)(type)) {
49
48
  dirPath = (0, node_path_1.join)(dirPath, (0, utils_1.slugify)("deprecated"));
50
- await this.generateCategoryMetafile("deprecated", dirPath, SIDEBAR_POSITION.LAST, "deprecated");
49
+ await this.generateCategoryMetafile("deprecated", dirPath, SidebarPosition.LAST, "deprecated");
51
50
  }
52
51
  if (this.group &&
53
52
  rootTypeName in this.group &&
@@ -68,7 +67,9 @@ class Renderer {
68
67
  const dirPath = await this.generateCategoryMetafileType(type[name], name, rootTypeName);
69
68
  return this.renderTypeEntities(dirPath, name, type[name]);
70
69
  })
71
- .filter((res) => typeof res !== "undefined"));
70
+ .filter((res) => {
71
+ return typeof res !== "undefined";
72
+ }));
72
73
  }
73
74
  async renderTypeEntities(dirPath, name, type) {
74
75
  const PageRegex = /(?<category>[A-Za-z0-9-]+)[\\/]+(?<pageId>[A-Za-z0-9-]+).mdx$/;
@@ -82,14 +83,14 @@ class Renderer {
82
83
  }
83
84
  }
84
85
  catch (error) {
85
- logger.warn(`An error occurred while processing "${type}"`);
86
+ (0, logger_1.log)(`An error occurred while processing "${type}"`, logger_1.LogLevel.warn);
86
87
  return undefined;
87
88
  }
88
89
  await (0, utils_1.saveFile)(filePath, content, this.prettify ? utils_1.prettifyMarkdown : undefined);
89
90
  const pagePath = (0, node_path_1.relative)(this.outputDir, filePath);
90
91
  const page = PageRegex.exec(pagePath);
91
92
  if (!page?.groups) {
92
- logger.warn(`An error occurred while processing file ${filePath} for type "${type}"`);
93
+ (0, logger_1.log)(`An error occurred while processing file ${filePath} for type "${type}"`, logger_1.LogLevel.warn);
93
94
  return undefined;
94
95
  }
95
96
  const slug = utils_1.pathUrl.join(page.groups.category, page.groups.pageId);
package/package.json CHANGED
@@ -5,11 +5,11 @@
5
5
  "bugs": {
6
6
  "url": "https://github.com/graphql-markdown/graphql-markdown/issues"
7
7
  },
8
- "version": "1.7.0-next.0",
8
+ "version": "1.7.0",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "graphql-markdown/graphql-markdown",
12
+ "url": "git+https://github.com/graphql-markdown/graphql-markdown.git",
13
13
  "directory": "packages/core"
14
14
  },
15
15
  "author": {
@@ -62,18 +62,18 @@
62
62
  "clean": "rm -rf ./dist"
63
63
  },
64
64
  "dependencies": {
65
- "@graphql-markdown/graphql": "^1.0.0-next.0",
66
- "@graphql-markdown/logger": "^1.0.0-next.0",
67
- "@graphql-markdown/utils": "^1.6.0-next.0"
65
+ "@graphql-markdown/graphql": "^1.0.0",
66
+ "@graphql-markdown/logger": "^1.0.0",
67
+ "@graphql-markdown/utils": "^1.6.0"
68
68
  },
69
69
  "peerDependencies": {
70
- "@graphql-markdown/diff": "^1.1.0-next.0",
71
- "@graphql-markdown/helpers": "^1.0.0-next.0",
72
- "@graphql-markdown/printer-legacy": "^1.5.0-next.0",
70
+ "@graphql-markdown/diff": "^1.1.0",
71
+ "@graphql-markdown/helpers": "^1.0.0",
72
+ "@graphql-markdown/printer-legacy": "^1.5.0",
73
73
  "graphql-config": "^5.0.2"
74
74
  },
75
75
  "devDependencies": {
76
- "@graphql-markdown/types": "^1.0.0-next.0"
76
+ "@graphql-markdown/types": "^1.0.0"
77
77
  },
78
78
  "peerDependenciesMeta": {
79
79
  "@graphql-markdown/printer-legacy": {