refactor: extract shared resolveCommandPath helper for colon-splitting

Deduplicate colon-separated command name logic across all 4 targets
(opencode, droid, gemini, qwen) into a single resolveCommandPath()
helper in utils/files.ts.

Addresses review feedback on PR #251.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matt Van Horn
2026-03-13 07:08:07 -07:00
parent a84682cd35
commit 1886c747d0
5 changed files with 26 additions and 44 deletions

View File

@@ -75,6 +75,21 @@ export async function walkFiles(root: string): Promise<string[]> {
return results
}
/**
* Resolve a colon-separated command name into a filesystem path.
* e.g. resolveCommandPath("/commands", "ce:plan", ".md") -> "/commands/ce/plan.md"
* Creates intermediate directories as needed.
*/
export async function resolveCommandPath(dir: string, name: string, ext: string): Promise<string> {
const parts = name.split(":")
if (parts.length > 1) {
const nestedDir = path.join(dir, ...parts.slice(0, -1))
await ensureDir(nestedDir)
return path.join(nestedDir, `${parts[parts.length - 1]}${ext}`)
}
return path.join(dir, `${name}${ext}`)
}
export async function copyDir(sourceDir: string, targetDir: string): Promise<void> {
await ensureDir(targetDir)
const entries = await fs.readdir(sourceDir, { withFileTypes: true })