-
Notifications
You must be signed in to change notification settings - Fork 57
/
react.css.build.js
57 lines (48 loc) · 1.23 KB
/
react.css.build.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
var fs = require('fs');
var nativeCSS = require('./native-css');
var mkdirp = require('mkdirp');
var fileList = [];
function walk(path) {
var dirList = fs.readdirSync(path);
dirList.forEach(function(item) {
if (fs.statSync(path + '/' + item).isDirectory()) {
walk(path + '/' + item + '/');
} else {
fileList.push(path + item);
}
});
}
walk('./css/');
console.log(fileList);
fileList.forEach(function(f){
if(/\.css$/i.test(f)){
transformCSS(f);
}
});
watch();
function watch(){
var chokidar = require('chokidar');
try{
var r = chokidar.watch('./css/').on('change',function(fileName){
fileName = './' + fileName;
console.log('检测到' + fileName + '有change');
try{
if(/\.css$/i.test(fileName)){
transformCSS(fileName);
}
}catch(e){
console.log(e);
}
})
}catch(e){}
console.log('start watching!');
}
function transformCSS(fileName){
var cssObject = nativeCSS.convert(fileName);
var newFileName = fileName.replace('/css/','/reactnative/css/').replace(/\.css$/,'.js');
console.log(newFileName);
var dir = newFileName.match(/(\..+\/)/)[0];
mkdirp.sync(dir);
console.log('build '+newFileName);
nativeCSS.generateFile(cssObject, newFileName, false);
}