-
Notifications
You must be signed in to change notification settings - Fork 16
/
gulpfile.js
198 lines (177 loc) · 4.63 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/**
* Load required gulp packages.
*/
const colors = require( 'ansi-colors' ),
log = require( 'fancy-log' ),
gulp = require( 'gulp' ),
debug = require( 'gulp-debug' ),
rename = require( 'gulp-rename' ),
sass = require( 'gulp-sass' ),
sassInheritance = require( 'gulp-sass-inheritance' ),
sourcemaps = require( 'gulp-sourcemaps' ),
uglify = require( 'gulp-uglify' ),
wpPot = require( 'gulp-wp-pot' ),
zip = require( 'gulp-zip' );
var plugin = {
name: 'Shared Counts',
slug: 'shared-counts',
files: [
'**',
// Exclude all the files/dirs below. Note the double negate (when ! is used inside the exclusion) - we may actually need some things.
'!**/*.map',
'!assets/scss/**',
'!assets/scss',
'!**/.github/**',
'!**/.github',
'!**/bin/**',
'!**/bin',
'!**/tests/**',
'!**/tests',
'!**/Test/**',
'!**/Test',
'!**/Tests/**',
'!**/Tests',
'!**/build/**',
'!**/build',
'!**/examples/**',
'!**/examples',
'!**/doc/**',
'!**/doc',
'!**/docs/**',
'!**/docs',
'!**/node_modules/**',
'!**/node_modules',
'!**/*.md',
'!**/*.rst',
'!**/*.xml',
'!**/*.dist',
'!**/*.json',
'!**/*.lock',
'!**/gulpfile.js',
'!LICENSE', // but include licenses in the packages
'!**/Makefile',
'!**/AUTHORS'
],
php: [
'**/*.php'
],
scss: [
'assets/scss/**/*.scss'
],
js: [
'assets/js/*.js',
'!assets/js/*.min.js'
]
};
gulp.task( 'scss', function(){
return processScss();
} );
gulp.task( 'js', function () {
return processJs();
} );
gulp.task( 'zip', function () {
return processZip();
} );
gulp.task( 'pot', function () {
return processPot();
} );
gulp.task( 'watch', function () {
gulp.watch( plugin.scss ).on( 'change', function ( path, stats ) {
processScss( path );
} );
gulp.watch( plugin.js ).on( 'change', function ( path, stats ) {
processJs( path );
} );
} );
gulp.task( 'build', gulp.series( 'scss', 'js', 'pot', 'zip' ) );
gulp.task( 'default', gulp.series( 'scss', 'js' ) );
/**
* Compiles SCSS into CSS files and includes source maps.
* Additionally creates minified versions.
*
* Only runs on updated files or its dependants.
*/
function processScss( path ) {
log();
log(
colors.gray( '====== ' ) +
colors.white( colors.bold( 'Processing .scss files' ) ) +
colors.gray( ' ======' )
);
let files = path || plugin.scss;
return gulp.src( files, { base: './' } )
// UnMinified file.
// Find files that depend on the files that have changed.
.pipe( sassInheritance( { dir: './assets/scss/' } ) )
.pipe( sourcemaps.init() )
.pipe( sass( { outputStyle: 'expanded' } )
.on( 'error', sass.logError ) )
.pipe( rename( function ( path ) {
path.dirname += '/../css';
path.extname = '.css';
} ) )
.pipe( sourcemaps.write() )
.pipe( gulp.dest( './' ) )
.pipe( debug( { title: '[sass] Compiled' } ) )
// Minified file.
.pipe( sass( { outputStyle: 'compressed' } )
.on( 'error', sass.logError ) )
.pipe( rename( function ( path ) {
path.dirname += '/../css';
path.extname = '.min.css';
} ) )
.pipe( gulp.dest( './' ) )
.pipe( debug( { title: '[sass] Minified' } ) );
}
/**
* Minifies the JS.
*
* Only runs on updated files.
*/
function processJs( path ) {
log();
log(
colors.gray( '====== ' ) +
colors.white( colors.bold( 'Processing .js files' ) ) +
colors.gray( ' ======' )
);
let files = path || plugin.js;
return gulp.src( files, { base: './' } )
.pipe( uglify() )
.on( 'error', log.error )
.pipe( rename( function ( path ) {
path.basename += '.min';
} ) )
.pipe( gulp.dest( './' ) )
.pipe( debug( { title: '[js] Minified' } ) );
}
function processPot( path ) {
log();
log(
colors.gray( '====== ' ) +
colors.white( colors.bold( 'Processing .pot file' ) ) +
colors.gray( ' ======' )
);
let files = path || plugin.php;
return gulp.src( files )
.pipe( wpPot( {
domain: plugin.slug,
package: plugin.name,
team: 'Shared Counts Team <[email protected]>'
} ) )
.pipe( gulp.dest( 'languages/' + plugin.slug + '.pot' ) )
.pipe( debug( { title: '[pot] Generated' } ) );
}
function processZip( path ) {
log();
log(
colors.gray( '====== ' ) +
colors.white( colors.bold( 'Generating .zip file' ) ) +
colors.gray( ' ======' )
);
let files = path || plugin.files;
return gulp.src( files, { base: '../' } )
.pipe( zip( plugin.slug + '.zip' ) )
.pipe( gulp.dest( './build' ) )
.pipe( debug( {title: '[zip] Generated' } ) );
}