@graphql-markdown/core 1.6.4 → 1.7.0-next.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,12 +5,15 @@
5
5
  "bugs": {
6
6
  "url": "https://github.com/graphql-markdown/graphql-markdown/issues"
7
7
  },
8
- "version": "1.6.4",
8
+ "version": "1.7.0-next.0",
9
9
  "license": "MIT",
10
- "main": "src/index.js",
11
10
  "repository": {
12
11
  "type": "git",
13
- "url": "https://github.com/graphql-markdown/graphql-markdown.git"
12
+ "url": "graphql-markdown/graphql-markdown",
13
+ "directory": "packages/core"
14
+ },
15
+ "author": {
16
+ "name": "Gregory Heitz"
14
17
  },
15
18
  "keywords": [
16
19
  "graphql",
@@ -19,23 +22,59 @@
19
22
  "markdown",
20
23
  "graphql-markdown"
21
24
  ],
22
- "author": {
23
- "name": "Gregory Heitz"
25
+ "main": "dist/index.js",
26
+ "types": "dist/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "require": {
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ },
33
+ "import": {
34
+ "types": "./dist/index.d.ts",
35
+ "default": "./dist/index.js"
36
+ },
37
+ "default": {
38
+ "types": "./dist/index.d.ts",
39
+ "default": "./dist/index.js"
40
+ }
41
+ },
42
+ "./*": {
43
+ "require": {
44
+ "types": "./dist/*.d.ts",
45
+ "default": "./dist/*.js"
46
+ },
47
+ "import": {
48
+ "types": "./dist/*.d.ts",
49
+ "default": "./dist/*.js"
50
+ },
51
+ "default": {
52
+ "types": "./dist/*.d.ts",
53
+ "default": "./dist/*.js"
54
+ }
55
+ },
56
+ "./package.json": "./package.json"
24
57
  },
25
58
  "scripts": {
26
59
  "prepack": "pinst --disable",
27
60
  "postpack": "pinst --enable",
28
- "test": "jest",
29
- "stryker": "stryker run"
61
+ "stryker": "stryker run",
62
+ "clean": "rm -rf ./dist"
30
63
  },
31
64
  "dependencies": {
32
- "@graphql-markdown/utils": "^1.5.1"
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"
33
68
  },
34
69
  "peerDependencies": {
35
- "@graphql-markdown/diff": "^1.0.14",
36
- "@graphql-markdown/printer-legacy": "^1.4.3",
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",
37
73
  "graphql-config": "^5.0.2"
38
74
  },
75
+ "devDependencies": {
76
+ "@graphql-markdown/types": "^1.0.0-next.0"
77
+ },
39
78
  "peerDependenciesMeta": {
40
79
  "@graphql-markdown/printer-legacy": {
41
80
  "optional": true
@@ -43,6 +82,9 @@
43
82
  "@graphql-markdown/diff": {
44
83
  "optional": true
45
84
  },
85
+ "@graphql-markdown/helpers": {
86
+ "optional": true
87
+ },
46
88
  "graphql-config": {
47
89
  "optional": true
48
90
  }
@@ -54,6 +96,14 @@
54
96
  "node": ">=16.14"
55
97
  },
56
98
  "publishConfig": {
99
+ "directory": "dist",
57
100
  "access": "public"
58
- }
101
+ },
102
+ "typescript": {
103
+ "definition": "dist/index.d.ts"
104
+ },
105
+ "files": [
106
+ "dist",
107
+ "assets"
108
+ ]
59
109
  }
@@ -1,8 +0,0 @@
1
- {
2
- "schemaSidebar": [
3
- {
4
- "type": "autogenerated",
5
- "dirName": "."
6
- }
7
- ]
8
- }
package/src/config.js DELETED
@@ -1,194 +0,0 @@
1
- const { join } = require("path");
2
- const { tmpdir } = require("os");
3
-
4
- const {
5
- object: { hasProperty },
6
- } = require("@graphql-markdown/utils");
7
-
8
- const { loadConfiguration } = require("./graphql-config");
9
-
10
- const PACKAGE_NAME = "@graphql-markdown/docusaurus";
11
- const ASSETS_LOCATION = join(__dirname, "../assets/");
12
-
13
- const DEFAULT_OPTIONS = {
14
- baseURL: "schema",
15
- customDirective: undefined,
16
- diffMethod: undefined,
17
- docOptions: {
18
- index: false,
19
- pagination: true,
20
- toc: true,
21
- },
22
- groupByDirective: undefined,
23
- homepage: join(ASSETS_LOCATION, "generated.md"),
24
- linkRoot: "/",
25
- loaders: {},
26
- pretty: false,
27
- printer: "@graphql-markdown/printer-legacy",
28
- printTypeOptions: {
29
- codeSection: true,
30
- deprecated: "default",
31
- parentTypePrefix: true,
32
- relatedTypeSection: true,
33
- typeBadges: true,
34
- },
35
- rootPath: "./docs",
36
- schema: "./schema.graphql",
37
- tmpDir: join(tmpdir(), PACKAGE_NAME),
38
- skipDocDirective: [],
39
- };
40
-
41
- function buildConfig(configFileOpts, cliOpts, id = undefined) {
42
- if (typeof cliOpts === "undefined" || cliOpts === null) {
43
- cliOpts = {};
44
- }
45
-
46
- const graphqlConfig = loadConfiguration(id);
47
- const config = { ...DEFAULT_OPTIONS, ...graphqlConfig, ...configFileOpts };
48
-
49
- const baseURL = cliOpts.base ?? config.baseURL;
50
- const skipDocDirective = getSkipDocDirectives(cliOpts, config);
51
-
52
- return {
53
- baseURL,
54
- customDirective: getCustomDirectives(
55
- config.customDirective,
56
- skipDocDirective,
57
- ),
58
- diffMethod: getDiffMethod(cliOpts.diff ?? config.diffMethod, cliOpts.force),
59
- docOptions: getDocOptions(cliOpts, config.docOptions),
60
- groupByDirective:
61
- parseGroupByOption(cliOpts.groupByDirective) || config.groupByDirective,
62
- homepageLocation: cliOpts.homepage ?? config.homepage,
63
- linkRoot: cliOpts.link ?? config.linkRoot,
64
- loaders: config.loaders,
65
- outputDir: join(cliOpts.root ?? config.rootPath, baseURL),
66
- prettify: cliOpts.pretty ?? config.pretty,
67
- printer: config.printer,
68
- printTypeOptions: gePrintTypeOptions(cliOpts, config.printTypeOptions),
69
- schemaLocation: cliOpts.schema ?? config.schema,
70
- skipDocDirective,
71
- tmpDir: cliOpts.tmp ?? config.tmpDir,
72
- };
73
- }
74
-
75
- function getCustomDirectives(customDirectiveOptions, skipDocDirective = []) {
76
- if (
77
- typeof customDirectiveOptions === "undefined" ||
78
- (typeof customDirectiveOptions === "object" &&
79
- Object.keys(customDirectiveOptions).length == 0)
80
- ) {
81
- return undefined;
82
- }
83
-
84
- for (const [name, option] of Object.entries(customDirectiveOptions)) {
85
- if (skipDocDirective.includes(name)) {
86
- delete customDirectiveOptions[name];
87
- } else if (
88
- (hasProperty(option, "descriptor") === false ||
89
- typeof option.descriptor !== "function") &&
90
- (hasProperty(option, "tag") === false || typeof option.tag !== "function")
91
- ) {
92
- throw new Error(
93
- `Wrong format for plugin custom directive "${name}".\nPlease refer to https://graphql-markdown.github.io/docs/advanced/custom-directive`,
94
- );
95
- }
96
- }
97
-
98
- return Object.keys(customDirectiveOptions).length === 0
99
- ? undefined
100
- : customDirectiveOptions;
101
- }
102
-
103
- function getDiffMethod(diff, force) {
104
- return force ? "FORCE" : diff;
105
- }
106
-
107
- function getDocOptions(cliOpts, configOptions) {
108
- return {
109
- pagination: !cliOpts.noPagination && configOptions.pagination,
110
- toc: !cliOpts.noToc && configOptions.toc,
111
- index: cliOpts.index || configOptions.index,
112
- };
113
- }
114
-
115
- function gePrintTypeOptions(cliOpts, configOptions) {
116
- return {
117
- codeSection: !cliOpts.noCode && configOptions.codeSection,
118
- deprecated:
119
- cliOpts.deprecated ??
120
- configOptions.deprecated ??
121
- DEFAULT_OPTIONS.printTypeOptions.deprecated,
122
- parentTypePrefix: !cliOpts.noParentType && configOptions.parentTypePrefix,
123
- relatedTypeSection:
124
- !cliOpts.noRelatedType && configOptions.relatedTypeSection,
125
- typeBadges: !cliOpts.noTypeBadges && configOptions.typeBadges,
126
- };
127
- }
128
-
129
- function getSkipDocDirectives(cliOpts = {}, configFileOpts = {}) {
130
- const directiveList = [].concat(
131
- cliOpts.skip ?? [],
132
- configFileOpts.skipDocDirective ?? [],
133
- );
134
-
135
- const skipDirectives = directiveList.map((option) =>
136
- getSkipDocDirective(option),
137
- );
138
-
139
- if (
140
- (hasProperty(configFileOpts, "printTypeOptions") === true &&
141
- configFileOpts.printTypeOptions.deprecated === "skip") ||
142
- (hasProperty(cliOpts, "deprecated") === true &&
143
- cliOpts.deprecated === "skip")
144
- ) {
145
- skipDirectives.push("deprecated");
146
- }
147
-
148
- return skipDirectives;
149
- }
150
-
151
- function getSkipDocDirective(option) {
152
- const OPTION_REGEX = /^@(?<directive>\w+)$/;
153
-
154
- if (typeof option !== "string") {
155
- throw new Error(`Invalid "${option}"`);
156
- }
157
-
158
- const parsedOption = OPTION_REGEX.exec(option);
159
-
160
- if (typeof parsedOption === "undefined" || parsedOption == null) {
161
- throw new Error(`Invalid "${option}"`);
162
- }
163
-
164
- return parsedOption.groups.directive;
165
- }
166
-
167
- function parseGroupByOption(groupOptions) {
168
- const DEFAULT_GROUP = "Miscellaneous";
169
- const OPTION_REGEX =
170
- /^@(?<directive>\w+)\((?<field>\w+)(?:\|=(?<fallback>\w+))?\)/;
171
-
172
- if (typeof groupOptions !== "string") {
173
- return undefined;
174
- }
175
-
176
- const parsedOptions = OPTION_REGEX.exec(groupOptions);
177
-
178
- if (typeof parsedOptions === "undefined" || parsedOptions == null) {
179
- throw new Error(`Invalid "${groupOptions}"`);
180
- }
181
-
182
- const { directive, field, fallback = DEFAULT_GROUP } = parsedOptions.groups;
183
- return { directive, field, fallback };
184
- }
185
-
186
- module.exports = {
187
- ASSETS_LOCATION,
188
- buildConfig,
189
- DEFAULT_OPTIONS,
190
- getCustomDirectives,
191
- getSkipDocDirective,
192
- getSkipDocDirectives,
193
- parseGroupByOption,
194
- };
package/src/diff.js DELETED
@@ -1,30 +0,0 @@
1
- const logger = require("@graphql-markdown/utils").logger.getInstance();
2
-
3
- const hasChanges = async (
4
- schema,
5
- tmpDir,
6
- diffMethod,
7
- diffModule = "@graphql-markdown/diff",
8
- ) => {
9
- if (
10
- typeof diffMethod === "undefined" ||
11
- diffMethod == null ||
12
- typeof diffModule === "undefined" ||
13
- diffModule == null
14
- ) {
15
- return true;
16
- }
17
-
18
- try {
19
- const { checkSchemaChanges } = require(diffModule);
20
- return await checkSchemaChanges(schema, tmpDir, diffMethod);
21
- } catch (error) {
22
- logger.warn(
23
- `Cannot find module '${diffModule}' from @graphql-markdown/core!`,
24
- );
25
- }
26
-
27
- return true;
28
- };
29
-
30
- module.exports = { hasChanges };
package/src/generator.js DELETED
@@ -1,99 +0,0 @@
1
- const {
2
- graphql: { getSchemaMap, loadSchema, getDocumentLoaders },
3
- group: { getGroups },
4
- directive: { getCustomDirectives },
5
- } = require("@graphql-markdown/utils");
6
-
7
- const { logger: Logger } = require("@graphql-markdown/utils");
8
- const Renderer = require("./renderer");
9
- const { hasChanges } = require("./diff");
10
- const { getPrinter } = require("./printer");
11
-
12
- const NS_PER_SEC = 1e9;
13
- const SEC_DECIMALS = 3;
14
-
15
- const generateDocFromSchema = async ({
16
- baseURL,
17
- schemaLocation,
18
- outputDir,
19
- linkRoot,
20
- homepageLocation,
21
- diffMethod,
22
- tmpDir,
23
- loaders: loadersList,
24
- groupByDirective,
25
- prettify,
26
- docOptions,
27
- printTypeOptions,
28
- printer: printerModule,
29
- skipDocDirective,
30
- customDirective,
31
- loggerModule,
32
- }) => {
33
- const start = process.hrtime.bigint();
34
-
35
- const logger = Logger.setInstance(loggerModule);
36
-
37
- const loaders = getDocumentLoaders(loadersList);
38
- const schema = await loadSchema(schemaLocation, loaders);
39
-
40
- const changed = await hasChanges(schema, tmpDir, diffMethod);
41
- if (!changed) {
42
- logger.info(`No changes detected in schema "${schemaLocation}".`);
43
- }
44
-
45
- const rootTypes = getSchemaMap(schema);
46
- const customDirectives = getCustomDirectives(rootTypes, customDirective);
47
- const groups = getGroups(rootTypes, groupByDirective);
48
- const printer = getPrinter(
49
- // module mandatory
50
- printerModule,
51
-
52
- // config mandatory
53
- {
54
- schema,
55
- baseURL,
56
- linkRoot,
57
- },
58
-
59
- // options
60
- {
61
- groups,
62
- printTypeOptions,
63
- skipDocDirective,
64
- customDirectives,
65
- },
66
- );
67
- const renderer = new Renderer(printer, outputDir, baseURL, groups, prettify, {
68
- ...docOptions,
69
- deprecated: printTypeOptions.deprecated,
70
- });
71
-
72
- const pages = await Promise.all(
73
- Object.keys(rootTypes).map((typeName) =>
74
- renderer.renderRootTypes(typeName, rootTypes[typeName]),
75
- ),
76
- );
77
-
78
- await renderer.renderHomepage(homepageLocation);
79
-
80
- const sidebarPath = await renderer.renderSidebar();
81
-
82
- const duration = (
83
- Number(process.hrtime.bigint() - start) / NS_PER_SEC
84
- ).toFixed(SEC_DECIMALS);
85
-
86
- logger.success(
87
- `Documentation successfully generated in "${outputDir}" with base URL "${baseURL}".`,
88
- );
89
- logger.info(
90
- `${
91
- pages.flat().length
92
- } pages generated in ${duration}s from schema "${schemaLocation}".`,
93
- );
94
- logger.info(
95
- `Remember to update your Docusaurus site's sidebars with "${sidebarPath}".`,
96
- );
97
- };
98
-
99
- module.exports = { generateDocFromSchema };
@@ -1,61 +0,0 @@
1
- const logger = require("@graphql-markdown/utils").logger.getInstance();
2
-
3
- const EXTENSION_NAME = "graphql-markdown";
4
-
5
- const loadConfiguration = (
6
- id = undefined,
7
- options = undefined,
8
- { throwOnMissing, throwOnEmpty } = {
9
- throwOnMissing: false,
10
- throwOnEmpty: false,
11
- },
12
- ) => {
13
- let GraphQLConfig;
14
- try {
15
- // eslint-disable-next-line node/no-missing-require
16
- GraphQLConfig = require("graphql-config");
17
- } catch (error) {
18
- logger.log("Cannot find module 'graphql-config'!");
19
- return undefined;
20
- }
21
-
22
- const config = GraphQLConfig.loadConfigSync({
23
- ...options,
24
- extensions: [() => ({ name: EXTENSION_NAME })],
25
- throwOnMissing,
26
- throwOnEmpty,
27
- });
28
-
29
- try {
30
- const projectConfig = config.getProject(id).extension(EXTENSION_NAME);
31
-
32
- if (typeof projectConfig?.schema !== "string") {
33
- const schema = projectConfig?.schema[0];
34
- if (typeof schema === "string") {
35
- projectConfig.schema = schema;
36
- } else {
37
- projectConfig.schema = Object.keys(schema)[0];
38
- projectConfig.loaders = setLoaderOptions(
39
- projectConfig.loaders,
40
- Object.values(schema)[0],
41
- );
42
- }
43
- }
44
- return projectConfig;
45
- } catch (error) {
46
- return undefined;
47
- }
48
- };
49
-
50
- const setLoaderOptions = (loaders, options) => {
51
- for (const loader in loaders) {
52
- if (typeof loaders[loader] === "string") {
53
- loaders[loader] = { module: loaders[loader], options };
54
- } else {
55
- loaders[loader].options = { ...options, ...loaders[loader].options };
56
- }
57
- }
58
- return loaders;
59
- };
60
-
61
- module.exports = { loadConfiguration, EXTENSION_NAME };
package/src/index.js DELETED
@@ -1,6 +0,0 @@
1
- /* istanbul ignore file */
2
-
3
- module.exports = {
4
- generateDocFromSchema: require("./generator").generateDocFromSchema,
5
- config: require("./config"),
6
- };
package/src/printer.js DELETED
@@ -1,24 +0,0 @@
1
- const getPrinter = (printerModule, config, options) => {
2
- let Printer = undefined;
3
-
4
- if (typeof printerModule !== "string") {
5
- throw new Error(
6
- 'Invalid printer module name in "printTypeOptions" settings.',
7
- );
8
- }
9
-
10
- try {
11
- Printer = require(printerModule);
12
- } catch (error) {
13
- throw new Error(
14
- `Cannot find module '${printerModule}' for @graphql-markdown/core in "printTypeOptions" settings.`,
15
- );
16
- }
17
-
18
- const { schema, baseURL, linkRoot } = config;
19
- Printer.init(schema, baseURL, linkRoot, { ...options });
20
-
21
- return Printer;
22
- };
23
-
24
- module.exports = { getPrinter };