diff --git a/README.md b/README.md index 9063ad9..781843e 100644 --- a/README.md +++ b/README.md @@ -61,3 +61,13 @@ This function parses the output of `unoconv --show` to attempt to detect support `callback` gets the arguments `err` and `result`. `result` is an object containing a collection of supported document types and output formats. +## API + +### 0.1.4 (Nov 9, 2014) + +* Support for pidfile argument + +### 0.1.3 (Nov 7, 2014) + +* Support for more unoconv options +* Bug fix: Error will be based on return code from spawn instead of data in stderr diff --git a/index.js b/index.js index 430bf47..49b9355 100644 --- a/index.js +++ b/index.js @@ -29,31 +29,50 @@ unoconv.convert = function(file, outputFormat, options, callback) { } args = [ - '-f' + outputFormat, - '--stdout' + '-f' + outputFormat ]; - if (options && options.port) { - args.push('-p' + options.port) + if (options) { + if (options.port) { + args.push('-p' + options.port) + } + if (options.verbose) { + args.push('-v'); + } + if (options.output) { + args.push('--output'); + args.push(options.output); + } + if (options.stdout) { + args.push('--stdout'); + } + if (options.doctype) { + args.push('-d' + options.doctype); + } + if (options.exportStr) { + args.push('-e' + options.exportStr); + } + if (options.nolaunch) { + args.push('-n'); + } + if (options.template) { + args.push('-t' + options.template); + } + if (options.timeout) { + args.push('-T' + options.timeout); + } + if (options.pidfile) { + args.push('--pidfile'); + args.push(options.pidfile); + } } - args.push(file); if (options && options.bin) { bin = options.bin; } - child = childProcess.spawn(bin, args, function (err, stdout, stderr) { - if (err) { - return callback(err); - } - - if (stderr) { - return callback(new Error(stderr.toString())); - } - - callback(null, stdout); - }); + child = childProcess.spawn(bin, args); child.stdout.on('data', function (data) { stdout.push(data); @@ -63,8 +82,8 @@ unoconv.convert = function(file, outputFormat, options, callback) { stderr.push(data); }); - child.on('exit', function () { - if (stderr.length) { + child.on('exit', function (code, signal) { + if (code !== 0 && stderr.length) { return callback(new Error(Buffer.concat(stderr).toString())); } diff --git a/package.json b/package.json index fb76b19..0dbc999 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "unoconv", - "version": "0.1.2", + "version": "0.1.5", "description": "Wrapper for converting documents with unoconv.", - "homepage": "https://github.com/gfloyd/node-unoconv", + "homepage": "https://github.com/colearnr/node-unoconv", "author": { "name": "Graham Floyd", "email": "grahamf@gmail.com" @@ -10,7 +10,7 @@ "main": "./index", "repository": { "type": "git", - "url": "https://github.com/gfloyd/node-unoconv.git" + "url": "https://github.com/colearnr/node-unoconv.git" }, "keywords": [ "unoconv",