import {existsSync, mkdirSync, cpSync, lstatSync} from "fs"; import {resolve} from "path"; const manifest = await Bun.file("manifest.json").json(); const pluginId: string = manifest.id; const vaultPath = process.argv[2] || process.env.OBSIDIAN_VAULT; if (!vaultPath) { console.error( "Usage: bun run scripts/install-to-vault.ts \n" + " or set OBSIDIAN_VAULT environment variable", ); process.exit(1); } const resolvedVault = resolve(vaultPath); const obsidianDir = resolve(resolvedVault, ".obsidian"); const pluginsDir = resolve(obsidianDir, "plugins"); const targetDir = resolve(pluginsDir, pluginId); const distDir = resolve(import.meta.dir, "..", "dist"); // Validation checks if (!existsSync(obsidianDir)) { console.error(`Invalid vault path: ${resolvedVault}`); console.error(`.obsidian directory not found at ${obsidianDir}`); process.exit(1); } if (!existsSync(distDir)) { console.error(`Build not found: run 'bun run build' first`); process.exit(1); } if (existsSync(targetDir) && lstatSync(targetDir).isSymbolicLink()) { console.error(`${targetDir} is a symlink. Use 'vault:install-symlink' instead.`); process.exit(1); } // Install if (!existsSync(pluginsDir)) { mkdirSync(pluginsDir, {recursive: true}); } cpSync(distDir, targetDir, {recursive: true}); console.log(`Installed to: ${targetDir}`);