summaryrefslogtreecommitdiffstats
path: root/lib/utils/images.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-03-10 16:31:43 -0700
committerSamy Pessé <samypesse@gmail.com>2015-03-10 16:31:43 -0700
commit3055139297a07b3185382e694b256fdb61618d91 (patch)
tree1644a285a175e5e3725cf965705dd67451f02b32 /lib/utils/images.js
parent3d6b099dea74a2049f835caf60566f4b39a7b10b (diff)
downloadgitbook-3055139297a07b3185382e694b256fdb61618d91.zip
gitbook-3055139297a07b3185382e694b256fdb61618d91.tar.gz
gitbook-3055139297a07b3185382e694b256fdb61618d91.tar.bz2
Fix run of svgexport on windows
Diffstat (limited to 'lib/utils/images.js')
-rw-r--r--lib/utils/images.js19
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/utils/images.js b/lib/utils/images.js
index f1302c3..59e8885 100644
--- a/lib/utils/images.js
+++ b/lib/utils/images.js
@@ -2,28 +2,29 @@ var _ = require("lodash");
var Q = require("q");
var fs = require("./fs");
var shellescape = require('shell-escape');
-var exec = require('child_process').exec;
+var spawn = require('spawn-cmd').spawn;
var links = require("./links");
// Convert a svg file
var convertSVG = function(source, dest, options) {
if (!fs.existsSync(source)) return Q.reject(new Error("File doesn't exist: "+source));
-
var d = Q.defer();
options = _.defaults(options || {}, {
});
- var command = shellescape(['svgexport', source, dest]);
+ //var command = shellescape(['svgexport', source, dest]);
+ var child = spawn('svgexport', [source, dest]);
- var child = exec(command, function (error, stdout, stderr) {
- if (error) {
- if (error.code == 127) error = new Error("Need to install 'svgexport' using 'npm install svgexport -g'");
- return d.reject(error);
- }
- if (fs.existsSync(dest)) {
+ child.on("error", function(error) {
+ if (error.code == "ENOENT") error = new Error("Need to install 'svgexport' using 'npm install svgexport -g'");
+ return d.reject(error);
+ });
+
+ child.on("close", function(code) {
+ if (code == 0 && fs.existsSync(dest)) {
d.resolve();
} else {
d.reject(new Error("Error converting "+source));