Skip to content

Commit 0a99edc

Browse files
committed
Added function in the ISourceFile itself to capture the project path, store it & return it when it's demanded rathen than computing it everytime
1 parent a29f8a0 commit 0a99edc

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

rocket-chatter-ingestion-server/src/process/prepare/sourceFile.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
import { readFileSync } from "fs"
2-
import { TreeNode } from "./processor/core/treeNode"
2+
import path from "path"
33
import { ISourceFile } from "./sourceFile.types"
44

55
export class SourceFile implements ISourceFile {
66
private _path: string
7-
private _syntaxNodes: Record<string, TreeNode> = {}
7+
private _projectPath: string
88

9-
constructor(path: string) {
10-
this._path = path.replace(/\\/g, "/")
9+
constructor(filepath: string) {
10+
// Normalize file path
11+
this._path = filepath.replace(/\\/g, "/")
12+
13+
// Get project path
14+
const sourceFileAbsolutePath = path.resolve(this._path).replace(/\\/g, "/")
15+
const projectPath = sourceFileAbsolutePath.slice(
16+
0,
17+
sourceFileAbsolutePath.indexOf(this._path)
18+
)
19+
this._projectPath = projectPath
1120
}
1221

1322
read(): string {
1423
const content = readFileSync(this._path, "utf-8")
1524
return content
1625
}
1726

27+
getProjectPath(): string {
28+
return this._projectPath
29+
}
30+
1831
getFullPath(): string {
1932
return this._path
2033
}

rocket-chatter-ingestion-server/src/process/prepare/sourceFile.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ export enum SourceFileType {
1313

1414
export interface ISourceFile {
1515
read(): string
16+
17+
getProjectPath(): string
1618
getFullPath(): string
1719
}

0 commit comments

Comments
 (0)