Skip to content

Commit

Permalink
feat: add sourceFilePath
Browse files Browse the repository at this point in the history
  • Loading branch information
velut committed Jan 9, 2024
1 parent cf52fca commit 29fb2e7
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/extract-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { headText } from "./head-text";
import { id } from "./id";
import { isHidden } from "./is-hidden";
import { modifiersText } from "./modifiers-text";
import { sourceFilePath } from "./source-file-path";
import { typeCheckerType } from "./type-checker-type";

export type ExtractedClass = {
Expand Down Expand Up @@ -71,7 +72,7 @@ export const extractClass = async (
id: classId,
name: exportName,
docs: docs(declaration),
file: declaration.getSourceFile().getFilePath() as string,
file: sourceFilePath(declaration),
line: declaration.getStartLineNumber(),
signature: await classSignature(declaration),
constructors: await extractClassConstructors(classId, declaration),
Expand Down Expand Up @@ -112,7 +113,7 @@ const extractClassConstructors = async (
id: id(classId, "constructor", index > 0 ? `${index}` : ""),
name: "constructor",
docs: docs(declaration),
file: declaration.getSourceFile().getFilePath() as string,
file: sourceFilePath(declaration),
line: declaration.getStartLineNumber(),
signature: await classConstructorSignature(declaration),
});
Expand Down Expand Up @@ -159,7 +160,7 @@ const extractClassProperties = async (
id: id(classId, "property", name),
name,
docs: docs(declaration),
file: declaration.getSourceFile().getFilePath() as string,
file: sourceFilePath(declaration),
line: declaration.getStartLineNumber(),
signature: await classPropertySignature(name, declaration),
});
Expand Down Expand Up @@ -220,7 +221,7 @@ const extractClassMethods = async (
id: id(classId, "method", name),
name,
docs: docs(declaration),
file: declaration.getSourceFile().getFilePath() as string,
file: sourceFilePath(declaration),
line: declaration.getStartLineNumber(),
signature: await classMethodSignature(name, declaration),
});
Expand Down
3 changes: 2 additions & 1 deletion src/extract-expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { docs } from "./docs";
import type { ExtractedVariable } from "./extract-variable";
import { formatSignature } from "./format-signature";
import { id } from "./id";
import { sourceFilePath } from "./source-file-path";

export const extractExpression = async (
containerName: string,
Expand All @@ -14,7 +15,7 @@ export const extractExpression = async (
id: id(containerName, "variable", exportName),
name: exportName,
docs: docs(declaration),
file: declaration.getSourceFile().getFilePath() as string,
file: sourceFilePath(declaration),
line: declaration.getStartLineNumber(),
signature: await expressionSignature(exportName, declaration),
});
Expand Down
3 changes: 2 additions & 1 deletion src/extract-function-expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { docs } from "./docs";
import type { ExtractedFunction } from "./extract-function";
import { formatSignature } from "./format-signature";
import { id } from "./id";
import { sourceFilePath } from "./source-file-path";
import { typeCheckerType } from "./type-checker-type";

export const extractFunctionExpression = async (
Expand All @@ -14,7 +15,7 @@ export const extractFunctionExpression = async (
id: id(containerName, "function", exportName),
name: exportName,
docs: docs(declaration),
file: declaration.getSourceFile().getFilePath() as string,
file: sourceFilePath(declaration),
line: declaration.getStartLineNumber(),
signature: await functionExpressionSignature(exportName, declaration),
});
Expand Down
3 changes: 2 additions & 1 deletion src/extract-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { FunctionDeclaration } from "ts-morph";
import { docs } from "./docs";
import { formatSignature } from "./format-signature";
import { id } from "./id";
import { sourceFilePath } from "./source-file-path";
import { typeCheckerType } from "./type-checker-type";

export type ExtractedFunction = {
Expand All @@ -23,7 +24,7 @@ export const extractFunction = async (
id: id(containerName, "function", exportName),
name: exportName,
docs: docs(declaration),
file: declaration.getSourceFile().getFilePath() as string,
file: sourceFilePath(declaration),
line: declaration.getStartLineNumber(),
signature: await functionSignature(exportName, declaration),
});
Expand Down
3 changes: 2 additions & 1 deletion src/extract-type-alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { TypeAliasDeclaration } from "ts-morph";
import { docs } from "./docs";
import { formatSignature } from "./format-signature";
import { id } from "./id";
import { sourceFilePath } from "./source-file-path";

export type ExtractedTypeAlias = {
kind: "type-alias";
Expand All @@ -22,7 +23,7 @@ export const extractTypeAlias = async (
id: id(containerName, "type-alias", exportName),
name: exportName,
docs: docs(declaration),
file: declaration.getSourceFile().getFilePath() as string,
file: sourceFilePath(declaration),
line: declaration.getStartLineNumber(),
signature: await typeAliasSignature(declaration),
});
Expand Down
3 changes: 2 additions & 1 deletion src/extract-variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { apparentType } from "./apparent-type";
import { docs } from "./docs";
import { formatSignature } from "./format-signature";
import { id } from "./id";
import { sourceFilePath } from "./source-file-path";

export type ExtractedVariable = {
kind: "variable";
Expand All @@ -23,7 +24,7 @@ export const extractVariable = async (
id: id(containerName, "variable", exportName),
name: exportName,
docs: docs(declaration),
file: declaration.getSourceFile().getFilePath() as string,
file: sourceFilePath(declaration),
line: declaration.getStartLineNumber(),
signature: await variableSignature(exportName, declaration),
});
Expand Down
5 changes: 5 additions & 0 deletions src/source-file-path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { Node } from "ts-morph";

export const sourceFilePath = (node: Node): string => {
return node.getSourceFile().getFilePath();
};

0 comments on commit 29fb2e7

Please sign in to comment.