This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
163 lines (145 loc) · 3.99 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
// Require all dev dependencies.
var gulp = require('gulp'),
minify = require('gulp-minify'),
watch = require('gulp-watch'),
cleanCSS = require('gulp-clean-css'),
rename = require('gulp-rename'),
postcss = require('gulp-postcss'),
sass = require('gulp-sass'),
zip = require('gulp-zip'),
autoprefixer = require('autoprefixer'),
browserSync = require('browser-sync').create(),
sourcemaps = require('gulp-sourcemaps'),
imagemin = require('gulp-imagemin');
// me.js contains vars to your specific setup
var me = require('./gulpconf.js');
var WEBSITE = me.WEBSITE;
var CONTENT_TYPE = me.CONTENT_TYPE;
var BASE_NAME = __dirname.match(/([^\/]*)\/*$/)[1];
// JS source, destination, and excludes.
var JS_EXCLD = '!assets/js/*.min.js',
JS_SRC = 'assets/js/*.js',
JS_DEST = 'assets/js/';
// CSS and SASS src, dest, and exclude.
var CSS_SRC = 'assets/css/*.css',
CSS_DEST = 'assets/css/',
CSS_EXCLD = '!assets/css/*.min.css',
SASS_WATCH = 'assets/scss/*.scss';
if( 'plugin' === CONTENT_TYPE){
SASS_SRC = 'assets/scss/*.scss';
}else{
SASS_SRC = ['assets/scss/*.scss', '!assets/scss/style.scss' ];
}
// Image src and dest.
var IMG_SRC = 'assets/images/*',
IMG_DEST = 'assets/images';
// Zip src and options.
var ZIP_SRC_ARR = [
'./**',
'!./composer.*',
'!./gulpfile.js',
'!./package.json',
'!./README.md',
'!./phpcs.xml',
'!./phpunit.xml.dist',
'!./{node_modules,node_modules/**}',
'!./{bin,bin/**}',
'!./{dist,dist/**}',
'!./{vendor,vendor/**}',
'!./{tests,tests/**}'
];
var ZIP_OPTS = { base: '..' };
// PHP Source.
var PHP_SRC = '**/*.php';
/*******************************************************************************
* Gulp Tasks
******************************************************************************/
/**
* Default gulp task. Initializes browserSync proxy server and watches src files
* for any changes.
*
* CMD: gulp
*/
gulp.task('default', function() {
browserSync.init({
proxy: WEBSITE
});
gulp.watch( SASS_SRC, ['build-sass']);
gulp.watch( JS_SRC , ['js-watch']);
gulp.watch( PHP_SRC, function(){
browserSync.reload();
});
});
/**
* JS Watch task. This is a dependency task for the default gulp task that
* builds the js files and reloads the browser in the correct order
*
* CMD: None. Not meant to be run as standalone command.
*/
gulp.task('js-watch', ['build-js'], function(){
browserSync.reload();
});
/**
* Compiles SCSS into regular CSS.
*
* CMD: gulp build-sass
*/
gulp.task('build-sass', function() {
gulp.src( SASS_SRC )
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(postcss([
autoprefixer({browsers: ['> 5% in US']})
]))
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(CSS_DEST));
gulp.src( 'assets/scss/style.scss' )
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(postcss([
autoprefixer({browsers: ['> 5% in US']})
]))
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('.'))
.pipe(browserSync.stream());
});
/**
* Minifies JS files.
*
* CMD: gulp build-js
*/
gulp.task('build-js', function(){
gulp.src( [ JS_SRC, JS_EXCLD ] )
.pipe(minify({
ext:{
src:'.js',
min:'.min.js'
},
noSource: true
}))
.pipe(gulp.dest( JS_DEST ));
});
gulp.task('build-img', function(){
gulp.src('assets/images/*')
.pipe(imagemin())
.pipe(gulp.dest('assets/images'));
});
/**
* Executes all of the build tasks in the correct sequence.
*
* CMD: gulp build
*/
gulp.task('build', ['build-sass','build-js', 'build-img']);
/**
* Creates a zip file of the current project without any of the config and dev
* files and saves it under the 'dist' folder.
*
* CMD: gulp zip
*/
gulp.task('zip', function(){
return gulp.src( ZIP_SRC_ARR, ZIP_OPTS )
.pipe( zip( BASE_NAME + '.zip' ) )
.pipe( gulp.dest('dist') );
});