-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
57 lines (41 loc) · 1.23 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var exec = require('child_process').execFile;
var os = require('os');
var path = require('path');
var ligatures = require('./lib/ligatures');
var render = require('./lib/template');
module.exports = bullshit;
var BIN = 'ttx';
function bullshit(words, options, callback) {
if (!Array.isArray(words))
words = [ words ];
if ('function' === typeof options) {
callback = options;
options = { };
}
var ligatureGlyphs = ligatures(words);
render(ligatureGlyphs, rendered);
function rendered(err, filename) {
generate(filename, { filename: options.filename, dir: options.dir }, callback);
}
function generate(file, options, callback) {
var args = [ ];
var dir = options.dir;
var filename = options.filename;
var fqdn;
if (filename)
args.push('-o', filename);
if (dir) {
dir = path.isAbsolute(dir) ? dir : path.join(process.cwd(), dir);
args.push('-d', dir);
}
args.push(file);
exec(BIN, args, { cwd: dir || os.tmpDir() }, function(err, stdout, stderr) {
if (err)
return callback(err);
dir = dir || path.dirname(file);
filename = filename || path.basename(file);
fqdn = path.join(dir, filename);
callback(null, fqdn);
});
}
}