-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
99 lines (85 loc) · 2.13 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
var gulp = require( 'gulp' );
// Plugins
var autoprefixer = require( 'gulp-autoprefixer' );
var cleanCSS = require( 'gulp-clean-css' );
var rename = require( 'gulp-rename' );
var uglifyEs = require( 'gulp-uglify-es' ).default;
var watch = require( 'gulp-watch' );
var zip = require( 'gulp-zip' );
// Directories
var dir_assets = 'modules/*/assets/',
dir_js = dir_assets + 'js/',
dir_css = dir_assets + 'css/';
/**
* TASK: styles
*/
var style_source_files = [
dir_css + '*.css',
'!' + dir_css + '*.min.css',
];
function styles() {
return gulp.src( style_source_files )
.pipe(
rename(
function(path) {
path.extname = '.min.css';
}
)
)
.pipe( autoprefixer( {cascade: false} ) )
.pipe( cleanCSS( {compatibility: 'ie8'} ) )
.pipe( gulp.dest( 'modules/' ) );
}
gulp.task( 'styles', styles );
/**
* TASK: scripts
*/
var script_source_files = [
dir_js + '*.js',
'!' + dir_js + '*.min.js',
];
function scripts() {
return gulp.src( script_source_files )
.pipe(
rename(
function(path) {
path.extname = '.min.js';
}
)
)
.pipe( uglifyEs() )
.pipe( gulp.dest( 'modules/' ) );
}
gulp.task( 'scripts', scripts );
/**
* TASK: watch
*
* Keep watching for changes in directories to automate tasks
*/
function watch_changes() {
gulp.watch( style_source_files, gulp.series( 'styles' ) );
gulp.watch( script_source_files, gulp.series( 'scripts' ) );
}
gulp.task( 'watch', watch_changes );
/**
* TASK: default
*
* Run style, script and generate a ZIP to be published
*/
var trunk_files = [
'./**/*',
'!node_modules/**/*',
'!vendor/**/*',
'!tests/**/*',
'!*',
'./index.php',
'./LICENSE.txt',
'./readme.txt',
'./woo-checkout-braspag.php'
];
function build() {
return gulp.src(trunk_files)
.pipe(zip('trunk.zip'))
.pipe(gulp.dest('.'));
}
gulp.task( 'default', gulp.series( gulp.parallel( styles, scripts ), build ) );