-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
executable file
·183 lines (149 loc) · 4.49 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
var gulp = require('gulp');
var pkg = require('./package.json');
var banner = ['/*',
'Theme Name: <%= pkg.themeName %>',
'Theme URI: <%= pkg.homepage %>',
'Author: <%= pkg.author %>',
'Author URI: <%= pkg.authorURI %>',
'Description: <%= pkg.description %>',
'Version: <%= pkg.version %>',
'License: <%= pkg.license %>',
'License URI: <%= pkg.licenseURI %>',
'Text Domain: <%= pkg.textDomain %>',
'Tags: education, theme-options',
'',
'@version v<%= pkg.version %>',
'@author Brandon Fuller <[email protected]>',
'@author John Pennypacker <[email protected]>',
'@author Alexandra Gauss <[email protected]>',
'',
'*/',
''].join('\n');
var bannerStatic = ['/*',
'===================================',
'== STATIC HTML VERSION ==',
'===================================',
'*/',
'',
''].join('\n');
// include plug-ins
var eslint = require('gulp-eslint');
var changed = require('gulp-changed');
var imagemin = require('gulp-imagemin');
var rename = require('gulp-rename');
var concat = require('gulp-concat');
var terser = require('gulp-terser');
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
};
// JS concat, strip debugging and minify
gulp.task('scripts', scripts);
function scripts(done) {
gulp.src('./js/**/*.js')
.pipe(eslint(done))
.pipe(eslint.format());
gulp.src('./src/js/**/*.js')
.pipe(eslint(done))
.pipe(eslint.format());
// Process top-level js (front side)
gulp.src('./src/js/*.js')
.pipe(concat('script.min.js'))
.pipe(terser())
.pipe(header(banner, { pkg : pkg } ))
.pipe(gulp.dest('./js/')) // Pipe to main
.pipe(rename('script.static.min.js'))
.pipe(header(bannerStatic))
.pipe(gulp.dest('./static/')); // Pipe to static
// Process block editor js (admin side)
gulp.src('./src/js/block-editor/*.js')
.pipe(concat('block-editor.min.js'))
.pipe(terser())
.pipe(gulp.dest('./js/')); // Pipe to main
done();
// console.log('scripts ran');
}
// CSS concat, auto-prefix and minify
gulp.task('styles', styles);
function styles(done) {
// Theme styles
gulp.src('./src/sass/main.scss')
.pipe(sourcemaps.init())
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(concat('style.css'))
.pipe(postcss([ autoprefixer() ]))
.pipe(header(banner, { pkg : pkg } ))
.pipe(sourcemaps.write('./map'))
.pipe(gulp.dest('.'));
// Static styles
gulp.src('./src/sass/static.scss')
.pipe(sourcemaps.init())
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(concat('style.static.css'))
.pipe(postcss([ autoprefixer() ]))
.pipe(header(banner, { pkg : pkg } ))
.pipe(header(bannerStatic))
.pipe(sourcemaps.write('./map'))
.pipe(gulp.dest('./static'));
// Block editor and admin-side styles
gulp.src('./src/sass/admin.scss')
.pipe(sourcemaps.init())
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(concat('style.admin.css'))
.pipe(postcss([ autoprefixer() ]))
.pipe(sourcemaps.write('./map'))
.pipe(gulp.dest('.'));
done();
//console.log('styles ran');
}
// Copy minified images to static dir
gulp.task('images', images);
function images(done) {
// Pipe to main
gulp.src('./src/images/**/*')
.pipe(changed('./images'))
.pipe(imagemin())
.pipe(gulp.dest('./images'));
// Pipe to static
gulp.src('./src/images/**/*')
.pipe(changed('./static/images'))
.pipe(imagemin())
.pipe(gulp.dest('./static/images'));
done();
//console.log('images ran');
}
// run codesniffer
gulp.task('sniffs', sniffs);
function sniffs(done) {
return gulp.src('.', {read:false})
.pipe(shell(['./.sniff']));
}
// watch
gulp.task('watcher', watcher);
function watcher(done) {
// watch for JS changes
gulp.watch('./src/js/*.js', scripts);
gulp.watch('./src/js/block-editor/*.js', scripts);
// watch for CSS changes
gulp.watch('./src/sass/**/*', styles);
// watch for image changes
gulp.watch('./src/images/**/*', images);
// watch for PHP change
gulp.watch('./**/*.php', sniffs);
done();
}
gulp.task( 'default',
gulp.parallel('images', 'scripts', 'styles', 'sniffs', 'watcher', function(done){
done();
})
);
function done() {
console.log('done');
}