Created
January 23, 2024 08:19
-
-
Save Rulexec/92629b80e43b53bc2c237204b430c348 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