-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
143 lines (130 loc) · 4.16 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
var gulp = require('gulp'),
sass = require('gulp-sass'),
less = require('gulp-less'),
path = require('path'),
streamify = require('gulp-streamify'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
browserify = require('browserify'),
babelify = require('babelify'),
sourcemaps = require('gulp-sourcemaps'),
babel = require('gulp-babel'),
source = require('vinyl-source-stream'),
gutil = require('gulp-util'),
jshint = require('gulp-jshint'),
stylish = require('jshint-stylish'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
clean = require('gulp-clean'),
concat = require('gulp-concat'),
gutil = require('gulp-util'),
notify = require('gulp-notify'),
browserSync = require('browser-sync'),
reload = browserSync.reload,
criticalCss = require('gulp-penthouse');
function swallow_error (error) {
console.log(error.toString());
this.emit('end');
}
gulp.task('critical-css', function () {
return gulp.src('./css/styles.min.css')
.pipe(criticalCss({
out: './styles.css',
url: 'http://botwiki.local/bot/emoji__polls',
width: 1300,
height: 900,
strict: true,
userAgent: 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
}))
.pipe(minifycss())
.on('error', swallow_error)
.pipe(gulp.dest('./css-critical/'));
});
gulp.task('browser-sync', function () {
var files = [
'css/*.css',
'js/*.js'
];
browserSync.init(files, {
proxy: "http://localhost/botwiki-v2/",
open: false
});
});
gulp.task('styles', function() {
return gulp.src('src/styles/styles.scss')
.pipe(sass({
paths: [ path.join(__dirname, 'scss', 'includes') ]
}))
.on('error', swallow_error)
.pipe(autoprefixer('last 3 version', 'android >= 3', { cascade: true }))
.on('error', swallow_error)
.pipe(gulp.dest('css'))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.on('error', swallow_error)
.pipe(gulp.dest('css'))
.pipe(reload({stream:true}));
});
gulp.task('admin-styles', function() {
return gulp.src('src/admin-styles/*.scss')
.pipe(sass({
paths: [ path.join(__dirname, 'scss', 'includes') ]
}))
.on('error', swallow_error)
.pipe(autoprefixer('last 3 version', 'android >= 3', { cascade: true }))
.on('error', swallow_error)
.pipe(gulp.dest('admin-css'))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.on('error', swallow_error)
.pipe(gulp.dest('admin-css'))
.pipe(reload({stream:true}));
});
gulp.task('admin-scripts', function() {
gulp.src('src/admin-scripts/*.js')
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['env']
}))
.on('error', swallow_error)
.pipe(concat('scripts.js'))
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./admin-js'))
});
gulp.task('scripts', function() {
gulp.src('src/scripts/*.js')
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['env']
}))
.on('error', swallow_error)
.pipe(concat('scripts.js'))
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./js'))
});
gulp.task('jslint', function(){
return gulp.src([
'./src/scripts/**/*.js'
]).pipe(jshint('tests/.jshintrc'))
.on('error',gutil.noop)
.pipe(jshint.reporter(stylish))
// .pipe(jshint.reporter('default'))
.on('error', swallow_error);
});
gulp.task('clean', function() {
return gulp.src(['css', 'js', 'admin-css', 'admin-js'], {read: false})
.pipe(clean());
});
gulp.task('watch', function() {
gulp.watch('src/admin-styles/**/*.*', ['admin-styles']);
gulp.watch('src/styles/**/*.*', ['styles','critical-css']);
gulp.watch('src/admin-scripts/**/*.*', ['jslint', 'admin-scripts']);
gulp.watch('src/scripts/**/*.*', ['jslint', 'scripts']);
});
gulp.task('default', ['clean'], function() {
gulp.start('styles', 'critical-css', 'admin-styles', 'jslint', 'admin-scripts', 'scripts', 'browser-sync', 'watch');
});