-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
105 lines (94 loc) · 3.68 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
var gulp = require('gulp'),
jshint = require('gulp-jshint'),
sourcemaps = require('gulp-sourcemaps'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
gutil = require('gulp-util'),
coffee = require('gulp-coffee'),
sass = require('gulp-sass'),
nodemon = require('gulp-nodemon'),
plumber = require('gulp-plumber'),
path = require('path');
gulp.task('default', ['package-js', 'sass', 'watch', 'nodemon']);
gulp.task('test', ['sass', 'jshint', 'package-js']);
gulp.task('prod', ['sass', 'jshint', 'package-js']);
var bowerComponentPath = 'static/assets/bower/bower_components/';
var bowerComponents = [
path.join(bowerComponentPath, 'jquery/dist/jquery.min.js'),
path.join(bowerComponentPath, 'foundation-sites/dist/foundation.min.js'),
path.join(bowerComponentPath, 'foundation-sites/dist/plugins/foundation.reveal.js'),
path.join(bowerComponentPath, 'foundation-sites/dist/plugins/foundation.dropdownMenu.js'),
path.join(bowerComponentPath, 'foundation-sites/dist/plugins/foundation.util.box.js'),
path.join(bowerComponentPath, 'foundation-sites/dist/plugins/foundation.util.keyboard.js'),
path.join(bowerComponentPath, 'foundation-sites/dist/plugins/foundation.util.motion.js'),
path.join(bowerComponentPath, 'foundation-sites/dist/plugins/foundation.util.nest.js'),
path.join(bowerComponentPath, 'd3/d3.min.js'),
path.join(bowerComponentPath, 'topojson/topojson.min.js'),
path.join(bowerComponentPath, 'jquery-throttle-debounce/jquery.ba-throttle-debounce.min.js'),
path.join(bowerComponentPath, 'jquery-form-validator/form-validator/jquery.form-validator.min.js'),
path.join(bowerComponentPath, 'jquery-form-validator/form-validator/file.js'),
path.join(bowerComponentPath, 'jquery-ui/jquery-ui.min.js'),
path.join(bowerComponentPath, 'slick-carousel/slick/slick.min.js'),
path.join(bowerComponentPath, 'underscore/underscore-min.js')
];
// Handle Errors
function handleError(err) {
gutil.log(err);
this.emit('end');
if(gutil.env.production) {
process.exit(1);
}
}
var plumberOptions = {
errorHandler: handleError
}
// SaSS Builder
gulp.task('sass', function () {
gulp.src('static/assets/scss/sdhacks.scss')
.pipe(plumber(plumberOptions))
.pipe(sass({outputStyle: 'compressed'}))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('static/assets/css'));
});
// JS Linter
gulp.task('jshint', function() {
gulp.src(['static/app/**/*.js', 'static/assets/js/*.js'])
.pipe(plumber(plumberOptions))
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
// JS Builder
gulp.task('build-js', function() {
gulp.src(['static/assets/js/*.js', 'static/assets/js/vendor/*.js'])
.pipe(plumber(plumberOptions))
.pipe(gutil.env.production ? gutil.noop() : sourcemaps.init())
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(concat('app.js'))
.pipe(gutil.env.production ? gutil.noop() : sourcemaps.write())
.pipe(gulp.dest('static/assets/js/dist'));
});
gulp.task('package-js', function() {
gulp.start(['build-js', 'package-bower']);
});
gulp.task('package-bower', function() {
gulp.src(bowerComponents, {base: bowerComponentPath})
.pipe(plumber(plumberOptions))
.pipe(concat('vendor.js'))
.pipe(gulp.dest('static/assets/js/dist'));
});
// Watcher
gulp.task('watch', function() {
gulp.watch('static/assets/scss/**/*.scss', ['sass']);
gulp.watch('static/assets/js/*.js', ['jshint']);
gulp.watch(['static/assets/js/*.js', 'static/assets/js/vendor/*.js'], ['package-js']);
});
// Nodemon
gulp.task('nodemon', function() {
nodemon({
script: 'server.js',
ext: 'js coffee',
env: { 'NODE_ENV': 'development' }
});
});