/
command.js
63 lines (47 loc) · 1.3 KB
/
command.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// gm - Copyright Aaron Heckmann <aaron.heckmann+github@gmail.com> (MIT Licensed)
/**
* Module dependencies.
*/
var exec = require('child_process').exec;
var escape = require('./utils').escape;
module.exports = function (proto) {
proto.arg = function arg (inargs, outargs) {
if (inargs) {
this._in = this._in.concat(inargs);
}
if (outargs) {
this._out = this._out.concat(outargs);
}
return this;
}
proto.write = function write (name, callback) {
if (!callback) callback = name, name = null;
if ("function" !== typeof callback) {
throw new TypeError("gm().write() expects a callback function")
}
if (!name) {
throw new TypeError("gm().write() expects a filename when writing new files")
}
if (name) {
this.outname = escape(name);
}
return this._exec(this.cmd(), callback);
}
proto._exec = function _exec (cmd, callback) {
var self = this;
exec(cmd, function (err, stdout, stderr) {
callback.call(self, err, stdout, stderr, cmd);
});
return self;
}
proto.cmd = function cmd () {
return "gm convert "
+ this._in.join(" ")
+ " "
+ this.source
+ " "
+ this._out.join(" ")
+ " "
+ this.outname || this.source;
}
}