-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
168 lines (145 loc) · 4.77 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
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var del = require('del');
var Q = require('q');
var config = {
assetsDir: 'app/Resources/assets',
sassPattern: 'sass/**/*.scss',
bowerDir: 'vendor/bower_components',
revManifestPath: 'app/Resources/assets/rev-manifest.json'
};
var app = {};
app.errorHandling = function(error) {
console.log(error.toString());
this.emit('end');
};
app.addStyle = function(paths, outputFilename) {
return gulp.src(paths)
.pipe(plugins.plumber(function(error) {
console.log(error.toString());
this.emit('end');
}))
.pipe(plugins.sourcemaps.init())
.pipe(plugins.sass())
.pipe(plugins.concat(outputFilename))
.pipe(plugins.cleanCss())
.pipe(plugins.rev())
.pipe(plugins.sourcemaps.write('.'))
.pipe(gulp.dest('web/css'))
// write the rev-manifest.json file for gulp-rev
.pipe(plugins.rev.manifest(config.revManifestPath, {
merge: true
}))
.pipe(gulp.dest('.'));
};
app.addScript = function(paths, outputFilename) {
return gulp.src(paths)
.pipe(plugins.plumber(function(error) {
console.log(error.toString());
this.emit('end');
}))
.pipe(plugins.sourcemaps.init())
.pipe(plugins.concat(outputFilename))
.pipe(plugins.uglify())
.pipe(plugins.rev())
.pipe(plugins.sourcemaps.write('.'))
.pipe(gulp.dest('web/js'))
// write the rev-manifest.json file for gulp-rev
.pipe(plugins.rev.manifest(config.revManifestPath, {
merge: true
}))
.pipe(gulp.dest('.'));
};
app.copy = function(srcFiles, outputDir) {
return gulp.src(srcFiles)
.pipe(gulp.dest(outputDir));
};
var Pipeline = function() {
this.entries = [];
};
Pipeline.prototype.add = function() {
this.entries.push(arguments);
};
Pipeline.prototype.run = function(callable) {
var deferred = Q.defer();
var i = 0;
var entries = this.entries;
var runNextEntry = function() {
// see if we're all done looping
if (typeof entries[i] === 'undefined') {
deferred.resolve();
return;
}
// pass app as this, though we should avoid using "this"
// in those functions anyways
callable.apply(app, entries[i]).on('end', function() {
i++;
runNextEntry();
});
};
runNextEntry();
return deferred.promise;
};
gulp.task('styles', function() {
var pipeline = new Pipeline();
pipeline.add([
config.bowerDir+'/bootstrap/scss/bootstrap-flex.scss'
], 'bootstrap-min.css');
pipeline.add([
config.bowerDir+'/fontawesome/css/font-awesome.css',
config.bowerDir+'/tether/dist/css/tether-theme-arrows.css',
config.bowerDir+'/jquery-ui/themes/smoothness/jquery-ui.css',
config.assetsDir+'/sass/base.scss'
], 'site-min.css');
return pipeline.run(app.addStyle);
});
gulp.task('scripts', function() {
var pipeline = new Pipeline();
pipeline.add(
[
config.bowerDir+'/jquery/dist/jquery.min.js'
],
'jquery-min.js'
);
pipeline.add(
[
config.bowerDir+'/jquery-ui/jquery-ui.js',
config.bowerDir+'/tether/dist/js/tether.js',
config.bowerDir+'/jquery-ui/ui/i18n/datepicker-fr.js',
config.bowerDir+'/jquery-ui/ui/i18n/datepicker-nl.js',
config.bowerDir+'/bootstrap/dist/js/bootstrap.js',
config.assetsDir+'/js/**/*.js'
],
'site-min.js'
);
return pipeline.run(app.addScript);
});
gulp.task('fonts', function() {
return app.copy(
config.bowerDir+'/fontawesome/fonts/*',
'web/fonts'
);
});
gulp.task('ui-images', function() {
return app.copy(
config.bowerDir+'/jquery-ui/themes/smoothness/images/*',
'web/css/images'
);
});
gulp.task('clean', function() {
del.sync(config.revManifestPath);
del.sync('web/css/*');
del.sync('web/js/*');
del.sync('web/fonts/*');
});
gulp.task('watch', function() {
gulp.watch(config.assetsDir+'/'+config.sassPattern, ['styles']);
gulp.watch(config.bowerDir+'/bootstrap/dist/css/bootstrap.css', ['styles']);
gulp.watch(config.bowerDir+'/bootstrap/scss/bootstrap-flex.scss', ['styles']);
gulp.watch(config.bowerDir+'/fontawesome/css/font-awesome.css', ['styles']);
gulp.watch(config.bowerDir+'/tether/dist/css/tether-theme-arrows.css', ['styles']);
gulp.watch(config.assetsDir+'/js/**/*.js', ['scripts']);
gulp.watch(config.bowerDir+'/bootstrap/dist/js/**/*.js', ['scripts']);
gulp.watch(config.bowerDir+'/tether/dist/js/**/*.js', ['scripts']);
});
gulp.task('default', ['styles', 'scripts', 'fonts']);