(config: PlatformConfig, spinner: Ora)
| 51 | }; |
| 52 | |
| 53 | function makePlatformInitializer(config: PlatformConfig, spinner: Ora) { |
| 54 | return { |
| 55 | name: config.name, |
| 56 | isEnabled: () => { |
| 57 | const filePath = path.join(process.cwd(), config.checkPath); |
| 58 | return fs.existsSync(filePath); |
| 59 | }, |
| 60 | init: async () => { |
| 61 | const filePath = path.join(process.cwd(), config.ciConfigPath); |
| 62 | const dirPath = path.dirname(filePath); |
| 63 | if (!fs.existsSync(dirPath)) { |
| 64 | fs.mkdirSync(dirPath, { recursive: true }); |
| 65 | } |
| 66 | let canWrite = true; |
| 67 | if (fs.existsSync(filePath)) { |
| 68 | canWrite = await confirm({ |
| 69 | message: `File ${filePath} already exists. Do you want to overwrite it?`, |
| 70 | default: false, |
| 71 | }); |
| 72 | } |
| 73 | if (canWrite) { |
| 74 | fs.writeFileSync(filePath, config.ciConfigContent); |
| 75 | spinner.succeed(`CI/CD initialized for ${config.name}`); |
| 76 | } else { |
| 77 | spinner.warn(`CI/CD not initialized for ${config.name}`); |
| 78 | } |
| 79 | }, |
| 80 | }; |
| 81 | } |
| 82 | |
| 83 | function makeGithubInitializer(spinner: Ora) { |
| 84 | return makePlatformInitializer( |
no test coverage detected