This repository has been archived on 2026-05-02. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
obsidian-plugin-auto-task-s.../scripts/symlink-to-vault.ts
Felipe Martin 6c464483f5
Some checks are pending
CI / build (push) Waiting to run
Migrate dev environment to Bun with modern tooling
- Switch package manager from npm to Bun (bun.lock replaces package-lock.json)
- Move source to src/main.ts, tests to test/ (flattened structure)
- Build output now goes to dist/ with git-based version stamping in manifest
- Replace ESLint legacy config with ESLint v9 flat config (typescript-eslint v8)
- Add Prettier for formatting (.prettierrc)
- Add Husky pre-commit hook running bun run lint
- Add vault management scripts (install, uninstall, symlink, unlink)
- Add GitHub Actions CI and release workflows
- Update tsconfig for TypeScript v5, add isolatedModules/esModuleInterop
- Upgrade Jest config to jsdom environment, coverage from src/**
- Remove Makefile, version-bump.mjs, versions.json (replaced by bun scripts and git-tag versioning)
2026-04-13 15:09:11 +02:00

51 lines
1.6 KiB
TypeScript

import { existsSync, lstatSync, symlinkSync, unlinkSync } 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/symlink-to-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(pluginsDir)) {
console.error(`Invalid vault path: ${resolvedVault}`);
console.error(`.obsidian/plugins directory not found at ${pluginsDir}`);
process.exit(1);
}
if (!existsSync(distDir)) {
console.error(`Build not found: run 'bun run build' first`);
process.exit(1);
}
if (existsSync(targetDir)) {
if (lstatSync(targetDir).isSymbolicLink()) {
const link = lstatSync(targetDir);
const linkTarget = resolve(pluginsDir, link.path);
if (linkTarget !== distDir) {
unlinkSync(targetDir);
symlinkSync(distDir, targetDir);
console.log(`Updated symlink: ${targetDir} -> ${distDir}`);
} else {
console.log(`Symlink already correct: ${targetDir} -> ${distDir}`);
}
} else {
console.error(`${targetDir} exists and is not a symlink. Refusing to remove for safety.`);
process.exit(1);
}
} else {
symlinkSync(distDir, targetDir);
console.log(`Created symlink: ${targetDir} -> ${distDir}`);
}