-
Notifications
You must be signed in to change notification settings - Fork 26
/
gulpfile.js
115 lines (103 loc) · 3.01 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
var gulp = require('gulp'),
sass = require('gulp-sass'),
postcss = require('gulp-postcss'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
foreach = require('gulp-flatmap'),
changed = require('gulp-changed'),
browserSync = require('browser-sync').create(),
wpPot = require('gulp-wp-pot'),
cssnano = require('cssnano'),
autoprefixer = require('autoprefixer'),
comments = require('postcss-discard-comments'),
Fiber = require('fibers');
var plugins = [
autoprefixer,
cssnano,
comments({
removeAllButFirst: true
})
]
sass.compiler = require('sass');
var paths = {
styles: {
src: 'assets/scss/style.scss',
dest: './'
},
scripts: {
src: [
'assets/js/source/app.js',
'node_modules/jquery/dist/jquery.slim.js',
'node_modules/bootstrap/dist/js/bootstrap.js',
'node_modules/popper.js/dist/umd/popper.js'
],
dest: 'assets/js'
},
languages: {
src: '**/*.php',
dest: 'languages/bootstrap-for-genesis.pot'
},
site: {
url: 'http://bootstrap.ddev.site'
}
}
function translation() {
return gulp.src(paths.languages.src)
.pipe(wpPot())
.pipe(gulp.dest(paths.languages.dest))
}
function scriptsLint() {
return gulp.src('assets/js/source/**/*','gulpfile.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
}
function style() {
return gulp.src(paths.styles.src)
.pipe(changed(paths.styles.dest))
.pipe(sass({fiber: Fiber}).on('error', sass.logError))
.pipe(concat('app.scss'))
.pipe(postcss(plugins))
.pipe(rename('style.css'))
.pipe(gulp.dest(paths.styles.dest))
.pipe(browserSync.stream())
.pipe(notify({ message: 'Styles task complete' }))
}
function js() {
return gulp.src(paths.scripts.src)
.pipe(changed(paths.scripts.dest))
.pipe(foreach(function(stream, file){
return stream
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
}))
.pipe(gulp.dest(paths.scripts.dest))
.pipe(browserSync.stream({match: '**/*.js'}))
.pipe(notify({ message: 'Scripts task complete' }));
}
function browserSyncServe(done) {
browserSync.init({
injectChanges: true,
proxy: paths.site.url
})
done();
}
function browserSyncReload(done) {
browserSync.reload();
done();
}
function watch() {
gulp.watch(['assets/scss/*.scss', 'assets/scss/**/*.scss'], style).on('change', browserSync.reload)
gulp.watch(paths.scripts.src, gulp.series(scriptsLint, js))
gulp.watch([
'*.php',
'lib/*',
'**/**/*.php'
],
gulp.series(browserSyncReload)
)
}
gulp.task('translation', translation);
gulp.task('default', gulp.parallel(style, js, browserSyncServe, watch));