-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathgulpfile.js
More file actions
234 lines (203 loc) · 5.81 KB
/
gulpfile.js
File metadata and controls
234 lines (203 loc) · 5.81 KB
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
'use strict';
var gulp = require('gulp'),
jade = require('jade'),
modRewrite = require('connect-modrewrite'),
yaml = require('gulp-yaml'),
merge = require('gulp-merge-json'),
ghPages = require('gulp-gh-pages');
var $ = require('gulp-load-plugins')({
pattern: ['gulp-*', 'del', 'browser-sync']
});
// Webpack
gulp.task('webpack', function() {
return gulp.src('app/scripts/entry.js')
.pipe($.webpack({
module: {
loaders: [
{ test: /\.json$/, loader: "json-loader" }
]
},
output: {
filename: "app.js"
}
}))
.pipe(gulp.dest('build/dev/scripts/'))
.pipe($.browserSync.reload({stream:true}));
});
// Html
gulp.task('html:dev', function() {
return gulp.src('build/dev/views/index.html')
.pipe(gulp.dest('build/dev'))
.pipe($.browserSync.reload({stream:true}));
});
gulp.task('html:dist', function() {
return gulp.src('build/dist/views/index.html')
.pipe(gulp.dest('build/dist'))
});
// Views
gulp.task('views:dev', function(){
return gulp.src('app/views/**/*.jade')
.pipe($.jade({
jade: jade,
pretty: true
}))
.pipe(gulp.dest('build/dev/views'));
});
gulp.task('views:dist', function(){
return gulp.src('app/views/**/*.jade')
.pipe($.jade({
jade: jade,
pretty: true
}))
.pipe(gulp.dest('build/dist/views'));
});
// Yaml
gulp.task('yaml:dev', function(){
return gulp.src('app/data/*.yml')
.pipe(yaml())
.pipe(merge('resume.json'))
.pipe(gulp.dest('build/dev'));
});
gulp.task('yaml:dist', function(){
return gulp.src('app/data/*.yml')
.pipe(yaml())
.pipe(merge('resume.json'))
.pipe(gulp.dest('build/dist'));
});
// Sass
gulp.task('sass', function () {
return $.rubySass('app/styles/app.scss', { sourcemap: true })
.on('error', function (err) {
console.error('Error!', err.message);
})
.pipe($.sourcemaps.write())
.pipe(gulp.dest('build/dev/styles'))
.pipe($.browserSync.reload({stream:true}));
});
// Images
gulp.task('images', function () {
return gulp.src('app/images/**/*')
.pipe(gulp.dest('build/dist/images/'))
.pipe($.browserSync.reload({stream:true}));
});
// .htaccess
gulp.task('htaccess', function () {
return gulp.src('.htaccess')
.pipe(gulp.dest('build/dist/'));
});
// Static server
gulp.task('serve:dev', function() {
$.browserSync({
server: {
baseDir: [".","build/dev","app"],
middleware: [
modRewrite([
'!\\.html|\\.js|\\.css|\\.png|\\.jpg|\\.gif|\\.svg|\\.txt$ /index.html [L]'
])
]
}
});
});
gulp.task('serve:dist', function() {
$.browserSync({
server: {
baseDir: ["build/dist"],
middleware: [
modRewrite([
'!\\.html|\\.js|\\.css|\\.png|\\.jpg|\\.gif|\\.svg|\\.txt$ /index.html [L]'
])
]
}
});
});
// e2e tests
gulp.task('webdriver-update', $.protractor.webdriver_update);
gulp.task('protractor', ['webdriver-update'], function () {
gulp.src(['test/e2e/**/*.js'])
.pipe($.protractor.protractor({
configFile: "test/protractor.config.js",
args: ['--baseUrl', 'http://localhost:3000']
}))
.on('error', function (e) {
throw e
});
});
// Bower dependencies
gulp.task('wiredep', function () {
var wiredep = require('wiredep').stream;
return gulp.src('app/index.html')
.pipe(wiredep({
directory: 'bower_components'
}))
.pipe(gulp.dest('app'));
});
gulp.task('bower', function() {
return $.bower();
});
// Clean
gulp.task('clean', function () {
$.del.sync(['build/dev/*', 'build/dist/*']);
});
// Default Task (Dev environment)
gulp.task('default', ['dev', 'serve:dev'], function(callback) {
gulp.start('html:dev');
// Scripts
gulp.watch(['app/scripts/**/*.js'], ['webpack']);
// Views
$.watch('app/views/**/*.jade')
.pipe($.jadeFindAffected())
.pipe($.jade({jade: jade, pretty: true}))
.pipe(gulp.dest('build/dev/views'));
// Yaml
gulp.watch('app/data/*.yml', ['yaml:dev']);
gulp.watch('build/dev/resume.json', ['html:dev']);
// Htmls
gulp.watch('build/dev/views/**/*.html', ['html:dev']);
// Styles
gulp.watch('app/styles/**/*.scss', ['sass']);
});
// Development
gulp.task('dev', ['clean', 'bower', 'webpack', 'sass', 'views:dev', 'html:dev', 'yaml:dev']);
gulp.task('deps', ['html:dist'], function () {
var assets = $.useref.assets();
return gulp.src(['build/dist/index.html'])
// Concatenates asset files from the build blocks inside the HTML
.pipe(assets)
// Appends hash to extracted files app.css → app-098f6bcd.css
.pipe($.rev())
// Adds AngularJS dependency injection annotations
.pipe($.if('*.js', $.ngAnnotate()))
// Uglifies js files
.pipe($.if('*.js', $.uglify()))
// Minifies css files
.pipe($.if('*.css', $.csso()))
// Brings back the previously filtered HTML files
.pipe(assets.restore())
// Parses build blocks in html to replace references to non-optimized scripts or stylesheets
.pipe($.useref())
// Rewrites occurences of filenames which have been renamed by rev
.pipe($.revReplace())
// Minifies html
.pipe($.if('*.html', $.minifyHtml({
empty: true,
spare: true,
quotes: true
})))
// Creates the actual files
.pipe(gulp.dest('build/dist/'))
// Print the file sizes
.pipe($.size({ title: 'build/dist/', showFiles: true }));
});
// Distribution
gulp.task('dist', ['clean', 'wiredep', 'dev', 'images', 'htaccess', 'views:dist', 'yaml:dist'], function () {
gulp.start('deps');
});
gulp.task('serveprod', function() {
return gulp.src('build/dev/views/index.html')
.pipe(gulp.dest('build/dev'))
.pipe($.browserSync.reload({stream:false}));
});
gulp.task('deploy', function() {
return gulp.src('./build/dist/**/*')
.pipe(ghPages({force: true, remoteUrl: 'https://github.com/jhoffner/jhoffner.github.io.git', branch: 'master'}));
});