( client: Client, cwd: string, autoConfirm = false )
| 5 | import type Client from '../client'; |
| 6 | |
| 7 | export async function inputRootDirectory( |
| 8 | client: Client, |
| 9 | cwd: string, |
| 10 | autoConfirm = false |
| 11 | ) { |
| 12 | if (autoConfirm) { |
| 13 | return null; |
| 14 | } |
| 15 | |
| 16 | while (true) { |
| 17 | const rootDirectory = await client.input.text({ |
| 18 | message: `Code directory?`, |
| 19 | transformer: (input: string) => { |
| 20 | return `${chalk.dim(`./`)}${input}`; |
| 21 | }, |
| 22 | }); |
| 23 | |
| 24 | if (!rootDirectory) { |
| 25 | return null; |
| 26 | } |
| 27 | |
| 28 | const normal = path.normalize(rootDirectory); |
| 29 | |
| 30 | if (normal === '.' || normal === './') { |
| 31 | return null; |
| 32 | } |
| 33 | |
| 34 | const fullPath = path.join(cwd, normal); |
| 35 | |
| 36 | if ( |
| 37 | (await validateRootDirectory( |
| 38 | cwd, |
| 39 | fullPath, |
| 40 | 'Please choose a different one.' |
| 41 | )) === false |
| 42 | ) { |
| 43 | continue; |
| 44 | } |
| 45 | |
| 46 | return normalizePath(normal); |
| 47 | } |
| 48 | } |
no test coverage detected