| 34 | ` |
| 35 | |
| 36 | const createHeaderFile = async (content, filePath) => { |
| 37 | const dir = path.dirname(filePath) |
| 38 | await fs.ensureDir(dir) |
| 39 | const fileContent = `${header}${content}` |
| 40 | const fileExists = await fs.pathExists(filePath) |
| 41 | if (fileExists) { |
| 42 | const { overwrite } = await inquirer.prompt([ |
| 43 | { |
| 44 | type: 'confirm', |
| 45 | name: 'overwrite', |
| 46 | message: `File ${filePath} already exists. Overwrite?`, |
| 47 | default: false, |
| 48 | }, |
| 49 | ]) |
| 50 | if (!overwrite) { |
| 51 | console.log('File not created.') |
| 52 | return |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | await fs.writeFile(filePath, fileContent) |
| 57 | console.log(`File created: ${filePath}`) |
| 58 | } |
| 59 | |
| 60 | export default createHeaderFile |