-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
executable file
·119 lines (101 loc) · 3.2 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
/*!
* @author: Shaun Janssens
* @copyright: open Summer of code
*/
// Load plugins
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
livereload = require('gulp-livereload'),
connect = require('gulp-connect'),
shell = require('gulp-shell'),
del = require('del');
// Html
gulp.task('html', function(){
gulp.src(['src/html/**/*'])
.pipe(gulp.dest('build'));
});
// Styles
gulp.task('styles', function() {
return sass('src/styles/style.scss', { style: 'expanded' })
.pipe(autoprefixer('last 2 version'))
.pipe(gulp.dest('build/css'))
.pipe(rename({ suffix: '.min' }))
.pipe(minifycss())
.pipe(gulp.dest('build/css'));
});
// Scripts
gulp.task('scripts', function() {
return gulp.src('src/scripts/**/*.js')
//.pipe(jshint())
//.pipe(jshint.reporter('default'))
.pipe(concat('main.js'))
.pipe(gulp.dest('build/js'))
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(gulp.dest('build/js'));
});
// Images
gulp.task('images', function() {
return gulp.src('src/images/**/*')
.pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
.pipe(gulp.dest('build/img'));
});
// jQuery
gulp.task('jquery', function(){
return gulp.src(['bower_components/jquery/dist/jquery.min.js'])
.pipe(gulp.dest('build/js'));
});
// Handlebars
gulp.task('handlebars', function(){
return gulp.src(['bower_components/handlebars/handlebars.runtime.min.js'])
.pipe(gulp.dest('build/js'));
});
// Handlebars template
gulp.task('handlebars-template', function () {
return gulp.src('*.js', {read: false})
.pipe(shell([
'handlebars src/templates/ >> src/scripts/templates.js'
]))
});
// TEMP Api files
gulp.task('api', function(){
return gulp.src(['src/api/**/*'])
.pipe(gulp.dest('build/api'));
});
// Clean
gulp.task('clean', function(cb) {
del(['build/', 'build/css', 'build/js', 'build/img', 'build/api'], cb);
gulp.start('html', 'styles', 'handlebars-template', 'scripts', 'images', 'jquery', 'handlebars', 'api');
});
// Server
gulp.task('server', function(cb) {
connect.server({
root: 'build',
livereload: true
});
});
// Default task
gulp.task('default', ['html', 'styles', 'handlebars-template', 'scripts', 'images', 'jquery', 'handlebars', 'api', 'server', 'watch']);
// Watch
gulp.task('watch', function() {
// Watch .scss files
gulp.watch('src/styles/**/*.scss', ['styles']);
// Watch .js files
gulp.watch('src/scripts/**/*.js', ['scripts']);
// Watch image files
gulp.watch('src/images/**/*', ['images']);
// Watch html files
gulp.watch('src/html/**/*', ['html']);
// Create LiveReload server
livereload.listen();
// Watch any files in build/, reload on change
gulp.watch(['build/**']).on('change', livereload.changed);
});