-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
245 lines (223 loc) · 5.62 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
/**
* carcassonne-scoreboard-client
*
* @author Andrea Sonny <[email protected]>
* @license MIT
*
* https://andreasonny.mit-license.org/
*
*/
const gulp = require('gulp');
const $ = require('gulp-load-plugins')();
const del = require('del');
const runSequence = require('run-sequence');
const browserSync = require('browser-sync');
const minimist = require('minimist');
const gutil = require('gulp-util');
const reload = browserSync.reload;
const Server = require('karma').Server;
const args = minimist(process.argv.slice(2));
// browser-sync task, only cares about compiled CSS
gulp.task('browser-sync', function() {
return browserSync({
// proxy from the node server
proxy: 'localhost:5000',
// Stop the browser from automatically opening
open: false,
});
});
// start webserver from dist folder to check how it will look in production
gulp.task('serve:dist', function(done) {
return browserSync({
server: {
baseDir: './dist/'
}
}, done);
});
// reload all Browsers
gulp.task('bs-reload', function() {
browserSync.reload();
});
// delete build folder
gulp.task('clean:build', function () {
return del([
'./dist/'
]);
});
// delete source folder
gulp.task('clean:src', function () {
return del([
'./client/',
// '.*',
'./gulpfile.js',
'./karma.*.js',
'*.md',
'*.log',
'*.lock',
'*.yml',
'bower.json',
'LICENSE'
]);
});
// optimize images
gulp.task('images', function() {
return gulp.src('./client/images/**/*')
.pipe($.changed('./dist/images'))
.pipe($.imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
}))
.pipe(gulp.dest('./dist/images'));
});
// copy fonts
gulp.task('fonts', ['iconfont'], function() {
return gulp.src(['./client/fonts/carcassonne-scoreboard-font/*.*'])
.pipe(gulp.dest('./dist/fonts/carcassonne-scoreboard-font'));
});
// copy base files
gulp.task('copy', function() {
return gulp
.src([
'./client/*.*',
'./client/.htaccess',
'!./client/index.html'
])
.pipe(gulp.dest('./dist/'));
});
// SASS task, will run when any SCSS files change
gulp.task('sass', function() {
return gulp
.src('./client/sass/main.scss')
.pipe($.sourcemaps.init())
.pipe($.sass({
outputStyle: 'expanded',
errLogToConsole: true
}))
.pipe($.sourcemaps.write('/'))
.pipe(gulp.dest('./client/css'))
.pipe(reload({
stream: true
}));
});
// SASS Build task
gulp.task('sass:build', function() {
return gulp
.src('client/sass/main.scss')
.pipe($.sourcemaps.init())
.pipe($.sass({
outputStyle: 'compact'
}))
.pipe($.autoprefixer(
'last 3 versions',
'safari 6',
'ie 9',
'opera 12.1',
'ios 6',
'android 4'
))
.pipe($.cssnano())
.pipe($.sourcemaps.write('/'))
.pipe(gulp.dest('./client/css'));
});
gulp.task('version', function() {
return gulp
.src('./dist/js/templates.js')
.pipe($.injectVersion())
.pipe(gulp.dest('./dist/js/'));
});
// index.html build
// script/css concatenation
gulp.task('usemin', function() {
var baseUrl = args.base_url ? args.base_url : '/';
return gulp
.src('./client/index.html')
// add templates path
.pipe($.htmlReplace({
'templates': '<script type="text/javascript" src="js/templates.js"></script>',
'base_url': '<base href="' + baseUrl + '">'
}))
.pipe($.usemin({
css: [$.cssnano()],
libs: [$.uglify()],
angularlibs: [$.uglify()],
angularconfig: [],
appcomponents: [$.uglify()],
mainapp: [$.uglify()]
}))
.pipe(gulp.dest('./dist/'));
});
// make templateCache from all HTML files
gulp.task('templates', function() {
return gulp
.src(['./client/app/**/*.html'])
.pipe($.htmlmin())
.pipe($.angularTemplatecache({
module: 'app',
root: 'app'
}))
.pipe(gulp.dest('dist/js'));
});
gulp.task('iconfont', function() {
var runTimestamp = Math.round(Date.now()/1000);
return gulp
.src(['./client/assets/icons/*.svg'])
.pipe($.iconfont({
fontName: 'carcassonne-scoreboard-font',
prependUnicode: true,
normalize: true,
formats: ['svg', 'ttf', 'eot', 'woff', 'woff2'],
timestamp: runTimestamp // recommended to get consistent builds when watching files
}))
.on('glyphs', function(glyphs, options) {
// console.log(glyphs, options);
})
.pipe(gulp.dest('./client/fonts/carcassonne-scoreboard-font'));
});
// default task to be run with `gulp` command
// this default task will use Gulp to watch files.
gulp.task('serve', ['fonts', 'browser-sync', 'sass'], function() {
gulp.watch('./client/css/*.css', function(file) {
if (file.type === "changed") {
reload(file.path);
}
});
gulp.watch(['./client/index.html', './client/app/**/*.html'], ['bs-reload']);
gulp.watch('./client/assets/icons/*.svg', ['fonts', 'bs-reload']);
gulp.watch('./client/app/**/*.js', ['bs-reload']);
gulp.watch('./client/sass/**/*.scss', ['sass']);
});
/**
* build task
*/
gulp.task('build', function(callback) {
runSequence(
'clean:build',
'copy',
'sass:build',
'fonts',
'images',
'templates',
'usemin',
'version',
callback);
});
/**
* don't run locally, this will clean all your local files
*/
gulp.task('deploy', function(callback) {
runSequence(
'build',
'clean:src',
callback);
});
/**
* Run test once and exit
*/
gulp.task('test', function (done) {
new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done).start();
});
gulp.task('default', ['serve']);