MCPcopy
hub / github.com/callumalpass/tasknotes / ensureFolderHierarchy

Function ensureFolderHierarchy

src/bootstrap/defaultBasesFiles.ts:23–54  ·  view source on GitHub ↗
(
	vault: Pick<App["vault"], "adapter" | "createFolder">,
	folderPath: string
)

Source from the content-addressed store, hash-verified

21};
22
23export 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
56export async function ensureDefaultBasesViewFiles(
57 host: DefaultBasesFileHost,

Callers 3

ensureStarterNoteFunction · 0.90

Calls 3

normalizePathFunction · 0.90
existsMethod · 0.80
createFolderMethod · 0.80

Tested by

no test coverage detected