/
config.coffee
108 lines (95 loc) · 4.07 KB
/
config.coffee
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
### ###############################################################################################
#
# This module contains all configuration for the build process
#
### ###############################################################################################
ANGULAR_TAG = "~1.4.6"
gulp = require("gulp")
path = require("path")
shell = require("gulp-shell")
# d3 is loaded on demand, so it is just copied in the static dir
gulp.task "copyd3", ->
gulp.src(["libs/d3/d3.min.js"])
.pipe(gulp.dest(config.dir.build))
config =
### ###########################################################################################
# Directories
### ###########################################################################################
dir:
# The build folder is where the app resides once it's completely built
build: 'buildbot_www/static'
### ###########################################################################################
# Bower dependancies configuration
### ###########################################################################################
bower:
# JavaScript libraries (order matters)
deps:
"guanlecoja-ui":
version: '~1.5.0'
files: ['vendors.js', 'scripts.js']
moment:
version: "~2.6.0"
files: 'moment.js'
d3: # d3 is loaded on demand via d3Service
version: "~3.4.11"
files: []
"font-awesome":
version: "~4.1.0"
files: []
"bootstrap":
version: "~3.1.1"
files: []
# here we have the choice: ngSocket: no reconnecting, and not evolving since 10mon
# reconnectingWebsocket implements reconnecting with expo backoff, but no good bower taging
# reimplement reconnecting ourselves
"reconnectingWebsocket":
version: "master"
files: ["reconnecting-websocket.js"]
'buildbot-data':
version: '~1.0.14'
files: 'dist/buildbot-data.js'
testdeps:
"angular-mocks":
version: ANGULAR_TAG
files: "angular-mocks.js"
buildtasks: ['scripts', 'styles', 'fonts', 'imgs',
'index', 'tests', 'fixtures', 'copyd3']
gulp.task 'processindex', ['index'], ->
indexpath = path.join(config.dir.build, 'index.html')
gulp.src ""
.pipe shell("buildbot processwwwindex -i '#{indexpath}'")
gulp.task 'proxy', ['processindex'], ->
# this is a task for developing, it proxy api request to http://nine.buildbot.net
argv = require('minimist')(process.argv)
argv.host?= 'nine.buildbot.net'
argv.port?= 8080
fs = require 'fs'
path = require 'path'
http = require 'http'
httpProxy = require 'http-proxy'
proxy = httpProxy.createProxyServer({})
proxy.on 'proxyReq', (proxyReq, req, res, options) ->
delete proxyReq.removeHeader('Origin')
delete proxyReq.removeHeader('Referer')
proxy.on 'proxyRes', (proxyRes, req, res) ->
proxyRes.headers['Access-Control-Allow-Origin'] = '*'
console.log "[Proxy] #{req.method} #{req.url}"
server = http.createServer (req, res) ->
if req.url.match /^\/(api|sse|avatar)/
proxy.web req, res, {target: 'http://' + argv.host}
else
filepath = config.dir.build + req.url.split('?')[0]
if fs.existsSync(filepath) and fs.lstatSync(filepath).isDirectory()
filepath = path.join(filepath, 'index.html')
fs.readFile filepath, (err, data) ->
if err
res.writeHead(404)
res.end(JSON.stringify(err))
else
res.writeHead(200)
res.end(data)
server.on 'upgrade', (req, socket, head) ->
proxy.ws req, socket, {target: 'ws://' + argv.host}
server.listen parseInt(argv.port)
console.log "[Proxy] server listening on port #{argv.port}"
module.exports = config