(code, type)
| 369 | } |
| 370 | |
| 371 | function showDiff(code, type) { |
| 372 | if (Object.keys(code.scm).length === 0 && type === 'pull') { |
| 373 | showLog('There is nothing to pull', LEVEL_WARN); |
| 374 | return; |
| 375 | } |
| 376 | //setting the diff model |
| 377 | const oldCode = type === 'push' ? code.scm : code.gas; |
| 378 | const newCode = type === 'push' ? code.gas : code.scm; |
| 379 | const gasFiles = Object.keys(code.gas); |
| 380 | const scmFiles = Object.keys(code.scm); |
| 381 | let diff = scmFiles.filter((e) => { |
| 382 | return gasFiles.indexOf(e) < 0; |
| 383 | }) |
| 384 | .concat(gasFiles) |
| 385 | .filter(file => { |
| 386 | const config = getConfig(); |
| 387 | if (config.manifestEnabled && file === 'appsscript.json') { |
| 388 | return true; |
| 389 | } |
| 390 | for (let i = 0; i < config.ignorePattern.length; i++) { |
| 391 | let p = new RegExp(svconfig.ignorePattern[i]); |
| 392 | if (svp.test(file)) return false; |
| 393 | } |
| 394 | const regex = new RegExp(`(.*?)(${getConfig().filetype}|\.html)$`) |
| 395 | const match = file.match(regex); |
| 396 | return match && match[1] && match[2]; |
| 397 | }) |
| 398 | .reduce((diff, file) => { |
| 399 | let mode = null; |
| 400 | if (!oldCode[file]) { |
| 401 | mode = 'new file mode 100644'; |
| 402 | } else if (!newCode[file]) { |
| 403 | if (file === 'appsscript.json') { |
| 404 | return diff; //can not delete manifest file |
| 405 | } |
| 406 | mode = 'deleted file mode 100644'; |
| 407 | } |
| 408 | let fileDiff = JsDiff.createPatch(file, oldCode[file] || '', newCode[file] || ''); |
| 409 | if (fileDiff.indexOf('@@') < 0) return diff; //no diff |
| 410 | let diffArr = fileDiff.split('\n'); |
| 411 | diffArr.splice(0, 2, `diff --git a/${file} b/${file}`); |
| 412 | if (mode) { |
| 413 | diffArr.splice(1, 0, mode); |
| 414 | } |
| 415 | fileDiff = diffArr.join('\n'); |
| 416 | return diff + fileDiff; |
| 417 | }, ''); |
| 418 | |
| 419 | if (diff === '') { |
| 420 | showLog('Everything already up-to-date', LEVEL_WARN); |
| 421 | return; |
| 422 | } |
| 423 | |
| 424 | const diffHtml = new Diff2HtmlUI({ |
| 425 | diff: diff |
| 426 | }); |
| 427 | diffHtml.draw('.scm-diff', { |
| 428 | inputFormat: 'json', |
no test coverage detected