run-if-exists.js 450 B

123456789101112131415161718
  1. const cp = require('node:child_process');
  2. const fs = require('node:fs');
  3. const checkPath = process.argv[2];
  4. const command = process.argv.slice(3);
  5. if (fs.existsSync(checkPath)) {
  6. const child = cp.spawn(
  7. `${command[0]}${process.platform === 'win32' ? '.cmd' : ''}`,
  8. command.slice(1),
  9. {
  10. stdio: 'inherit',
  11. cwd: checkPath,
  12. shell: process.platform === 'win32'
  13. }
  14. );
  15. child.on('exit', code => process.exit(code));
  16. }