forked from womenhackfornonprofits/seo-london
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
160 lines (143 loc) · 4.24 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
'use strict';
const gulp = require('gulp');
const sequence = require('run-sequence').use(gulp);
const gulpLoadPlugins = require('gulp-load-plugins');
const $ = gulpLoadPlugins({
rename: {
'gulp-clean-css': 'cssmin'
}
});
const semanticBuild = require('./semantic/tasks/build');
const semanticWatch = require('./semantic/tasks/watch');
/**
* Stop sass and uglify errors from crashing the gulp watch
* @param error
*/
function onError(error) {
console.error(error);
this.emit('end');
}
/**
* Lint our JavaScript for errors using ESLint
*/
gulp.task('js:lint', () => {
// ESLint ignores files with "node_modules" paths.
// So, it's best to have gulp ignore the directory as well.
// Also, Be sure to return the stream from the task;
// Otherwise, the task may end before the stream has finished.
return gulp.src([
'seolondon/js/**/*.js',
'!node_modules/**'
])
// eslint() attaches the lint output to the "eslint" property
// of the file object so it can be used by other modules.
.pipe($.eslint())
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe($.eslint.format())
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failAfterError last.
.pipe($.eslint.failAfterError());
});
/**
* Compile our JavaScript files using Babel and Uglify
*/
gulp.task('js:compile', ['js:lint'], () => {
return gulp.src([
'seolondon/js/main.js',
'seolondon/js/**/*.js',
])
.pipe($.sourcemaps.init())
.pipe($.babel({
presets: ['es2015']
}))
.pipe($.concat('scripts.min.js'))
.pipe($.uglify({
mangle: true,
compress: true,
preserveComments: 'license'
}))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('seolondon/static/dist/temp/'));
});
/**
* Concatenate our compiled JavaScript files with minified vendor files
*/
gulp.task('js:concat', ['js:compile'], () => {
return gulp.src([
'node_modules/jquery/dist/jquery.min.js',
'seolondon/static/dist/semantic.min.js',
'seolondon/vendor/unslider/js/unslider-min.js',
'seolondon/static/dist/temp/scripts.min.js'
])
.pipe($.sourcemaps.init({
loadMaps: true
}))
.pipe($.concat('scripts.min.js'))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('seolondon/static/dist/'))
.pipe($.livereload());
});
gulp.task('js', ['js:lint', 'js:compile', 'js:concat']);
/**
* Compile our SASS styles
*/
gulp.task('css:compile', () => {
return gulp.src([
'seolondon/sass/style.scss'
])
.pipe($.sourcemaps.init())
.pipe($.sass())
.on('error', onError)
.pipe($.autoprefixer('> 0.01%', 'ie 8'))
.pipe($.csslint())
.pipe($.cssmin())
.pipe($.rename({
extname: '.min.css'
}))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('seolondon/static/dist/temp'));
});
/**
* Concatenate our compiled SASS with minified vendor CSS files
*/
gulp.task('css:concat', ['css:compile'], () => {
return gulp.src([
'seolondon/static/dist/semantic.min.css',
'seolondon/static/dist/temp/style.min.css',
'seolondon/vendor/unslider/css/unslider.css',
'seolondon/vendor/unslider/css/unslider-dots.css'
])
.pipe($.sourcemaps.init({
loadMaps: true
}))
.pipe($.concat('styles.min.css'))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('seolondon/static/dist/'))
.pipe($.filter('**/*.css'))
.pipe($.livereload());
});
gulp.task('css', ['css:compile', 'css:concat']);
gulp.task('semantic:build', semanticBuild);
gulp.task('semantic:watch', semanticWatch);
/**
* Watching for changes
*/
gulp.task('watch', () => {
$.livereload.listen();
gulp.watch('seolondon/static/dist/**/*.css', ['css']);
gulp.watch('seolondon/sass/**/*.scss', ['css']);
gulp.watch('seolondon/js/**/*.js', {interval: 500}, ['js']);
gulp.watch('**/*.html', () => {
// gulp.src('seolondon/urls.py')
// .pipe($.touch());
setTimeout(() => $.livereload.reload(), 0); // wait for django to reload
});
sequence('semantic:watch'); // NOTE: run semantic watch without callback
});
gulp.task('build', (done) => {
sequence(['css', 'js'], done);
});
gulp.task('default', (done) => {
sequence('build', ['semantic:watch', 'watch'], done);
});