-
Notifications
You must be signed in to change notification settings - Fork 2
/
.aegir.ts
39 lines (35 loc) · 992 Bytes
/
.aegir.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
import { readFileSync } from 'node:fs'
import { type Libp2p, createLibp2p } from 'libp2p'
import { getConfig } from './utils/circuit-relay.js'
interface BeforeResult {
env: {
W3_TOKEN: string
},
libp2p: Libp2p
}
/** @type {import('aegir').PartialOptions} */
export default {
test: {
before: async (): Promise<BeforeResult> => {
// get web3.storage token from shell or .env file
let token: null | string = null
if (typeof process.env.W3_TOKEN === 'string' && process.env.W3_TOKEN.length > 0) {
token = process.env.W3_TOKEN
} else {
try {
token = readFileSync('.w3_token', { encoding: 'utf-8'}).split('\n')[0]
} catch {}
}
const libp2p = await createLibp2p(await getConfig())
return {
env: {
W3_TOKEN: token || ''
},
libp2p
}
},
after: async (_: any, beforeResult: BeforeResult): Promise<void> => {
await beforeResult.libp2p.stop()
}
}
}