1
|
|
|
'use strict'; |
2
|
|
|
|
3
|
|
|
// Useful vars for configuring in your environment |
4
|
|
|
/*-------------------------------------------------------------------------------------------------*/ |
5
|
|
|
|
6
|
|
|
// var parentThemeRoot = "../../../vendor/erdiko/wordpress/themes/clean-blog/"; // for themes updated with composer |
7
|
|
|
var renderedThemeRoot = "../../public/"; |
8
|
|
|
|
9
|
|
|
var themeName = "bootstrap"; |
10
|
|
|
var renderedTheme = renderedThemeRoot+'themes/'+themeName; |
11
|
|
|
|
12
|
|
|
var jQueryJs = "node_modules/jquery/dist/jquery.slim.js"; |
13
|
|
|
|
14
|
|
|
var tetherJs = "node_modules/tether/dist/js/tether.js"; |
15
|
|
|
|
16
|
|
|
var popperJs = "node_modules/popper.js/dist/umd/popper.min.js"; |
17
|
|
|
|
18
|
|
|
var bootstrapJs = "node_modules/bootstrap/dist/js/bootstrap.js"; |
19
|
|
|
|
20
|
|
|
// var cleanBlogJs = parentThemeRoot+"scripts/clean-blog.js"; |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
// Boilerplate & Setup |
24
|
|
|
/*-------------------------------------------------------------------------------------------------*/ |
25
|
|
|
|
26
|
|
|
var gulp = require('gulp'); |
27
|
|
|
|
28
|
|
|
// load plugins from package.json file |
29
|
|
|
var $ = require('gulp-load-plugins')(); |
30
|
|
|
$.del = require('del'); |
31
|
|
|
$.runSequence = require('run-sequence'); |
32
|
|
|
|
33
|
|
|
// Make 'build' the default task |
34
|
|
|
gulp.task('default', function() { |
35
|
|
|
gulp.start('build'); |
36
|
|
|
}); |
37
|
|
|
|
38
|
|
|
// Notify when build is complete |
39
|
|
|
gulp.task('notify:buildComplete', function(callback) { |
40
|
|
|
$.notify().write("Build Complete"); |
41
|
|
|
callback(); |
42
|
|
|
}); |
43
|
|
|
|
44
|
|
|
// Empty 'stage' directory so we can start fresh |
45
|
|
|
gulp.task('clean:stage', function(callback) { |
46
|
|
|
$.del([ |
47
|
|
|
'stage/**/*', |
48
|
|
|
], callback); |
49
|
|
|
}); |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
// Main Tasks |
53
|
|
|
/*-------------------------------------------------------------------------------------------------*/ |
54
|
|
|
|
55
|
|
|
// build - The main task that runs all subtasks |
56
|
|
|
gulp.task('build', function(callback) { |
57
|
|
|
$.runSequence( |
58
|
|
|
'clean:stage', |
59
|
|
|
['styles', |
60
|
|
|
'tether-scripts', |
61
|
|
|
'popper-scripts', |
62
|
|
|
'bootstrap-scripts', 'jquery-scripts', 'scripts'], |
63
|
|
|
['minify-css', 'minify-js'], |
64
|
|
|
'notify:buildComplete', |
65
|
|
|
callback |
66
|
|
|
); |
67
|
|
|
}); |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
// Subtasks |
71
|
|
|
/*-------------------------------------------------------------------------------------------------*/ |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
// Compile SASS |
75
|
|
|
gulp.task('styles', function(callback) { |
76
|
|
|
return gulp.src('styles/**/*.scss') |
77
|
|
|
.pipe($.order([ |
78
|
|
|
"styles.css", |
79
|
|
|
"**/*.scss" |
80
|
|
|
])) |
81
|
|
|
// Load existing internal sourcemap |
82
|
|
|
.pipe($.sourcemaps.init()) |
83
|
|
|
// generate CSS from SASS |
84
|
|
|
.pipe($.sass()) |
85
|
|
|
// Catch any errors and prevent them from crashing gulp |
86
|
|
|
.on('error', function (error) { |
87
|
|
|
$.notify().write(error); |
88
|
|
|
this.emit('end'); |
89
|
|
|
}) |
90
|
|
|
// autoprefix CSS using bootstrap standards |
91
|
|
|
.pipe($.autoprefixer({ |
92
|
|
|
browsers: [ |
93
|
|
|
"Android 2.3", |
94
|
|
|
"Android >= 4", |
95
|
|
|
"Chrome >= 20", |
96
|
|
|
"Firefox >= 24", |
97
|
|
|
"Explorer >= 8", |
98
|
|
|
"iOS >= 6", |
99
|
|
|
"Opera >= 12", |
100
|
|
|
"Safari >= 6" |
101
|
|
|
], |
102
|
|
|
remove: false |
103
|
|
|
})) |
104
|
|
|
// Write final .map file |
105
|
|
|
.pipe($.sourcemaps.write()) |
106
|
|
|
// move files to stage |
107
|
|
|
.pipe(gulp.dest('stage/styles'), callback); |
108
|
|
|
}); |
109
|
|
|
|
110
|
|
|
// Javascript |
111
|
|
|
gulp.task('scripts', function(callback) { |
112
|
|
|
return gulp.src('scripts/**/*.js') |
113
|
|
|
// copy scripts to stage |
114
|
|
|
.pipe(gulp.dest('stage/scripts'), callback); |
115
|
|
|
}); |
116
|
|
|
|
117
|
|
|
// Tether Javascript |
118
|
|
|
gulp.task('tether-scripts', function(callback) { |
119
|
|
|
return gulp.src(tetherJs) |
120
|
|
|
// copy scripts to stage |
121
|
|
|
.pipe(gulp.dest('stage/scripts/vendor'), callback); |
122
|
|
|
}); |
123
|
|
|
|
124
|
|
|
// Popper Javascript |
125
|
|
|
gulp.task('popper-scripts', function(callback) { |
126
|
|
|
return gulp.src(popperJs) |
127
|
|
|
// copy scripts to stage |
128
|
|
|
.pipe(gulp.dest('stage/scripts/vendor'), callback); |
129
|
|
|
}); |
130
|
|
|
|
131
|
|
|
// Bootstrap Javascript |
132
|
|
|
gulp.task('bootstrap-scripts', function(callback) { |
133
|
|
|
return gulp.src(bootstrapJs) |
134
|
|
|
// copy scripts to stage |
135
|
|
|
.pipe(gulp.dest('stage/scripts/vendor'), callback); |
136
|
|
|
}); |
137
|
|
|
|
138
|
|
|
// jQuery Javascript |
139
|
|
|
gulp.task('jquery-scripts', function(callback) { |
140
|
|
|
return gulp.src(jQueryJs) |
141
|
|
|
// copy scripts to stage |
142
|
|
|
.pipe(gulp.dest('stage/scripts/vendor'), callback); |
143
|
|
|
}); |
144
|
|
|
|
145
|
|
|
// Minify CSS and put it in the public dir |
146
|
|
|
gulp.task('minify-css', function() { |
147
|
|
|
return gulp.src('stage/styles/**/*.css') |
148
|
|
|
.pipe($.cleanCss({ |
149
|
|
|
processImport: false |
150
|
|
|
})) |
151
|
|
|
.pipe($.rename({ |
152
|
|
|
basename: 'main', |
153
|
|
|
suffix: '.min', |
154
|
|
|
extname: '.css' |
155
|
|
|
})) |
156
|
|
|
.pipe(gulp.dest(renderedTheme+'/css')); |
157
|
|
|
}); |
158
|
|
|
|
159
|
|
|
// minify JS and put in the public dir |
160
|
|
|
gulp.task('minify-js', function () { |
161
|
|
|
|
162
|
|
|
return gulp.src(['stage/scripts/**/*.js']) |
163
|
|
|
.pipe($.order([ |
164
|
|
|
"vendor/jquery.slim.js", |
165
|
|
|
"vendor/tether.js", |
166
|
|
|
"vendor/popper.min.js", |
167
|
|
|
"vendor/bootstrap.js", |
168
|
|
|
"vendor/*.js", |
169
|
|
|
"**/*.js" |
170
|
|
|
])) |
171
|
|
|
.pipe($.concat('scripts.min.js')) |
172
|
|
|
.pipe($.uglify()) |
173
|
|
|
.pipe(gulp.dest(renderedTheme+'/js')); |
174
|
|
|
}); |
175
|
|
|
|