Facebook
From Toxic Mosquito, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 152
  1. const { spawn } = require('child_process');
  2. const { basename, join, resolve } = require('path');
  3.  
  4. // Path where the executables of local npm dependencies are.
  5. const appRoot = resolve(__dirname, '..');
  6.  
  7. // General colors
  8. const reset = "\x1b[0m";
  9.  
  10. // Fore ground colors.
  11. const fgRed = "\x1b[31m";
  12. const fgYellow = "\x1b[33m";
  13. const fgGreen = "\x1b[32m";
  14. const fgMagenta = "\x1b[35m";
  15. const fgCyan = "\x1b[36m";
  16.  
  17. const gulpSpawn = (cmd, args, done) => {
  18.     const stream = spawn(
  19.         resolve(__dirname, '../node_modules/.bin', cmd),
  20.         args,
  21.         { stdio: 'inherit', cwd: appRoot, shell: true }
  22.     );
  23.     stream.on('exit', (code) => {
  24.         const colored = `${fgCyan}${basename(cmd)} ${args.join(' ')}${reset}`;
  25.         console.log(`\nChild process [ ${colored} ] exited with code ${code}\n`);
  26.        
  27.         if (code !== 0) {
  28.             process.exit(code);
  29.         }
  30.  
  31.         done();
  32.     });
  33. };
  34.  
  35. module.exports.gulpSpawn = gulpSpawn;
  36.