-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
234 lines (208 loc) · 5.71 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
// Require
var gulp = require( 'gulp' );
var plumber = require( 'gulp-plumber' );
var notify = require( 'gulp-notify' );
var changed = require( 'gulp-changed' );
var livereload = require( 'gulp-livereload' );
var gutil = require( 'gulp-util' );
var rename = require( 'gulp-rename' );
var sass = require( 'gulp-sass' );
var sourcemaps = require( 'gulp-sourcemaps' );
var autoprefixer = require( 'gulp-autoprefixer' );
var sassLint = require( 'gulp-sass-lint' );
var coffee = require( 'gulp-coffee' );
var coffeelint = require( 'gulp-coffeelint' );
var concat = require( 'gulp-concat' );
var cssnano = require( 'gulp-cssnano' );
var uglify = require( 'gulp-uglify' );
var del = require( 'del' );
var runSequence = require( 'run-sequence' );
// Variables
var app = 'app/';
var src = app + 'src/';
var appAssets = app + 'assets/';
var dist = 'dist/';
var distAssets = dist + 'assets/';
// Options
var coffeeOptions = {
bare: true,
};
var coffeeLintOptions = {
optFile: 'coffeelint.json',
};
var uglifyOptions = {
compress: {
drop_console: true,
},
};
var renameOptions = {
suffix: '.min',
};
var onError = function(error) {
notify.onError({
title: "<%= error.plugin %> error",
message: "Error: <%= error.message %>",
sound: "Sosumi"
}) (error);
this.emit('end');
};
// TASKS
// Clean
gulp.task('clean:app', function() {
return del([
appAssets + 'css/**/*.css',
appAssets + 'js/**/*.js',
]);
});
gulp.task('clean:dist', function() {
return del([
distAssets,
dist + 'controllers',
dist + 'views',
]);
});
// PHP
gulp.task('phpWatch', function() {
return gulp
.src( app + '**/*.php' )
.pipe( livereload() )
});
// Move css vendor files to the assets
gulp.task( 'cssVendor', function() {
return gulp
.src( src + 'css/**/*.css' )
.pipe( gulp.dest( appAssets + 'css/vendor' ) )
});
// Move js vendor files to the assets
gulp.task( 'jsVendor', function() {
return gulp
.src( src + 'js/**/*.js' )
.pipe( gulp.dest( appAssets + 'js/vendor' ) )
});
// Move php files to dist
gulp.task( 'php', function() {
return gulp
.src( [ app + '**/*.php', '!' + app + 'config.php' ] )
.pipe( gulp.dest( dist ) )
});
// Move font files to dist/assets
gulp.task( 'fonts', function() {
return gulp
.src( appAssets + 'fonts/**' )
.pipe( gulp.dest( distAssets + 'fonts' ) )
});
// Move images to dist/assets
gulp.task( 'images', function() {
return gulp
.src( appAssets + 'images/**' )
.pipe( gulp.dest( distAssets + 'images' ) )
});
// Move videos to dist/assets
gulp.task( 'videos', function() {
return gulp
.src( appAssets + 'videos/**' )
.pipe( gulp.dest( distAssets + 'videos' ) )
});
// Move svgs to dist/assets
gulp.task( 'svgs', function() {
return gulp
.src( appAssets + 'svgs/**' )
.pipe( gulp.dest( distAssets + 'svgs' ) )
});
// SASS
gulp.task( 'sass', function() {
return gulp
.src( src + 'sass/*.sass' )
.pipe( plumber( { errorHandler: onError } ) )
.pipe( changed( src + 'css', { extension: '.css' } ) )
.pipe( sourcemaps.init() )
.pipe( sass({
errLogToConsole: true,
outputStyle: 'expanded',
}))
.pipe( sourcemaps.write() )
.pipe( sassLint() )
.pipe( sassLint.format() )
.pipe( sassLint.failOnError() )
.pipe( autoprefixer() )
.pipe( gulp.dest( appAssets + 'css/build' ) )
.pipe( livereload() )
});
// CSS Concat
gulp.task( 'cssconcat', function() {
return gulp
.src( [appAssets + 'css/vendor/*.css', '!' + appAssets + 'css/build/lte-ie9.css', appAssets + 'css/build/*.css'] )
.pipe( concat( 'application.css' ) )
.pipe( gulp.dest( appAssets + 'css' ) )
});
gulp.task( 'lte-ie9-css', function() {
return gulp
.src( appAssets + 'css/build/lte-ie9.css' )
.pipe( gulp.dest( appAssets + 'css' ) )
});
// CSS Minification
gulp.task( 'cssnano', function() {
return gulp
.src( appAssets + 'css/*.css' )
.pipe( cssnano({
safe: true
}) )
.pipe( rename( renameOptions ) )
.pipe( gulp.dest( distAssets + 'stylesheets' ) )
});
// CoffeeScript
gulp.task( 'coffee', function() {
gulp
.src( src + 'coffee/**/*.coffee' )
.pipe( plumber( { errorHandler: onError } ) )
.pipe( changed( src + 'js', { extension: '.js' } ) )
.pipe( coffeelint( coffeeLintOptions ) )
.pipe( coffeelint.reporter() )
.pipe( sourcemaps.init() )
.pipe( coffee( coffeeOptions ).on( 'error', gutil.log ) )
.pipe( sourcemaps.write() )
.pipe( gulp.dest( appAssets + 'js/build' ) )
.pipe( livereload() )
});
// JS Concat
gulp.task( 'jsconcat', function() {
return gulp
.src( [ appAssets + 'js/vendor/*.js', '!' + appAssets + 'js/build/lte-ie9.js', appAssets + 'js/build/**/*.js' ] )
.pipe( concat( 'application.js' ) )
.pipe( gulp.dest( appAssets + 'js' ) )
});
gulp.task( 'lte-ie9-js', function() {
return gulp
.src( appAssets + 'js/build/lte-ie9.js' )
.pipe( gulp.dest( appAssets + 'js' ) )
});
// JS Uglify
gulp.task( 'uglify', function() {
return gulp
.src( appAssets + 'js/*.js' )
.pipe( uglify( uglifyOptions ) )
.pipe( rename( renameOptions ) )
.pipe( gulp.dest( distAssets + 'javascripts' ) )
});
// Watch
gulp.task( 'watch', function() {
livereload.listen();
gulp.watch( app + '**/*.php', ['phpWatch'] );
gulp.watch( src + 'sass/**/*.sass', ['sass'] );
gulp.watch( src + 'coffee/**/*.coffee', ['coffee'] );
});
// Development
gulp.task( 'default', function(callback) {
runSequence( 'clean:app', 'cssVendor', 'jsVendor',
[ 'sass', 'coffee', 'watch' ],
callback
)
});
// Production
gulp.task( 'prod', function(callback) {
runSequence( 'clean:dist',
[ 'php', 'fonts', 'images', 'videos', 'svgs', 'cssconcat', 'lte-ie9-css', 'jsconcat', 'lte-ie9-js' ],
[ 'cssnano', 'uglify' ],
callback
)
});