From 233df7952d03282205191359a988cef772429bfa Mon Sep 17 00:00:00 2001 From: "Michael J. Pedersen" Date: Mon, 13 Feb 2023 10:32:55 -0500 Subject: [PATCH] Making destroyVault recursive, switching away from await/async when it's not necessary. --- src/main.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main.ts b/src/main.ts index 4df0af3..d72aef8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import {Plugin} from 'obsidian'; +import {Plugin, TFolder} from 'obsidian'; import {newLoremNote} from "./loremnotes"; import {TestingVaultModal} from "./vault"; @@ -9,11 +9,20 @@ import {TestingVaultModal} from "./vault"; which might be interesting for linguistic-related plugins */ +function destroyVault(root: TFolder) { + for (let child of root.children) { + if (child instanceof TFolder) { + destroyVault(child); + this.app.vault.delete(child, true); + } else { + this.app.vault.delete(child, true); + } + } +} + export default class TestingVaultPlugin extends Plugin { - async deleteVaultContents() { - this.app.vault.getFiles().map(async (fname) => { - await this.app.vault.delete(fname, true) - }); + deleteVaultContents() { + destroyVault(this.app.vault.getRoot()); } async onload() {