Skip to content

Commit

Permalink
Avoid double docgen on docsite startup
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenpetryk committed Jun 15, 2024
1 parent ae94fb4 commit 4520319
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"test:e2e": "tsx scripts/testgen.ts && playwright test",
"build": "tsx scripts/build.ts",
"build:docs": "pnpm -s docgen && cd docs && pnpm -s build",
"docgen": "tsx scripts/docgen.ts",
"docgen": "tsx scripts/docgen-cli.ts",
"api-report:update": "pnpm tsc && api-extractor run --local",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"format": "prettier --write .",
Expand Down
14 changes: 14 additions & 0 deletions scripts/docgen-cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import fg from "fast-glob"
import { projectRoot, writeDocgenResults } from "./docgen"
import path from "node:path"

import * as docgen from "react-docgen-typescript"

const tsConfigPath = path.join(projectRoot, "tsconfig.json")
const parse = docgen.withCustomConfig(tsConfigPath, {
shouldRemoveUndefinedFromOptional: true,
}).parseWithProgramProvider

const paths = fg.sync("src/**/*.tsx", { ignore: ["src/index.tsx"] })
const docgenInfo = parse(paths)
writeDocgenResults(docgenInfo)
17 changes: 3 additions & 14 deletions scripts/docgen.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import fg from "fast-glob"
import fs from "node:fs"
import { fileURLToPath } from "node:url"
import path from "node:path"
import type * as docgen from "react-docgen-typescript"

import * as docgen from "react-docgen-typescript"

const projectRoot = path.join(path.dirname(fileURLToPath(import.meta.url)), "..")
const tsConfigPath = path.join(projectRoot, "tsconfig.json")
const parse = docgen.withCustomConfig(tsConfigPath, {
shouldRemoveUndefinedFromOptional: true,
}).parseWithProgramProvider
export const projectRoot = path.join(path.dirname(fileURLToPath(import.meta.url)), "..")

export function writeDocgenResults(docgenInfo: docgen.ComponentDoc[]) {
const writePath = path.join(projectRoot, "docs/generated-docgen.tsx")
Expand All @@ -28,10 +22,5 @@ export function writeDocgenResults(docgenInfo: docgen.ComponentDoc[]) {
].join("\n") + "\n",
)

console.log(`Docgen updated ${writePath}`)
console.error(`Docgen updated ${writePath}`)
}

const paths = fg.sync("src/**/*.tsx", { ignore: ["src/index.tsx"] })

const docgenInfo = parse(paths)
writeDocgenResults(docgenInfo)

0 comments on commit 4520319

Please sign in to comment.