-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepare.js
More file actions
executable file
·42 lines (34 loc) · 1.11 KB
/
prepare.js
File metadata and controls
executable file
·42 lines (34 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env node
/**
* Safe prepare script that only runs lefthook for local development.
* Skips when installing globally or in CI environments.
*/
import { execSync } from "node:child_process";
import { existsSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const projectRoot = join(__dirname, "..");
// Skip if not in a git repo (e.g., npm global install)
const isGitRepo = existsSync(join(projectRoot, ".git"));
// Skip in CI environments
const isCI = !!process.env.CI;
if (!isGitRepo) {
console.log("Skipping git hooks setup (not a git repository)");
process.exit(0);
}
if (isCI) {
console.log("Skipping git hooks setup (CI environment)");
process.exit(0);
}
try {
execSync("lefthook install", { stdio: "inherit", cwd: projectRoot });
} catch {
console.warn("Warning: Failed to install git hooks (lefthook)");
console.warn(
'This is optional for development. You can run "npm run prepare" manually later.',
);
// Don't fail the install
process.exit(0);
}