Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from 'fs';
import path from 'path';
import { cpSync } from 'fs';

const spaScript = `
<!-- Start Single Page Apps for GitHub Pages -->
Expand All @@ -13,14 +12,14 @@ const spaScript = `
<!-- End Single Page Apps for GitHub Pages -->
`;

// 1. Deep copy deploy/docs -> docs
cpSync('deploy/include', 'docs/', { recursive: true });
// 1. Deep copy deploy-website/docs -> docs
fs.cpSync('deploy-website/include', 'docs/', { recursive: true });

// 2. Insert SPA script into index.html
const indexFile = path.join('docs', 'index.html');
let html = fs.readFileSync(indexFile, 'utf-8');

// Find <title> tag and insert after it
// Find the <title> tag and insert after it
html = html.replace(/(<title>.*?<\/title>)/, `$1\n${spaScript}`);

fs.writeFileSync(indexFile, html, 'utf-8');
Expand Down
File renamed without changes.
15 changes: 6 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "docgen-tool",
"type": "module",
"version": "6.4.4",
"version": "6.4.5",
"description": "A tool for creating HTML and PDF documentation",
"packageManager": "pnpm@10.28.0",
"bin": "./dist/cli/cli.js",
Expand All @@ -11,14 +11,14 @@
"scripts": {
"check:types": "tsc --noEmit",
"bundle:cli": "vite build --config ./vite.bundle.cli.config.ts && chmod +x dist/cli/cli.js",
"bundle:app": "rimraf dist/app dist/template && ncp src/app dist/app && ncp src/template dist/template",
"bundle:app": "tsx scripts/bundle-app.ts",
"bundle": "pnpm bundle:cli && pnpm bundle:app",
"dev:docs": "tsx src/cli/cli.ts dev -i src/docs -o ./docs",
"build:docs": "tsx src/cli/cli.ts build -i src/docs -o ./docs",
"preview:docs": "pnpx serve -s ./docs",
"build:docs:gh": "tsx src/cli/cli.ts build -i src/docs -o ./docs && pnpm copy:gh:files",
"copy:gh:files": "node deploy/before-deploy-website.js",
"preview:style:variables": "rimraf src/app/styles/style-variables && pnpx style-dictionary build --config src/app/styles/config.json && pnpm formatting:fix",
"copy:gh:files": "node deploy-website/before-deploy-website.ts",
"preview:style:variables": "tsx scripts/build-styles-preview.ts",
"test": "pnpm formatting:check",
"test:run": "tsx src/cli/cli.ts build -i src/__test__/test-run -o src/__test__/test-run-output",
"test:scaffold": "tsx src/cli/cli.ts scaffold -o src/__test__/test-run-output",
Expand All @@ -38,14 +38,12 @@
},
"dependencies": {
"@react-pdf/renderer": "^4.3.2",
"@tanstack/react-router": "^1.150.0",
"@tanstack/react-router": "^1.151.1",
"@vitejs/plugin-react": "5.1.2",
"classnames": "^2.5.1",
"commander": "^14.0.2",
"dotenv": "^17.2.3",
"fs-extra": "^11.3.3",
"husky": "^9.1.7",
"lint-staged": "^16.2.7",
"marked": "^17.0.1",
"node-html-parser": "^7.0.2",
"picocolors": "^1.1.1",
Expand All @@ -66,10 +64,9 @@
"@prettier/plugin-oxc": "^0.1.3",
"@types/node": "^25.0.9",
"@types/react": "^19.2.8",
"ncp": "^2.0.0",
"lint-staged": "^16.2.7",
"oxlint": "^1.39.0",
"prettier": "^3.8.0",
"rimraf": "^6.1.2",
"tsx": "^4.21.0",
"typescript": "^5.9.3"
},
Expand Down
99 changes: 17 additions & 82 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions scripts/build-styles-preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { rmSync } from 'fs';
import { execSync } from 'child_process';

rmSync('src/app/styles/style-variables', { recursive: true, force: true });

execSync('pnpm style-dictionary build --config src/app/styles/config.json', {
stdio: 'inherit',
});

execSync('pnpm formatting:fix', { stdio: 'inherit' });
10 changes: 10 additions & 0 deletions scripts/bundle-app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { rmSync, cpSync } from 'fs';

const paths = ['dist/app', 'dist/template'];

// Clean
paths.forEach((p) => rmSync(p, { recursive: true, force: true }));

// Copy
cpSync('src/app', 'dist/app', { recursive: true });
cpSync('src/template', 'dist/template', { recursive: true });
18 changes: 7 additions & 11 deletions src/docgen/fs/fs.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import path from 'path';
import path from 'node:path';
import { promises as fs } from 'node:fs';
import pico from 'picocolors';
import { promises as fsp } from 'fs';
import fs from 'fs-extra';

export const readFile = async (filePath: string) => {
const normalized = path.normalize(filePath);
try {
const content = await fsp.readFile(normalized, { encoding: 'utf8' });
const content = await fs.readFile(normalized, { encoding: 'utf8' });
// remove the BOM (byte-order-mark) from UTF-8 files, if present
return content?.replace(/^\uFEFF/, '');
} catch (error) {
Expand All @@ -25,18 +24,15 @@ export const copyDirectory = async (
const normalizedSource = path.normalize(source);
const normalizedDestination = path.normalize(destination);
try {
await fs.copySync(normalizedSource, normalizedDestination);
await fs.cp(normalizedSource, normalizedDestination, { recursive: true });
} catch (error) {
console.log(
pico.red(
'Error copying directory: ' +
normalizedSource +
' to ' +
normalizedDestination,
`Error copying directory: ${normalizedSource} to ${normalizedDestination}`,
),
);
if (verbose === true) {
console.log(pico.red(error));
if (verbose) {
console.log(pico.red(error instanceof Error ? error.message : error));
}
}
};
Loading