forked from ethersphere/swarm-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
devkit.mjs
53 lines (43 loc) · 1.18 KB
/
devkit.mjs
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
#!/usr/bin/env node
import envPaths from 'env-paths'
import open from 'open'
import cpy from 'cpy'
import { readFile, rm } from 'node:fs/promises'
import { join } from 'node:path'
const paths = envPaths('Swarm Desktop', { suffix: '' })
const requestedCommand = process.argv[2]
switch (requestedCommand) {
case 'open:ui':
await openUi()
break
case 'copy:ui':
await copyUi()
await copyEtherjot()
break
case 'purge:data':
await purgeData()
break
case 'purge:logs':
await purgeLogs()
break
default:
throw new Error(`Unknown command "${requestedCommand}"!`)
}
function purgeData() {
return rm(paths.data, { recursive: true, force: true })
}
function purgeLogs() {
return rm(paths.log, { recursive: true, force: true })
}
function copyUi() {
return cpy('.', join('..', '..', 'dist', 'ui'), { cwd: join('ui', 'build') })
}
function copyEtherjot() {
return cpy('.', join('..', 'dist', 'etherjot'), { cwd: join('.', 'etherjot') })
}
async function openUi() {
const apiKey = await readFile(join(paths.data, 'api-key.txt'), { encoding: 'utf-8' })
const url = `http://localhost:3002/?v=${apiKey}#/`
console.log('Opening: ' + url)
await open(url)
}