-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
129 lines (110 loc) · 3.64 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
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var del = require('del');
var Q = require('q');
var config = {
assetsDir: 'src/Resources/assets',
sassPattern: '**/*.scss',
production: !!plugins.util.env.production,
sourceMaps: !plugins.util.env.production,
bowerDir: 'vendor/bower_components',
revManifestPath: 'src/Resources/assets/rev-manifest.json'
};
var app = {};
app.addStyle = function(paths, outputFilename) {
return gulp.src(paths)
.pipe(plugins.plumber())
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.init()))
.pipe(plugins.sass())
.pipe(plugins.concat('css/'+outputFilename))
.pipe(config.production ? plugins.minifyCss() : plugins.util.noop())
.pipe(plugins.rev())
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.write('.')))
.pipe(gulp.dest('web'))
// 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())
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.init()))
.pipe(plugins.concat('js/'+outputFilename))
.pipe(config.production ? plugins.uglify() : plugins.util.noop())
.pipe(plugins.rev())
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.write('.')))
.pipe(gulp.dest('web'))
// 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.assetsDir+'/css/bootstrap.scss',
config.bowerDir+'/font-awesome/css/font-awesome.css',
config.assetsDir+'/css/flag-icon.css',
config.assetsDir+'/css/styles.scss'
], 'main.css');
return pipeline.run(app.addStyle);
});
gulp.task('scripts', function() {
var pipeline = new Pipeline();
pipeline.add([
config.bowerDir+'/jquery/jquery.js',
config.assetsDir+'/js/bootstrap.min.js',
config.assetsDir+'/js/main.js'
], 'site.js');
return pipeline.run(app.addScript);
});
gulp.task('fonts', function() {
return app.copy(
config.bowerDir+'/font-awesome/font/*',
'web/font'
);
});
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.assetsDir+'/js/**/*.js', ['scripts']);
});
gulp.task('default', ['clean', 'styles', 'scripts', 'fonts', 'watch']);