-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
292 lines (241 loc) · 6.65 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*
** Globals variabls
*/
var config = {
baseTestDir:"app/",
baseBuildDir:"build/",
removableBuild:[
'build/**/sass',
'build/**/jade-files',
'build/**/js/src'
],
shared: {
files:[
"./bower_components/angular/angular.min.js",
"./bower_components/angular-ui-router/release/angular-ui-router.min.js",
"./bower_components/fontawesome/css/font-awesome.min.css",
"./bower_components/normalize.css/normalize.css",
"./bower_components/fontawesome/fonts/*",
"./bower_components/nprogress/nprogress.css",
"./bower_components/nprogress/nprogress.js"
],
cssOrder:[
"normalize.css",
"font-awesome.min.css",
"nprogress.css",
"*"
],
jsOrder:[
"angular.min.js",
"angular-ui-router.min.js",
"nprogress.js",
"*"
],
jsConcatFiles: [
'app/shared/js/src/**/*.js'
]
},
blog : {
jsConcatFiles: [
'app/blog/js/src/**/*.js'
]
},
site : {
jsConcatFiles: [
'app/site/js/src/**/*.js'
]
},
admin : {
jsConcatFiles: [
'app/site/js/src/**/*.js'
]
}
};
/*
** Require scripts
*/
// adding gulp plugins
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
// adding other plugins
var del = require('del'),
browserSync = require('browser-sync'),
reload = browserSync.reload;
gulp.task('jade', ['jade:shared', 'jade:site', 'jade:blog']);
gulp.task('scripts', ['scripts:shared', 'scripts:site', 'scripts:blog']);
gulp.task('sass',['sass:shared', 'sass:site', 'sass:blog']);
gulp.task('watch',['watch:shared', 'watch:site', 'watch:blog', 'watch:admin']);
// task for browser sync
gulp.task('browser-sync', function(){
browserSync({
server:{
baseDir: config.baseTestDir
},
notify: false,
ghostMode: {
clicks: false,
forms: false,
scroll: false
}
});
});
gulp.task('default', ['bower', 'sass', 'jade', 'scripts', 'watch:blog', 'browser-sync']);
/*
** Error function
*/
function throwErr(error){
console.log(error.message);
this.emit('end');
}
/*
** Task scripts
*/
// task for jades
function jadeFiles(src, dest){
gulp.src(src)
.pipe(plugins.jade({ pretty: true }))
.pipe(gulp.dest(dest))
.pipe(reload({stream: true}));
}
gulp.task('jade:shared', function(){
jadeFiles("app/shared/jade-files/**/*.jade", "app/shared/html");
});
gulp.task('jade:site', function(){
jadeFiles("app/site/jade-files/**/*.jade", "app/site/html");
});
gulp.task('jade:blog', function(){
jadeFiles("app/blog/jade-files/**/*.jade", "app/blog/html");
});
// task for root
gulp.task('index', function(){
reload({stream: true});
});
// task for scripts
function scriptFiles(src, dest, fileName){
gulp.src(src)
.pipe(plugins.concat('tmp.js'))
.pipe(plugins.rename(fileName+".js"))
.pipe(gulp.dest(dest))
.pipe(plugins.uglify())
.on('error', throwErr)
.pipe(plugins.rename(fileName+".min.js"))
.pipe(gulp.dest(dest))
.pipe(reload({stream: true}));
}
gulp.task('scripts:shared', function(){
scriptFiles(config.shared.jsConcatFiles, "app/shared/js", "shared");
});
gulp.task('scripts:site', function(){
scriptFiles(config.site.jsConcatFiles, "app/site/js", "site");
});
gulp.task('scripts:blog', function(){
scriptFiles(config.blog.jsConcatFiles, "app/blog/js", "blog");
});
// task for sass
function sassFiles(src, dest, fileName){
gulp.src(src)
.pipe(plugins.plumber())
.pipe(plugins.sass({
includePaths: ['css'],
outputStyle: 'expanded',
}))
.on('error', throwErr)
.pipe(plugins.autoprefixer('last 2 versions'))
.pipe(plugins.rename(fileName))
.pipe(gulp.dest(dest))
.pipe(reload({stream: true}));
}
gulp.task('sass:shared', function(){
sassFiles("app/shared/sass/shared.sass", "app/shared/css", "shared.css");
});
gulp.task('sass:site', function(){
sassFiles("app/site/sass/site.sass", "app/site/css", "site.css");
});
gulp.task('sass:blog', function(){
sassFiles("app/blog/sass/blog.sass", "app/blog/css", "blog.css");
});
/*
** Watch tasks
*/
function addWatch(rootDir ,cb){
gulp.watch(rootDir+'/js/src/**/*.js', ['scripts:'+cb]);
gulp.watch(rootDir+'/sass/**/*.sass', ['sass:'+cb]);
gulp.watch(rootDir+'/jade-files/**/*.jade', ['jade:'+cb]);
gulp.watch(rootDir+'/index.html', function(){
reload();
});
}
gulp.task('watch:site', function(){ addWatch('./app/site', 'site') });
gulp.task('watch:blog', function(){ addWatch('./app/blog', 'blog') });
gulp.task('watch:admin', function(){ addWatch('./app/admin', 'admin') });
gulp.task('watch:shared', function(){ addWatch('./app/shared', 'shared') });
/*
** Default tasks
*/
// adding bower tools
gulp.task('bower', function(){
// adding bower files to share
if(config.shared.files !== undefined)
addBowerFiles(config.shared, 'app/shared');
// adding bower files to site
if(config.site.files !== undefined)
addBowerFiles(config.site, 'app/site');
// adding bower files to blog
if(config.blog.files !== undefined)
addBowerFiles(config.blog, 'app/blog');
// adding bower files to blog
if(config.admin.files !== undefined)
addBowerFiles(config.admin, 'app/admin');
});
function addBowerFiles(mainFile, dest){
// add css files
gulp.src(mainFile.files)
.pipe(plugins.filter('*.css'))
.pipe(plugins.order(mainFile.cssOrder))
.pipe(plugins.concatCss("tmp.css", {rebaseUrls:false}))
.pipe(plugins.rename('tools.css'))
.on('error', throwErr)
.pipe(plugins.minifyCss())
.pipe(gulp.dest(dest+"/css"));
// adding javascripts files
gulp.src(mainFile.files)
.pipe(plugins.filter('*.js'))
.pipe(plugins.order(mainFile.jsOrder))
.pipe(plugins.concat('tmp.js'))
.pipe(plugins.uglify())
.on('error', throwErr)
.pipe(plugins.rename('tools.js'))
.pipe(gulp.dest(dest+"/js"));
// adding font files
gulp.src(mainFile.files)
.pipe(plugins.filter('**/*.{eot,svg,ttf,woff,woff2}'))
.pipe(gulp.dest(dest+"/fonts"))
.pipe(reload({stream: true}));
}
/*
* task for building app
*/
// cleaning the build folder
gulp.task("build:clean", function(cb){
del([
"build/**"
], cb);
});
// copying files to build
gulp.task("build:copy",['build:clean'], function(){
return gulp.src('./app/**/*')
.pipe(gulp.dest('build/'));
});
// removing unnecessary files from build
gulp.task('build:remove', ['build:copy'], function(cb){
del(config.removableBuild, cb);
});
gulp.task('build', ['build:copy', 'build:remove']);
// serving build
gulp.task('build:serve', function(){
browserSync({
server:{
baseDir: config.baseBuildDir
}
});
});