react-lib-tools 0.0.2 → 0.0.4
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/lib/types.ts +35 -0
- package/package.json +2 -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 +1 -1
package/lib/types.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type Intent = "danger" | "none" | "primary" | "success" | "warning";
|
|
2
|
+
|
|
3
|
+
export type Section = {
|
|
4
|
+
content: string;
|
|
5
|
+
intent?: Intent | undefined;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type ComponentPropMetadata = {
|
|
9
|
+
description: Section[];
|
|
10
|
+
html: string;
|
|
11
|
+
name: string;
|
|
12
|
+
required: boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type ComponentMetadata = {
|
|
16
|
+
description: Section[];
|
|
17
|
+
filePath: string;
|
|
18
|
+
name: string;
|
|
19
|
+
props: {
|
|
20
|
+
[name: string]: ComponentPropMetadata;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type ImperativeHandleMethodMetadata = {
|
|
25
|
+
description: Section[];
|
|
26
|
+
html: string;
|
|
27
|
+
name: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type ImperativeHandleMetadata = {
|
|
31
|
+
description: Section[];
|
|
32
|
+
filePath: string;
|
|
33
|
+
name: string;
|
|
34
|
+
methods: ImperativeHandleMethodMetadata[];
|
|
35
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-lib-tools",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "Brian Vaughn <brian.david.vaughn@gmail.com> (https://github.com/bvaughn/)",
|
|
6
6
|
"contributors": [
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"types": "dist/react-lib-tools.d.ts",
|
|
17
17
|
"files": [
|
|
18
18
|
"dist",
|
|
19
|
+
"lib/types.ts",
|
|
19
20
|
"scripts",
|
|
20
21
|
"styles.css"
|
|
21
22
|
],
|
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 "../../../lib/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 "../../../lib/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
|
});
|