docgen-tool 6.3.1 → 6.4.1
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/app/pdf/pdf-generator/pdf-page/pdf-html-block/custom-renderers/custom-renderers.tsx +18 -8
- package/dist/app/pdf/pdf-generator/pdf-page/pdf-html-block/pdf-html-block.tsx +2 -2
- package/dist/app/pdf/pdf-generator/pdf-page/pdf-page.tsx +3 -7
- package/dist/app/pdf/pdf-generator/pdf-styles/pdf-styles.ts +1 -11
- package/dist/app/pdf/pdf-generator/react-pdf.tsx +0 -2
- package/dist/app/pdf/pdf-generator/use-generate.pdf.tsx +2 -2
- package/dist/app/styles/style-tokens/colors.json +21 -7
- package/dist/cli/cli.js +12 -7
- package/package.json +31 -28
- package/dist/app/views/assets/.DS_Store +0 -0
- package/dist/app/views/assets/styles/.DS_Store +0 -0
- package/dist/app/views/assets/styles/fonts/.DS_Store +0 -0
package/dist/app/pdf/pdf-generator/pdf-page/pdf-html-block/custom-renderers/custom-renderers.tsx
CHANGED
|
@@ -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 = (
|
|
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 {
|
|
31
|
-
|
|
32
|
-
const $ = cheerio.load(
|
|
30
|
+
const { element, style } = payload;
|
|
31
|
+
const html = element.innerHTML ?? '';
|
|
32
|
+
const $ = cheerio.load(html);
|
|
33
33
|
const code = $('code');
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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,
|
|
6
|
+
export const PdfHtmlBlock = ({ page, stylesheet }) => {
|
|
7
7
|
return (
|
|
8
8
|
<Html
|
|
9
9
|
style={{ fontSize }}
|
|
10
10
|
stylesheet={stylesheet}
|
|
11
|
-
renderers={customRenderers(
|
|
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,
|
|
11
|
-
const reactPdfStyles = StyleSheet.create(getPdfStyleSheet(
|
|
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 = (
|
|
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',
|
|
@@ -133,7 +124,6 @@ export const getHtmlStyleSheet = (styles: any) => {
|
|
|
133
124
|
li_content: {
|
|
134
125
|
textAlign: 'left',
|
|
135
126
|
flexGrow: 1,
|
|
136
|
-
flexBasis: 1,
|
|
137
127
|
},
|
|
138
128
|
thead: {
|
|
139
129
|
display: 'flex',
|
|
@@ -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
|
|
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
|
|
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
|
-
"@": {
|
|
94
|
-
|
|
93
|
+
"@": {
|
|
94
|
+
"value": "2px solid {color.primary.@}"
|
|
95
|
+
},
|
|
96
|
+
"inverted": {
|
|
97
|
+
"value": "2px solid {color.primary.@}"
|
|
98
|
+
}
|
|
95
99
|
},
|
|
96
100
|
"background": {
|
|
97
|
-
"@": {
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
"@": {
|
|
103
|
-
|
|
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
|
@@ -26,9 +26,10 @@ const deriveParameters = ({ rawParameters, setVersion, setReleaseDate }) => {
|
|
|
26
26
|
}, readFile = async (filePath) => {
|
|
27
27
|
const normalized = path$1.normalize(filePath);
|
|
28
28
|
try {
|
|
29
|
-
|
|
29
|
+
const content = await promises.readFile(normalized, { encoding: "utf8" });
|
|
30
|
+
return content?.replace(/^\uFEFF/, "");
|
|
30
31
|
} catch (error) {
|
|
31
|
-
console.log(pico.red(
|
|
32
|
+
if (console.log(pico.red(`Error reading file: ${normalized}`)), error instanceof Error) console.log(pico.dim(error.message));
|
|
32
33
|
}
|
|
33
34
|
}, copyDirectory = async (source, destination, verbose) => {
|
|
34
35
|
const normalizedSource = path$1.normalize(source), normalizedDestination = path$1.normalize(destination);
|
|
@@ -243,7 +244,7 @@ const deriveParameters = ({ rawParameters, setVersion, setReleaseDate }) => {
|
|
|
243
244
|
return accessSync(dir, constants.R_OK), dir;
|
|
244
245
|
} catch {}
|
|
245
246
|
throw new Error(`template directory not found under ${root}`);
|
|
246
|
-
}, styleVariablesPlugin = (appDir) => {
|
|
247
|
+
}, styleVariablesPlugin = (appDir, inputDir) => {
|
|
247
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")}`;
|
|
248
249
|
return {
|
|
249
250
|
name: "style-variables-plugin",
|
|
@@ -256,6 +257,8 @@ const deriveParameters = ({ rawParameters, setVersion, setReleaseDate }) => {
|
|
|
256
257
|
if (id === resolvedCssPath || id === resolvedJsPath) {
|
|
257
258
|
const configPath = path.join(appDir, "styles/config.json"), configContent = fs$1.readFileSync(configPath, "utf-8"), config = JSON.parse(configContent);
|
|
258
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);
|
|
259
262
|
const sd = new StyleDictionary(config);
|
|
260
263
|
if (id === resolvedCssPath) {
|
|
261
264
|
const files = await sd.formatPlatform("css");
|
|
@@ -268,7 +271,8 @@ const deriveParameters = ({ rawParameters, setVersion, setReleaseDate }) => {
|
|
|
268
271
|
}
|
|
269
272
|
},
|
|
270
273
|
handleHotUpdate({ file, server }) {
|
|
271
|
-
|
|
274
|
+
const isStyleToken = file.includes("/style-tokens/"), isTheme = file === path.join(inputDir, "theme.json");
|
|
275
|
+
if (!isStyleToken && !isTheme) return;
|
|
272
276
|
const ids = [resolvedCssPath, resolvedJsPath];
|
|
273
277
|
return ids.forEach((id) => {
|
|
274
278
|
const mod = server.moduleGraph.getModuleById(id);
|
|
@@ -318,7 +322,7 @@ const require = createRequire(import.meta.url), basePath = process.env.BASE_PATH
|
|
|
318
322
|
} },
|
|
319
323
|
plugins: [
|
|
320
324
|
nodePolyfills({ include: ["buffer"] }),
|
|
321
|
-
styleVariablesPlugin(appPath),
|
|
325
|
+
styleVariablesPlugin(appPath, inputDir),
|
|
322
326
|
react({ exclude: /\/src\/app\/pdf\// }),
|
|
323
327
|
htmlTransformPlugin(parameters.title ?? "DocGen"),
|
|
324
328
|
...mode !== "build" ? [watchInputDirPlugin(inputDir)] : []
|
|
@@ -334,7 +338,8 @@ const require = createRequire(import.meta.url), basePath = process.env.BASE_PATH
|
|
|
334
338
|
...baseConfig,
|
|
335
339
|
build: {
|
|
336
340
|
outDir: outputDir,
|
|
337
|
-
emptyOutDir: true
|
|
341
|
+
emptyOutDir: true,
|
|
342
|
+
minify: false
|
|
338
343
|
}
|
|
339
344
|
});
|
|
340
345
|
else {
|
|
@@ -344,7 +349,7 @@ const require = createRequire(import.meta.url), basePath = process.env.BASE_PATH
|
|
|
344
349
|
}, scaffold = async (command) => {
|
|
345
350
|
const inputDir = findTemplateDir(import.meta.dirname), outputDir = path.normalize(command.output + "/"), verbose = command.verbose === true;
|
|
346
351
|
console.log(pico.green("Creating scaffold template directory")), await copyDirectory(inputDir, outputDir, verbose);
|
|
347
|
-
}, version = "6.
|
|
352
|
+
}, version = "6.4.1";
|
|
348
353
|
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) => {
|
|
349
354
|
scaffold(command);
|
|
350
355
|
}), 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.
|
|
4
|
+
"version": "6.4.1",
|
|
5
5
|
"description": "A tool for creating HTML and PDF documentation",
|
|
6
6
|
"bin": "./dist/cli/cli.js",
|
|
7
7
|
"files": [
|
|
@@ -17,59 +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
|
|
21
|
-
"test": "npm run
|
|
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
|
-
"
|
|
26
|
-
"
|
|
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}":
|
|
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.
|
|
35
|
-
"@tanstack/react-router": "^1.
|
|
36
|
-
"@vitejs/plugin-react": "
|
|
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.
|
|
44
|
+
"commander": "^14.0.2",
|
|
40
45
|
"dotenv": "^17.2.3",
|
|
41
|
-
"fs-extra": "^11.3.
|
|
46
|
+
"fs-extra": "^11.3.3",
|
|
42
47
|
"husky": "^9.1.7",
|
|
43
|
-
"lint-staged": "^16.
|
|
44
|
-
"marked": "^
|
|
48
|
+
"lint-staged": "^16.2.7",
|
|
49
|
+
"marked": "^17.0.1",
|
|
45
50
|
"picocolors": "^1.1.1",
|
|
46
|
-
"react": "^19.
|
|
47
|
-
"react-dom": "^19.
|
|
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.
|
|
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": "^7.3.
|
|
56
|
-
"style-dictionary": "^5.1.
|
|
60
|
+
"rolldown-vite": "^7.3.1",
|
|
61
|
+
"style-dictionary": "^5.1.3",
|
|
57
62
|
"vite": "npm:rolldown-vite@latest",
|
|
58
63
|
"vite-plugin-node-polyfills": "0.22.0",
|
|
59
64
|
"z-schema": "^6.0.2"
|
|
60
65
|
},
|
|
61
66
|
"devDependencies": {
|
|
62
|
-
"@
|
|
63
|
-
"@types/node": "^
|
|
64
|
-
"@types/react": "^19.
|
|
65
|
-
"eslint": "^9.31.0",
|
|
66
|
-
"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",
|
|
67
70
|
"ncp": "^2.0.0",
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"typescript
|
|
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"
|
|
73
76
|
},
|
|
74
77
|
"repository": {
|
|
75
78
|
"type": "git",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|