-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdevkit.mjs
More file actions
53 lines (43 loc) · 1.35 KB
/
Copy pathdevkit.mjs
File metadata and controls
53 lines (43 loc) · 1.35 KB
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('Nook', { suffix: '' })
const requestedCommand = process.argv[2]
switch (requestedCommand) {
case 'open:ui':
await openUi()
break
case 'copy:ui':
await copyUi()
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 })
}
async function copyUi() {
// Clear the destination first — Vite emits hash-named chunks, so without this
// each build's chunks pile up on top of the previous one's, accumulating dead
// files in dist/ui and bloating the packaged app.asar unbounded across builds.
await rm(join('dist', 'ui'), { recursive: true, force: true })
return cpy('.', join('..', '..', 'dist', 'ui'), { cwd: join('ui', 'build') })
}
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)
}