forked from impress-org/givewp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
198 lines (179 loc) · 7.5 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
/**
* Give Gulp File
*
* @description: Used for automating development tasks such as minifying files, compiling SASS and live-reload; using Gulp.js
*/
/* Modules (Can be installed with npm install command using package.json)
------------------------------------- */
var bower = require('gulp-bower'),
bowerMain = require('main-bower-files'),
concat = require('gulp-concat'),
del = require('del'),
filter = require('gulp-filter'),
gulp = require('gulp'),
livereload = require('gulp-livereload'),
cssmin = require('gulp-cssmin'),
notify = require('gulp-notify'),
rename = require('gulp-rename'),
sass = require('gulp-sass'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify'),
sort = require('gulp-sort'),
wpPot = require('gulp-wp-pot'),
watch = require('gulp-watch');
/* Paths
------------------------------------- */
var source_paths = {
admin_styles: ['./assets/scss/**/give-admin.scss'],
frontend_styles: ['./assets/scss/**/give-frontend.scss'],
plugin_styles: ['./assets/scss/plugins/*.scss'],
scripts: ['./assets/js/**/*.js', '!./assets/js/**/*.min.js'],
frontend_scripts: [
'./assets/js/plugins/accounting.min.js',
'./assets/js/plugins/float-labels.min.js',
'./assets/js/plugins/jquery.blockUI.min.js',
'./assets/js/plugins/jquery.magnific-popup.min.js',
'./assets/js/plugins/jquery.payment.min.js',
'./assets/js/plugins/jquery.qtip.min.js',
'./assets/js/frontend/*.min.js' //Frontend scripts need to be loaded last
]
};
/* Admin SCSS Task
------------------------------------- */
gulp.task('admin_styles', function () {
gulp.src(source_paths.admin_styles)
.pipe(sourcemaps.init())
.pipe(sass({
errLogToConsole: true
}))
.pipe(rename('give-admin.css'))
.pipe(sourcemaps.write('../sourcemaps')) //write SCSS source maps to the appropriate plugin dir
.pipe(gulp.dest('./assets/css'))
.pipe(rename('give-admin.min.css'))
.pipe(cssmin())
.pipe(gulp.dest('./assets/css'))
.pipe(livereload())
.pipe(notify({
message: 'Admin styles task complete!',
onLast: true //only notify on completion of task
}));
});
/* Frontend SCSS Task
------------------------------------- */
gulp.task('frontend_styles', function () {
gulp.src(source_paths.frontend_styles)
.pipe(sourcemaps.init()) //start up sourcemapping
.pipe(sass({
errLogToConsole: true
})) //compile SASS; ensure any errors don't stop gulp watch\
.pipe(rename('give.css')) //rename for our main un-minfied file
.pipe(sourcemaps.write('../assets/sourcemaps')) //write SCSS source maps to the appropriate plugin dir
.pipe(gulp.dest('./templates')) //place compiled file in appropriate directory
.pipe(cssmin())
.pipe(rename('give.min.css')) //rename for our minified version
.pipe(gulp.dest('./templates')) //place the minified compiled file
.pipe(livereload()) //reload browser
.pipe(notify({
message: 'Frontend styles task complete!',
onLast: true //notify developer: only notify on completion of task (prevents multiple notifications per file)
}));
});
/* Concatenate & Minify JS
------------------------------------- */
gulp.task('scripts', function () {
return gulp.src(source_paths.scripts)
.pipe(uglify({
preserveComments: 'false'
}))
.pipe(rename({suffix: ".min"}))
.pipe(gulp.dest('assets/js'))
.pipe(notify({
message: 'Scripts task complete!',
onLast: true //only notify on completion of task (prevents multiple notifications per file)
}))
.pipe(livereload());
});
gulp.task('concat_scripts', function (cb) {
del([
'assets/js/frontend/give.all.min.js'
]).then(function () {
return gulp.src(source_paths.frontend_scripts)
.pipe(concat('give.all.min.js')) //Add all compressed frontend JS scripts into one minified file for production
.pipe(gulp.dest('assets/js/frontend'))
.pipe(notify({
message: 'Concat scripts task complete!',
onLast: true //only notify on completion of task (prevents multiple notifications per file)
}))
});
});
/* Watch Files For Changes
------------------------------------- */
gulp.task('watch', function () {
//Start up livereload on this biz
livereload.listen();
//Add watching on Admin SCSS-files
gulp.watch('assets/scss/admin/*.scss', ['admin_styles']);
//Add watching on Frontend SCSS-files
gulp.watch('assets/scss/frontend/*.scss', ['frontend_styles']);
//Add watching on JS files
gulp.watch(source_paths.scripts, ['scripts', 'concat_scripts']);
//Add watching on template-files
gulp.watch('templates/*.php', function () {
livereload(); //and reload when changed
});
});
/* POT file task
------------------------------------- */
gulp.task('pot', function () {
return gulp.src('**/*.php')
.pipe(sort())
.pipe(wpPot({
package: 'Give',
domain: 'give',
destFile: 'give.pot',
bugReport: 'https://github.com/WordImpress/Give/issues/new',
lastTranslator: '',
team: 'WordImpress <[email protected]>'
}))
.pipe(gulp.dest('languages'));
});
/* Default Gulp task
------------------------------------- */
gulp.task('default', function () {
var overrides = {
"chosen": {main: ['chosen.jquery.js']},
"float-labels.js": {main: ['dist/float-labels.js', 'src/scss/float-labels.scss']},
"Flot": {main: ['jquery.flot.js', 'jquery.flot.time.js', 'jquery.flot.resize.js']},
"flot.orderbars": {main: ['js/jquery.flot.orderBars.js']},
"jquery": {ignore: true},
"magnific-popup": {main: ['dist/jquery.magnific-popup.js', 'src/css/*.scss']},
"qtip2": {main: ['jquery.qtip.js', 'jquery.qtip.css'], dependencies: null}
};
// run bower install
bower()
.pipe(gulp.dest('bower'))
.on('end', function () {
// copy bower plugin scripts to assets
gulp.src(bowerMain({overrides: overrides}))
.pipe(filter(['*.js']))
.pipe(gulp.dest('assets/js/plugins/'))
.on('end', function () {
// copy bower plugin (s)css to assets
gulp.src(bowerMain({overrides: overrides}))
.pipe(filter(['*.css', '*.scss']))
.pipe(rename(function (path) {
path.extname = '.scss';
if (path.basename === 'main') {
path.basename = 'magnific-popup';
} else if (path.basename === 'jquery.qtip') {
path.basename = 'qtip';
}
}))
.pipe(gulp.dest('assets/scss/plugins/'))
.on('end', function () {
// ... and now we run all the tasks!
gulp.start('watch', 'admin_styles', 'frontend_styles', 'scripts', 'concat_scripts');
});
});
});
});