Skip to content

Instantly share code, notes, and snippets.

@alexeyraspopov
Created October 3, 2019 13:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexeyraspopov/2dc6ae570994f0d49837a752931dc963 to your computer and use it in GitHub Desktop.
Save alexeyraspopov/2dc6ae570994f0d49837a752931dc963 to your computer and use it in GitHub Desktop.
let childProcess = require('child_process');
function createHandler(commands) {
return new Proxy(function() {}, {
get(target, property) {
return createHandler(commands.concat(property));
},
apply(target, context, args) {
return new Promise((resolve, reject) => {
let command = commands.concat(args).join(' ');
childProcess.exec(command, { cwd: process.cwd() }, (error, stdout) => {
if (error) {
reject(error);
} else {
resolve(stdout);
}
});
});
}
});
}
module.exports = createHandler([]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment