react-lib-tools 0.0.1 → 0.0.3
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/react-lib-tools.d.ts +8 -32
- package/package.json +1 -1
- package/scripts/compile-docs.ts +5 -0
- package/scripts/utils/assert.ts +10 -0
- package/scripts/utils/docs/compileComponent.ts +2 -2
- package/scripts/utils/docs/compileComponents.ts +5 -2
- package/scripts/utils/docs/compileImperativeHandle.ts +1 -1
- package/scripts/utils/docs/compileImperativeHandles.ts +12 -7
- package/scripts/utils/docs/parseDescription.ts +2 -2
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { AnchorHTMLAttributes } from 'react';
|
|
2
2
|
import { ClassValue } from 'clsx';
|
|
3
|
+
import { ComponentMetadata } from '../types';
|
|
3
4
|
import { ComponentType } from 'react';
|
|
4
5
|
import { CSSProperties } from 'react';
|
|
5
6
|
import { HTMLAttributes } from 'react';
|
|
7
|
+
import { ImperativeHandleMetadata } from '../types';
|
|
6
8
|
import { InputHTMLAttributes } from 'react';
|
|
9
|
+
import { Intent } from '../types';
|
|
7
10
|
import { JSX } from 'react/jsx-runtime';
|
|
8
11
|
import { LazyExoticComponent } from 'react';
|
|
9
12
|
import { MouseEvent as MouseEvent_2 } from 'react';
|
|
10
13
|
import { PropsWithChildren } from 'react';
|
|
11
14
|
import { ReactNode } from 'react';
|
|
15
|
+
import { Section } from '../types';
|
|
12
16
|
|
|
13
17
|
export declare function AppRoot({ hideVersions, navLinks, packageDescription, packageName, routes }: {
|
|
14
18
|
hideVersions?: boolean | undefined;
|
|
@@ -65,21 +69,7 @@ export declare function Code({ className, html }: {
|
|
|
65
69
|
html: string;
|
|
66
70
|
}): JSX.Element;
|
|
67
71
|
|
|
68
|
-
|
|
69
|
-
description: Section[];
|
|
70
|
-
filePath: string;
|
|
71
|
-
name: string;
|
|
72
|
-
props: {
|
|
73
|
-
[name: string]: ComponentPropMetadata;
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
declare type ComponentPropMetadata = {
|
|
78
|
-
description: Section[];
|
|
79
|
-
html: string;
|
|
80
|
-
name: string;
|
|
81
|
-
required: boolean;
|
|
82
|
-
};
|
|
72
|
+
export { ComponentMetadata }
|
|
83
73
|
|
|
84
74
|
export declare function ComponentProps({ json, section }: {
|
|
85
75
|
json: ComponentMetadata;
|
|
@@ -105,18 +95,7 @@ export declare function ImperativeHandle({ json, section }: {
|
|
|
105
95
|
section: string;
|
|
106
96
|
}): JSX.Element;
|
|
107
97
|
|
|
108
|
-
|
|
109
|
-
description: Section[];
|
|
110
|
-
filePath: string;
|
|
111
|
-
name: string;
|
|
112
|
-
methods: ImperativeHandleMethodMetadata[];
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
declare type ImperativeHandleMethodMetadata = {
|
|
116
|
-
description: Section[];
|
|
117
|
-
html: string;
|
|
118
|
-
name: string;
|
|
119
|
-
};
|
|
98
|
+
export { ImperativeHandleMetadata }
|
|
120
99
|
|
|
121
100
|
export declare function Input<Type extends string>({ children, className, onChange, value, ...rest }: PropsWithChildren<Omit<InputHTMLAttributes<HTMLInputElement>, "onChange"> & {
|
|
122
101
|
className?: string | undefined;
|
|
@@ -124,7 +103,7 @@ export declare function Input<Type extends string>({ children, className, onChan
|
|
|
124
103
|
value: Type;
|
|
125
104
|
}>): JSX.Element;
|
|
126
105
|
|
|
127
|
-
|
|
106
|
+
export { Intent }
|
|
128
107
|
|
|
129
108
|
export declare function Link({ children, onClick, to, ...rest }: Omit<HTMLAttributes<HTMLSpanElement>, "children"> & {
|
|
130
109
|
children?: ReactNode | RenderFunction;
|
|
@@ -160,10 +139,7 @@ declare type RenderFunction = (params: {
|
|
|
160
139
|
isPending: boolean;
|
|
161
140
|
}) => ReactNode;
|
|
162
141
|
|
|
163
|
-
|
|
164
|
-
content: string;
|
|
165
|
-
intent?: Intent | undefined;
|
|
166
|
-
};
|
|
142
|
+
export { Section }
|
|
167
143
|
|
|
168
144
|
export declare function Select<Value extends string>({ className, defaultValue, onChange, options, placeholder, value }: {
|
|
169
145
|
className?: string;
|
package/package.json
CHANGED
package/scripts/compile-docs.ts
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
import { compileComponents } from "./utils/docs/compileComponents.ts";
|
|
2
2
|
import { compileImperativeHandles } from "./utils/docs/compileImperativeHandles.ts";
|
|
3
|
+
import type { CompilerOptions } from "typescript";
|
|
3
4
|
|
|
4
5
|
export async function compileDocs({
|
|
6
|
+
compilerOptions = {},
|
|
5
7
|
componentNames,
|
|
6
8
|
imperativeHandleNames,
|
|
7
9
|
outputDirName = "docs"
|
|
8
10
|
}: {
|
|
11
|
+
compilerOptions: Partial<CompilerOptions>;
|
|
9
12
|
componentNames: string[];
|
|
10
13
|
imperativeHandleNames: string[];
|
|
11
14
|
outputDirName?: string | undefined;
|
|
12
15
|
}) {
|
|
13
16
|
await compileComponents({
|
|
17
|
+
compilerOptions,
|
|
14
18
|
componentNames,
|
|
15
19
|
outputDirName
|
|
16
20
|
});
|
|
17
21
|
|
|
18
22
|
await compileImperativeHandles({
|
|
23
|
+
compilerOptions,
|
|
19
24
|
names: imperativeHandleNames,
|
|
20
25
|
outputDirName
|
|
21
26
|
});
|
|
@@ -2,8 +2,8 @@ import { writeFile } from "node:fs/promises";
|
|
|
2
2
|
import { join, relative } from "node:path";
|
|
3
3
|
import { cwd } from "node:process";
|
|
4
4
|
import { type FileParser, type PropItem } from "react-docgen-typescript";
|
|
5
|
-
import type { ComponentMetadata } from "../../../
|
|
6
|
-
import { assert } from "
|
|
5
|
+
import type { ComponentMetadata } from "../../../types.ts";
|
|
6
|
+
import { assert } from "../assert.ts";
|
|
7
7
|
import { syntaxHighlight } from "../syntax-highlight.ts";
|
|
8
8
|
import { getPropTypeText } from "./getPropTypeText.ts";
|
|
9
9
|
import { parseDescription } from "./parseDescription.ts";
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { readFile, writeFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { cwd } from "node:process";
|
|
4
|
-
import {
|
|
4
|
+
import { withCompilerOptions } from "react-docgen-typescript";
|
|
5
|
+
import type { CompilerOptions } from "typescript";
|
|
5
6
|
import { initialize } from "../initialize.ts";
|
|
6
7
|
import { compileComponent } from "./compileComponent.ts";
|
|
7
8
|
import { insertPropsMarkdown } from "./insertPropsMarkdown.ts";
|
|
8
9
|
|
|
9
10
|
export async function compileComponents({
|
|
11
|
+
compilerOptions,
|
|
10
12
|
componentNames,
|
|
11
13
|
outputDirName
|
|
12
14
|
}: {
|
|
15
|
+
compilerOptions: Partial<CompilerOptions>;
|
|
13
16
|
componentNames: string[];
|
|
14
17
|
outputDirName: string;
|
|
15
18
|
}) {
|
|
16
|
-
const parser =
|
|
19
|
+
const parser = withCompilerOptions(compilerOptions, {
|
|
17
20
|
savePropValueAsString: true,
|
|
18
21
|
shouldExtractLiteralValuesFromEnum: true,
|
|
19
22
|
shouldExtractValuesFromUnion: true,
|
|
@@ -2,7 +2,7 @@ import type { InterfaceNode } from "@ts-ast-parser/core";
|
|
|
2
2
|
import assert from "node:assert";
|
|
3
3
|
import { writeFile } from "node:fs/promises";
|
|
4
4
|
import { join } from "path";
|
|
5
|
-
import type { ImperativeHandleMetadata } from "../../../
|
|
5
|
+
import type { ImperativeHandleMetadata } from "../../../types.ts";
|
|
6
6
|
import { syntaxHighlight } from "../syntax-highlight.ts";
|
|
7
7
|
import { parseDescription } from "./parseDescription.ts";
|
|
8
8
|
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { parseFromProject, type InterfaceNode } from "@ts-ast-parser/core";
|
|
2
|
-
import tsConfig from "../../../tsconfig.json" with { type: "json" };
|
|
3
|
-
import { compileImperativeHandle } from "./compileImperativeHandle.ts";
|
|
4
2
|
import { join } from "node:path";
|
|
5
3
|
import { cwd } from "node:process";
|
|
4
|
+
import type { CompilerOptions } from "typescript";
|
|
5
|
+
import { compileImperativeHandle } from "./compileImperativeHandle.ts";
|
|
6
6
|
|
|
7
7
|
export async function compileImperativeHandles({
|
|
8
|
+
compilerOptions,
|
|
8
9
|
names,
|
|
9
10
|
outputDirName
|
|
10
11
|
}: {
|
|
12
|
+
compilerOptions: Partial<CompilerOptions>;
|
|
11
13
|
names: string[];
|
|
12
14
|
outputDirName: string;
|
|
13
15
|
}) {
|
|
14
16
|
const outputDir = join(cwd(), "public", "generated", outputDirName);
|
|
15
17
|
|
|
16
|
-
const result = await parseFromProject(
|
|
18
|
+
const result = await parseFromProject({ compilerOptions });
|
|
17
19
|
const reflectedModules = result.project?.getModules() ?? [];
|
|
18
20
|
|
|
19
21
|
const nodes: {
|
|
@@ -25,10 +27,13 @@ export async function compileImperativeHandles({
|
|
|
25
27
|
reflectedModules.forEach((reflectedModule) => {
|
|
26
28
|
const node = reflectedModule.getDeclarationByName(name);
|
|
27
29
|
if (node) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const filePath = reflectedModule.getSourcePath();
|
|
31
|
+
if (filePath.startsWith("lib/")) {
|
|
32
|
+
nodes.push({
|
|
33
|
+
filePath,
|
|
34
|
+
node: node as unknown as InterfaceNode
|
|
35
|
+
});
|
|
36
|
+
}
|
|
32
37
|
}
|
|
33
38
|
});
|
|
34
39
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Intent, Section } from "../../../
|
|
2
|
-
import { formatDescriptionText } from "./formatDescriptionText.ts";
|
|
1
|
+
import type { Intent, Section } from "../../../types.ts";
|
|
3
2
|
import { syntaxHighlight, type Language } from "../syntax-highlight.ts";
|
|
3
|
+
import { formatDescriptionText } from "./formatDescriptionText.ts";
|
|
4
4
|
|
|
5
5
|
export async function parseDescription(rawText: string) {
|
|
6
6
|
const sections: Section[] = [];
|