Repository navigation
Expand file tree
/
Copy pathsetup-plugins.ts
More file actions
81 lines (75 loc) · 2.39 KB
/
Copy pathsetup-plugins.ts
File metadata and controls
81 lines (75 loc) · 2.39 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* Plugin setup steps service
* SRP: plugin scanning, dependency installation, statusline wiring and
* CLAUDE.md sync.
*/
import { existsSync } from "node:fs";
import { join } from "node:path";
import * as p from "@clack/prompts";
import {
filesAreEqual,
installPluginDeps,
makeScriptsExecutable,
} from "../utils/fs-helpers";
import { findPluginDepDirs } from "../utils/dep-scanner";
import { scanPlugins } from "./plugin-scanner";
import type { Settings } from "./settings-manager";
import { configureStatusLine } from "./settings-manager";
/** Scan plugins and make scripts executable */
export async function scanAndPrepare(pluginsDir: string): Promise<void> {
const s = p.spinner();
s.start("Scanning plugins...");
const plugins = scanPlugins({ pluginsDir });
const withHooks = plugins.filter((pl) => pl.hasHooks);
s.stop(`${withHooks.length} plugins with hooks detected`);
s.start("Making scripts executable...");
const scriptCount = await makeScriptsExecutable(pluginsDir);
s.stop(`${scriptCount} scripts made executable`);
}
/** Install CLAUDE.md if newer */
export async function installClaudeMd(
src: string,
dest: string,
): Promise<void> {
if (!existsSync(src)) return;
const same = await filesAreEqual(src, dest);
if (!same) {
await Bun.write(dest, await Bun.file(src).text());
p.log.success("CLAUDE.md installed");
} else {
p.log.info("CLAUDE.md already up to date");
}
}
/** Install dependencies for every plugin dir holding a package.json */
export async function installDeps(pluginsDir: string): Promise<void> {
const s = p.spinner();
s.start("Installing plugin dependencies...");
const dirs = findPluginDepDirs(pluginsDir);
let ok = 0;
for (const dir of dirs) {
try {
if (await installPluginDeps(dir)) ok++;
} catch {
p.log.warn(`Dependency install failed: ${dir}`);
}
}
s.stop(`${ok}/${dirs.length} plugin dep dirs installed`);
}
/** Setup statusline if available */
export async function setupStatusline(
pluginsDir: string,
settings: Settings,
): Promise<Settings> {
const statuslineDir = join(pluginsDir, "core-guards/statusline");
if (!existsSync(statuslineDir)) return settings;
const s = p.spinner();
s.start("Installing statusline...");
try {
await installPluginDeps(statuslineDir);
settings = configureStatusLine(settings, statuslineDir);
s.stop("Statusline configured");
} catch {
s.stop("Statusline installation failed");
}
return settings;
}