-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
117 lines (95 loc) · 2.97 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
// We have to require our dependencies
var gulp = require('gulp');
var ghPages = require('gulp-gh-pages');
var sass = require('gulp-sass');
var del = require('del');
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var util = require('gulp-util');
var runSequence = require('run-sequence');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var bases = {
app: 'app/',
dist: 'dist/',
};
var paths = {
scripts: ['js/**/*.js', '!scripts/libs/**/*.js'],
libs: ['lib/**'],
css: ['css/**/*.scss'],
html: ['index.html', '*.html'],
images: ['images/**/*.png', 'images/**/*.gif'],
elements: ['elements/**/*.html'],
};
// Delete the dist directory
gulp.task('clean', function() {
return del.sync(bases.dist);
});
// Process scripts and concatenate them into one output file
gulp.task('scripts', function() {
return gulp.src(paths.scripts, {cwd: bases.app})
.pipe(jshint())
.pipe(jshint.reporter('default'))
//.pipe(uglify())
.pipe(concat('app.min.js'))
.pipe(gulp.dest(bases.dist + 'js/'));
});
// Imagemin images and ouput them in dist
gulp.task('imagemin', function() {
return gulp.src(paths.images, {cwd: bases.app})
.pipe(imagemin())
.pipe(gulp.dest(bases.dist + 'images/'));
});
// compile Sass into CSS using gulp-sass
gulp.task('css', function() {
return gulp.src(['./app/**/*.scss'])
.pipe(sass({style: 'expanded'}))
.pipe(gulp.dest('./dist/'));
});
// Copy all other files to dist directly
gulp.task('copy', function() {
// Copy html
gulp.src(paths.html, {cwd: bases.app})
.pipe(gulp.dest(bases.dist));
// Copy lib scripts, maintaining the original directory structure
gulp.src(paths.libs, {cwd: 'app/**'})
.pipe(gulp.dest(bases.dist));
// Copy lib scripts, maintaining the original directory structure
return gulp.src(paths.elements, {cwd: 'app/**'})
.pipe(gulp.dest(bases.dist));
});
// gh pages deploy task
gulp.task('deploy-gh-pages', function() {
return gulp.src('./dist/**/*')
.pipe(ghPages({push: true, message: "update"}));
});
// somehow this task doesn't work right
/*gulp.task('deploy', function(cb) {
runSequence('build',
'deploy-gh-pages',
cb);
}); */
// A development task to run anytime a file changes
gulp.task('watch', function() {
gulp.watch('app/**/*', ['scripts', 'css', 'copy']);
});
// Build task
gulp.task('build', function(cb) {
runSequence('clean',
['scripts', 'css', 'imagemin', 'copy'],
cb);
});
gulp.task('serve', ['build'], function() {
browserSync.init({
server: {
baseDir: bases.dist
}
});
gulp.watch(['app/**/*.html'], ['copy', reload]);
gulp.watch(['app/css/**/*.css', 'app/css/**/*.scss'], ['css', reload]);
gulp.watch(['app/images/**/*'], ['imagemin', reload]);
gulp.watch(['app/js/**/*.js'], ['scripts', reload]);
});
gulp.task('default', ['build']);