@graphql-markdown/docusaurus 1.35.2 → 1.37.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAWzE;;;;;;;;GAQG;AACH,wBAA8B,yBAAyB,CACrD,CAAC,EAAE,WAAW,EACd,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,aAAa,CAAC,GAC1D,OAAO,CAAC,MAAM,CAAC,CAkCjB;AAED,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AA4CzE;;;;;;;;GAQG;AACH,wBAA8B,yBAAyB,CACrD,CAAC,EAAE,WAAW,EACd,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,aAAa,CAAC,GAC1D,OAAO,CAAC,MAAM,CAAC,CAiCjB;AAED,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC"}
package/dist/index.js CHANGED
@@ -11,6 +11,16 @@ const logger_1 = __importDefault(require("@graphql-markdown/logger"));
11
11
  const NAME = "docusaurus-graphql-doc-generator";
12
12
  const LOGGER_MODULE = "@docusaurus/logger";
13
13
  const MDX_PACKAGE = "@graphql-markdown/docusaurus/mdx";
14
+ const isCommanderCompatibleCommand = (value) => {
15
+ return (typeof value === "object" &&
16
+ value !== null &&
17
+ typeof value.name === "function");
18
+ };
19
+ const assertCommanderCompatibleCommand = (value) => {
20
+ if (!isCommanderCompatibleCommand(value)) {
21
+ throw new TypeError("GraphQL-Markdown CLI command is not compatible with Docusaurus commander interface.");
22
+ }
23
+ };
14
24
  /**
15
25
  * Docusaurus plugin wrapper that wires GraphQL-Markdown into the build,
16
26
  * optionally running the CLI during `docusaurus build` and registering
@@ -33,17 +43,16 @@ async function pluginGraphQLDocGenerator(_, options) {
33
43
  * @returns void
34
44
  */
35
45
  extendCli(cli) {
36
- // @graphql-markdown/cli uses commander v15; @docusaurus/types types extendCli
37
- // with commander v5's Command. The two are structurally compatible at runtime
38
- // but TypeScript sees them as different types due to dual-version resolution.
39
- cli.addCommand((0, cli_1.getGraphQLMarkdownCli)({
46
+ const command = (0, cli_1.getGraphQLMarkdownCli)({
40
47
  ...options,
41
48
  docOptions: {
42
49
  generatorFrameworkName: "docusaurus",
43
50
  generatorFrameworkVersion: utils_1.DOCUSAURUS_VERSION,
44
51
  ...options.docOptions,
45
52
  },
46
- }, LOGGER_MODULE, options.formatter ?? options.mdxParser ?? MDX_PACKAGE));
53
+ }, LOGGER_MODULE, options.formatter ?? MDX_PACKAGE);
54
+ assertCommanderCompatibleCommand(command);
55
+ cli.addCommand(command);
47
56
  },
48
57
  };
49
58
  }
@@ -4,6 +4,7 @@
4
4
  *
5
5
  * @packageDocumentation
6
6
  */
7
+ import type { OutputAdapter } from "@graphql-markdown/types";
7
8
  /**
8
9
  * Hook that materializes a `_category_.yml` file before Docusaurus indexes
9
10
  * a directory, ensuring generated bundles have labels, ordering, and
@@ -15,6 +16,7 @@ export declare const beforeGenerateIndexMetafileHook: (event: {
15
16
  data: {
16
17
  dirPath: string;
17
18
  category: string;
19
+ outputAdapter?: OutputAdapter;
18
20
  options?: Record<string, unknown>;
19
21
  };
20
22
  }) => Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"category.d.ts","sourceRoot":"","sources":["../../src/mdx/category.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAkBH;;;;;;GAMG;AACH,eAAO,MAAM,+BAA+B,UAAiB;IAC3D,IAAI,EAAE;QACJ,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACnC,CAAC;CACH,KAAG,OAAO,CAAC,IAAI,CA2Bf,CAAC"}
1
+ {"version":3,"file":"category.d.ts","sourceRoot":"","sources":["../../src/mdx/category.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAU7D;;;;;;GAMG;AACH,eAAO,MAAM,+BAA+B,UAAiB;IAC3D,IAAI,EAAE;QACJ,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,aAAa,CAAC,EAAE,aAAa,CAAC;QAC9B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACnC,CAAC;CACH,KAAG,OAAO,CAAC,IAAI,CA+Bf,CAAC"}
@@ -23,9 +23,13 @@ var SidebarPosition;
23
23
  * @param event - Hook payload containing the target directory, category name, and generator options.
24
24
  */
25
25
  const beforeGenerateIndexMetafileHook = async (event) => {
26
- const { dirPath, category, options } = event.data;
26
+ const { dirPath, category, options, outputAdapter } = event.data;
27
27
  const filePath = (0, node_path_1.join)(dirPath, CATEGORY_YAML);
28
- if (await (0, utils_1.fileExists)(filePath)) {
28
+ // the metafile goes to the same destination as the pages, so a custom output
29
+ // adapter keeps the sidebar metadata alongside what it wrote
30
+ const adapter = outputAdapter ?? utils_1.fsOutputAdapter;
31
+ // preserve a metafile that is already there
32
+ if (typeof (await adapter.readFile(filePath)) === "string") {
29
33
  return;
30
34
  }
31
35
  const label = (0, utils_1.startCase)(category);
@@ -41,7 +45,7 @@ const beforeGenerateIndexMetafileHook = async (event) => {
41
45
  ? options.sidebarPosition
42
46
  : SidebarPosition.FIRST;
43
47
  const content = `label: ${label}\nposition: ${position}\n${className}link: ${link}\ncollapsible: ${Boolean(options?.collapsible ?? true)}\ncollapsed: ${Boolean(options?.collapsed ?? true)}\n`;
44
- await (0, utils_1.ensureDir)(dirPath);
45
- await (0, utils_1.saveFile)(filePath, content);
48
+ await adapter.ensureDir?.(dirPath);
49
+ await adapter.writeFile(filePath, content);
46
50
  };
47
51
  exports.beforeGenerateIndexMetafileHook = beforeGenerateIndexMetafileHook;
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.35.2",
8
+ "version": "1.37.0",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",