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

@@ -1,5 +1,5 @@
import path from "path"
import { backupFile, copyDir, ensureDir, pathExists, readJson, writeJson, writeText } from "../utils/files"
import { backupFile, copyDir, ensureDir, pathExists, readJson, resolveCommandPath, writeJson, writeText } from "../utils/files"
import type { OpenCodeBundle, OpenCodeConfig } from "../types/opencode"
// Merges plugin config into existing opencode.json. User keys win on conflict. See ADR-002.
@@ -75,17 +75,7 @@ export async function writeOpenCodeBundle(outputRoot: string, bundle: OpenCodeBu
}
for (const commandFile of bundle.commandFiles) {
// Split colon-separated names into nested directories (e.g. "ce:plan" -> "ce/plan.md")
// to avoid colons in filenames which are invalid on Windows/NTFS
const parts = commandFile.name.split(":")
let dest: string
if (parts.length > 1) {
const nestedDir = path.join(openCodePaths.commandDir, ...parts.slice(0, -1))
await ensureDir(nestedDir)
dest = path.join(nestedDir, `${parts[parts.length - 1]}.md`)
} else {
dest = path.join(openCodePaths.commandDir, `${commandFile.name}.md`)
}
const dest = await resolveCommandPath(openCodePaths.commandDir, commandFile.name, ".md")
const cmdBackupPath = await backupFile(dest)
if (cmdBackupPath) {
console.log(`Backed up existing command file to ${cmdBackupPath}`)