-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
280 lines (243 loc) · 7.67 KB
/
gulpfile.babel.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
// generated on 2015-11-17 using generator-gulp-webapp 1.0.3
import gulp from 'gulp';
import gulpLoadPlugins from 'gulp-load-plugins';
import browserSync from 'browser-sync';
import del from 'del';
import spritesmith from 'gulp.spritesmith';
import merge from 'merge-stream';
import fileInclude from 'gulp-file-include';
import { stream as wiredep } from 'wiredep';
const $ = gulpLoadPlugins();
const reload = browserSync.reload;
var header = require('gulp-header');
var pkg = require('./package.json');
var banner = [
'/*!\n' +
' * <%= pkg.title %>\n' +
' * <%= pkg.description %>\n' +
' * <%= pkg.url %>\n' +
' * @author <%= pkg.author %>\n' +
' * @version <%= pkg.version %>\n' +
' * Copyright ' + new Date().getFullYear() + '. <%= pkg.license %> licensed.\n' +
' */',
'\n'
].join('');
gulp.task('styles', () => {
return gulp.src('app/sass/*.scss')
.pipe($.plumber())
.pipe($.sourcemaps.init())
.pipe($.sass.sync({
outputStyle: 'expanded',
precision: 10,
includePaths: ['.']
}).on('error', $.sass.logError))
.pipe($.autoprefixer({
browsers: ['last 1 version']
}))
.pipe(header(banner, {
pkg: pkg
}))
.pipe($.sourcemaps.write('/'))
.pipe(gulp.dest('.tmp/css'))
.pipe(reload({
stream: true
}));
});
var banner = [
'/*!\n' +
' * <%= pkg.title %>\n' +
' * <%= pkg.description %>\n' +
' * <%= pkg.url %>\n' +
' * @author <%= pkg.author %>\n' +
' * @version <%= pkg.version %>\n' +
' * Copyright ' + new Date().getFullYear() + '. <%= pkg.license %> licensed.\n' +
' */',
'\n'
].join('');
gulp.task('fileinclude', () => {
gulp.src('app/tpl/*.html')
.pipe(fileInclude({
prefix: '@@',
basepath: '@file'
}))
.pipe(gulp.dest('app/'));
});
gulp.task('uncss', function() {
return gulp.src('.tmp/css/main.css')
.pipe($.uncss({
html: ['app/*.html'],
ignore: [
'.fa',
/(#|\.)active(\-[a-zA-Z]+)?/,
/(#|\.)current-menu-item(\-[a-zA-Z]+)?/,
/(#|\.)selectboxit(\-[a-zA-Z]+)?/,
/(#|\.)mfp(\-[a-zA-Z]+)?/,
/(#|\.)slicknav(\-[a-zA-Z]+)?/,
/(#|\.)store-legends(\-[a-zA-Z]+)?/,
/(#|\.|:)-webkit(\-[a-zA-Z]+)?/, //This is used to ignore pseudo elements that use double semi-columns
]
}))
.pipe(gulp.dest('.tmp/css'));
});
function lint(files, options) {
return () => {
return gulp.src(files)
.pipe(reload({
stream: true,
once: true
}))
.pipe($.eslint(options))
.pipe($.eslint.format())
.pipe($.if(!browserSync.active, $.eslint.failAfterError()));
};
}
const testLintOptions = {
env: {
mocha: true
}
};
gulp.task('lint', lint('app/js/**/*.js'));
gulp.task('lint:test', lint('test/spec/**/*.js', testLintOptions));
gulp.task('html', ['styles'], () => {
const assets = $.useref.assets({
searchPath: ['.tmp', 'app', '.']
});
return gulp.src('app/*.html')
.pipe(assets)
.pipe($.if('*.js', $.uglify()))
.pipe($.if('*.css', $.minifyCss({
compatibility: '*'
})))
.pipe(assets.restore())
.pipe($.useref())
.pipe(gulp.dest('dist'));
});
gulp.task('images', () => {
return gulp.src('app/img/**/*')
.pipe($.if($.if.isFile, $.cache($.imagemin({
progressive: true,
interlaced: true,
// don't remove IDs from SVGs, they are often used
// as hooks for embedding and styling
svgoPlugins: [{
cleanupIDs: false
}]
}))
.on('error', function(err) {
console.log(err);
this.end();
})))
.pipe(gulp.dest('dist/img'));
});
gulp.task('sprites', function() {
var globalSprites = gulp.src('app/img/sprites/*.png').pipe(spritesmith({
imgName: 'sprites.png',
cssName: '_sprites.css',
imgPath: '../img/sprites.png'
})),
cssGlobal = globalSprites.css.pipe(gulp.dest('app/sass/base')),
imgGlobal = globalSprites.img.pipe(gulp.dest('app/img/'));
return merge(cssGlobal, imgGlobal);
});
gulp.task('fonts', () => {
/*main-bower-files is a plugin that scans bower.json and returns an array of files defined in the "main" property of the package.json*/
return gulp.src(require('main-bower-files')({
/*This is a filter to only return font files from bower packages (specifically bootstrap-sass & font-awesome) */
filter: '**/*.{eot,svg,ttf,woff,woff2}'
}).concat('app/fonts/**/*'))
.pipe(gulp.dest('.tmp/fonts'))
.pipe(gulp.dest('dist/fonts'));
});
// If there are extra files within the root of /app directory, copy it to the dist (i.e. favicons, etc)
gulp.task('extras', () => {
return gulp.src([
'app/*.*',
'app/**/*',
'!app/sass{,/**} ',
'!app/tpl{,/**} ',
'!app/*.html'
], {
dot: true
}).pipe(gulp.dest('dist'));
});
gulp.task('views', () => {
return gulp.src('app/views/**/*', {
base: './app'
})
.pipe(gulp.dest('dist'));
});
gulp.task('clean', del.bind(null, ['.tmp', 'dist']));
gulp.task('serve', ['styles', 'fonts'], () => {
browserSync({
notify: false,
port: 9000,
server: {
baseDir: ['.tmp', 'app'],
routes: {
'/bower_components': 'bower_components'
}
}
});
gulp.watch('app/tpl/**/*.html', ['fileinclude']);
gulp.watch('app/sass/**/*.scss', ['styles']);
gulp.watch('app/js/**/*.js', ['lint']);
gulp.watch('app/fonts/**/*', ['fonts']);
gulp.watch('app/img/**/*', ['sprites']);
gulp.watch('bower.json', ['wiredep', 'fonts']);
gulp.watch('app/**/*').on('change',reload);
});
gulp.task('serve:dist', () => {
browserSync({
notify: false,
port: 9000,
server: {
baseDir: ['dist']
}
});
});
gulp.task('serve:test', () => {
browserSync({
notify: false,
port: 9000,
ui: false,
server: {
baseDir: 'test',
routes: {
'/bower_components': 'bower_components'
}
}
});
gulp.watch('test/spec/**/*.js').on('change', reload);
gulp.watch('test/spec/**/*.js', ['lint:test']);
});
// inject bower components upon update of bower.json file
gulp.task('wiredep', () => {
// This will inject sass files of vendors(i.e. bootstrap or fontawesome) inside our main.scss files
gulp.src('app/sass/main.scss')
.pipe(wiredep({
ignorePath: /^(\.\.\/)+/
}))
.pipe(gulp.dest('app/sass'));
// This will scan .html files and will inject vendor files in js & css blocks
gulp.src('app/tpl/global/*.html')
.pipe(wiredep({
exclude: ['bootstrap-sass'], //'exclude' means not to include certain packages within the bower file
ignorePath: /^(\.\.\/)*\.\./
}))
.pipe(gulp.dest('app/tpl/global'));
});
gulp.task('build', ['html', 'images', 'fonts', 'extras'], () => {
return gulp.src('dist/**/*').pipe($.size({
title: 'build',
gzip: true
}));
});
gulp.task('build:angular', ['lint', 'html', 'images', 'fonts', 'extras', 'views'], () => {
return gulp.src('dist/**/*').pipe($.size({
title: 'build',
gzip: true
}));
});
gulp.task('default', ['clean'], () => {
gulp.start('build');
});