@graphql-markdown/core 1.0.1 → 1.1.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/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.0.1",
8
+ "version": "1.1.0",
9
9
  "license": "MIT",
10
10
  "main": "src/index.js",
11
11
  "repository": {
@@ -32,9 +32,9 @@
32
32
  "@graphql-markdown/utils": "^1.0.1"
33
33
  },
34
34
  "peerDependencies": {
35
- "@graphql-markdown/printer-legacy": "^1.0.0",
36
- "@graphql-markdown/diff": "^1.0.0",
37
- "prettier": "^2.5"
35
+ "@graphql-markdown/printer-legacy": "^1.1.0",
36
+ "@graphql-markdown/diff": "^1.0.2",
37
+ "prettier": "^2.8"
38
38
  },
39
39
  "peerDependenciesMeta": {
40
40
  "@graphql-markdown/printer-legacy": {
package/src/config.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const { join } = require("path");
2
2
  const { tmpdir } = require("os");
3
3
 
4
- const { parseGroupByOption } = require("./lib/group-info");
4
+ const { parseGroupByOption } = require("./group-info");
5
5
 
6
6
  const PACKAGE_NAME = "@graphql-markdown/docusaurus";
7
7
  const ASSETS_LOCATION = join(__dirname, "../assets/");
@@ -27,6 +27,7 @@ const DEFAULT_OPTIONS = {
27
27
  relatedTypeSection: true,
28
28
  typeBadges: true,
29
29
  },
30
+ skipDocDirective: undefined,
30
31
  };
31
32
 
32
33
  function buildConfig(configFileOpts, cliOpts) {
@@ -57,6 +58,9 @@ function buildConfig(configFileOpts, cliOpts) {
57
58
  docOptions: getDocOptions(cliOpts, config.docOptions),
58
59
  printTypeOptions: gePrintTypeOptions(cliOpts, config.printTypeOptions),
59
60
  printer: config.printer,
61
+ skipDocDirective: getSkipDocDirective(
62
+ cliOpts.skip ?? config.skipDocDirective,
63
+ ),
60
64
  };
61
65
  }
62
66
 
@@ -81,4 +85,20 @@ function gePrintTypeOptions(cliOpts, configOptions) {
81
85
  };
82
86
  }
83
87
 
88
+ function getSkipDocDirective(option) {
89
+ const OPTION_REGEX = /^@(?<directive>\w+)$/;
90
+
91
+ if (typeof option !== "string") {
92
+ return undefined;
93
+ }
94
+
95
+ const parsedOption = OPTION_REGEX.exec(option);
96
+
97
+ if (typeof parsedOption === "undefined" || parsedOption == null) {
98
+ throw new Error(`Invalid "${option}"`);
99
+ }
100
+
101
+ return parsedOption.groups.directive;
102
+ }
103
+
84
104
  module.exports = { buildConfig, DEFAULT_OPTIONS, ASSETS_LOCATION };
@@ -34,6 +34,7 @@ const getPrinter = (
34
34
  groups,
35
35
  printTypeOptions,
36
36
  printerModule,
37
+ skipDocDirective,
37
38
  ) => {
38
39
  if (typeof printerModule !== "string") {
39
40
  throw new Error(
@@ -46,6 +47,7 @@ const getPrinter = (
46
47
  return new Printer(schema, baseURL, linkRoot, {
47
48
  groups,
48
49
  printTypeOptions,
50
+ skipDocDirective,
49
51
  });
50
52
  } catch (error) {
51
53
  throw new Error(
@@ -68,6 +70,7 @@ const generateDocFromSchema = async ({
68
70
  docOptions,
69
71
  printTypeOptions,
70
72
  printer: printerModule,
73
+ skipDocDirective,
71
74
  }) => {
72
75
  const loaders = getDocumentLoaders(loadersList);
73
76
  const schema = await loadSchema(schemaLocation, loaders);
@@ -86,6 +89,7 @@ const generateDocFromSchema = async ({
86
89
  groups,
87
90
  printTypeOptions,
88
91
  printerModule,
92
+ skipDocDirective,
89
93
  );
90
94
  const renderer = new Renderer(
91
95
  printer,
@@ -94,6 +98,7 @@ const generateDocFromSchema = async ({
94
98
  groups,
95
99
  prettify,
96
100
  docOptions,
101
+ skipDocDirective,
97
102
  );
98
103
 
99
104
  const pages = await Promise.all(
@@ -1,6 +1,4 @@
1
- const {
2
- array: { convertArrayToObject },
3
- } = require("@graphql-markdown/utils").scalars;
1
+ const { convertArrayToObject } = require("@graphql-markdown/utils").array;
4
2
 
5
3
  const DEFAULT_GROUP = "Miscellaneous";
6
4
  const OPTION_REGEX =
package/src/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* istanbul ignore file */
2
2
 
3
3
  module.exports = {
4
- generateDocFromSchema: require("./lib/generator").generateDocFromSchema,
5
- groupInfo: require("./lib/group-info"),
4
+ generateDocFromSchema: require("./generator").generateDocFromSchema,
5
+ groupInfo: require("./group-info"),
6
6
  config: require("./config"),
7
7
  };
@@ -1,18 +1,15 @@
1
1
  const path = require("path");
2
2
 
3
3
  const {
4
- array: { convertArrayToObject },
5
4
  object: { hasProperty },
6
5
  string: { toSlug, startCase },
7
6
  url: { pathUrl },
8
- } = require("@graphql-markdown/utils").scalars;
9
-
10
- const {
7
+ graphql: { hasDirective },
11
8
  prettier: { prettifyJavascript, prettifyMarkdown },
12
9
  fs: { saveFile, ensureDir, copyFile, readFile, fileExists },
13
- } = require("@graphql-markdown/utils").helpers;
10
+ } = require("@graphql-markdown/utils");
14
11
 
15
- const { ASSETS_LOCATION } = require("../config");
12
+ const { ASSETS_LOCATION } = require("./config");
16
13
  const { schemaSidebar } = require(`${ASSETS_LOCATION}/sidebar.json`);
17
14
 
18
15
  const SIDEBAR = "sidebar-schema.js";
@@ -20,13 +17,22 @@ const HOMEPAGE_ID = "schema";
20
17
  const CATEGORY_YAML = "_category_.yml";
21
18
 
22
19
  module.exports = class Renderer {
23
- constructor(printer, outputDir, baseURL, group, prettify, docOptions) {
20
+ constructor(
21
+ printer,
22
+ outputDir,
23
+ baseURL,
24
+ group,
25
+ prettify,
26
+ docOptions,
27
+ skipDocDirective,
28
+ ) {
24
29
  this.group = group;
25
30
  this.outputDir = outputDir;
26
31
  this.baseURL = baseURL;
27
32
  this.printer = printer;
28
33
  this.prettify = prettify;
29
34
  this.options = docOptions;
35
+ this.skipDocDirective = skipDocDirective;
30
36
  }
31
37
 
32
38
  async generateCategoryMetafile(category, dirPath) {
@@ -48,33 +54,35 @@ module.exports = class Renderer {
48
54
  }
49
55
 
50
56
  async renderRootTypes(rootTypeName, type) {
51
- if (typeof type === "undefined" || type === null) {
57
+ if (typeof type !== "object" || type === null) {
52
58
  return undefined;
53
59
  }
54
60
 
55
- if (Array.isArray(type)) {
56
- type = convertArrayToObject(type);
57
- }
58
-
59
61
  return Promise.all(
60
- Object.keys(type).map(async (name) => {
61
- let dirPath = this.outputDir;
62
+ Object.keys(type)
63
+ .map(async (name) => {
64
+ let dirPath = this.outputDir;
62
65
 
63
- if (hasProperty(this.group, name)) {
64
- dirPath = path.join(dirPath, toSlug(this.group[name]));
65
- await this.generateCategoryMetafile(this.group[name], dirPath);
66
- }
66
+ if (hasProperty(this.group, name)) {
67
+ dirPath = path.join(dirPath, toSlug(this.group[name]));
68
+ await this.generateCategoryMetafile(this.group[name], dirPath);
69
+ }
67
70
 
68
- dirPath = path.join(dirPath, toSlug(rootTypeName));
69
- await this.generateCategoryMetafile(rootTypeName, dirPath);
71
+ dirPath = path.join(dirPath, toSlug(rootTypeName));
72
+ await this.generateCategoryMetafile(rootTypeName, dirPath);
70
73
 
71
- return this.renderTypeEntities(dirPath, name, type[name]);
72
- }),
74
+ return this.renderTypeEntities(dirPath, name, type[name]);
75
+ })
76
+ .filter((res) => typeof res !== "undefined"),
73
77
  );
74
78
  }
75
79
 
76
80
  async renderTypeEntities(dirPath, name, type) {
77
- if (typeof type === "undefined" || type === null) {
81
+ if (
82
+ typeof type === "undefined" ||
83
+ type === null ||
84
+ hasDirective(type, this.skipDocDirective)
85
+ ) {
78
86
  return undefined;
79
87
  }
80
88