Skip to content

Commit 8305566

Browse files
committed
Adding more menu navigations
1 parent f7c3a81 commit 8305566

File tree

3 files changed

+50
-15
lines changed

3 files changed

+50
-15
lines changed

index.js

+35-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const figlet = require('figlet')
55
const clear = require('clear')
66

77
const { infoMsg, errorMsg, successMsg } = require('./lib/colorStates')
8-
const { savePlugin, removePlugin } = require('./lib/files')
8+
const { savePlugin, removePlugin, updatePlugins } = require('./lib/files')
99
const { getPlugNameFromConfig } = require('./lib/helpers')
1010
const { fetchPluginDetails, queryPlugins } = require('./lib/api')
1111
const {
@@ -29,18 +29,39 @@ const runCommand = async (command) => {
2929
if (command === 'query') {
3030
const { query } = await askForQuery()
3131
const results = await queryPlugins({ query })
32-
const { selection } = await askPluginSelection(results.plugins)
32+
const { selection, action } = await askPluginSelection(results.plugins)
3333

34-
savePlugin(selection)
34+
switch (action) {
35+
case 'info':
36+
const details = await fetchPluginDetails(selection.slug)
37+
Object.keys(details).forEach((val) =>
38+
infoMsg(`${val}: ${details[val]}`)
39+
)
40+
runMenu()
41+
break
42+
43+
case 'install':
44+
savePlugin(selection)
45+
runMenu()
46+
break
47+
48+
case 'back':
49+
runCommand('query')
50+
break
51+
52+
case 'exit':
53+
return false
54+
55+
default:
56+
errorMsg('Invalid action for plugin')
57+
return false
58+
}
3559
}
3660

3761
if (command === 'list') {
3862
const { plugin, action } = await installedPluginsList()
3963

4064
switch (action) {
41-
case 'update':
42-
break
43-
4465
case 'info':
4566
const details = await fetchPluginDetails(getPlugNameFromConfig(plugin))
4667
Object.keys(details).forEach((val) =>
@@ -55,7 +76,7 @@ const runCommand = async (command) => {
5576
break
5677

5778
case 'back':
58-
runMenu()
79+
runCommand('list')
5980
break
6081

6182
case 'exit':
@@ -67,6 +88,12 @@ const runCommand = async (command) => {
6788
}
6889
}
6990

91+
if (command === 'update') {
92+
updatePlugins()
93+
successMsg('Plugins Updated!\n')
94+
runMenu()
95+
}
96+
7097
if (command === 'exit') {
7198
return false
7299
}
@@ -87,7 +114,7 @@ const run = async () => {
87114
store.set('vimpath', vimpath)
88115
store.set('vimtype', vimtype)
89116

90-
successMsg("Saved. Let's continue...")
117+
successMsg("Saved. Let's continue...\n")
91118
runMenu()
92119
} else {
93120
runMenu()

lib/files.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ const installPlugins = () =>
4848
const cleanPlugins = () =>
4949
exec(`${store.get('vimtype')} +"PlugClean --sync" +qall &> /dev/null`)
5050

51+
const updatePlugins = () =>
52+
exec(`${store.get('vimtype')} +"PlugUpdate --sync" +qall &> /dev/null`)
53+
5154
const savePlugin = async ({ name, github_url }) => {
5255
if (plugExists(await getConfigPlugins(), github_url)) {
5356
return infoMsg(`Good news! ${name} is already installed.`)
@@ -74,7 +77,7 @@ const savePlugin = async ({ name, github_url }) => {
7477
successMsg(`${name} installed`)
7578
} catch (e) {
7679
status.stop()
77-
return errorMsg(e)
80+
errorMsg(e)
7881
}
7982
}
8083
}
@@ -100,16 +103,15 @@ const removePlugin = async (plugLine) => {
100103
successMsg(`${plugName} uninstalled\n`)
101104
} catch (e) {
102105
status.stop()
103-
return errorMsg(e)
106+
errorMsg(e)
104107
}
105108
}
106109

107-
// TODO: Update plugins
108-
109110
module.exports = {
110111
getCurrentDir: () => path.basename(process.cwd()),
111112
dirExists: (fpath) => fs.existsSync(fpath),
112113
getConfigPlugins,
113114
savePlugin,
114-
removePlugin
115+
removePlugin,
116+
updatePlugins
115117
}

lib/prompts.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ const askPluginSelection = (plugins) =>
5656
value: p,
5757
short: `${p.name} - ${emojify(p.short_desc)}`
5858
}))
59+
},
60+
{
61+
name: 'action',
62+
type: 'list',
63+
choices: ['info', 'install', 'back', 'exit'],
64+
default: 'info'
5965
}
6066
])
6167

@@ -76,7 +82,7 @@ const installedPluginsList = async () => {
7682
{
7783
name: 'action',
7884
type: 'list',
79-
choices: ['update', 'info', 'uninstall', 'back', 'exit']
85+
choices: ['info', 'uninstall', 'back', 'exit']
8086
}
8187
])
8288
}
@@ -86,7 +92,7 @@ const menuSelection = () =>
8692
{
8793
name: 'command',
8894
type: 'list',
89-
choices: ['query', 'install', 'list', 'exit'],
95+
choices: ['query', 'list', 'update', 'exit'],
9096
default: 'query'
9197
}
9298
])

0 commit comments

Comments
 (0)