* Diffs a file against new content. * If `argv.fix` is true, the file is written with the new content, otherwise * errors out. * @param {string} callerTask * @param {string} filepath * @param {string} tentative * @param {Array =} opt_gitDiffFlags * @return {Promise }
( callerTask, filepath, tentative, opt_gitDiffFlags )
| 37 | * @return {Promise<void>} |
| 38 | */ |
| 39 | async function writeDiffOrFail( |
| 40 | callerTask, |
| 41 | filepath, |
| 42 | tentative, |
| 43 | opt_gitDiffFlags |
| 44 | ) { |
| 45 | const diff = await diffTentative(filepath, tentative, opt_gitDiffFlags); |
| 46 | |
| 47 | if (!diff.length) { |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | logWithoutTimestamp(); |
| 52 | logWithoutTimestamp(diff); |
| 53 | logWithoutTimestamp(); |
| 54 | |
| 55 | if (!argv.fix) { |
| 56 | log(red('ERROR:'), cyan(filepath), 'is missing the changes above.'); |
| 57 | log('⤷ To automatically apply them, run', cyan(`amp ${callerTask} --fix`)); |
| 58 | throw new Error(`${filepath} is outdated`); |
| 59 | } |
| 60 | |
| 61 | await writeFile(filepath, tentative); |
| 62 | log('Wrote', bold(blue(filepath))); |
| 63 | } |
| 64 | |
| 65 | module.exports = { |
| 66 | diffTentative, |
no test coverage detected