forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
86 lines (77 loc) · 2.59 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
// @ts-check
const log = require('fancy-log')
const gulp = require('gulp')
const createWebpackCompiler = require('webpack')
const WebpackDevServer = require('webpack-dev-server')
const { graphQLTypes, schema, watchGraphQLTypes, watchSchema } = require('../shared/gulpfile')
const webpackConfig = require('./webpack.config')
const WEBPACK_STATS_OPTIONS = {
all: false,
timings: true,
errors: true,
warnings: true,
colors: true,
}
/**
* @param {import('webpack').Stats} stats
*/
const logWebpackStats = stats => {
log(stats.toString(WEBPACK_STATS_OPTIONS))
}
async function webpack() {
const compiler = createWebpackCompiler(webpackConfig)
/** @type {import('webpack').Stats} */
const stats = await new Promise((resolve, reject) => {
compiler.run((err, stats) => (err ? reject(err) : resolve(stats)))
})
logWebpackStats(stats)
if (stats.hasErrors()) {
throw Object.assign(new Error('Failed to compile'), { showStack: false })
}
}
async function webpackDevServer() {
const sockHost = process.env.SOURCEGRAPH_HTTPS_DOMAIN || 'sourcegraph.test'
const sockPort = Number(process.env.SOURCEGRAPH_HTTPS_PORT || 3443)
/** @type {import('webpack-dev-server').Configuration & { liveReload?: boolean }} */
const options = {
hot: !process.env.NO_HOT,
inline: !process.env.NO_HOT,
allowedHosts: ['.host.docker.internal'],
host: 'localhost',
port: 3080,
publicPath: '/.assets/',
contentBase: './ui/assets',
stats: WEBPACK_STATS_OPTIONS,
noInfo: false,
disableHostCheck: true,
proxy: {
'/': {
target: 'http://localhost:3081',
// Avoid crashing on "read ECONNRESET".
onError: err => console.error(err),
onProxyReqWs: (_proxyReq, _req, socket) =>
socket.on('error', err => console.error('WebSocket proxy error:', err)),
},
},
sockHost,
sockPort,
}
WebpackDevServer.addDevServerEntrypoints(webpackConfig, options)
const server = new WebpackDevServer(createWebpackCompiler(webpackConfig), options)
await new Promise((resolve, reject) => {
server.listen(3080, '0.0.0.0', err => (err ? reject(err) : resolve()))
})
}
/**
* Builds everything.
*/
const build = gulp.parallel(gulp.series(gulp.parallel(schema, graphQLTypes), gulp.parallel(webpack)))
/**
* Watches everything and rebuilds on file changes.
*/
const watch = gulp.series(
// Ensure the typings that TypeScript depends on are build to avoid first-time-run errors
gulp.parallel(schema, graphQLTypes),
gulp.parallel(watchSchema, watchGraphQLTypes, webpackDevServer)
)
module.exports = { build, watch, webpackDevServer, webpack }