@iviva/react-tsdoc 0.1.7 → 0.2.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.
Files changed (50) hide show
  1. package/README.md +217 -26
  2. package/bin/react-tsdoc.js +1 -1
  3. package/dist/cli/index.d.ts +1 -0
  4. package/dist/cli/index.js +38 -0
  5. package/dist/cli/index.js.map +1 -0
  6. package/dist/core/analyzer.d.ts +18 -0
  7. package/dist/core/analyzer.js +574 -0
  8. package/dist/core/analyzer.js.map +1 -0
  9. package/dist/core/parser.d.ts +4 -0
  10. package/dist/core/parser.js +73 -0
  11. package/dist/core/parser.js.map +1 -0
  12. package/dist/core/types.d.ts +134 -0
  13. package/dist/core/types.js +10 -0
  14. package/dist/core/types.js.map +1 -0
  15. package/dist/generators/docs/component.d.ts +7 -0
  16. package/dist/generators/docs/component.js +87 -0
  17. package/dist/generators/docs/component.js.map +1 -0
  18. package/dist/generators/docs/function.d.ts +2 -0
  19. package/dist/generators/docs/function.js +38 -0
  20. package/dist/generators/docs/function.js.map +1 -0
  21. package/dist/generators/docs/hook.d.ts +2 -0
  22. package/dist/generators/docs/hook.js +36 -0
  23. package/dist/generators/docs/hook.js.map +1 -0
  24. package/dist/generators/docs/type.d.ts +2 -0
  25. package/dist/generators/docs/type.js +61 -0
  26. package/dist/generators/docs/type.js.map +1 -0
  27. package/dist/generators/markdown.d.ts +8 -0
  28. package/dist/generators/markdown.js +44 -0
  29. package/dist/generators/markdown.js.map +1 -0
  30. package/dist/generators/types/module.d.ts +4 -0
  31. package/dist/generators/types/module.js +242 -0
  32. package/dist/generators/types/module.js.map +1 -0
  33. package/dist/index.d.ts +4 -1
  34. package/dist/index.js +116 -603
  35. package/dist/index.js.map +1 -1
  36. package/dist/utils/file.d.ts +3 -0
  37. package/dist/utils/file.js +45 -0
  38. package/dist/utils/file.js.map +1 -0
  39. package/dist/utils/logger.d.ts +5 -0
  40. package/dist/utils/logger.js +28 -0
  41. package/dist/utils/logger.js.map +1 -0
  42. package/dist/utils/type-helpers.d.ts +13 -0
  43. package/dist/utils/type-helpers.js +160 -0
  44. package/dist/utils/type-helpers.js.map +1 -0
  45. package/package.json +28 -18
  46. package/.github/workflows/npm-publish.yml +0 -37
  47. package/clap.d.ts +0 -1
  48. package/package-lock.json +0 -104
  49. package/src/index.ts +0 -812
  50. package/tsconfig.json +0 -15
package/README.md CHANGED
@@ -1,49 +1,240 @@
1
- # React Typescript Document Generator
2
- Documentation generator for React Components written in Typescript.
1
+ # React TypeScript Document Generator
3
2
 
4
- This exists to generate docs for your react components.
3
+ **React TypeScript Document Generator** is a command-line tool that helps you automatically generate **clear, well-structured documentation** and **type definitions** for your React components, hooks, and utility functions written in TypeScript.
5
4
 
6
- It extracts documentation from your components and their props.
5
+ It scans your code, reads **TSDoc-style comments**, and produces:
6
+ - **Markdown documentation** with prop tables, examples, and type signatures.
7
+ - **Type definition files** (`.d.ts`) for easy API sharing.
7
8
 
8
- ## Usage
9
+ Whether you’re building a reusable UI library or maintaining an internal component set, this tool saves you from writing documentation manually and keeps it consistent with your code.
9
10
 
10
- Use tsdoc-style comments for your components:
11
+ ---
11
12
 
13
+ ## Why Use This Tool?
14
+ - **Stay in sync**: Documentation is generated directly from your source code.
15
+ - **Easy to maintain**: Update your comments, re-run the tool, and everything stays current.
16
+ - **Supports multiple React patterns**: Functional components, class components, hooks, and more.
17
+ - **Clear output**: Easy-to-read Markdown for documentation sites and type definitions for developers.
18
+
19
+ ---
20
+
21
+ ## Installation
22
+
23
+ Install globally via npm:
24
+
25
+ ```bash
26
+ npm install -g react-tsdoc
27
+ ````
28
+
29
+ ---
30
+
31
+ ## How It Works
32
+
33
+ 1. **You write code with TSDoc comments** describing your components, props, hooks, or functions.
34
+ 2. **Run the CLI commands** to generate documentation and type definitions.
35
+ 3. **Share or publish** the generated docs and `.d.ts` files.
36
+
37
+ ---
38
+
39
+ ## Commands & Parameters
40
+
41
+ The CLI provides two main commands:
42
+
43
+ ### 1. Generate Type Definitions
44
+
45
+ ```bash
46
+ react-tsdoc types <path-to-root-ts> <output.d.ts> --module-name <module-name>
12
47
  ```
13
- /**
14
48
 
15
- */
49
+ **Purpose**: Creates a `.d.ts` type definition file for your public API.
50
+
51
+ **Parameters**:
52
+
53
+ * `<path-to-root-ts>` — Entry point TypeScript file (e.g., `src/index.ts`).
54
+ * `<output.d.ts>` — Path to save the generated type definitions (e.g., `dist/types.d.ts`).
55
+ * `--module-name <module-name>` — The name of your library/module (e.g., `my-lib`).
56
+
57
+ ---
58
+
59
+ ### 2. Generate Documentation
60
+
61
+ ```bash
62
+ react-tsdoc docs <path-to-root-ts> <output-folder> --module-name <module-name>
16
63
  ```
17
64
 
18
- Your components must either be classes that inherit from `React.Component<P,S>` or, if you're using new-style function components,
19
- then they should be declared as variables of type `React.FunctionComponent<P>`.
65
+ **Purpose**: Generates Markdown documentation in categorized folders (`components`, `hooks`, etc.).
66
+
67
+ **Parameters**:
68
+
69
+ * `<path-to-root-ts>` — Entry point TypeScript file.
70
+ * `<output-folder>` — Folder to store generated Markdown files (e.g., `docs`).
71
+ * `--module-name <module-name>` — Your library/module name.
72
+
73
+ ---
20
74
 
21
- Examples:
75
+ ## Supported Code Patterns
22
76
 
77
+ The generator supports common React patterns and outputs clear documentation for each.
78
+
79
+ ### Functional Components
80
+
81
+ Declared with `React.FC` or `React.FunctionComponent`.
82
+
83
+ ```typescript
84
+ interface ILabelProps {
85
+ /** The label text to display */
86
+ value: string;
87
+ }
88
+ /**
89
+ * A simple label component
90
+ * @export
91
+ * @example <Label value="Hello" />
92
+ */
93
+ const Label: React.FC<ILabelProps> = ({ value }) => <span>{value}</span>;
23
94
  ```
95
+ ---
96
+
97
+ ### Class Components
98
+
99
+ Extend `React.Component` with props (and optional state).
100
+
101
+ ```typescript
24
102
  interface ILabelProps {
25
- /**
26
- * the label text to be set
27
- */
28
- value: string;
103
+ /** The label text to display */
104
+ value: string;
105
+ }
106
+ /**
107
+ * A class-based label component
108
+ * @export
109
+ * @example <Label2 value="Hello" />
110
+ */
111
+ class Label2 extends React.Component<ILabelProps> {
112
+ render() {
113
+ return <span>{this.props.value}</span>;
114
+ }
29
115
  }
116
+ ```
117
+ ---
30
118
 
119
+ ### ForwardRef Components
120
+
121
+ Expose refs using `React.forwardRef`.
122
+
123
+ ```typescript
124
+ interface IRef { focus(): void; }
125
+ interface IInputProps { value: string; }
31
126
  /**
32
- * A simple component to render a static label
33
- */
34
- const Label:React.Component<ILabelProps> = (props) => <span>{props.value}</span>;
127
+ * An input with ref support
128
+ * @export
129
+ * @example <Input ref={ref} value="Hello" />
130
+ */
131
+ const Input = React.forwardRef<IRef, IInputProps>((props, ref) => (
132
+ <input ref={ref} value={props.value} />
133
+ ));
134
+ ```
135
+ ---
35
136
 
137
+ ### Memoized Components
36
138
 
139
+ Use `React.memo` to optimize rendering.
140
+
141
+ ```typescript
142
+ interface IMemoProps { value: string; }
37
143
  /**
38
- * A simple component to render a static label
39
- */
40
- class Label2 extends React.Component<ILabelProps,{}> {
41
- render() {
42
- return <span>{this.props.value}</span>;
43
- }
144
+ * A memoized label
145
+ * @export
146
+ * @example <MemoedLabel value="Hello" />
147
+ */
148
+ const MemoLabel: React.FC<IMemoProps> = ({ value }) => <span>{value}</span>;
149
+ const MemoedLabel = React.memo(MemoLabel);
150
+ ```
151
+ ---
152
+
153
+ ## Functions & Hooks
154
+
155
+ ### Functions
156
+
157
+ Standalone utility functions.
158
+
159
+ ```typescript
160
+ /**
161
+ * Adds two numbers
162
+ * @export
163
+ * @example add(2, 3) // Returns 5
164
+ */
165
+ function add(a: number, b: number): number {
166
+ return a + b;
44
167
  }
45
168
  ```
169
+ ---
46
170
 
47
- ## Commands
48
- react-tsdoc types <path-to-root-ts> <output.d.ts> --module-name <module-name>
171
+ ### Hooks
172
+
173
+ Custom hooks starting with `use`.
174
+
175
+ ```typescript
176
+ /**
177
+ * Fetches data from a URL
178
+ * @export
179
+ * @hook
180
+ * @example const data = useFetchData('url');
181
+ */
182
+ function useFetchData(url: string): string {
183
+ return "data";
184
+ }
185
+ ```
186
+ ---
187
+
188
+ ## Supported TSDoc Annotations
189
+
190
+ | Tag | Description |
191
+ | ---------- | ----------------------------------------------------------------------------------------- |
192
+ | `@export` | Marks the item for inclusion in docs and type definitions. Required for public API items. |
193
+ | `@example` | Adds usage examples (supports multiple). |
194
+ | `@hook` | Optional for hooks; classifies them in generated docs. |
195
+
196
+ ---
197
+
198
+ ## Example Workflow
199
+
200
+ 1. Document your code with TSDoc annotations.
201
+ 2. Generate type definitions:
202
+
203
+ ```bash
204
+ react-tsdoc types src/index.ts dist/types.d.ts --module-name my-ui
205
+ ```
206
+ 3. Generate documentation:
207
+
208
+ ```bash
209
+ react-tsdoc docs src/index.ts docs --module-name my-ui
210
+ ```
211
+
212
+ ---
213
+
214
+ ## Tips for Best Results
215
+
216
+ * Write **clear, concise comments** for props, parameters, and return values.
217
+ * Include **examples** that developers can copy and paste.
218
+ * Keep your public API clean and well-annotated.
219
+
220
+ ---
221
+
222
+ ## Contributing
223
+
224
+ We welcome contributions!
225
+ Here’s how you can help:
226
+
227
+ 1. **Report issues** or suggest features on [GitHub](https://github.com/lucy-platform/react-tsdoc/issues).
228
+ 2. **Submit pull requests** with bug fixes or enhancements.
229
+ 3. Improve this documentation with clearer examples or new sections.
230
+
231
+ Before contributing, please:
232
+
233
+ * Fork the repository.
234
+ * Create a new branch for your changes.
235
+ * Ensure your code follows the existing coding style.
236
+ * Add or update tests when applicable.
237
+
238
+ ---
49
239
 
240
+ Happy documenting! 🚀
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- require('../dist/index').main();
2
+ require('../dist/cli/index').main();
@@ -0,0 +1 @@
1
+ export declare function main(): void;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.main = void 0;
4
+ const commander_1 = require("commander");
5
+ const index_1 = require("../index");
6
+ const logger_1 = require("../utils/logger");
7
+ function main() {
8
+ try {
9
+ commander_1.program
10
+ .name('react-tsdoc')
11
+ .description('Generate docs for React components')
12
+ .version('0.1.9');
13
+ commander_1.program
14
+ .command('types')
15
+ .description('Generate type definitions')
16
+ .argument('[input.ts]', 'Input TypeScript file')
17
+ .argument('[output.d.ts]', 'Output declaration file')
18
+ .option('--module-name <name>', 'Module name for type definitions')
19
+ .action((input, output, options) => {
20
+ (0, index_1.generateTypeDefinition)(input, output, options.moduleName);
21
+ });
22
+ commander_1.program
23
+ .command('docs')
24
+ .description('Generate Markdown documentation')
25
+ .argument('[input.ts]', 'Input TypeScript file')
26
+ .argument('[output-folder]', 'Output folder for documentation')
27
+ .option('--module-name <name>', 'Module name for documentation')
28
+ .action((input, output, options) => {
29
+ (0, index_1.generateDocs)(input, output, options.moduleName);
30
+ });
31
+ commander_1.program.parse(process.argv);
32
+ }
33
+ catch (e) {
34
+ (0, logger_1.logError)(e);
35
+ }
36
+ }
37
+ exports.main = main;
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;AAAA,yCAAoC;AACpC,oCAAgE;AAChE,4CAA2C;AAE3C,SAAgB,IAAI;IAChB,IAAI;QACA,mBAAO;aACF,IAAI,CAAC,aAAa,CAAC;aACnB,WAAW,CAAC,oCAAoC,CAAC;aACjD,OAAO,CAAC,OAAO,CAAC,CAAC;QAEtB,mBAAO;aACF,OAAO,CAAC,OAAO,CAAC;aAChB,WAAW,CAAC,2BAA2B,CAAC;aACxC,QAAQ,CAAC,YAAY,EAAE,uBAAuB,CAAC;aAC/C,QAAQ,CAAC,eAAe,EAAE,yBAAyB,CAAC;aACpD,MAAM,CAAC,sBAAsB,EAAE,kCAAkC,CAAC;aAClE,MAAM,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE;YAC/B,IAAA,8BAAsB,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;QAC9D,CAAC,CAAC,CAAC;QAEP,mBAAO;aACF,OAAO,CAAC,MAAM,CAAC;aACf,WAAW,CAAC,iCAAiC,CAAC;aAC9C,QAAQ,CAAC,YAAY,EAAE,uBAAuB,CAAC;aAC/C,QAAQ,CAAC,iBAAiB,EAAE,iCAAiC,CAAC;aAC9D,MAAM,CAAC,sBAAsB,EAAE,+BAA+B,CAAC;aAC/D,MAAM,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE;YAC/B,IAAA,oBAAY,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;QAEP,mBAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KAC/B;IAAC,OAAO,CAAC,EAAE;QACR,IAAA,iBAAQ,EAAC,CAAC,CAAC,CAAC;KACf;AACL,CAAC;AA/BD,oBA+BC"}
@@ -0,0 +1,18 @@
1
+ import * as ts from 'typescript';
2
+ import { IDocInfo, IReactComponent } from './types';
3
+ export declare function extractComment(node: ts.Node): string;
4
+ export declare function getCode(node: ts.Node): string;
5
+ export declare function unwrapCallWrappers(expr: ts.Expression): {
6
+ inner: ts.Expression;
7
+ wrappers: string[];
8
+ };
9
+ export declare function analyzeComponentPattern(init: ts.Expression, name: string, comment: string, checker: ts.TypeChecker, docInfo: IDocInfo, declaredType?: ts.TypeNode): IReactComponent | null;
10
+ export declare function parseInterfaceDeclaration(node: ts.Node, docInfo: IDocInfo): void;
11
+ export declare function parseVariableDeclaration(node: ts.Node, docInfo: IDocInfo, checker: ts.TypeChecker): void;
12
+ export declare function parseClassDeclaration(node: ts.Node, docInfo: IDocInfo, checker?: ts.TypeChecker): void;
13
+ export declare function parseFunctionDeclaration(node: ts.Node, docInfo: IDocInfo, checker?: ts.TypeChecker): void;
14
+ export declare function parseEnumDeclaration(node: ts.Node, docInfo: IDocInfo): void;
15
+ export declare function parseTypeAlias(node: ts.Node, docInfo: IDocInfo): void;
16
+ export declare function walkTree(node: ts.Node, docInfo: IDocInfo, checker: ts.TypeChecker): void;
17
+ export declare function validateProgram(program: ts.Program): void;
18
+ export declare function getSources(program: ts.Program): string[];