forked from libp2p/js-libp2p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.aegir.js
63 lines (57 loc) · 1.74 KB
/
.aegir.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
import { spawn, exec } from 'child_process'
import { existsSync } from 'fs'
import defer from 'p-defer'
/** @type {import('aegir/types').PartialOptions} */
export default {
test: {
async before() {
if (!existsSync('./go-libp2p-webtransport-server/main')) {
await new Promise((resolve, reject) => {
exec('go build -o main main.go',
{ cwd: './go-libp2p-webtransport-server' },
(error, stdout, stderr) => {
if (error) {
reject(error)
console.error(`exec error: ${error}`)
return
}
resolve()
})
})
}
const server = spawn('./main', [], { cwd: './go-libp2p-webtransport-server', killSignal: 'SIGINT' })
server.stderr.on('data', (data) => {
console.log('stderr:', data.toString())
})
const serverAddr = defer()
const serverAddr6 = defer()
const disableIp6 = process.env.DISABLE_IPV6 != null
server.stdout.on('data', (buf) => {
const data = buf.toString()
console.log('stdout:', data);
if (data.includes('addr=/ip4')) {
// Parse the addr out
serverAddr.resolve(`/ip4${data.match(/addr=\/ip4(.*)/)[1]}`)
}
if (data.includes('addr=/ip6')) {
// Parse the addr out
serverAddr6.resolve(`/ip6${data.match(/addr=\/ip6(.*)/)[1]}`)
}
})
return {
server,
env: {
serverAddr: await serverAddr.promise,
serverAddr6: disableIp6 === false ? await serverAddr6.promise : 'skipping',
disableIp6
}
}
},
async after(_, { server }) {
server.kill('SIGINT')
}
},
build: {
bundlesizeMax: '18kB'
}
}