allow custom diff header labels
This commit is contained in:
parent
436acf7299
commit
4f17754f4c
1 changed files with 15 additions and 6 deletions
|
|
@ -13,16 +13,25 @@ const toBase64 = str => Buffer.from(str, 'utf-8').toString('base64');
|
||||||
* terrible terrible terrible string diff helper for debugging
|
* terrible terrible terrible string diff helper for debugging
|
||||||
* @param {string} a
|
* @param {string} a
|
||||||
* @param {string} b
|
* @param {string} b
|
||||||
|
* @param {object} page Page object from the API, used to generate diff labels
|
||||||
*/
|
*/
|
||||||
export function diff (a, b) {
|
export function diff (a, b, page) {
|
||||||
|
let labels = null;
|
||||||
|
if (page) { // generate diff labels based on
|
||||||
|
labels = [
|
||||||
|
`${page.title} (${page.revid ? `revision ${page.revid}` : 'current revision'}${page.timestamp ? ` from ${page.timestamp}` : ''})`,
|
||||||
|
`${page.title} (pending edit)`,
|
||||||
|
];
|
||||||
|
}
|
||||||
// base64 input strings before passing to shell to avoid escaping issues
|
// base64 input strings before passing to shell to avoid escaping issues
|
||||||
// https://stackoverflow.com/a/60221847
|
// https://stackoverflow.com/a/60221847
|
||||||
// use tail to cut off useless file info lines
|
// use tail to cut off file info lines and re-add with fake filenames/dates
|
||||||
execSync(String.raw`bash <<- EOF
|
// this function is so extra now holy shit
|
||||||
|
execSync(String.raw`bash <<- 'EOF'
|
||||||
diff --color=always -u \
|
diff --color=always -u \
|
||||||
<(echo "${toBase64(a)}" | base64 -d) \
|
${labels ? `--label="$(echo '${toBase64(labels[0])}' | base64 -d)" ` : ''}<(echo '${toBase64(a)}' | base64 -d) \
|
||||||
<(echo "${toBase64(b)}" | base64 -d) \
|
${labels ? `--label="$(echo '${toBase64(labels[1])}' | base64 -d)" ` : ''}<(echo '${toBase64(b)}' | base64 -d) \
|
||||||
| tail -n +3
|
${labels ? `|| true` : `| tail -n +3` /* cut off header if no labels */}
|
||||||
EOF`, {
|
EOF`, {
|
||||||
// display result directly in terminal
|
// display result directly in terminal
|
||||||
stdio: 'inherit',
|
stdio: 'inherit',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue