-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
37 lines (29 loc) · 774 Bytes
/
index.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
var exec = require('child_process').exec
, util = require('util');
module.exports = function (options, callback) {
if (typeof options === 'string') {
options = {file: options};
}
if (!options.file) {
return callback('must specify a file');
}
if (!options.index) {
options.index = 0;
}
if (!options.offset) {
options.offset = 0;
}
if (options.index && !options.offset) {
return callback('must specify an offset');
}
var cmd = util.format('echoprint-codegen "%s" %d %d', options.file, options.index, options.offset);
exec(cmd, function (err, stdout) {
if (err) return callback(err);
try {
var data = JSON.parse(stdout)[0];
callback(data.error, data);
} catch (e) {
callback(e);
}
});
};