-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
76 lines (58 loc) · 1.73 KB
/
app.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
69
70
71
72
73
74
75
const fs = require('fs')
const os = require('os')
const path = require('path')
const inquirer = require('inquirer')
const replace = require('replace-in-file')
const TrelloManager = require('./TrelloManager')
const ui = require('./lib/ui')
// Release the Kraken! (aka, run this thing)
getAuth()
.then((auth) => {
const tMan = new TrelloManager(auth)
tMan.fillStore()
.then((store) => ui.drawUI(store, tMan))
})
/**
* Checks for existing auth files. If none, prompts for key and token
* and stores the on $HOME/.termllo/auth.js
*/
async function getAuth () {
// Check if local auth
if (fs.existsSync("./auth.js")) {
return require('./auth')
}
// Create config file on $HOME
const homedir = os.homedir()
const termlloDir = path.join(homedir, '.termllo')
if (!fs.existsSync(termlloDir)) {
fs.mkdirSync(termlloDir)
}
// Check for home auth
const homeAuth = path.join(homedir, '.termllo', 'auth.js')
if (fs.existsSync(homeAuth)) {
return require(homeAuth)
}
// Prompt for auth
console.log('\nAuth config missing. Please:')
console.log(' 1. Get your api key and token from https://trello.com/app-key')
console.log(' 2. Copy paste them here:')
const answers = await inquirer.prompt([
{ type: 'input', name: 'key', message: 'Your API Key:' },
{ type: 'input', name: 'token', message: 'Your Token:' },
])
// Copy example to $HOME/.termllo/auth.js
const pathExample = path.join(__dirname, './auth.js.example')
fs.copyFileSync(pathExample, homeAuth)
// Replace key and token with placeholders
await replace({
files: homeAuth,
from: 'your-key',
to: answers.key,
})
await replace({
files: homeAuth,
from: 'your-token',
to: answers.token,
})
return answers
}