-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
195 lines (169 loc) · 4.44 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
'use strict';
// Generated on 2014-04-14 using generator-leaflet 0.0.14
var gulp = require('gulp');
var open = require('open');
var wiredep = require('wiredep').stream;
var port = 9820; // @custom
var project = {
name: 'ecv-ijba'
}
var paths = {
appDir: 'app/',
buildDir: 'dist/',
scripts: {
dir: 'app/scripts/',
src: 'app/scripts/**/*.js',
dest: 'dist/js'
},
styles: {
dir: 'app/styles/',
src: 'app/styles/**/*.scss',
dest: 'dist/styles'
},
images: {
dir: 'app/images',
src: 'app/images/**/*',
dest: 'dist/images',
}
};
var gulp = require('gulp');
var sass = require('gulp-sass');
// Load plugins
var $ = require('gulp-load-plugins')();
gulp.task('styles', function () {
gulp.src([paths.styles.src])
.pipe(sass({
style: 'expanded',
errLogToConsole: true
}))
.pipe(gulp.dest(paths.styles.dir));
});
// Scripts
gulp.task('scripts', function () {
return gulp.src([paths.scripts.src])
.pipe($.jshint('.jshintrc'))
.pipe($.jshint.reporter('default'))
.pipe($.size());
});
// HTML
gulp.task('html', ['styles', 'scripts'], function () {
var jsFilter = $.filter('**/*.js');
var cssFilter = $.filter('**/*.css');
return gulp.src('app/*.html')
.pipe($.useref.assets())
.pipe(jsFilter)
.pipe($.uglify())
.pipe(jsFilter.restore())
.pipe(cssFilter)
.pipe($.csso())
.pipe(cssFilter.restore())
.pipe($.useref.restore())
.pipe($.useref())
.pipe(gulp.dest('dist'))
.pipe($.size());
});
// Images
gulp.task('images', function () {
return gulp.src([
'app/images/**/*',
'app/lib/images/*'])
.pipe($.cache($.imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
})))
.pipe(gulp.dest('dist/images'))
.pipe($.size());
});
// Data
gulp.task('data', function () {
return gulp.src([
paths.scripts.dir + '/**/*.csv',
paths.scripts.dir + '/**/*.json'])
.pipe(gulp.dest('dist/scripts'))
.pipe($.size());
});
// Fonts
gulp.task('fonts', function() {
return gulp.src([
'app/bower_components/font-awesome/fonts/fontawesome-webfont.*'])
.pipe(gulp.dest('dist/fonts/'));
});
// Clean
gulp.task('clean', function () {
return gulp.src(['dist/styles', 'dist/scripts', 'dist/images'], { read: false }).pipe($.clean());
});
// Build
gulp.task('build', ['html', 'images', 'data', 'fonts']);
// Default task
gulp.task('default', ['clean'], function () {
gulp.start('build');
});
// Connect
gulp.task('connect', $.connect.server({
root: ['app'],
port: port,
livereload: true
}));
// Open
gulp.task('serve', ['connect'], function() {
open("http://localhost:"+port);
});
// Inject Bower components
gulp.task('wiredep', function () {
gulp.src('app/styles/*.css')
.pipe(wiredep({
directory: 'app/bower_components',
ignorePath: 'app/bower_components/'
}))
.pipe(gulp.dest(paths.styles.dir));
gulp.src('app/*.html')
.pipe(wiredep({
directory: 'app/bower_components',
ignorePath: paths.appDir
}))
.pipe(gulp.dest('app'));
});
// Watch
gulp.task('watch', ['connect', 'serve'], function () {
// Watch for changes in `app` folder
gulp.watch([
'app/*.html',
paths.styles.src,
paths.scripts.src,
paths.images.src
], function (event) {
console.log('reload');
return gulp.src(event.path)
.pipe($.connect.reload());
});
// Watch .scss files
gulp.watch(paths.styles.src, ['styles']);
// Watch .js files
gulp.watch(paths.scripts.src, ['scripts']);
// Watch image files
gulp.watch(paths.images.src, ['images']);
// Watch bower files
gulp.watch('bower.json', ['wiredep']);
});
// @custom
gulp.task('deploy', ['build'] , function() {
var rsync = require('rsyncwrapper').rsync;
var gutil = require('gulp-util');
rsync({
ssh: true,
src: paths.buildDir,
dest: '/srv/edouard-lopez/demo/'+project.name,
host: 'ed8@vm-ed',
port: '822',
recursive: true,
syncDest: true,
args: ['--verbose'],
exclude: ['.git*','*.scss','node_modules'],
}, function(error, stdout, stderr, cmd) {
gutil.log(cmd);
gutil.log(stdout);
gutil.log(error);
gutil.log(stderr);
});
});