MCPcopy Index your code
hub / github.com/ampproject/amphtml / writeDiffOrFail

Function writeDiffOrFail

build-system/common/diff.js:39–63  ·  view source on GitHub ↗

* 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
)

Source from the content-addressed store, hash-verified

37 * @return {Promise<void>}
38 */
39async 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
65module.exports = {
66 diffTentative,

Callers 5

checkIgnoreListsFunction · 0.85
checkVideoInterfaceListFunction · 0.85
getZindexFunction · 0.85
markdownTocFunction · 0.85

Calls 5

diffTentativeFunction · 0.85
logWithoutTimestampFunction · 0.85
redFunction · 0.85
cyanFunction · 0.85
logFunction · 0.70

Tested by

no test coverage detected