react-lib-tools 0.0.2 → 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.
@@ -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
- export declare type ComponentMetadata = {
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
- export declare type ImperativeHandleMetadata = {
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
- export declare type Intent = "danger" | "none" | "primary" | "success" | "warning";
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
- export declare type Section = {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-lib-tools",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "author": "Brian Vaughn <brian.david.vaughn@gmail.com> (https://github.com/bvaughn/)",
6
6
  "contributors": [
@@ -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
  });
@@ -0,0 +1,10 @@
1
+ export function assert(
2
+ expectedCondition: unknown,
3
+ message: string = "Assertion error"
4
+ ): asserts expectedCondition {
5
+ if (!expectedCondition) {
6
+ console.error(message);
7
+
8
+ throw Error(message);
9
+ }
10
+ }
@@ -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 "react-lib-tools";
6
- import { assert } from "../../../lib/utils/assert.ts";
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 { withCustomConfig } from "react-docgen-typescript";
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 = withCustomConfig("./tsconfig.json", {
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 "react-lib-tools";
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(tsConfig);
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
- nodes.push({
29
- filePath: reflectedModule.getSourcePath(),
30
- node: node as unknown as InterfaceNode
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,4 +1,4 @@
1
- import type { Intent, Section } from "react-lib-tools";
1
+ import type { Intent, Section } from "../../../types.ts";
2
2
  import { syntaxHighlight, type Language } from "../syntax-highlight.ts";
3
3
  import { formatDescriptionText } from "./formatDescriptionText.ts";
4
4