From 6191a5d883048b694404dbf42527caba395828ea Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Mon, 1 Apr 2024 10:21:18 +0200 Subject: docs: rewrite api-docs generation using ts-morph (#2628) --- scripts/apidocs/processing/source.ts | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 scripts/apidocs/processing/source.ts (limited to 'scripts/apidocs/processing/source.ts') 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; + +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, + }; +} -- cgit v1.2.3