-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
119 lines (98 loc) · 3.27 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
var gulp = require('gulp'),
configLocal = require('./gulp-config.json'),
merge = require('merge'),
sass = require('gulp-sass'),
cleanCss = require('gulp-clean-css'),
bless = require('gulp-bless'),
bower = require('gulp-bower'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
jshint = require('gulp-jshint'),
jshintStylish = require('jshint-stylish'),
scsslint = require('gulp-scss-lint'),
autoprefixer = require('gulp-autoprefixer'),
browserSync = require('browser-sync').create();
var configDefault = {
scssPath: './src/scss',
cssPath: './static/css',
jsPath: './src/js',
jsMinPath: './static/js',
fontPath: './static/fonts',
componentsPath: './src/components',
sync: false,
syncTarget: 'http://localhost/'
},
config = merge(configDefault, configLocal);
// Run Bower
gulp.task('bower', function() {
bower()
.pipe(gulp.dest(config.componentsPath))
.on('end', function() {
// Add Glyphicons to fonts dir
gulp.src(config.componentsPath + '/bootstrap-sass-official/assets/fonts/*/*')
.pipe(gulp.dest(config.fontPath));
gulp.src(config.componentsPath + '/font-awesome/fonts/*')
.pipe(gulp.dest(config.fontPath + '/font-awesome/'));
gulp.src(config.componentsPath + '/weather-icons/font/*')
.pipe(gulp.dest(config.fontPath + '/weather-icons/'));
});
});
// Lint all scss files
gulp.task('scss-lint', function() {
gulp.src(config.scssPath + '/*.scss')
.pipe(scsslint());
});
// Compile + bless primary scss files
gulp.task('css-main', function() {
gulp.src(config.scssPath + '/style.scss')
.pipe(sass().on('error', sass.logError))
.pipe(cleanCss({compatibility: 'ie8'}))
.pipe(rename('style.min.css'))
.pipe(autoprefixer({
browsers: ['last 2 versions', 'ie >= 8'],
cascade: false
}))
.pipe(bless())
.pipe(gulp.dest(config.cssPath))
.pipe(browserSync.stream());
});
// All css-related tasks
gulp.task('css', ['scss-lint', 'css-main']);
// Run jshint on all js files in jsPath (except already minified files.)
gulp.task('js-lint', function() {
gulp.src([config.jsPath + '/*.js', '!' + config.jsPath + '/*.min.js'])
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
});
// Concat and uglify primary js files.
gulp.task('js-main', function() {
var minified = [
config.componentsPath + '/bootstrap-sass-official/assets/javascripts/bootstrap.js',
config.componentsPath + '/matchHeight/jquery.matchHeight.js',
config.jsPath + '/script.js'
];
gulp.src(minified)
.pipe(concat('script.min.js'))
.pipe(uglify())
.pipe(gulp.dest(config.jsMinPath))
.pipe(browserSync.stream());
});
// All js-related tasks
gulp.task('js', ['js-lint', 'js-main']);
// Rerun tasks when files change
gulp.task('watch', function() {
if (config.sync) {
browserSync.init({
proxy: {
target: config.syncTarget
}
});
}
gulp.watch(config.scssPath + '/*.scss', ['css']);
gulp.watch(config.jsPath + '/*.js', ['js']).on('change', browserSync.reload);
gulp.watch('*.php').on('change', browserSync.reload);
});
// Default task
gulp.task('default', ['bower', 'css', 'js']);