-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
185 lines (173 loc) · 4.09 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
/**
* Load plugins.
*/
import gulp from 'gulp';
import cached from 'gulp-cached';
import debug from 'gulp-debug';
import imagemin from 'gulp-imagemin';
import packageJSON from './package.json' assert { type: 'json' };
import process from 'child_process';
import rename from 'gulp-rename';
import gulpSass from 'gulp-sass';
import sourcemaps from 'gulp-sourcemaps';
import uglify from 'gulp-uglify';
import zip from 'gulp-zip';
import sassCompiler from 'sass';
import composer from 'gulp-composer';
const exec = process.exec;
const sass = gulpSass( sassCompiler );
const plugin = {
name: 'File Upload Types',
slug: 'file-upload-types',
files: [
'**',
// Exclude all the files/dirs below. Note the double negate (when ! is used inside the exclusion) - we may actually need some things.
'!**/*.map',
'!LICENSE',
'!assets/**/*.scss',
'!assets/wporg/**',
'!assets/wporg',
'!**/.github/**',
'!**/.github',
'!**/bin/**',
'!**/bin',
'!**/tests/**',
'!**/tests',
'!**/Tests/**',
'!**/Tests',
'!**/test/**',
'!**/test',
'!**/Test/**',
'!**/Test',
'!**/build/**',
'!**/build',
'!**/example/**',
'!**/example',
'!**/examples/**',
'!**/examples',
'!**/doc/**',
'!**/doc',
'!**/docs/**',
'!**/docs',
'!**/node_modules/**',
'!**/node_modules',
'!**/*.md',
'!**/*.sh',
'!**/*.rst',
'!**/*.xml',
'loco.xml',
'!**/*.yml',
'!**/*.dist',
'!**/*.json',
'assets/file-types-list.json',
'assets/file-types-list-v2.json',
'!**/*.lock',
'!**/gulpfile.js',
'!**/Makefile',
'!**/AUTHORS',
'!vendor/composer/installers/**'
],
php: [
'**/*.php',
'!vendor/**',
'!tests/**'
],
scss: [
'assets/css/**/*.scss',
],
js: [
'assets/js/*.js',
'!assets/js/*.min.js'
],
images: [
'assets/images/**/*',
]
};
/**
* Compile SCSS to CSS, compress.
*/
gulp.task( 'css', function() {
return gulp.src( plugin.scss )
// UnMinified file.
.pipe( cached( 'processCSS' ) )
.pipe( sourcemaps.init() )
// Minified file.
.pipe( sass( { outputStyle: 'compressed' } ).on( 'error', sass.logError ) )
.pipe( rename( function( path ) {
path.dirname = '/assets/css';
path.extname = '.css';
} ) )
.pipe( sourcemaps.write( '.' ) )
.pipe( gulp.dest( '.' ) )
.pipe( debug( { title: '[css]' } ) );
} );
/**
* Compress js.
*/
gulp.task( 'js', function() {
return gulp.src( plugin.js )
.pipe( cached( 'processJS' ) )
.pipe( uglify() ).on( 'error', console.log )
.pipe( rename( function( path ) {
path.dirname = '/assets/js';
path.basename += '.min';
} ) )
.pipe( gulp.dest( '.' ) )
.pipe( debug( { title: '[js]' } ) );
} );
/**
* Optimize image files.
*/
gulp.task( 'img', function() {
return gulp.src( plugin.images )
.pipe( imagemin() )
.pipe( gulp.dest( function( file ) {
return file.base;
} ) )
.pipe( debug( { title: '[img]' } ) );
} );
/**
* Generate .pot files.
*/
gulp.task( 'pot', function( cb ) {
exec( 'wp i18n make-pot ./ ./languages/file-upload-types.pot --slug="' + plugin.slug + '" --domain="' + plugin.slug + '" --package-name="' + plugin.name + '" --file-comment=""', function( err, stdout, stderr ) {
console.log( stdout );
console.log( stderr );
cb( err );
} );
} );
/**
* Generate a .zip file.
*/
gulp.task( 'zip', function() {
const files = plugin.files;
// Modifying 'base' to include plugin directory in a zip.
return gulp.src( files, { base: '.' } )
.pipe( rename( function( file ) {
file.dirname = plugin.slug + '/' + file.dirname;
} ) )
.pipe( zip( plugin.slug + '-' + packageJSON.version + '.zip' ) )
.pipe( gulp.dest( './build' ) )
.pipe( debug( { title: '[zip]' } ) );
} );
/**
* Run composer with no dev dependencies.
*/
gulp.task( 'composer', function () {
return composer( { 'no-dev': true } );
} );
/**
* Task: build.
*/
gulp.task( 'build', gulp.series( gulp.parallel( 'css', 'js', 'img', 'pot', 'composer' ), 'zip' ) );
/**
* Look out for relevant sass/js changes.
*/
gulp.task( 'watch', function() {
gulp.watch( plugin.scss, gulp.parallel( 'css' ) );
gulp.watch( plugin.js, gulp.parallel( 'js' ) );
} );
/**
* Default.
*/
gulp.task( 'default', gulp.parallel( 'css', 'js', 'pot' ) );