-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
92 lines (78 loc) · 2.29 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
const gulp = require( 'gulp' );
const sass = require( 'gulp-sass' )( require( 'sass' ) );
const sourcemaps = require( 'gulp-sourcemaps' );
const cleanCSS = require( 'gulp-clean-css' );
const browserSync = require( 'browser-sync' ).create();
const file_system = require( 'fs' );
const uglify = require( 'gulp-uglify' );
const pump = require( 'pump' );
const wp_pot = require( 'gulp-wp-pot' );
const update_assets_version = function () {
file_system.writeFile( './assets/last_update', ( new Date() ).toISOString().replace( /[^0-9]/g, '' ), function ( error ) {
if ( error ) {
return console.log( error );
}
console.log( "The file was saved!" );
} );
};
gulp.task( 'make_pot', function ( done ) {
gulp.src( './**/*.php' )
.pipe( wp_pot( {
domain : 'wp-plugin-domain',
package : 'WP Plugins Boilerplate',
headers : {
poedit : true,
'x-poedit-keywordslist' : true
},
lastTranslator : 'Nabeel Molham <[email protected]>'
} ) )
.pipe( gulp.dest( './languages/template.pot' ) );
done();
} );
gulp.task( 'styles', function ( done ) {
gulp.src( [ './assets/src/css/**/*.scss', './assets/src/css/**/*.css' ] )
.pipe( sourcemaps.init() )
.pipe( sass().on( 'error', sass.logError ) )
.pipe( cleanCSS( { compatibility : 'ie8' } ) )
.pipe( sourcemaps.write( './maps' ) )
.pipe( gulp.dest( './assets/dist/css/' ) )
.pipe( browserSync.stream() );
update_assets_version();
done();
} );
gulp.task( 'compress_js', function ( done ) {
pump( [
gulp.src( './assets/src/js/**/*.js' ),
uglify( {
mangle : {
eval : true
}
} ),
gulp.dest( './assets/dist/js/' )
], done );
update_assets_version();
} );
const start_watch_assets = function () {
gulp.watch( [
'assets/src/css/**/*.scss',
'assets/src/css/**/*.css',
'style.css'
], gulp.series( 'styles' ) );
gulp.watch( [
'assets/src/js/**/*.js'
], gulp.series( 'compress_js' ) );
gulp.watch( [
'**/*.php'
], gulp.series( 'make_pot' ) );
};
gulp.task( 'watch_assets', gulp.series( 'styles', 'compress_js', 'make_pot', function ( done ) {
start_watch_assets();
done();
} ) );
gulp.task( 'serve', gulp.series( 'styles', 'compress_js', 'make_pot', function ( done ) {
browserSync.init( {
proxy : "localhost"
} );
start_watch_assets();
done();
} ) );