forked from chrislondon/PieJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJakefile
189 lines (148 loc) · 4.61 KB
/
Jakefile
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
var fs = require('fs');
var minify = function(source, destination) {
console.log('Building ' + destination + '...');
var data = fs.readFileSync(source),
jsmin = require('jsmin').jsmin;
fs.writeFileSync(destination, jsmin(data.toString()));
console.log('done');
};
var concat = function(folder, destination, require) {
if (require === undefined) {
require = true;
}
var list, i, loaded = {}, data = '';
console.log('Building ' + destination + '...');
list = new jake.FileList();
list.include(folder);
list = list.toArray();
var loadFile = function(filename) {
var i, fileData, requires, pattern = /require\(('|")(.*)('|")\);/gi;
if (loaded[filename] !== undefined) {
return;
}
fileData = '' + fs.readFileSync(filename);
if (require) {
// find requires
requires = fileData.match(pattern);
if (requires !== null) {
for (i in requires) {
if (requires.hasOwnProperty(i)) {
loadFile(requires[i].substr(9, requires[i].length - 12));
}
}
}
fileData = fileData.replace(pattern, '');
}
console.log('Loading file ' + filename);
loaded[filename] = true;
data += fileData + "\n\n";
}
for (i in list) {
if (list.hasOwnProperty(i)) {
loadFile(list[i]);
}
}
fs.writeFileSync(destination, data);
console.log('done');
};
var deleteFolderRecursive = function(path) {
var files = [];
if( fs.existsSync(path) ) {
files = fs.readdirSync(path);
files.forEach(function(file,index){
var curPath = path + "/" + file;
if(fs.statSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
};
desc('Make sure we have the correct build folder');
directory('./webroot/js', [], function() {
console.log('Creating build directory');
});
desc('Make sure we have the correct view folder');
directory('./webroot/views', [], function() {
console.log('Creating view directory');
});
task('build-views', ['./webroot/views'], function() {
var list, i, filename, filedir, targetDir, loaded = {};
list = new jake.FileList();
list.include('App/View/**/*.html');
list.include('Lib/PieJS/src/View/**/*.html');
list = list.toArray();
for (i in list) {
if (list.hasOwnProperty(i)) {
filename = (list[i].substr(0, 3) === 'App' ? list[i].substr(9) : list[i].substr(19)).toLowerCase();
if (loaded[filename] !== undefined) {
continue;
}
loaded[filename] = true;
filedir = filename.split('/');
filename = filedir.pop();
filedir.join('/');
targetDir = './webroot/views/' + filedir;
jake.mkdirP(targetDir);
fs.writeFileSync(targetDir + '/' + filename, fs.readFileSync(list[i]));
// copy file over
console.log(filename);
}
}
});
desc('Create unminified pie.js');
file('./webroot/js/pie.js', ['./webroot/js'], function() {
concat('Lib/PieJS/src/*.js', './webroot/js/pie.js');
});
desc ('This is the minify task');
file('./webroot/js/pie.min.js', ['./webroot/js/pie.js'], function() {
minify('./webroot/js/pie.js', './webroot/js/pie.min.js');
});
desc ('Make sure we have handlebars');
file('./webroot/js/handlebars.js', ['./webroot/js'], function() {
concat('Lib/Handlebars/*.js', './webroot/js/handlebars.js', false);
});
desc ('Minify handlebars');
file('./webroot/js/handlebars.min.js', ['./webroot/js/handlebars.js'], function() {
minify('./webroot/js/handlebars.js', './webroot/js/handlebars.min.js');
});
desc('Create unminified app.js');
file('./webroot/js/app.js', ['./webroot/js'], function() {
concat(['App/*.js', 'App/**/*.js'], './webroot/js/app.js');
});
desc ('This is the minify task');
file('./webroot/js/app.min.js', ['./webroot/js/app.js'], function() {
minify('./webroot/js/app.js', './webroot/js/app.min.js');
});
desc ('Remove all build files');
task('clean', [], function() {
console.log('Removing previous build...');
var i, filesList = [
'./webroot/js/pie.js',
'./webroot/js/pie.min.js',
'./webroot/js/app.js',
'./webroot/js/app.min.js',
'./webroot/js/handlebars.js',
'./webroot/js/handlebars.min.js'
];
for (i in filesList) {
if (filesList.hasOwnProperty(i)) {
try {
fs.unlinkSync(filesList[i]);
} catch(e) {
console.log(filesList[i] + ' missing');
}
}
}
deleteFolderRecursive('./webroot/views');
console.log('done');
});
desc('Main build task');
task('build', ['./webroot/js/pie.min.js', './webroot/js/app.min.js', 'build-views', './webroot/js/handlebars.min.js'], function() {
console.log('Build complete');
});
task('rebuild', ['clean', 'build'], function() {
console.log('Rebuild complete');
});