Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
92 lines (80 loc) · 2.63 KB

File metadata and controls

92 lines (80 loc) · 2.63 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env node
/**
* Interactive dev mode selector.
* Usage: node scripts/dev-select.mjs
*
* Arrow keys to move, Enter to confirm.
* Remembers last selection in node_modules/.cache/dev-mode.
*/
import { execSync } from 'child_process'
import { readFileSync, writeFileSync, mkdirSync } from 'fs'
import { join, dirname } from 'path'
import { fileURLToPath } from 'url'
const __dirname = dirname(fileURLToPath(import.meta.url))
const rootDir = join(__dirname, '..')
const cacheFile = join(rootDir, 'node_modules', '.cache', 'dev-mode')
const options = [
{ key: 'desktop', label: 'Desktop (Electron)', command: 'pnpm run dev:desktop' },
{ key: 'web', label: 'Web (CLI start + frontend)', command: 'pnpm run dev:web' },
{ key: 'server', label: 'Server Only (API backend)', command: 'pnpm run dev:serve' },
{ key: 'docs', label: 'Docs (VitePress)', command: 'pnpm run docs:dev' },
]
function loadLastChoice() {
try {
const key = readFileSync(cacheFile, 'utf8').trim()
const idx = options.findIndex((o) => o.key === key)
return idx >= 0 ? idx : 0
} catch {
return 0
}
}
function saveChoice(key) {
try {
mkdirSync(dirname(cacheFile), { recursive: true })
writeFileSync(cacheFile, key)
} catch {
// best-effort
}
}
let selected = loadLastChoice()
function render() {
process.stdout.write(`\x1b[${options.length}A`)
for (let i = 0; i < options.length; i++) {
const prefix = i === selected ? '\x1b[36m❯\x1b[0m' : ' '
const text = i === selected ? `\x1b[1m${options[i].label}\x1b[0m` : options[i].label
process.stdout.write(`\x1b[2K ${prefix} ${text}\n`)
}
}
function run() {
console.log('\n\x1b[1mSelect dev mode:\x1b[0m (↑↓ to move, Enter to confirm)\n')
for (let i = 0; i < options.length; i++) process.stdout.write('\n')
render()
process.stdin.setRawMode(true)
process.stdin.resume()
process.stdin.setEncoding('utf8')
process.stdin.on('data', (key) => {
if (key === '\x1b[A') {
selected = (selected - 1 + options.length) % options.length
render()
} else if (key === '\x1b[B') {
selected = (selected + 1) % options.length
render()
} else if (key === '\r' || key === '\n') {
process.stdin.setRawMode(false)
process.stdin.pause()
const choice = options[selected]
saveChoice(choice.key)
console.log(`\n\x1b[32m▶\x1b[0m Running: ${choice.command}\n`)
try {
execSync(choice.command, { stdio: 'inherit' })
} catch {
process.exit(1)
}
} else if (key === '\x03') {
process.stdin.setRawMode(false)
console.log()
process.exit(0)
}
})
}
run()
Morty Proxy This is a proxified and sanitized view of the page, visit original site.