diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-02-11 21:44:38 +0100 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-02-11 21:44:38 +0100 |
commit | 669f3b39849890c48171d807225cd6eaa3c9086b (patch) | |
tree | bc07fefc4e13ac8f737174166ac1d19512379298 /lib/utils/command.js | |
parent | e7eed2abbe91fa44bd071819123bd9ea04d1702a (diff) | |
download | gitbook-669f3b39849890c48171d807225cd6eaa3c9086b.zip gitbook-669f3b39849890c48171d807225cd6eaa3c9086b.tar.gz gitbook-669f3b39849890c48171d807225cd6eaa3c9086b.tar.bz2 |
Add base for normalizing html
Diffstat (limited to 'lib/utils/command.js')
-rw-r--r-- | lib/utils/command.js | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/lib/utils/command.js b/lib/utils/command.js index f395fa1..4269d6c 100644 --- a/lib/utils/command.js +++ b/lib/utils/command.js @@ -13,7 +13,32 @@ function exec(command, options) { return Promise.nfcall(childProcess.exec, command, options); } +// Spawn an executable +function spawn(command, args, options) { + if (!isAvailable) { + return Promise.reject(new Error('Command execution is not possible on this platform')); + } + + var d = Promise.deferred(); + var child = childProcess.spawn(command, args, options); + + child.on('error', function(error) { + return d.reject(error); + }); + + child.on('close', function(code) { + if (code === 0) { + d.resolve(); + } else { + d.reject(new Error('Error with command "'+command+'"')); + } + }); + + return d.promise; +} + module.exports = { isAvailable: isAvailable, - exec: exec + exec: exec, + spawn: spawn }; |