-
Notifications
You must be signed in to change notification settings - Fork 15
/
gulpfile.js
149 lines (131 loc) · 4.52 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
var gulp = require('gulp');
var autoprefixer = require('gulp-autoprefixer');
var sass = require('gulp-sass');
var plumber = require('gulp-plumber');
var notify = require('gulp-notify');
var path = require('path');
var del = require('del');
var gutil = require('gulp-util');
var args = require('yargs').argv;
var gulpif = require('gulp-if');
var minifyCss = require('gulp-minify-css');
var uglifyjs = require('gulp-uglify');
var paths = {
styles: 'src/static/styles/**/*.{scss,css}',
scripts: 'src/static/scripts/**/*.js',
images: 'src/static/images/**/*.{jpg,jpeg,png,svg,gif}',
fonts: 'src/static/fonts/*',
php: 'src/**/*.{php,json,pem}',
stuff: ['src/.htaccess', 'src/humans.txt', 'src/robots.txt', 'src/favicon.ico'],
locale: ['src/locale/**/*'],
vendor: ['vendor/**/*'],
};
var destination = args.deploy ? 'deploy' : 'build';
var reportError = function(error) {
if ('CI' in process.env && process.env.CI === 'true') {
process.exit(1);
}
notify({
title: error.plugin + ' failed!',
message: error.message
}).write(error);
// Prevent the 'watch' task from stopping
this.emit('end');
};
gulp.task('clean', function() {
// Must be synchronous if we're going to use this task as a dependency
del.sync(destination + '/');
});
gulp.task('styles', function() {
return gulp.src(paths.styles)
.pipe(plumber({
errorHandler: reportError
}))
.pipe(sass())
.on('error', reportError)
.pipe(autoprefixer())
.pipe(gulpif(args.deploy, minifyCss()))
.pipe(gulp.dest(destination + '/static/styles'));
});
gulp.task('scripts', function() {
return gulp.src('src/static/scripts/**/*.js')
.pipe(gulpif(args.deploy, uglifyjs()))
.pipe(gulp.dest(destination + '/static/scripts'));
});
gulp.task('images', function() {
return gulp.src(paths.images)
.pipe(gulp.dest(destination + '/static/images'));
});
gulp.task('fonts', function() {
return gulp.src(paths.fonts)
.pipe(gulp.dest(destination + '/static/fonts'));
});
gulp.task('php', function() {
return gulp.src(paths.php)
.pipe(gulp.dest(destination + '/'));
});
gulp.task('stuff', function() {
return gulp.src(paths.stuff)
.pipe(gulp.dest(destination + '/'));
});
gulp.task('locale', function() {
return gulp.src(paths.locale, {dot: true})
.pipe(gulp.dest(destination + '/locale'));
});
gulp.task('vendor', function() {
return gulp.src(paths.vendor, {dot: true})
.pipe(gulp.dest(destination + '/vendor/'));
});
gulp.task('watch', ['default'], function() {
function deleter() {
var replaceFunc = null;
if (typeof arguments[0] === 'string') {
var before = arguments[0];
var after = arguments[1];
replaceFunc = function(file) {
return file.replace(before, after);
};
}
else if (typeof arguments[0] === 'function') {
replaceFunc = arguments[0];
}
return function(event) {
if (event.type == 'deleted') {
var file = path.relative('./', event.path);
if (typeof replaceFunc === 'function') {
file = replaceFunc(file);
}
del(file);
gutil.log('Deleted file', '\'' + file + '\'');
}
};
}
var srcToBuildDeleter = deleter('src/', destination + '/');
gulp.watch(paths.styles, ['styles'])
.on('change', deleter(function(file) {
return file.replace('src/', destination + '/')
.replace(/\.scss$/, '.css');
}));
gulp.watch(paths.scripts, ['scripts'])
.on('change', srcToBuildDeleter);
gulp.watch(paths.images, ['images'])
.on('change', srcToBuildDeleter);
gulp.watch(paths.fonts, ['fonts'])
.on('change', srcToBuildDeleter);
gulp.watch(paths.php, ['php'])
.on('change', srcToBuildDeleter);
gulp.watch(paths.stuff, ['stuff'])
.on('change', srcToBuildDeleter);
gulp.watch(paths.locale, ['locale'])
.on('change', srcToBuildDeleter);
gulp.watch(paths.vendor, {dot: true})
.on('change', deleter('vendor/', destination + '/vendor/'));
});
gulp.task('build', ['styles', 'scripts', 'images', 'fonts', 'php', 'stuff', 'locale', 'vendor']);
gulp.task('default', ['clean'], function() {
gulp.run('build', function(){
if (args.deploy) {
del.sync(['deploy/.htaccess', 'deploy/index.php', 'deploy/app/config.php']);
}
});
});