mirror of
https://github.com/rohitg00/skillkit.git
synced 2026-11-18 18:04:26 +00:00
simplify: extract toAdapterInfo helper, remove spawnGit overloads
- helpers.ts: extract toAdapterInfo() to eliminate 4x repeated object
construction
- base.ts: remove redundant spawnGit overload signatures, remove
?? (() => {}) since spawnGit already handles undefined onProgress
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
// Re-export commonly used functions with proper adapters
|
||||
import {
|
||||
loadConfig,
|
||||
getSearchDirs as coreGetSearchDirs,
|
||||
@@ -11,66 +10,37 @@ import {
|
||||
import { getAdapter, detectAgent, getAllAdapters } from "@skillkit/agents";
|
||||
import type { AgentType, AgentAdapterInfo } from "@skillkit/core";
|
||||
|
||||
// Re-export metadata functions directly (they don't need adapter bridging)
|
||||
export const loadSkillMetadata = coreLoadSkillMetadata;
|
||||
export const saveSkillMetadata = coreSaveSkillMetadata;
|
||||
|
||||
function toAdapterInfo(adapter: { type: AgentType; name: string; skillsDir: string; configFile: string }): AgentAdapterInfo {
|
||||
return { type: adapter.type, name: adapter.name, skillsDir: adapter.skillsDir, configFile: adapter.configFile };
|
||||
}
|
||||
|
||||
export function getSearchDirs(agentType?: AgentType): string[] {
|
||||
const dirs = new Set<string>();
|
||||
|
||||
const adapters = agentType
|
||||
? [getAdapter(agentType)]
|
||||
: getAllAdapters();
|
||||
|
||||
const adapters = agentType ? [getAdapter(agentType)] : getAllAdapters();
|
||||
for (const adapter of adapters) {
|
||||
const info: AgentAdapterInfo = {
|
||||
type: adapter.type,
|
||||
name: adapter.name,
|
||||
skillsDir: adapter.skillsDir,
|
||||
configFile: adapter.configFile,
|
||||
};
|
||||
for (const dir of coreGetSearchDirs(info)) {
|
||||
for (const dir of coreGetSearchDirs(toAdapterInfo(adapter))) {
|
||||
dirs.add(dir);
|
||||
}
|
||||
}
|
||||
|
||||
return [...dirs];
|
||||
}
|
||||
|
||||
export function getInstallDir(global = false, agentType?: AgentType): string {
|
||||
const type = agentType || loadConfig().agent;
|
||||
const adapter = getAdapter(type);
|
||||
const adapterInfo: AgentAdapterInfo = {
|
||||
type: adapter.type,
|
||||
name: adapter.name,
|
||||
skillsDir: adapter.skillsDir,
|
||||
configFile: adapter.configFile,
|
||||
};
|
||||
return coreGetInstallDir(adapterInfo, global);
|
||||
return coreGetInstallDir(toAdapterInfo(getAdapter(type)), global);
|
||||
}
|
||||
|
||||
export function getAgentConfigPath(agentType?: AgentType): string {
|
||||
const type = agentType || loadConfig().agent;
|
||||
const adapter = getAdapter(type);
|
||||
const adapterInfo: AgentAdapterInfo = {
|
||||
type: adapter.type,
|
||||
name: adapter.name,
|
||||
skillsDir: adapter.skillsDir,
|
||||
configFile: adapter.configFile,
|
||||
};
|
||||
return coreGetAgentConfigPath(adapterInfo);
|
||||
return coreGetAgentConfigPath(toAdapterInfo(getAdapter(type)));
|
||||
}
|
||||
|
||||
export async function initProject(agentType?: AgentType): Promise<void> {
|
||||
const type = agentType || (await detectAgent());
|
||||
const adapter = getAdapter(type);
|
||||
const adapterInfo: AgentAdapterInfo = {
|
||||
type: adapter.type,
|
||||
name: adapter.name,
|
||||
skillsDir: adapter.skillsDir,
|
||||
configFile: adapter.configFile,
|
||||
};
|
||||
return coreInitProject(type, adapterInfo);
|
||||
return coreInitProject(type, toAdapterInfo(getAdapter(type)));
|
||||
}
|
||||
|
||||
export function formatCount(count: number): string {
|
||||
|
||||
@@ -50,8 +50,6 @@ function parseGitProgress(text: string): string | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
function spawnGit(args: string[]): Promise<void>;
|
||||
function spawnGit(args: string[], onProgress: (msg: string) => void): Promise<void>;
|
||||
function spawnGit(args: string[], onProgress?: (msg: string) => void): Promise<void> {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const proc = spawn('git', args, { stdio: ['pipe', 'ignore', 'pipe'] });
|
||||
@@ -96,7 +94,7 @@ export async function cloneRepo(
|
||||
|
||||
let partialCloneOk = false;
|
||||
try {
|
||||
await spawnGit(partialArgs, options.onProgress ?? (() => {}));
|
||||
await spawnGit(partialArgs, options.onProgress);
|
||||
partialCloneOk = true;
|
||||
} catch {
|
||||
options.onProgress?.('Partial clone unsupported, falling back to full clone');
|
||||
@@ -124,14 +122,14 @@ export async function cloneRepo(
|
||||
);
|
||||
|
||||
options.onProgress?.('Checking out files');
|
||||
await spawnGit(['-C', tempDir, 'checkout'], options.onProgress ?? (() => {}));
|
||||
await spawnGit(['-C', tempDir, 'checkout'], options.onProgress);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
args.push(cloneUrl, tempDir);
|
||||
await spawnGit(args, options.onProgress ?? (() => {}));
|
||||
await spawnGit(args, options.onProgress);
|
||||
}
|
||||
|
||||
export function parseShorthand(source: string): { owner: string; repo: string; subpath?: string } | null {
|
||||
|
||||
Reference in New Issue
Block a user