()
| 100 | } |
| 101 | |
| 102 | function writeAllWorkflowsToDefaultConfig(): ConfigBackup | null { |
| 103 | const configPath = getOpenSpecDefaultConfigPath(); |
| 104 | const backupPath = configPath + '.comet-backup'; |
| 105 | let hadExisting = false; |
| 106 | |
| 107 | try { |
| 108 | hadExisting = fs.existsSync(configPath); |
| 109 | if (hadExisting) { |
| 110 | fs.copyFileSync(configPath, backupPath); |
| 111 | } |
| 112 | |
| 113 | const configDir = path.dirname(configPath); |
| 114 | if (!fs.existsSync(configDir)) { |
| 115 | fs.mkdirSync(configDir, { recursive: true }); |
| 116 | } |
| 117 | fs.writeFileSync(configPath, ALL_WORKFLOWS_CONFIG, 'utf-8'); |
| 118 | |
| 119 | return { configPath, backupPath, hadExisting }; |
| 120 | } catch { |
| 121 | if (hadExisting) { |
| 122 | try { |
| 123 | fs.unlinkSync(backupPath); |
| 124 | } catch { |
| 125 | // Best-effort cleanup |
| 126 | } |
| 127 | } |
| 128 | return null; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | function restoreDefaultConfig(backup: ConfigBackup | null): void { |
| 133 | if (!backup) return; |
no test coverage detected