Are there any tips or libs for managing multiple vaults?

I need to manage API keys in multiple vaults. The keys are stored in plugin settings. I guess the way easy to do that is to write a script to update the plugin settings in all vaults.

I can do it myself, but I’m looking for tips or libs that helps me do it better

FYI: Support env for API key management - #5 by pjeby

Here is my code. It runs on Deno:

import { join } from "jsr:@std/path";

type AbsolutePath = string & { readonly isAbsolute: true };
const ALL_VAULT_FOLDER = "D:\\Quả Cầu\\Vaults" as AbsolutePath;
const API_GITHUB = "XXXXXXXXXXXXXXXXXXXX"

async function hasObsidianSetting(folder: AbsolutePath) {
  try {
    for await (const dirEntry of Deno.readDir(folder)) {
      if (dirEntry.isDirectory && dirEntry.name === ".obsidian") return true;
    }
    return false;
  }
  return false;
}

async function updateEnvEnveloppe(subfolder: AbsolutePath) {
const env = `GITHUB_TOKEN=${API_GITHUB}`
  const pathToEnvEnveloppe = join(subfolder, ".obsidian", "plugins", "obsidian-mkdocs-publisher", "env");
  try {
    await Deno.writeTextFile(pathToEnvEnveloppe, env);
  }
}

async function updateAllVault(folder: AbsolutePath = ALL_VAULT_FOLDER) {
  for await (const dirEntry of Deno.readDir(folder)) {
    const subFolder = join(folder, dirEntry.name) as AbsolutePath;
    if (await hasObsidianSetting(subFolder)) {
      await updateEnvEnveloppe(subFolder);
    } else if (dirEntry.isDirectory) {
      await updateAllVault(subFolder);
    }
  }
}

await updateAllVault();