-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
79 lines (64 loc) · 1.9 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var fs = require('fs');
var path = require('path');
exports.summary = 'Auto vendor prefix for CSS3 properties';
exports.usage = '<src> [options]';
exports.options = {
"dest":{
alias:'d',
describe:'destination file'
},
"browsers": {
describe: "specify the browsers you want to target in your project"
},
"suffix" : {
alias : 's'
,default : '.prefixed'
,describe : 'destination file suffix append'
},
'output': {
alias: 'o'
,default : 'file'
,describe : 'specify output type: file pipe'
},
"charset":{
alias:'c',
default:'utf-8',
describe:'file encoding type'
}
};
exports.run = function (options) {
var dest = options.dest;
var charset = options.charset;
var suffix = options.suffix;
var output = options.output;
var browsers = options.browsers;
var file = exports.file;
var prefixed;
exports.files.forEach(function (inputFile) {
var outputFile;
if( output !== 'file' ){
outputFile = null;
}else if( !dest ) {
outputFile = inputFile;
}else if( file.isDirFormat(dest) ){
var filename = path.basename(inputFile);
outputFile = path.join(dest, filename);
}else{
outputFile = dest;
}
if(suffix && outputFile){
outputFile = file.suffix(outputFile, suffix);
}
var fileContent = file.read(inputFile, charset);
prefixed = exports.autoprefixer(browsers, fileContent);
if( outputFile ){
exports.log(inputFile, ">", outputFile);
file.write(outputFile, prefixed, charset);
}
});
return prefixed;
};
exports.autoprefixer = function(browsers, css){
var autoprefixer = require('autoprefixer')(browsers);
return autoprefixer.compile(css)
}