-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (38 loc) · 1.22 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
var path = require('path');
exports.summary = 'Compile coffeescript files to javascript';
exports.usage = '<src> [options]';
exports.options = {
"dest" : {
alias : 'd'
,default : '<src>'
,describe : 'destination file'
},
"charset" : {
alias : 'c'
,default : 'utf-8'
,describe : 'file encoding type'
}
};
exports.run = function (options, done) {
var src = options.src;
var dest = options.dest;
exports.async.eachSeries(exports.files, function(inputFile, callback){
var outputFile = dest;
if(exports.file.isDirFormat(dest)){
outputFile = path.join(dest , path.basename(inputFile) );
// replace file extname to .js
outputFile = outputFile.replace('.coffee', '.js');
}
exports.compileCoffee(inputFile, outputFile, options, callback);
}, done);
};
exports.compileCoffee = function(inputFile, outputFile, options, done){
var coffee = require('coffee-script');
var code = exports.file.read(inputFile);
var js = coffee.compile(code, options);
if (outputFile) {
exports.file.write(outputFile, js);
exports.log(inputFile, ">", outputFile);
}
done(null, js);
}