( vault: Pick<App["vault"], "adapter" | "createFolder">, folderPath: string )
| 21 | }; |
| 22 | |
| 23 | export async function ensureFolderHierarchy( |
| 24 | vault: Pick<App["vault"], "adapter" | "createFolder">, |
| 25 | folderPath: string |
| 26 | ): Promise<void> { |
| 27 | if (!folderPath) { |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | const normalized = normalizePath(folderPath); |
| 32 | const segments = normalized.split("/").filter((segment) => segment.length > 0); |
| 33 | |
| 34 | if (segments.length === 0) { |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | let currentPath = ""; |
| 39 | for (const segment of segments) { |
| 40 | currentPath = currentPath ? `${currentPath}/${segment}` : segment; |
| 41 | |
| 42 | if (await vault.adapter.exists(currentPath)) { |
| 43 | continue; |
| 44 | } |
| 45 | |
| 46 | try { |
| 47 | await vault.createFolder(currentPath); |
| 48 | } catch (error) { |
| 49 | if (!(await vault.adapter.exists(currentPath))) { |
| 50 | throw error; |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | export async function ensureDefaultBasesViewFiles( |
| 57 | host: DefaultBasesFileHost, |
no test coverage detected