Restructure project files
This commit is contained in:
parent
107fa221c9
commit
8f07661fb2
6 changed files with 6 additions and 5 deletions
30
lib/util/diff.js
Normal file
30
lib/util/diff.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// Helper for displaying edit changes so they can be manually verified
|
||||
|
||||
import {execSync} from 'node:child_process';
|
||||
|
||||
/**
|
||||
* Converts a string from UTF-8 to base64.
|
||||
* @param {string} str
|
||||
* @returns {string}
|
||||
*/
|
||||
const toBase64 = str => Buffer.from(str, 'utf-8').toString('base64');
|
||||
|
||||
/**
|
||||
* terrible terrible terrible string diff helper for debugging
|
||||
* @param {string} a
|
||||
* @param {string} b
|
||||
*/
|
||||
export function diff (a, b) {
|
||||
// base64 input strings before passing to shell to avoid escaping issues
|
||||
// https://stackoverflow.com/a/60221847
|
||||
// use tail to cut off useless file info lines
|
||||
execSync(String.raw`bash <<- EOF
|
||||
diff --color=always -u \
|
||||
<(echo "${toBase64(a)}" | base64 -d) \
|
||||
<(echo "${toBase64(b)}" | base64 -d) \
|
||||
| tail -n +3
|
||||
EOF`, {
|
||||
// display result directly in terminal
|
||||
stdio: 'inherit',
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue