diff options
-rw-r--r-- | lib/utils/command.js | 27 | ||||
-rw-r--r-- | lib/utils/images.js | 1 | ||||
-rw-r--r-- | package.json | 3 |
3 files changed, 14 insertions, 17 deletions
diff --git a/lib/utils/command.js b/lib/utils/command.js index d2beba0..de240df 100644 --- a/lib/utils/command.js +++ b/lib/utils/command.js @@ -1,16 +1,10 @@ var _ = require('lodash'); var childProcess = require('child_process'); +var spawn = require("spawn-cmd").spawn; var Promise = require('./promise'); -// On borwser, command execution is not possible -var isAvailable = childProcess && childProcess.exec; - // Execute a command function exec(command, options) { - if (!isAvailable) { - return Promise.reject(new Error('Command execution is not possible on this platform')); - } - var d = Promise.defer(); var child = childProcess.exec(command, options, function(err, stdout, stderr) { @@ -34,18 +28,22 @@ function 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')); - } - +function spawnCmd(command, args, options) { var d = Promise.defer(); - var child = childProcess.spawn(command, args, options); + var child = spawn(command, args, options); child.on('error', function(error) { return d.reject(error); }); + child.stdout.on('data', function (data) { + d.notify(data); + }); + + child.stderr.on('data', function (data) { + d.notify(data); + }); + child.on('close', function(code) { if (code === 0) { d.resolve(); @@ -76,8 +74,7 @@ function optionsToShellArgs(options) { } module.exports = { - isAvailable: isAvailable, exec: exec, - spawn: spawn, + spawn: spawnCmd, optionsToShellArgs: optionsToShellArgs }; diff --git a/lib/utils/images.js b/lib/utils/images.js index 1dd8df9..e387d6b 100644 --- a/lib/utils/images.js +++ b/lib/utils/images.js @@ -5,7 +5,6 @@ var error = require('./error'); // Convert a svg file to a pmg function convertSVGToPNG(source, dest, options) { - if (!command.isAvailable) return Promise.reject(new Error('Could not convert SVG in this platform')); if (!fs.existsSync(source)) return Promise.reject(new error.FileNotFoundError({ filename: source })); return command.spawn('svgexport', [source, dest]) diff --git a/package.json b/package.json index 1520d50..f6af9df 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,8 @@ "direction": "0.1.5", "moment": "2.11.2", "i18n-t": "1.0.0", - "front-matter": "2.0.6" + "front-matter": "2.0.6", + "spawn-cmd": "0.0.2" }, "devDependencies": { "eslint": "1.5.0", |