docgen-tool 6.3.0 → 6.4.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.
@@ -13,7 +13,7 @@ declare const __BASE_PATH__: string;
13
13
  (and renderers.tsx for more details)
14
14
  */
15
15
 
16
- export const customRenderers = ({ options }) => ({
16
+ export const customRenderers = () => ({
17
17
  div: (payload) => {
18
18
  const { children, style, element } = payload;
19
19
  const classNames = element.classList.toString();
@@ -27,14 +27,24 @@ export const customRenderers = ({ options }) => ({
27
27
  return <View style={style}>{children}</View>;
28
28
  },
29
29
  pre: (payload) => {
30
- const { children, element, style } = payload;
31
- //strip and handle code blocks
32
- const $ = cheerio.load(element.content.join());
30
+ const { element, style } = payload;
31
+ const html = element.innerHTML ?? '';
32
+ const $ = cheerio.load(html);
33
33
  const code = $('code');
34
- if (code.length) {
35
- return <Text style={style}>{code.text().trim()}</Text>;
36
- }
37
- return <Text style={style}>{children}</Text>;
34
+ const text = code.length ? code.text() : $.text();
35
+
36
+ // Preserve indentation and multiple spaces with Non-Breaking Spaces
37
+ // to ensure react-pdf doesn't collapse them
38
+ const formattedText = text
39
+ // Trim spaces at the start
40
+ .replace(/^ +/gm, (match) => '\u00A0'.repeat(match.length))
41
+ // preserve internal indentation
42
+ .replace(/ {2,}/g, (match) => '\u00A0'.repeat(match.length))
43
+ // consistent tab width
44
+ .replace(/\t/g, '\u00A0\u00A0')
45
+ .trimEnd();
46
+
47
+ return <Text style={style}>{formattedText}</Text>;
38
48
  },
39
49
  img: (payload) => {
40
50
  const { element, style } = payload;
@@ -3,12 +3,12 @@ import Html from 'react-pdf-html-simple';
3
3
  import { fontSize } from '../../pdf-styles/pdf-styles.ts';
4
4
  import { customRenderers } from './custom-renderers/custom-renderers.tsx';
5
5
 
6
- export const PdfHtmlBlock = ({ page, options, stylesheet }) => {
6
+ export const PdfHtmlBlock = ({ page, stylesheet }) => {
7
7
  return (
8
8
  <Html
9
9
  style={{ fontSize }}
10
10
  stylesheet={stylesheet}
11
- renderers={customRenderers({ options })}
11
+ renderers={customRenderers()}
12
12
  >
13
13
  {page}
14
14
  </Html>
@@ -7,18 +7,14 @@ import {
7
7
  getHtmlStyleSheet,
8
8
  } from '../pdf-styles/pdf-styles.ts';
9
9
 
10
- export const PdfPage = ({ page, parameters, options, styleVariables }) => {
11
- const reactPdfStyles = StyleSheet.create(getPdfStyleSheet(styleVariables));
10
+ export const PdfPage = ({ page, parameters, styleVariables }) => {
11
+ const reactPdfStyles = StyleSheet.create(getPdfStyleSheet());
12
12
  const htmlStylesheet = getHtmlStyleSheet(styleVariables);
13
13
 
14
14
  return (
15
15
  <Page size="A4" style={reactPdfStyles.page}>
16
16
  <View>
17
- <PdfHtmlBlock
18
- page={page}
19
- options={options}
20
- stylesheet={htmlStylesheet}
21
- />
17
+ <PdfHtmlBlock page={page} stylesheet={htmlStylesheet} />
22
18
  </View>
23
19
  <PdfFooter parameters={parameters} />
24
20
  </Page>
@@ -4,7 +4,7 @@ import { getPdfTableStyles } from './pdf-table-styles.ts';
4
4
 
5
5
  export const fontSize = 10;
6
6
 
7
- export const getPdfStyleSheet = (styles: any) => ({
7
+ export const getPdfStyleSheet = () => ({
8
8
  page: {
9
9
  paddingTop: 35,
10
10
  paddingBottom: 65,
@@ -25,15 +25,6 @@ export const getHtmlStyleSheet = (styles: any) => {
25
25
  const pdfAdmonitionsStyles = getPdfAdmonitionsStyles(styles);
26
26
  const pdfTableStyles = getPdfTableStyles(styles);
27
27
 
28
- const styleInfo = {
29
- color: styles.ColorTextInfo,
30
- backgroundColor: styles.ColorBackgroundInfo,
31
- borderLeft: `5px solid ${styles.ColorBorderInfo}`,
32
- padding: styles.SizeMessagePadding,
33
- marginLeft: 0,
34
- marginRight: 0,
35
- };
36
-
37
28
  return {
38
29
  'h1, h2, h3, h4, h5, h6': {
39
30
  fontWeight: 'bold',
@@ -53,7 +53,6 @@ Font.register({
53
53
 
54
54
  export const Pdf = ({ loadedPages, styleVariables }) => {
55
55
  const parameters = __DOCGEN_PARAMETERS__;
56
- const options = {};
57
56
  const allSources = Object.values(__DOCGEN_PAGES__).flatMap((columns) =>
58
57
  columns.flatMap((section) => section.pages.map((p: any) => p.source)),
59
58
  );
@@ -67,7 +66,6 @@ export const Pdf = ({ loadedPages, styleVariables }) => {
67
66
  key={i}
68
67
  page={html}
69
68
  parameters={parameters}
70
- options={options}
71
69
  styleVariables={styleVariables}
72
70
  />
73
71
  );
@@ -1,6 +1,6 @@
1
1
  import { useState, useEffect } from 'react';
2
2
  import * as styles from 'virtual:style-variables.js';
3
- import WorkerURL from './generate-pdf.worker.tsx?worker';
3
+ import * as WorkerModule from './generate-pdf.worker.tsx?worker';
4
4
 
5
5
  export type TGeneratedPdf = {
6
6
  pdfBlob: Blob | null;
@@ -21,7 +21,7 @@ export const useGeneratePdf = () => {
21
21
  return;
22
22
  }
23
23
 
24
- const worker = new WorkerURL();
24
+ const worker = new WorkerModule.default();
25
25
 
26
26
  worker.onmessage = (e) => {
27
27
  if (e.data.type === 'complete') {
@@ -90,17 +90,31 @@
90
90
  },
91
91
  "button": {
92
92
  "border": {
93
- "@": { "value": "2px solid {color.primary.@}" },
94
- "inverted": { "value": "2px solid {color.primary.@}" }
93
+ "@": {
94
+ "value": "2px solid {color.primary.@}"
95
+ },
96
+ "inverted": {
97
+ "value": "2px solid {color.primary.@}"
98
+ }
95
99
  },
96
100
  "background": {
97
- "@": { "value": "{color.primary.@}" },
98
- "hover": { "value": "#0042b4" },
99
- "inverted": { "value": "#fff" }
101
+ "@": {
102
+ "value": "{color.primary.@}"
103
+ },
104
+ "hover": {
105
+ "value": "{color.primary.dark}"
106
+ },
107
+ "inverted": {
108
+ "value": "#fff"
109
+ }
100
110
  },
101
111
  "text": {
102
- "@": { "value": "#fff" },
103
- "inverted": { "value": "{color.primary.@}" }
112
+ "@": {
113
+ "value": "#fff"
114
+ },
115
+ "inverted": {
116
+ "value": "{color.primary.@}"
117
+ }
104
118
  },
105
119
  "shadow": {
106
120
  "value": "none"
package/dist/cli/cli.js CHANGED
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env node
2
+ import { createRequire } from "node:module";
2
3
  import { program } from "commander";
3
4
  import path, { join, resolve } from "node:path";
4
5
  import { build, createServer } from "vite";
5
6
  import react from "@vitejs/plugin-react";
7
+ import { nodePolyfills } from "vite-plugin-node-polyfills";
6
8
  import dotenv from "dotenv";
7
9
  import pico from "picocolors";
8
10
  import path$1 from "path";
@@ -24,9 +26,10 @@ const deriveParameters = ({ rawParameters, setVersion, setReleaseDate }) => {
24
26
  }, readFile = async (filePath) => {
25
27
  const normalized = path$1.normalize(filePath);
26
28
  try {
27
- return (await promises.readFile(normalized, { encoding: "utf8" }))?.replace(/^\uFEFF/, "");
29
+ const content = await promises.readFile(normalized, { encoding: "utf8" });
30
+ return content?.replace(/^\uFEFF/, "");
28
31
  } catch (error) {
29
- console.log(pico.red("Error reading file: " + normalized));
32
+ if (console.log(pico.red(`Error reading file: ${normalized}`)), error instanceof Error) console.log(pico.dim(error.message));
30
33
  }
31
34
  }, copyDirectory = async (source, destination, verbose) => {
32
35
  const normalizedSource = path$1.normalize(source), normalizedDestination = path$1.normalize(destination);
@@ -241,8 +244,8 @@ const deriveParameters = ({ rawParameters, setVersion, setReleaseDate }) => {
241
244
  return accessSync(dir, constants.R_OK), dir;
242
245
  } catch {}
243
246
  throw new Error(`template directory not found under ${root}`);
244
- }, styleVariablesPlugin = (appDir) => {
245
- const cssVirtualModuleId = "virtual:style-variables.css", jsVirtualModuleId = "virtual:style-variables.js", resolvedCssPath = path.join(appDir, "virtual-style-variables.css"), resolvedJsPath = path.join(appDir, "virtual-style-variables.js");
247
+ }, styleVariablesPlugin = (appDir, inputDir) => {
248
+ const cssVirtualModuleId = "virtual:style-variables.css", jsVirtualModuleId = "virtual:style-variables.js", resolvedCssPath = `\0${path.join(appDir, "virtual-style-variables.css")}`, resolvedJsPath = `\0${path.join(appDir, "virtual-style-variables.js")}`;
246
249
  return {
247
250
  name: "style-variables-plugin",
248
251
  enforce: "pre",
@@ -254,6 +257,8 @@ const deriveParameters = ({ rawParameters, setVersion, setReleaseDate }) => {
254
257
  if (id === resolvedCssPath || id === resolvedJsPath) {
255
258
  const configPath = path.join(appDir, "styles/config.json"), configContent = fs$1.readFileSync(configPath, "utf-8"), config = JSON.parse(configContent);
256
259
  config.source = [path.join(appDir, "styles/style-tokens/**/*.json")];
260
+ const themePath = path.join(inputDir, "theme.json");
261
+ if (fs$1.existsSync(themePath)) config.source.push(themePath);
257
262
  const sd = new StyleDictionary(config);
258
263
  if (id === resolvedCssPath) {
259
264
  const files = await sd.formatPlatform("css");
@@ -266,7 +271,8 @@ const deriveParameters = ({ rawParameters, setVersion, setReleaseDate }) => {
266
271
  }
267
272
  },
268
273
  handleHotUpdate({ file, server }) {
269
- if (!file.includes("/style-tokens/")) return;
274
+ const isStyleToken = file.includes("/style-tokens/"), isTheme = file === path.join(inputDir, "theme.json");
275
+ if (!isStyleToken && !isTheme) return;
270
276
  const ids = [resolvedCssPath, resolvedJsPath];
271
277
  return ids.forEach((id) => {
272
278
  const mod = server.moduleGraph.getModuleById(id);
@@ -295,7 +301,7 @@ const deriveParameters = ({ rawParameters, setVersion, setReleaseDate }) => {
295
301
  };
296
302
  };
297
303
  dotenv.config({ path: path.resolve(process.cwd(), ".env") });
298
- const basePath = process.env.BASE_PATH || "/", generate = async (command, mode) => {
304
+ const require = createRequire(import.meta.url), basePath = process.env.BASE_PATH || "/", generate = async (command, mode) => {
299
305
  const inputDir = path.resolve(process.cwd(), command.input), outputDir = path.resolve(process.cwd(), command.output), inputs = await loadInputs({
300
306
  inputPath: inputDir,
301
307
  verbose: false
@@ -309,8 +315,14 @@ const basePath = process.env.BASE_PATH || "/", generate = async (command, mode)
309
315
  root: appPath,
310
316
  publicDir: inputDir,
311
317
  base: basePath,
318
+ resolve: { alias: {
319
+ "vite-plugin-node-polyfills/shims/process": require.resolve("vite-plugin-node-polyfills/shims/process"),
320
+ "vite-plugin-node-polyfills/shims/buffer": require.resolve("vite-plugin-node-polyfills/shims/buffer"),
321
+ "vite-plugin-node-polyfills/shims/global": require.resolve("vite-plugin-node-polyfills/shims/global")
322
+ } },
312
323
  plugins: [
313
- styleVariablesPlugin(appPath),
324
+ nodePolyfills({ include: ["buffer"] }),
325
+ styleVariablesPlugin(appPath, inputDir),
314
326
  react({ exclude: /\/src\/app\/pdf\// }),
315
327
  htmlTransformPlugin(parameters.title ?? "DocGen"),
316
328
  ...mode !== "build" ? [watchInputDirPlugin(inputDir)] : []
@@ -336,7 +348,7 @@ const basePath = process.env.BASE_PATH || "/", generate = async (command, mode)
336
348
  }, scaffold = async (command) => {
337
349
  const inputDir = findTemplateDir(import.meta.dirname), outputDir = path.normalize(command.output + "/"), verbose = command.verbose === true;
338
350
  console.log(pico.green("Creating scaffold template directory")), await copyDirectory(inputDir, outputDir, verbose);
339
- }, version = "6.3.0";
351
+ }, version = "6.4.0";
340
352
  if (program.version(version).usage("[command] [--option]"), program.command("scaffold").usage("[--option]").description("create a template input directory").option("-o, --output [path]", "path to the output directory (default: ./)", "./").option("-v, --verbose", "show verbose output including detailed errors").action((command) => {
341
353
  scaffold(command);
342
354
  }), program.command("dev").usage("[--option]").description("create a static website from an input directory").option("-i, --input [path]", "path to the input directory [default: ./]", "./").option("-o, --output [path]", "path to the output directory [default: ./output]", "./output").option("-p, --pdf", "create a PDF document").option("-s, --set-version [version]", "override parameters.version (useful for build tools) [default: false]", false).option("-R, --set-release-date [date]", "override parameters.date (useful for build tools) [default: false]", false).option("-v, --verbose", "show verbose output including detailed errors").action((command) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "docgen-tool",
3
3
  "type": "module",
4
- "version": "6.3.0",
4
+ "version": "6.4.0",
5
5
  "description": "A tool for creating HTML and PDF documentation",
6
6
  "bin": "./dist/cli/cli.js",
7
7
  "files": [
@@ -17,58 +17,62 @@
17
17
  "preview:docs": "npx serve -s ./docs",
18
18
  "build:docs:gh": "tsx src/cli/cli.ts build -i src/docs -o ./docs && yarn copy:gh:files",
19
19
  "copy:gh:files": "node deploy/before-deploy-website.js",
20
- "preview:style:variables": "rimraf src/app/styles/style-variables && npx style-dictionary build --config src/app/styles/config.json && yarn prettier:fix",
21
- "test": "npm run prettier:check",
20
+ "preview:style:variables": "rimraf src/app/styles/style-variables && npx style-dictionary build --config src/app/styles/config.json && yarn formatting:fix",
21
+ "test": "npm run formatting:check",
22
22
  "test:run": "tsx src/cli/cli.ts build -i src/__test__/test-run -o src/__test__/test-run-output",
23
23
  "test:scaffold": "tsx src/cli/cli.ts scaffold -o src/__test__/test-run-output",
24
24
  "test:prod:run": "./dist/cli/cli.js build -i src/__test__/test-run -o ../source/__test__/test-run-output",
25
- "prettier:check": "prettier --check 'src/**/*.{ts,js,tsx,jsx,json,css}'",
26
- "prettier:fix": "prettier --write 'src/**/*.{ts,js,tsx,jsx,json,css}'",
25
+ "formatting:check": "prettier --check 'src/**/*.{ts,js,tsx,jsx,json,css}'",
26
+ "formatting:fix": "prettier --write 'src/**/*.{ts,js,tsx,jsx,json,css}'",
27
+ "lint:check": "oxlint .",
28
+ "lint:fix": "oxlint --fix .",
27
29
  "test:publish": "sh ./src/__test__/test-publish/test-publish.sh",
28
30
  "prepare": "husky"
29
31
  },
30
32
  "lint-staged": {
31
- "src/**/*.{ts,js,tsx,jsx,json,css}": "prettier --write"
33
+ "src/**/*.{ts,js,tsx,jsx,json,css}": [
34
+ "oxlint --fix",
35
+ "prettier --write"
36
+ ]
32
37
  },
33
38
  "dependencies": {
34
- "@react-pdf/renderer": "^4.3.0",
35
- "@tanstack/react-router": "^1.130.12",
36
- "@vitejs/plugin-react": "^5.0.0",
39
+ "@react-pdf/renderer": "^4.3.2",
40
+ "@tanstack/react-router": "^1.147.0",
41
+ "@vitejs/plugin-react": "5.0.2",
37
42
  "cheerio": "^1.1.2",
38
43
  "classnames": "^2.5.1",
39
- "commander": "^14.0.0",
44
+ "commander": "^14.0.2",
40
45
  "dotenv": "^17.2.3",
41
- "fs-extra": "^11.3.0",
46
+ "fs-extra": "^11.3.3",
42
47
  "husky": "^9.1.7",
43
- "lint-staged": "^16.1.2",
44
- "marked": "^16.2.0",
48
+ "lint-staged": "^16.2.7",
49
+ "marked": "^17.0.1",
45
50
  "picocolors": "^1.1.1",
46
- "react": "^19.1.0",
47
- "react-dom": "^19.1.0",
51
+ "react": "^19.2.3",
52
+ "react-dom": "^19.2.3",
48
53
  "react-icons": "^5.5.0",
49
54
  "react-markdown": "^10.1.0",
50
- "react-pdf": "^10.2.0",
55
+ "react-pdf": "^10.3.0",
51
56
  "react-pdf-html-simple": "^2.1.4",
52
57
  "react-resize-detector": "^12.3.0",
53
58
  "rehype-raw": "^7.0.0",
54
59
  "remark-gfm": "^4.0.1",
55
- "rolldown-vite": "npm:rolldown-vite@latest",
56
- "style-dictionary": "^5.1.1",
60
+ "rolldown-vite": "^7.3.1",
61
+ "style-dictionary": "^5.1.3",
57
62
  "vite": "npm:rolldown-vite@latest",
63
+ "vite-plugin-node-polyfills": "0.22.0",
58
64
  "z-schema": "^6.0.2"
59
65
  },
60
66
  "devDependencies": {
61
- "@eslint/js": "^9.31.0",
62
- "@types/node": "^24.1.0",
63
- "@types/react": "^19.1.13",
64
- "eslint": "^9.31.0",
65
- "eslint-config-prettier": "^10.1.8",
67
+ "@prettier/plugin-oxc": "^0.1.3",
68
+ "@types/node": "^25.0.5",
69
+ "@types/react": "^19.2.8",
66
70
  "ncp": "^2.0.0",
67
- "prettier": "^3.6.2",
68
- "rimraf": "^6.0.1",
69
- "tsx": "^4.20.3",
70
- "typescript": "^5.8.3",
71
- "typescript-eslint": "^8.38.0"
71
+ "oxlint": "^1.38.0",
72
+ "prettier": "^3.7.4",
73
+ "rimraf": "^6.1.2",
74
+ "tsx": "^4.21.0",
75
+ "typescript": "^5.9.3"
72
76
  },
73
77
  "repository": {
74
78
  "type": "git",
@@ -80,4 +84,4 @@
80
84
  "url": "https://github.com/mtmacdonald/docgen/issues"
81
85
  },
82
86
  "homepage": "https://mtmacdonald.github.io/docgen/docs/index.html"
83
- }
87
+ }