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:
@@ -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}`)
|
||||
|
||||
Reference in New Issue
Block a user