forked from serverlesspub/pandoc-aws-lambda-binary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpandoc.js
More file actions
46 lines (45 loc) · 1.18 KB
/
pandoc.js
File metadata and controls
46 lines (45 loc) · 1.18 KB
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
/*global module, require, __dirname, Promise */
var os = require('os'),
path = require('path'),
fs = require('fs'),
cp = require('./child-process-promise'),
exists = function (target) {
'use strict';
return new Promise(function (resolve, reject) {
fs.access(target, function (err) {
if (err) {
reject(target);
} else {
resolve(target);
}
});
});
},
makeExecutable = function (target) {
'use strict';
return new Promise(function (resolve, reject) {
fs.chmod(target, '0700', function (err) {
if (err) {
reject(target);
} else {
resolve(target);
}
});
});
},
unzip = function (targetPath) {
'use strict';
return cp.exec('cat ' + path.join(__dirname, 'vendor', 'pandoc.gz') + ' | gzip -d > ' + targetPath).then(function () {
return makeExecutable(targetPath);
});
},
findUnpackedBinary = function () {
'use strict';
return exists(path.join(os.tmpdir(), 'pandoc')).catch(unzip);
};
module.exports = function pandoc(inPath, outPath, additionalOptions) {
'use strict';
return findUnpackedBinary().then(function (commandPath) {
return cp.spawn(commandPath, [inPath, '-o', outPath].concat(additionalOptions || []));
});
};