-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·124 lines (90 loc) · 2.48 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
var gulp = require('gulp');
var pkg = require('./package.json');
// include plug-ins
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');
var concat = require('gulp-concat');
//var stripDebug = require('gulp-strip-debug');
var terser = require('gulp-terser');
var replace = require('gulp-replace-task');
var sass = require('gulp-sass')(require('sass'));
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('autoprefixer');
var postcss = require('gulp-postcss');
var header = require('gulp-header');
var shell = require('gulp-shell');
// options
var sassOptions = {
errLogToConsole: true,
outputStyle: 'compressed' //expanded, nested, compact, compressed
};
// CSS concat, auto-prefix and minify
gulp.task('styles', styles);
function styles(done) {
gulp.src('./src/sass/main.scss')
.pipe(sourcemaps.init())
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(concat('style.built.css'))
.pipe(postcss([ autoprefixer() ]))
.pipe(sourcemaps.write('./map'))
.pipe(gulp.dest('./css/'));
done();
//console.log('styles ran');
}
// JS concat, strip debugging and minify
gulp.task('scripts', scripts);
function scripts(done) {
// Run JSHint for src js
gulp.src('./src/js/*.js')
.pipe(jshint(done))
.pipe(jshint.reporter('default'));
// Run jscs for src js
gulp.src('./src/js/*.js')
.pipe(jscs(done))
.pipe(jscs.reporter());
// Compile src js
gulp.src('./src/js/*.js')
.pipe(concat('script.built.js'))
//.pipe(stripDebug())
.pipe(terser())
.pipe(gulp.dest('./js/'));
done();
// console.log('scripts ran');
}
// run codesniffer
gulp.task('sniffs', sniffs);
function sniffs(done) {
return gulp.src('.', {read:false})
.pipe(shell(['./.sniff']));
}
// Update plugin version
gulp.task('version', version);
function version(done) {
gulp.src('./uri-code-compliance.php')
.pipe(replace({
patterns: [{
match: /Version:\s([^\n\r]*)/,
replace: 'Version: ' + pkg.version
}]
}))
.pipe(gulp.dest('./'));
}
// watch
gulp.task('watcher', watcher);
function watcher(done) {
// watch for CSS changes
gulp.watch('./src/sass/**/*', styles);
// watch for JS changes
gulp.watch('./src/js/*.js', scripts);
// watch for PHP change
gulp.watch('./**/*.php', sniffs);
done();
}
gulp.task( 'default',
gulp.parallel('styles', 'scripts', 'sniffs', 'version', 'watcher', function(done){
done();
})
);
function done() {
console.log('done');
}