-
Notifications
You must be signed in to change notification settings - Fork 107
/
gulpfile.js
256 lines (208 loc) · 5.57 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
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
var gulp = require('gulp')
var run = require('run-sequence')
var plugins = require('gulp-load-plugins')()
var del = require('del')
var autoprefixer = require('autoprefixer-core')
var version = require('./package.json').version
var spawn = require('child_process').spawn
/**
* Clean builds
*/
gulp.task('clean:dist', function (done) {
del('dist', done)
})
gulp.task('clean:sass', function (done) {
del('app/css/*', done)
})
gulp.task('clean', function (done) {
run(['clean:dist', 'clean:sass'], done)
})
/**
* Clean deps
*/
gulp.task('clean:npm', function (done) {
del('node_modules', done)
})
/**
* Compile CSS
*/
gulp.task('sass', function () {
return gulp.src('app/scss/*', { base: 'app/scss' })
.pipe(plugins.sourcemaps.init())
.pipe(plugins.sass())
.on('error', function (err) {
plugins.util.log('sass error', err.message)
plugins.util.beep()
})
.pipe(plugins.postcss([ autoprefixer({ browsers: ['last 2 version'] }) ]))
.pipe(plugins.sourcemaps.write())
.pipe(gulp.dest('app/css'))
})
/**
* Compile templates
*/
gulp.task('ejs', function () {
return gulp.src('app/app.ejs')
.pipe(plugins.ejs({ version: version }, { ext: '.js' }))
.on('error', function (err) {
plugins.util.log('ejs error', err.message)
plugins.util.beep()
})
.pipe(gulp.dest('app'))
})
/**
* Compile templates
*/
gulp.task('hjs', function (done) {
var opts = {
cwd: __dirname + '/node_modules/highlight.js'
}
var npmInstall = spawn('npm', ['install'], opts)
npmInstall.stdout.pipe(process.stdout)
npmInstall.stderr.pipe(process.stderr)
npmInstall.on('close', function (code) {
if (0 !== code) throw new Error('npm install exited with ' + code)
var build = spawn('node', ['tools/build.js', '-n', 'json'], opts)
build.stdout.pipe(process.stdout)
build.stderr.pipe(process.stderr)
build.on('close', function (code) {
if (0 !== code) throw new Error('node tools/build.js exited with ' + code)
done()
})
})
})
/**
* Launch server + livereload in dev mode
*/
gulp.task('app', ['build:app'], function (done) {
gulp.watch('app/scss/*.scss', ['sass'])
gulp.watch('app/app.ejs', ['ejs'])
plugins.livereload({ start: true })
gulp.watch([
'app/**/*',
'!app/app.ejs',
'!app/scss/*',
]).on('change', function (file) {
plugins.livereload.changed(file.path)
})
plugins.util.log('spinning rtail client and server ... http://localhost:8888/app')
var rTailServer = spawn('node', ['--harmony', 'cli/rtail-server.js', '--web-version', 'development'])
rTailServer.stdout.pipe(process.stdout)
rTailServer.stderr.pipe(process.stdout)
var rTailClient = spawn('node', ['--harmony', 'cli/rtail-client.js'])
rTailClient.stdout.pipe(process.stdout)
rTailClient.stderr.pipe(process.stdout)
var lines = [
'<script>alert(1)</script>',
'A B C',
'200 GET /1/geocode?address=ny',
'200 GET /1/config',
'500 GET /1/users/556605ede9fa35333befa9e6/profile',
'200 POST /1/signin',
'200 GET /1/users/556605ede9fa35333befa9e6/profile',
'200 PUT /1/me/gcm_tokens/duUOo8jRIxq547jAaAHvsF9v',
'200 PUT /1/me/review_status/seen',
'301 GET /1/config',
'200 GET /1/users/555f7494e9fa35333befa9ab/profile',
'200 POST /1/signin',
'200 GET /1/users/555f7494e9fa35333befa9ab/profile',
'400 PUT /1/me/gcm_tokens/3G7ggYFcGXIHkIgaGLW16s4sobrkAPA91bGM8t9MJwfDbFA',
'200 GET /1/me/notifications',
'200 GET /1/me/picture',
'200 GET /1/alive'
]
function log2rtail(str) {
rTailClient.stdin.write(str + '\n')
}
setInterval(function () {
var debug = require('debug')('api:logs')
var index = Math.floor(Math.random() * lines.length)
var line = lines[index]
debug.log = log2rtail
if (Math.random() < 0.8) {
debug(line)
} else {
log2rtail(JSON.stringify({
foo: 'bar',
bar: 'foo',
count: Math.random() * 1000,
list: [
"foo",
"bar"
],
doc: {
foo: 'bar',
bar: 'foo'
},
link: "http://google.com",
regexp: /a.?/,
color: "#fff"
}))
}
}, 1000)
})
/**
* Build app
*/
gulp.task('build:app', function (done) {
run('clean:sass', 'sass', 'ejs', 'hjs', done)
})
/**
* Copy SVG
*/
gulp.task('copy:images', function () {
return gulp.src('app/images/**/*')
.pipe(gulp.dest('dist/images'))
})
/**
* Bundle CSS / JS
*/
gulp.task('html', function () {
var assets = plugins.useref.assets()
return gulp.src('app/index.html')
.pipe(assets)
.pipe(assets.restore())
.pipe(plugins.useref())
.pipe(gulp.dest('dist'))
})
/**
* Minify JS
*/
gulp.task('minify:js', function () {
return gulp.src('dist/bundle.min.js')
.pipe(plugins.ngAnnotate())
.pipe(plugins.uglify())
.pipe(gulp.dest('dist/'))
})
/**
* Minify CSS
*/
gulp.task('minify:css', function () {
return gulp.src('dist/css/bundle.min.css')
.pipe(plugins.minifyCss( { keepSpecialComments: 0, keepBreaks: true }))
.pipe(gulp.dest('dist/css/'))
})
/**
* Minify HTML
*/
gulp.task('minify:html', function () {
return gulp.src('dist/index.html')
.pipe(plugins.minifyHtml( { conditionals: true, quotes: true }))
.pipe(gulp.dest('dist/'))
})
/**
* Minify all
*/
gulp.task('minify', function (done) {
run(['minify:js', 'minify:css', 'minify:html'], done)
})
/**
* Build dist
*/
gulp.task('build:dist', function (done) {
run(['build:app', 'clean:dist'], 'copy:images', 'html', 'minify', done)
})
/**
* Default task
*/
gulp.task('default', ['build:dist'])