-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntFile.js
74 lines (68 loc) · 1.73 KB
/
GruntFile.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
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.initConfig({
watch: {
options: {
livereload: true,
},
build_dev: {
files: ['src/*.js'],
tasks: 'build_dev'
}
},
connect: {
dev: {
options: {
port: 3000,
base: '',
keepalive: true
}
}
}
});
grunt.registerTask('build_dev', '', function() {
fs = require('fs');
function compile(file, buffer) {
var parent = false;
if(typeof buffer === 'undefined') {
buffer = [];
parent = true;
}
var cwd = process.cwd();
var data = fs.readFileSync(file, 'utf8');
var basepath = file.substring(0, file.lastIndexOf('/')+1);
process.chdir(basepath);
var pos = -1;
var startPos = 0;
while( (pos = data.indexOf('include "', startPos)) != -1 ) {
buffer.push(data.substring(startPos, pos));
var fname = '';
var c;
pos += 9;
while( (c = data[pos++]) != '"' )
fname += c;
if(/^[a-zA-Z_\-]/.test(fname))
fname = './' + fname;
startPos = pos + 1;
compile(fname, buffer);
}
buffer.push(data.substring(startPos));
process.chdir(cwd);
if(parent)
return buffer.join('');
}
var input = './src/timber.js';
var output = './timber_compiled.js';
var data = compile(input);
var done = this.async();
fs.writeFile(output, data, function(err) {
if(err) {
grunt.log.writeln(err);
} else {
grunt.log.writeln("The file was saved!");
}
done();
});
});
};