Skip to content

Commit f0da49c

Browse files
committed
refactor: consolidate types into own module
1 parent a141606 commit f0da49c

19 files changed

+309
-465
lines changed

src/all-extracted-declaration.test.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/all-extracted-declaration.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/extract-class.ts

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,49 +17,12 @@ import { isHidden } from "./is-hidden";
1717
import { modifiersText } from "./modifiers-text";
1818
import { sourceFilePath } from "./source-file-path";
1919
import { typeCheckerType } from "./type-checker-type";
20-
21-
export type ExtractedClass = {
22-
kind: "class";
23-
id: string;
24-
name: string;
25-
docs: string[];
26-
file: string;
27-
line: number;
28-
signature: string;
29-
constructors: ExtractedClassConstructor[];
30-
properties: ExtractedClassProperty[];
31-
methods: ExtractedClassMethod[];
32-
};
33-
34-
export type ExtractedClassConstructor = {
35-
kind: "class-constructor";
36-
id: string;
37-
name: string;
38-
docs: string[];
39-
file: string;
40-
line: number;
41-
signature: string;
42-
};
43-
44-
export type ExtractedClassProperty = {
45-
kind: "class-property";
46-
id: string;
47-
name: string;
48-
docs: string[];
49-
file: string;
50-
line: number;
51-
signature: string;
52-
};
53-
54-
export type ExtractedClassMethod = {
55-
kind: "class-method";
56-
id: string;
57-
name: string;
58-
docs: string[];
59-
file: string;
60-
line: number;
61-
signature: string;
62-
};
20+
import type {
21+
ExtractedClass,
22+
ExtractedClassConstructor,
23+
ExtractedClassMethod,
24+
ExtractedClassProperty,
25+
} from "./types";
6326

6427
export const extractClass = async (
6528
containerName: string,

src/extract-declarations.ts

Lines changed: 9 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
import { orderBy } from "natural-orderby";
2-
import {
3-
Node,
4-
type ExportedDeclarations,
5-
type ModuleDeclaration,
6-
type Project,
7-
type SourceFile,
8-
} from "ts-morph";
2+
import { Node, type ExportedDeclarations } from "ts-morph";
93
import { ambientModulesDeclarations } from "./ambient-modules-declarations";
104
import { exportEqualsDeclarations } from "./export-equals-declarations";
115
import { exportedDeclarations } from "./exported-declarations";
12-
import { extractClass, type ExtractedClass } from "./extract-class";
13-
import { extractEnum, type ExtractedEnum } from "./extract-enum";
6+
import { extractClass } from "./extract-class";
7+
import { extractEnum } from "./extract-enum";
148
import { extractExpression } from "./extract-expression";
159
import { extractFileModule } from "./extract-file-module";
16-
import { extractFunction, type ExtractedFunction } from "./extract-function";
10+
import { extractFunction } from "./extract-function";
1711
import { extractFunctionExpression } from "./extract-function-expression";
18-
import { extractInterface, type ExtractedInterface } from "./extract-interface";
19-
import { extractNamespace, type ExtractedNamespace } from "./extract-namespace";
20-
import { extractTypeAlias, type ExtractedTypeAlias } from "./extract-type-alias";
21-
import { extractVariable, type ExtractedVariable } from "./extract-variable";
12+
import { extractInterface } from "./extract-interface";
13+
import { extractNamespace } from "./extract-namespace";
14+
import { extractTypeAlias } from "./extract-type-alias";
15+
import { extractVariable } from "./extract-variable";
2216
import { extractVariableAssignmentExpression } from "./extract-variable-assignment-expression";
2317
import { globalAmbientDeclarations } from "./global-ambient-declarations";
2418
import { id } from "./id";
@@ -33,55 +27,7 @@ import { isNamespace } from "./is-namespace";
3327
import { isTypeAlias } from "./is-type-alias";
3428
import { isVariable } from "./is-variable";
3529
import { isVariableAssignmentExpression } from "./is-variable-assignment-expression";
36-
37-
/**
38-
`ExtractDeclarationsOptions` contains all the options
39-
for calling {@link extractDeclarations}.
40-
41-
@internal
42-
*/
43-
export type ExtractDeclarationsOptions = {
44-
/**
45-
Name of the container that contains the top-level declarations
46-
(e.g., a namespace's name). This is used to generate declaration IDs.
47-
*/
48-
containerName: string;
49-
50-
/** Container that contains the top-level declarations. */
51-
container: SourceFile | ModuleDeclaration;
52-
53-
/** Maximum extraction depth for nested namespaces. */
54-
maxDepth: number;
55-
56-
/**
57-
Instance of a `ts-morph` `Project`. This is used to find ambient modules.
58-
*/
59-
project?: Project;
60-
61-
/**
62-
Name of the package being analyzed. This is used to filter ambient modules.
63-
*/
64-
pkgName?: string;
65-
};
66-
67-
/**
68-
`ExtractedDeclaration` is the union of all possible top-level declarations
69-
that can be extracted from a package, module or namespace.
70-
*/
71-
export type ExtractedDeclaration =
72-
| ExtractedVariable
73-
| ExtractedFunction
74-
| ExtractedClass
75-
| ExtractedInterface
76-
| ExtractedEnum
77-
| ExtractedTypeAlias
78-
| ExtractedNamespace;
79-
80-
/**
81-
`ExtractedDeclarationKind` is the union of all discriminators
82-
used to detect the kind of top-level declaration.
83-
*/
84-
export type ExtractedDeclarationKind = ExtractedDeclaration["kind"];
30+
import type { ExtractDeclarationsOptions, ExtractedDeclaration } from "./types";
8531

8632
/**
8733
`extractDeclarations` extracts the top-level declarations found in a container

src/extract-enum.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,7 @@ import { headText } from "./head-text";
55
import { id } from "./id";
66
import { isHidden } from "./is-hidden";
77
import { sourceFilePath } from "./source-file-path";
8-
9-
export type ExtractedEnum = {
10-
kind: "enum";
11-
id: string;
12-
name: string;
13-
docs: string[];
14-
file: string;
15-
line: number;
16-
signature: string;
17-
members: ExtractedEnumMember[];
18-
};
19-
20-
export type ExtractedEnumMember = {
21-
kind: "enum-member";
22-
id: string;
23-
name: string;
24-
docs: string[];
25-
file: string;
26-
line: number;
27-
signature: string;
28-
};
8+
import type { ExtractedEnum, ExtractedEnumMember } from "./types";
299

3010
export const extractEnum = async (
3111
containerName: string,

src/extract-expression.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { Expression } from "ts-morph";
22
import { apparentType } from "./apparent-type";
33
import { docs } from "./docs";
4-
import type { ExtractedVariable } from "./extract-variable";
54
import { formatSignature } from "./format-signature";
65
import { id } from "./id";
76
import { sourceFilePath } from "./source-file-path";
7+
import type { ExtractedVariable } from "./types";
88

99
export const extractExpression = async (
1010
containerName: string,

src/extract-file-module.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { SourceFile, SyntaxKind } from "ts-morph";
2-
import type { ExtractedDeclaration } from "./extract-declarations";
3-
import type { ExtractedNamespace } from "./extract-namespace";
42
import { formatSignature } from "./format-signature";
53
import { id } from "./id";
64
import { sourceFilePath } from "./source-file-path";
5+
import type { ExtractedDeclaration, ExtractedNamespace } from "./types";
76

87
export const extractFileModule = async (
98
containerName: string,

src/extract-function-expression.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { VariableDeclaration } from "ts-morph";
22
import { docs } from "./docs";
3-
import type { ExtractedFunction } from "./extract-function";
43
import { formatSignature } from "./format-signature";
54
import { id } from "./id";
65
import { sourceFilePath } from "./source-file-path";
76
import { typeCheckerType } from "./type-checker-type";
7+
import type { ExtractedFunction } from "./types";
88

99
export const extractFunctionExpression = async (
1010
containerName: string,

src/extract-function.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,7 @@ import { formatSignature } from "./format-signature";
44
import { id } from "./id";
55
import { sourceFilePath } from "./source-file-path";
66
import { typeCheckerType } from "./type-checker-type";
7-
8-
export type ExtractedFunction = {
9-
kind: "function";
10-
id: string;
11-
name: string;
12-
docs: string[];
13-
file: string;
14-
line: number;
15-
signature: string;
16-
};
7+
import type { ExtractedFunction } from "./types";
178

189
export const extractFunction = async (
1910
containerName: string,

0 commit comments

Comments
 (0)