( ide: IDE, dir: string, )
| 11 | import { joinPathsToUri } from "../util/uri"; |
| 12 | |
| 13 | export async function getPromptFilesFromDir( |
| 14 | ide: IDE, |
| 15 | dir: string, |
| 16 | ): Promise<{ path: string; content: string }[]> { |
| 17 | try { |
| 18 | const exists = await ide.fileExists(dir); |
| 19 | |
| 20 | if (!exists) { |
| 21 | return []; |
| 22 | } |
| 23 | |
| 24 | const uris = await walkDir(dir, ide, { |
| 25 | source: "get dir prompt files", |
| 26 | }); |
| 27 | const promptFilePaths = uris.filter( |
| 28 | (p) => p.endsWith(".prompt") || p.endsWith(".md"), |
| 29 | ); |
| 30 | const results = promptFilePaths.map(async (uri) => { |
| 31 | const content = await ide.readFile(uri); // make a try catch |
| 32 | return { path: uri, content }; |
| 33 | }); |
| 34 | return Promise.all(results); |
| 35 | } catch (e) { |
| 36 | console.error(e); |
| 37 | return []; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | export async function getAllPromptFiles( |
| 42 | ide: IDE, |
no test coverage detected