Created
August 28, 2024 12:54
-
-
Save Rulexec/4237d7e7efda603c6bf9dbe6b5d45d48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const child_process = require('child_process'); | |
const texts = process.argv.slice(2); | |
(async () => { | |
const commandsDef = texts.map((text, index) => { | |
const isFirst = index === 0; | |
const isLast = index === texts.length - 1; | |
return { | |
command: isFirst ? 'rg' : 'xargs', | |
args: [...(isFirst ? [] : ['rg']), '-g', '!node_modules/', '-lF', text], | |
isFirst, | |
isLast, | |
}; | |
}); | |
let prevChild; | |
commandsDef.forEach(({command, args, isLast}) => { | |
const child = child_process.spawn(command, args, { | |
stdio: [ | |
prevChild ? prevChild.stdout : 'ignore', | |
isLast ? 'inherit' : 'pipe', | |
'inherit', | |
], | |
}); | |
prevChild = child; | |
}); | |
})().catch((error) => { | |
console.error(error); | |
process.exit(1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment