import path from "node:path"; import { spawnSync } from "node:child_process"; import { fileURLToPath } from "node:url"; const scriptDir = path.dirname(fileURLToPath(import.meta.url)); const repoRoot = path.resolve(scriptDir, ".."); const huskyBin = path.join(repoRoot, "node_modules", "husky", "bin.js"); function run(command, args, options = {}) { const result = spawnSync(command, args, { cwd: repoRoot, encoding: "utf8", ...options, }); if (result.error) { throw result.error; } return result; } const worktreeResult = run("git", ["rev-parse", "--show-toplevel"]); if (worktreeResult.status !== 0) { console.log("Skipping Husky install because front-end-vue is not attached to a Git worktree."); process.exit(0); } const gitRoot = path.resolve(worktreeResult.stdout.trim()); if (gitRoot !== repoRoot) { console.log(`Skipping Husky install because Git root is ${gitRoot}, not ${repoRoot}.`); process.exit(0); } const huskyResult = run(process.execPath, [huskyBin], { stdio: "inherit" }); process.exit(huskyResult.status ?? 1);