(inputPath)
| 3 | import { isDirectory, isFile, pathExists, listImmediateDirectories, readJson } from "../lib/files.js"; |
| 4 | |
| 5 | export async function resolveTarget(inputPath) { |
| 6 | const resolvedPath = path.resolve(inputPath); |
| 7 | if (await isFile(resolvedPath)) { |
| 8 | if (path.basename(resolvedPath) === "SKILL.md") { |
| 9 | return { |
| 10 | kind: "skill", |
| 11 | path: path.dirname(resolvedPath), |
| 12 | entryPath: resolvedPath, |
| 13 | name: path.basename(path.dirname(resolvedPath)), |
| 14 | }; |
| 15 | } |
| 16 | if ( |
| 17 | path.basename(resolvedPath) === "plugin.json" && |
| 18 | path.basename(path.dirname(resolvedPath)) === ".codex-plugin" |
| 19 | ) { |
| 20 | return { |
| 21 | kind: "plugin", |
| 22 | path: path.dirname(path.dirname(resolvedPath)), |
| 23 | entryPath: resolvedPath, |
| 24 | name: path.basename(path.dirname(path.dirname(resolvedPath))), |
| 25 | }; |
| 26 | } |
| 27 | |
| 28 | return { |
| 29 | kind: "file", |
| 30 | path: resolvedPath, |
| 31 | entryPath: resolvedPath, |
| 32 | name: path.basename(resolvedPath), |
| 33 | }; |
| 34 | } |
| 35 | |
| 36 | if (!(await isDirectory(resolvedPath))) { |
| 37 | throw new Error(`Target path does not exist: ${resolvedPath}`); |
| 38 | } |
| 39 | |
| 40 | const pluginManifestPath = path.join(resolvedPath, ".codex-plugin", "plugin.json"); |
| 41 | if (await pathExists(pluginManifestPath)) { |
| 42 | return { |
| 43 | kind: "plugin", |
| 44 | path: resolvedPath, |
| 45 | entryPath: pluginManifestPath, |
| 46 | name: path.basename(resolvedPath), |
| 47 | }; |
| 48 | } |
| 49 | |
| 50 | const skillPath = path.join(resolvedPath, "SKILL.md"); |
| 51 | if (await pathExists(skillPath)) { |
| 52 | return { |
| 53 | kind: "skill", |
| 54 | path: resolvedPath, |
| 55 | entryPath: skillPath, |
| 56 | name: path.basename(resolvedPath), |
| 57 | }; |
| 58 | } |
| 59 | |
| 60 | return { |
| 61 | kind: "directory", |
| 62 | path: resolvedPath, |
no test coverage detected