| 78 | * Writes a file to the `config.outDir` directory, taking into account the configuration and existing files. |
| 79 | */ |
| 80 | const writeFileToOutDir = (file: Domain.File) => |
| 81 | Effect.gen(function*() { |
| 82 | const config = yield* Configuration.Configuration |
| 83 | const fs = yield* FileSystem.FileSystem |
| 84 | const path = yield* Path.Path |
| 85 | const process = yield* Domain.Process |
| 86 | const cwd = yield* process.cwd |
| 87 | const fileName = path.relative(path.join(cwd, config.outDir), file.path) |
| 88 | |
| 89 | const exists = yield* fs.exists(file.path) |
| 90 | if (exists) { |
| 91 | if (file.isOverwriteable) { |
| 92 | yield* Effect.logDebug(`Overwriting file ${chalk.black(fileName)}...`) |
| 93 | yield* fs.makeDirectory(path.dirname(file.path), { recursive: true }) |
| 94 | yield* fs.writeFileString(file.path, file.content) |
| 95 | } else { |
| 96 | yield* Effect.logDebug( |
| 97 | `File ${chalk.black(fileName)} already exists, skipping creation.` |
| 98 | ) |
| 99 | } |
| 100 | } else { |
| 101 | yield* fs.makeDirectory(path.dirname(file.path), { recursive: true }) |
| 102 | yield* fs.writeFileString(file.path, file.content) |
| 103 | } |
| 104 | }) |
| 105 | |
| 106 | const writeFilesToOutDir = ( |
| 107 | files: ReadonlyArray<Domain.File> |