| 6 | const d = debug('electron-forge:init:directory'); |
| 7 | |
| 8 | export const initDirectory = async ( |
| 9 | dir: string, |
| 10 | task: ForgeListrTask<any>, |
| 11 | force = false, |
| 12 | ): Promise<void> => { |
| 13 | d('creating directory:', dir); |
| 14 | await fs.mkdirs(dir); |
| 15 | |
| 16 | const files = await fs.readdir(dir); |
| 17 | if (files.length !== 0) { |
| 18 | d(`found ${files.length} files in the directory. warning the user`); |
| 19 | |
| 20 | if (force) { |
| 21 | task.output = `${logSymbols.warning} The specified path "${dir}" is not empty. "force" was set to true, so proceeding to initialize. Files may be overwritten`; |
| 22 | } else { |
| 23 | throw new Error( |
| 24 | `The specified path: "${dir}" is not empty. Please ensure it is empty before initializing a new project`, |
| 25 | ); |
| 26 | } |
| 27 | } |
| 28 | }; |