forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.ts
76 lines (71 loc) · 2.63 KB
/
gulpfile.ts
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
import log from 'fancy-log'
import gulp from 'gulp'
import createWebpackCompiler, { Stats } from 'webpack'
import WebpackDevServer from 'webpack-dev-server'
import { phabricator, watchPhabricator } from '../browser/gulpfile'
import { graphQLTypes, schema, watchGraphQLTypes, watchSchema } from '../shared/gulpfile'
import webpackConfig from './webpack.config'
const WEBPACK_STATS_OPTIONS: Stats.ToStringOptions & { colors?: boolean } = {
all: false,
timings: true,
errors: true,
warnings: true,
warningsFilter: warning =>
// This is intended, so ignore warning
/node_modules\/monaco-editor\/.*\/editorSimpleWorker.js.*\n.*dependency is an expression/.test(warning),
colors: true,
}
const logWebpackStats = (stats: Stats) => log(stats.toString(WEBPACK_STATS_OPTIONS))
export async function webpack(): Promise<void> {
const compiler = createWebpackCompiler(webpackConfig)
const stats = await new Promise<Stats>((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 })
}
}
export async function webpackDevServer(): Promise<void> {
const compiler = createWebpackCompiler(webpackConfig)
const server = new WebpackDevServer(compiler as any, {
allowedHosts: ['.host.docker.internal'],
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)),
},
},
})
return new Promise<void>((resolve, reject) => {
server.listen(3080, '0.0.0.0', (err?: Error) => {
if (err) {
reject(err)
} else {
resolve()
}
})
})
}
/**
* Builds everything.
*/
export const build = gulp.parallel(
gulp.series(gulp.parallel(schema, graphQLTypes), gulp.parallel(webpack, phabricator))
)
/**
* Watches everything and rebuilds on file changes.
*/
export 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, watchPhabricator)
)