-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·124 lines (101 loc) · 2.61 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env node
/* eslint-disable no-case-declarations */
const figlet = require('figlet')
const clear = require('clear')
const { infoMsg, errorMsg, successMsg } = require('./lib/colorStates')
const { savePlugin, removePlugin, updatePlugins } = require('./lib/files')
const { getPlugNameFromConfig } = require('./lib/helpers')
const { fetchPluginDetails, queryPlugins } = require('./lib/api')
const {
askForVimInfo,
askForQuery,
askPluginSelection,
installedPluginsList,
menuSelection
} = require('./lib/prompts')
const store = require('./lib/store')
const sendCliHeading = () =>
infoMsg(
figlet.textSync('Vim Awesome Query', {
font: 'Shadow',
horizontalLayout: 'fitted'
})
)
const runCommand = async (command) => {
if (command === 'query') {
const { query } = await askForQuery()
const results = await queryPlugins({ query })
const { selection, action } = await askPluginSelection(results.plugins)
switch (action) {
case 'info':
const details = await fetchPluginDetails(selection.slug)
Object.keys(details).forEach((val) =>
infoMsg(`${val}: ${details[val]}`)
)
runMenu()
break
case 'install':
savePlugin(selection)
runMenu()
break
case 'back':
runCommand('query')
break
case 'exit':
return false
default:
errorMsg('Invalid action for plugin')
return false
}
}
if (command === 'list') {
const { plugin, action } = await installedPluginsList()
switch (action) {
case 'info':
const details = await fetchPluginDetails(getPlugNameFromConfig(plugin))
Object.keys(details).forEach((val) =>
infoMsg(`${val}: ${details[val]}`)
)
runMenu()
break
case 'uninstall':
removePlugin(plugin)
runMenu()
break
case 'back':
runCommand('list')
break
case 'exit':
return false
default:
errorMsg('Invalid action for plugin')
return false
}
}
if (command === 'update') {
updatePlugins()
successMsg('Plugins Updated!\n')
runMenu()
}
if (command === 'exit') {
return false
}
}
const runMenu = async () => {
const { command } = await menuSelection()
runCommand(command)
}
const run = async () => {
clear()
sendCliHeading()
if (!store.get('vimpath')) {
const { vimpath, vimtype } = await askForVimInfo()
store.set('vimpath', vimpath)
store.set('vimtype', vimtype)
successMsg("Saved. Let's continue...\n")
runMenu()
} else {
runMenu()
}
}
run()