-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
165 lines (143 loc) · 3.68 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
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
var gulp = require("gulp");
var watch = require("gulp-watch");
var concat = require("gulp-concat");
var rename = require("gulp-rename");
var uglify = require("gulp-uglify");
var concatCss = require("gulp-concat-css");
var minifyCss = require("gulp-minify-css");
var templateCache = require("gulp-angular-templatecache");
var copy = require("gulp-copy");
var path = {
lib: "src/AppBundle/Resources/public/js/lib/",
app: "src/AppBundle/Resources/public/js/app/",
todo: "src/TodoBundle/Resources/public/",
dest: "web/public/js/"
};
var bundles = {
jquery: {
bundleName: "jquery.bundle",
js_paths: [
path.lib + "jquery/dist/jquery.min.js",
path.lib + "jquery-ui/jquery-ui.min.js"
],
dest: path.dest + "lib/"
},
angular: {
bundleName: "angular.bundle",
js_paths: [
path.lib + "angular/angular.js",
path.lib + "angular-resource/angular-resource.min.js",
path.lib + "angular-ui-router/release/angular-ui-router.min.js"
],
dest: path.dest + "lib/"
},
materialize: {
bundleName: "materialize.bundle",
js_paths: [
path.lib + "Materialize/bin/materialize.js"
],
dest: path.dest + "lib/"
},
app: {
bundleName: "app.bundle",
js_paths: [
path.app + "/**/*.js"
],
dest: path.dest + "app/",
watchable: true
},
todo: {
bundleName: "todo.bundle",
tpl_module: "application.todo",
js_paths: [
path.todo + "js/todo/todo.module.js",
path.todo + "js/todo/**/*.js"
],
tpl_paths: [
path.todo + "js/todo/**/*.html"
],
css_paths: [
path.todo + "css/todo/**/*.css"
],
dest: path.dest + "app/",
watchable: true
}
};
var jsBuildTasks = [];
var tplBuildTasks = [];
var cssBuildTasks = [];
var watcherTasks = [];
var taskConstructor = function(bundle){
if(bundle.js_paths.length > 0){
// add task to build js bundle
var jsTaskName = "build-" + bundle.bundleName;
gulp.task(
jsTaskName,
function(){
return gulp.src(bundle.js_paths)
.pipe(concat(bundle.bundleName + ".js"))
.pipe(gulp.dest(bundle.dest))
;
}
);
jsBuildTasks.push(jsTaskName);
if(bundle.watchable){
gulp.task(jsTaskName+"-watcher", function(){
return gulp.watch(bundle.js_paths, [jsTaskName]);
});
watcherTasks.push(jsTaskName+"-watcher");
}
}
if(bundle.css_paths && bundle.css_paths.length > 0){
// add task to build css
var cssTaskName = "build-" + bundle.bundleName + "-css";
gulp.task(
cssTaskName,
function(){
return gulp.src(bundle.css_paths)
.pipe(concatCss(bundle.bundleName + ".css"))
.pipe(gulp.dest(bundle.dest))
;
}
);
cssBuildTasks.push(cssTaskName);
if(bundle.watchable){
gulp.task(cssTaskName+"-watcher", function(){
return gulp.watch(bundle.css_paths, [cssTaskName]);
});
watcherTasks.push(cssTaskName+"-watcher");
}
}
if(bundle.tpl_paths && bundle.tpl_paths){
// add task to build angular templates
var tplTaskName = "build-" + bundle.bundleName + "-tpl";
gulp.task(
tplTaskName,
function(){
return gulp.src(bundle.tpl_paths)
.pipe(templateCache(bundle.bundleName + ".templates.js", {
module: bundle.tpl_module,
standalone: false}))
.pipe(gulp.dest(bundle.dest))
;
}
);
tplBuildTasks.push(tplTaskName);
if(bundle.watchable){
gulp.task(tplTaskName+"-watcher", function(){
return gulp.watch(bundle.tpl_paths, [tplTaskName]);
});
watcherTasks.push(tplTaskName+"-watcher");
}
}
};
for(var bundleKey in bundles){
taskConstructor(bundles[bundleKey]);
}
// tasks to build all js/tpl/css
gulp.task("js-build", jsBuildTasks);
gulp.task("tpl-build", tplBuildTasks);
gulp.task("css-build", cssBuildTasks);
// watchers task
gulp.task("watchers-build", watcherTasks);
gulp.task('default', ["js-build", "tpl-build", "css-build"]);