-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
127 lines (105 loc) · 2.8 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
var paths = {
app: 'app/Resources',
src: 'web/assets',
dest: 'web/vendor'
};
var gulp = require('gulp'),
bower = require('gulp-bower'),
bowerFiles = require('main-bower-files'),
less = require('gulp-less-sourcemap'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
flatten = require('gulp-flatten'),
dev = false
;
gulp.task('setdev', function() {
dev = true;
gulp.start('default');
});
gulp.task('startsymfonyserver', function() {
var exec = require('child_process').exec;
exec('php bin/console server:start', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
});
});
gulp.task('stopsymfonyserver', function() {
var exec = require('child_process').exec;
exec('php bin/console server:stop', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
});
});
gulp.task('less', function() {
var options = {
compress: true
};
if (dev) {
options = {
compress: true,
sourceMap: {
sourceMapRootpath: ''
}
};
}
return gulp.src(paths.app + '/less/app.less').pipe(less(options))
.on('error', function (e) { console.log('less', e) })
.pipe(gulp.dest(paths.dest))
;
});
gulp.task('js', function() {
var src = gulp.src(paths.app + '/js/**/*.js');
if (dev) {
src.pipe(sourcemaps.init());
}
if (!dev) {
src.pipe(uglify({
preserveComments: true,
mangle: true
}).on('error', function (e) {
console.log('uglify', e);
}));
}
if (dev) {
src.pipe(sourcemaps.write());
}
return src
.pipe(concat('app.js'))
.pipe(gulp.dest(paths.dest))
;
});
gulp.task('font', function() {
return gulp.src(paths.src + '/**/*.{ttf,woff,eof,svg}')
.pipe(flatten())
.pipe(gulp.dest(paths.dest))
;
});
gulp.task('bower', function() {
var files = bowerFiles({filter: ['**/*.js'], debug: false});
var src = gulp.src(files);
if (dev) {
src.pipe(sourcemaps.init());
}
if (! dev) {
src.pipe(uglify({
preserveComments: true,
mangle: true
}).on('error', function (e) {
console.log('uglify', e);
}));
}
if (dev) {
src.pipe(sourcemaps.write());
}
return src
.pipe(concat('vendor.js'))
.pipe(gulp.dest(paths.dest))
;
});
gulp.task('default', ['less', 'bower', 'js', 'font']);
gulp.task('dev', ['startsymfonyserver', 'setdev'], function() {
gulp.watch(paths.app + '/less/**/*.less', ['less']);
gulp.watch(paths.app + '/js/**/*.js', ['js']);
});
gulp.task('stop', ['stopsymfonyserver']);