SHARE
TWEET

Untitled

a guest Oct 21st, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let childProcess = require('child_process');
  2.  
  3. function createHandler(commands) {
  4.   return new Proxy(function() {}, {
  5.     get(target, property) {
  6.       return createHandler(commands.concat(property));
  7.     },
  8.     apply(target, context, args) {
  9.       return new Promise((resolve, reject) => {
  10.         let command = commands.concat(args).join(' ');
  11.         childProcess.exec(command, { cwd: process.cwd() }, (error, stdout) => {
  12.           if (error) {
  13.             reject(error);
  14.           } else {
  15.             resolve(stdout);
  16.           }
  17.         });
  18.       });
  19.     }
  20.   });
  21. }
  22.  
  23. module.exports = createHandler([]);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top