-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbake.js
More file actions
executable file
·47 lines (35 loc) · 1.1 KB
/
bake.js
File metadata and controls
executable file
·47 lines (35 loc) · 1.1 KB
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
var stalker = require('stalker');
var spawn = require('child_process').spawn;
var sys = require('sys');
var fs = require('fs');
var exec = function(command, params) {
var subprocess = spawn(command, params);
subprocess.stdout.on('data', function(data) {
sys.print(data.asciiSlice(0, data.length));
});
subprocess.stderr.on('data', function(data) {
sys.print(data.asciiSlice(0, data.length));
});
};
var baker = function(input_path, output_path) {
stalker.watch(input_path, function(err, file_path) {
if(err) {
console.log('Error: ' + err);
return;
}
var extension = file_path.split('.').pop();
if(extension !== 'less')
return;
var compile = function() {
var new_file_path = file_path.replace(input_path, output_path).replace(/^.*\\/, '').replace(/\.[^\.]*$/, '.css');
console.log('less - compiled ' + new_file_path);
exec('lessc', [file_path, new_file_path]);
};
compile();
fs.watchFile(file_path, function(curr, prev) {
if(curr.mtime > prev.mtime)
compile();
});
});
};
baker(__dirname + '/source/theme.less', __dirname + '/build/theme.css');