(fsPath: string)
| 21 | } |
| 22 | |
| 23 | export async function getNodeIdFromFile(fsPath: string): Promise<string> { |
| 24 | const fileContent: string = await fse.readFile(fsPath, "utf8"); |
| 25 | let id: string = ""; |
| 26 | const matchResults: RegExpMatchArray | null = fileContent.match(/@lc.+id=(.+?) /); |
| 27 | if (matchResults && matchResults.length === 2) { |
| 28 | id = matchResults[1]; |
| 29 | } |
| 30 | // Try to get id from file name if getting from comments failed |
| 31 | if (!id) { |
| 32 | id = path.basename(fsPath).split(".")[0]; |
| 33 | } |
| 34 | |
| 35 | return id; |
| 36 | } |