-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
131 lines (73 loc) · 2.08 KB
/
gulpfile.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
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
var gulp = require('gulp');
var del = require('del');
var concat = require("gulp-concat");
var less = require('gulp-less');
var through2 = require("through2");
var File = require('vinyl');
var path = require('path');
var fs = require('fs');
var dependencies = function() {
var sources = [];
var MATCH_REGEXP = /^\/\/= require (.*)$/mg;
var processDependencies = function(file, callback) {
var s = String(file.contents);
var deps = [];
while(match = MATCH_REGEXP.exec(s)) {
deps.push(match[1]);
}
s = s.replace(MATCH_REGEXP, '');
file.contents = new Buffer(s);
var dir = path.dirname(file.path);
deps.forEach(function(dep) {
var filepath = path.normalize( path.join(dir, dep+'.js') );
if( fs.existsSync(filepath) ) {
var f = new File({
path: filepath,
contents: fs.readFileSync(filepath)
});
processDependencies(f, callback);
callback(f);
}
});
// callback(file, callback);
};
var processFile = function(chunk, enc, callback) {
var stream = this;
if( chunk.isBuffer() ) {
processDependencies(chunk, function(file){
// console.log(file.path)
if(sources.indexOf(file.path) == -1) {
stream.push(file);
}
sources.push(file.path);
});
this.push(chunk);
}
callback();
}
return through2.obj(processFile);
};
gulp.task('scripts', function() {
gulp.src(["js/core/core.js", "js/data/data.js", "js/layouts/layouts.js", "js/includes/includes.js", "js/html/html.js"])
.pipe(dependencies())
.pipe(concat("ergojs-core.js"))
.pipe(gulp.dest("dist"));
gulp.src(["js/widgets/widgets.js"])
.pipe(dependencies())
.pipe(concat("ergojs-widgets-all.js"))
.pipe(gulp.dest("dist"));
});
gulp.task('styles', function() {
gulp.src(["css/ergojs-layouts.less"])
.pipe(less())
.pipe(concat("ergojs.css"))
.pipe(gulp.dest("dist"));
});
gulp.task('watch', function() {
gulp.watch('js/**', ['scripts']);
gulp.watch('css/**', ['styles']);
});
gulp.task('clear', function() {
del(['dist/*']);
});
gulp.task('default', ['clear', 'scripts', 'styles']);