diff --git a/package.json b/package.json index cb48734..98e2148 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,12 @@ { "name": "reachat", - "version": "0.0.1", + "version": "1.0.0", "description": "Chat UI for Building LLMs", "scripts": { "build-storybook": "storybook build", - "build": "vite build --mode library", + "build": "npm run build:js && npm run build:docs", + "build:js": "vite build --mode library", + "build:docs": "node scripts/docs.js", "lint": "eslint --ext js,ts,tsx", "lint:fix": "eslint --ext js,ts,tsx --fix src", "lint:prettier": "prettier --loglevel warn --write 'src/**/*.{ts,tsx,js,jsx}'", @@ -29,6 +31,7 @@ "require": "./dist/index.umd.cjs", "types": "./dist/index.d.ts" }, + "./docs.json": "./dist/docs.json", "./index.css": "./dist/index.css" }, "browser": "dist/index.js", @@ -39,7 +42,7 @@ "framer-motion": "^10.16.16", "highlight.js": "^11.10.0", "mdast-util-find-and-replace": "^3.0.1", - "reablocks": "^8.4.3", + "reablocks": "^8.4.0", "react-markdown": "^9.0.1", "reakeys": "^2.0.3", "remark-gfm": "^4.0.0", diff --git a/scripts/docs.js b/scripts/docs.js new file mode 100644 index 0000000..9ac71d4 --- /dev/null +++ b/scripts/docs.js @@ -0,0 +1,59 @@ +import { readFileSync, writeFileSync } from 'fs'; +import fg from 'fast-glob'; +import { resolve } from 'path'; +import docgen from 'react-docgen-typescript'; + +/** + * Builds the doc types. + */ +function buildDocs() { + const files = fg.sync('src/**/!(*.stories).tsx'); + + const result = []; + let count = 0; + let fail = 0; + const options = { + savePropValueAsString: true, + // Skip generating docs for HTML attributes + propFilter: (prop) => { + if (prop.declarations !== undefined && prop.declarations.length > 0) { + const hasPropAdditionalDescription = prop.declarations.find((declaration) => { + return !declaration.fileName.includes('node_modules'); + }); + + return Boolean(hasPropAdditionalDescription); + } + + return true; + }, + }; + + const docgenWithTSConfig = docgen.withCustomConfig( + './tsconfig.json', + options + ); + + files.forEach(file => { + console.log('Reading', file); + + try { + const documentation = docgenWithTSConfig.parse(file, options); + if (documentation) { + result.push(...documentation); + count++; + } + } catch (e) { + fail++; + console.error('Error reading', file, e); + } + }); + + const fileName = resolve('dist', 'docs.json'); + writeFileSync(fileName, JSON.stringify(result, null, 2)); + + console.info('Docs created!', fileName); + console.info('Failed:', fail); + console.info('Total Doc:', count); +} + +buildDocs();