(dir: string)
| 119 | } |
| 120 | |
| 121 | async function detectPluginRoot(dir: string): Promise<string> { |
| 122 | if (await hasManifest(dir)) return dir; |
| 123 | |
| 124 | const entries = await readdir(dir, { withFileTypes: true }); |
| 125 | const childDirs = entries.filter((entry) => entry.isDirectory()); |
| 126 | const childDir = childDirs.length === 1 ? childDirs[0] : undefined; |
| 127 | if (childDir !== undefined) { |
| 128 | const child = path.join(dir, childDir.name); |
| 129 | if (await hasManifest(child)) return child; |
| 130 | } |
| 131 | |
| 132 | return dir; |
| 133 | } |
| 134 | |
| 135 | async function hasManifest(dir: string): Promise<boolean> { |
| 136 | const rootManifest = path.join(dir, 'kimi.plugin.json'); |
no test coverage detected