Declare prettier, eslint, and husky in package.json so the lint and prepare scripts work without relying on globally-installed tools. Add a .prettierrc.json matching the project's tabs/no-bracket-spacing style and apply prettier --write across the tree.
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import {existsSync, lstatSync, unlinkSync, readlinkSync} 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/unlink-from-vault.ts <vault-path>\n" +
|
|
" or set OBSIDIAN_VAULT environment variable",
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
const resolvedVault = resolve(vaultPath);
|
|
const pluginsDir = resolve(resolvedVault, ".obsidian", "plugins");
|
|
const targetDir = resolve(pluginsDir, pluginId);
|
|
const distDir = resolve(import.meta.dir, "..", "dist");
|
|
|
|
if (!existsSync(targetDir)) {
|
|
console.log(`Symlink not found: ${targetDir} does not exist`);
|
|
process.exit(0);
|
|
}
|
|
|
|
if (!lstatSync(targetDir).isSymbolicLink()) {
|
|
console.error(`${targetDir} is not a symlink. Use 'vault:uninstall' instead.`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const linkTarget = readlinkSync(targetDir);
|
|
const resolvedLinkTarget = resolve(pluginsDir, linkTarget);
|
|
|
|
if (resolvedLinkTarget !== distDir) {
|
|
console.error(
|
|
`Refusing to remove for safety: symlink points to ${resolvedLinkTarget}, not ${distDir}`,
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
unlinkSync(targetDir);
|
|
console.log(`Removed symlink: ${targetDir}`);
|