Created
October 3, 2019 13:47
-
-
Save alexeyraspopov/2dc6ae570994f0d49837a752931dc963 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
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