-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (42 loc) · 1.41 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
const schedule = require('./alfred-schedule')
function showLists () {
const alfred = require('./alfred')
return alfred.getLists()
}
function showCards () {
const alfy = require('alfy')
const alfred = require('./alfred')
const { listId } = process.env
const gotCards = alfred.getCards(listId)
const gotCreateCard = alfred.getCreateCard(alfy.input, listId)
return Promise.all([gotCards, gotCreateCard]).then(([cardItems, createCardItem]) => {
cardItems.unshift(createCardItem)
return cardItems
})
}
function handleAction ({ action, data }) {
const notifier = require('node-notifier')
const open = require('open')
const { postCard } = require('./trello')
const notify = (title, message, url) => notifier.notify({ title, message, open: url })
if (action === 'create') {
postCard(data)
.then(newCard => notify('It worked ⚡️', "Your card's now on Trello.", newCard.url))
.catch(reason => notify('Oops 🌧', `Hit a problem: ${reason}`))
} else if (action === 'show') {
open(data.url)
}
}
schedule(first =>
first(showLists)
.next(showCards)
.next(handleAction)
)
// enqueues functions in the PersistentFunctionQueue
// fq.enqueue(showLists)
// fq.enqueue(showCards)
// fq.enqueue(handleAction)
// final pretty syntax:
// outputResult(showLists)
// .then(selectedList => outputResult(showCards(selectedList)))
// .then(selectedCard => handleAction(selectedCard))