-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
92 lines (79 loc) · 2.71 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
gulp = require('gulp');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var rename = require('gulp-rename');
var notify = require('gulp-notify'); //when on Windows 7 it falls back to Growl, so this should be installed for best experience.
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var jshint = require('gulp-jshint');
var sass = require('gulp-sass');
var minifyCSS = require('gulp-minify-css');
var autoprefixer = require('gulp-autoprefixer');
var copy = require('gulp-copy');
/********************************************************/
/* Settings and helper functions */
var settings = {
localhost: '',
baseDir: 'www/',
scriptsDir: 'js/',
scriptName: 'fadePager.js',
mainSassFile: 'fadePager.scss',
stylesDir: 'css/'
};
settings = function initializeSettings() {
settings.scriptsDir = settings.baseDir + settings.scriptsDir;
settings.stylesDir = settings.baseDir + settings.stylesDir;
return settings;
}();
function handleError(error) {
console.log('--!!ERROR!!--', error.toString());
gulp.src('').pipe(notify(error));
this.emit('end');
}
/********************************************************/
gulp.task('browser-sync', function() {
console.log('BrowserSync started');
browserSync({
server: {
baseDir: settings.baseDir
}
});
});
gulp.task('views-updated', function() {
console.log('running task: views-updated');
gulp.src(settings.baseDir+'**/*.html')
.pipe(reload({stream:true}))
.pipe(notify('Views updated'));
});
gulp.task('javascript', function() {
console.log('running task: javascript');
gulp.src(settings.scriptsDir+settings.scriptName)
.pipe(jshint())
.pipe(jshint.reporter('default'))
.on('error', handleError)
.pipe(uglify({ mangle: true }))
.pipe(rename('fadePager.min.js'))
.pipe(gulp.dest(settings.scriptsDir))
.pipe(reload({stream:true}))
});
gulp.task('sass', function () {
console.log('STARTING SASSS!!');
gulp.src(settings.stylesDir+settings.mainSassFile)
.pipe(sass())
.on('error', handleError)
.pipe(minifyCSS())
.pipe(rename('fadePager.min.css'))
.pipe(gulp.dest(settings.stylesDir))
.pipe(reload({stream: true}));
});
gulp.task('distribute', function () {
gulp.src([settings.scriptsDir+'fadePager.min.js', settings.stylesDir+'fadePager.min.css'])
.pipe(copy('dist', {
prefix: 2
}));
});
gulp.task('default', ['javascript','sass','distribute', 'browser-sync'], function() {
gulp.watch(settings.baseDir+'**/*.html', ['views-updated']);
gulp.watch(settings.scriptsDir+settings.scriptName, ['javascript', 'distribute']);
gulp.watch(settings.stylesDir+'**/*.scss', ['sass', 'distribute']);
});