-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
47 lines (39 loc) · 985 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
38
39
40
41
42
43
44
45
46
47
'use strict';
var through = require('through2');
var path = require('path');
var fs = require('fs');
var _ = require('lodash');
var exec = require('child_process').exec;
// insert defaults here
var defaults = {
log:false,
sheet:null,
textureFormat:null,
data:null,
format:null,
backgroundColor:null,
}
var self = function(options){
options = _.extend({},defaults,options);
var argsAvaible = [
'sheet',
'textureFormat',
'data',
'format',
'backgroundColor',
];
return through.obj(function (file, enc, done) {
var filename = path.basename(file.path, path.extname(file.path));
var args = _.reduce(_.pick(options,argsAvaible),function(resp,val,i){
if(val!==null){
resp.push('--'+_.kebabCase(i)+' '+val.toString().replace('%name%', filename));
}
return resp;
},[]).join(" ");
exec('TexturePacker '+file.path+' '+args, function(err, stdout, stderr){
if(options.log) console.log(stdout);
done(err,file);
})
})
}
module.exports = self;