-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
48 lines (42 loc) · 1.51 KB
/
main.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
//main.js
//It compiles coffeescript to js and runs the main.coffe aka. main.js
var settings = require('./package.json').settings;
//define path
var coffeePath=__dirname+'/lib/', jsPath=__dirname+'/src/'
//if package.json > settings.debug is true, the coffeescript will compile
if (settings.debug) {
var fs = require('fs')
var coffee = require('coffee-script');
var createDirIfNotExist = function(dir) {
if (fs.existsSync(dir)==false)
fs.mkdirSync(dir);
};
//compiles the file_path from coffeescript to js and write it to jsPath+file_name
compileToCoffe = function(file_path,file_name) {
var file_name_js = file_name.slice(0,file_name.length-6)+'js';
var data=fs.readFileSync(file_path,'utf8');
fs.writeFileSync(jsPath+file_name_js,coffee.compile(data));
};
//Scan all files in cofeescript dir
files = fs.readdirSync(coffeePath);
createDirIfNotExist(jsPath);
for(var i=0;i<files.length;i++) {
var file = files[i];
compileToCoffe(coffeePath+file,file);
}
//Compile LESS to CSS
var lessPath=__dirname+'/less/', cssPath=__dirname+'/css/'
var less = require('less');
files = fs.readdirSync(lessPath);
createDirIfNotExist(cssPath);
for(var i=0;i<files.length;i++) {
var file = files[i];
var cssFile = file.slice(0,file.length-4)+'css';
var fileDate = fs.readFileSync(lessPath+file,'utf8');
less.render(fileDate,function (e,output) {
fs.writeFileSync(cssPath+cssFile,output.css,'utf8');
});
}
}
//Run the main APP (jsPath+'main.js')
require(jsPath+'main');