aboutsummaryrefslogtreecommitdiff
path: root/scripts/apidocs/processing/source.ts
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2024-04-01 10:21:18 +0200
committerGitHub <[email protected]>2024-04-01 10:21:18 +0200
commit6191a5d883048b694404dbf42527caba395828ea (patch)
treed0f18f17789cb0bbdb5d6087f1a95772438dfe27 /scripts/apidocs/processing/source.ts
parent7dae52bfcd93c41ec9d2c4dd4d96a07f31c3dfc1 (diff)
downloadfaker-6191a5d883048b694404dbf42527caba395828ea.tar.xz
faker-6191a5d883048b694404dbf42527caba395828ea.zip
docs: rewrite api-docs generation using ts-morph (#2628)
Diffstat (limited to 'scripts/apidocs/processing/source.ts')
-rw-r--r--scripts/apidocs/processing/source.ts37
1 files changed, 37 insertions, 0 deletions
diff --git a/scripts/apidocs/processing/source.ts b/scripts/apidocs/processing/source.ts
new file mode 100644
index 00000000..ac23c9fb
--- /dev/null
+++ b/scripts/apidocs/processing/source.ts
@@ -0,0 +1,37 @@
+import type { Node } from 'ts-morph';
+import { FILE_PATH_PROJECT } from '../utils/paths';
+
+/**
+ * Represents a source element in the raw API docs.
+ */
+export interface RawApiDocsSource {
+ /**
+ * The file path of the target element.
+ */
+ filePath: string;
+ /**
+ * The line number of the target element.
+ */
+ line: number;
+ /**
+ * The column number of the target element.
+ */
+ column: number;
+}
+
+export type SourceableNode = Pick<Node, 'getSourceFile' | 'getStart'>;
+
+export function getSourcePath(node: SourceableNode): RawApiDocsSource {
+ const sourceFile = node.getSourceFile();
+ const filePath = sourceFile
+ .getFilePath()
+ .substring(FILE_PATH_PROJECT.length + 1);
+ const startPosition = node.getStart();
+ const { line, column } = sourceFile.getLineAndColumnAtPos(startPosition);
+
+ return {
+ filePath,
+ line,
+ column,
+ };
+}