-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
68 lines (64 loc) · 1.55 KB
/
index.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
64
65
66
67
68
const { fetch, output, error } = require('alfy')
const requireOrExit = (file) => {
try {
return require(file)
} catch (e) {
error(e)
process.exit(1)
}
}
const path = require('path')
const home = require('os').homedir()
const config = requireOrExit(path.join(home, '.hotel', 'conf.json'))
const { host = 'localhost', port = 2000, tld = 'localhost' } = config
const hotel = `http://${host}:${port}`
fetch(`${hotel}/_/servers`)
.then((servers) => Object.keys(servers).map((id) => {
const { status, cwd } = servers[id]
const url = `http://${id}.${tld}`
const run = (command) => `{
"alfredworkflow": {
"arg": "${hotel}/_/servers/${id}",
"variables": {
"app": "${id}",
"command": "${command}"
}
}
}`
return {
uid: url,
title: id,
subtitle: status,
arg: url,
text: {
copy: url,
largetype: url
},
quicklookurl: status === 'running' ? url : null,
mods: {
alt: {
arg: `${hotel}/${id}`,
subtitle: 'open without proxy'
},
ctrl: {
arg: `file://${cwd}`,
type: 'file',
subtitle: 'open project folder'
},
fn: status === 'running' ? {
arg: run('restart'),
subtitle: 'restart'
} : {},
cmd: status === 'running'
? {
arg: run('stop'),
subtitle: 'stop'
}
: {
arg: run('start'),
subtitle: 'start'
}
}
}
}))
.then(output)