Skip to content

Commit c9f6c39

Browse files
committedJul 25, 2020
Moving to normal node setup without prettier
1 parent 3992809 commit c9f6c39

15 files changed

+1349
-9174
lines changed
 

‎.eslintrc.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
env:
2+
commonjs: true
23
es2020: true
34
node: true
45
extends:
56
- standard
67
parserOptions:
78
ecmaVersion: 11
8-
sourceType: module
99
rules: {}

‎index.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env node
2+
3+
const figlet = require('figlet')
4+
const clear = require('clear')
5+
const { Spinner } = require('clui')
6+
7+
const {
8+
normalMsg,
9+
errorMsg,
10+
infoMsg,
11+
successMsg
12+
} = require('./lib/colorStates')
13+
const { savePlugin } = require('./lib/files')
14+
const { fetchAllPlugins, queryPlugins } = require('./lib/api')
15+
const {
16+
askForVimInfo,
17+
askForQuery,
18+
askPluginSelection,
19+
menuSelection
20+
} = require('./lib/prompts')
21+
const store = require('./lib/store')
22+
23+
const sendCliHeading = () =>
24+
normalMsg(
25+
figlet.textSync('vaq', {
26+
font: 'Doom',
27+
horizontalLayout: 'full'
28+
})
29+
)
30+
31+
const runCommand = async (command) => {
32+
if (command === 'query') {
33+
const { query } = await askForQuery()
34+
const results = await queryPlugins({ query })
35+
const { selection } = await askPluginSelection(results.plugins)
36+
37+
savePlugin(selection.github_url)
38+
}
39+
}
40+
41+
const runMenu = async () => {
42+
const { command } = await menuSelection()
43+
runCommand(command)
44+
}
45+
46+
const run = async () => {
47+
clear()
48+
sendCliHeading()
49+
50+
if (!store.get('vimpath')) {
51+
const { vimpath, vimtype } = await askForVimInfo()
52+
53+
const status = new Spinner('Getting set up...')
54+
status.start()
55+
56+
store.set('vimpath', vimpath)
57+
store.set('vimtype', vimtype)
58+
59+
status.stop()
60+
61+
successMsg("Saved. Let's continue...")
62+
63+
runMenu()
64+
65+
// display options
66+
} else {
67+
runMenu()
68+
}
69+
}
70+
71+
run()

‎src/api.js ‎lib/api.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import axios from 'axios'
1+
const axios = require('axios')
22

33
// vim awesome api
44
const API = 'https://vimawesome.com/api/plugins'
@@ -9,4 +9,11 @@ const fetchPluginData = (pageNum = 1, query = '') =>
99
.then((res) => res.data)
1010
.catch((err) => console.log(err))
1111

12-
export const fetchAllPlugins = async () => await fetchPluginData()
12+
const fetchAllPlugins = async () => await fetchPluginData()
13+
14+
const queryPlugins = async ({ query }) => await fetchPluginData(1, query)
15+
16+
module.exports = {
17+
fetchAllPlugins,
18+
queryPlugins
19+
}

‎lib/colorStates.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const chalk = require('chalk')
2+
3+
module.exports = {
4+
normalMsg: (msg) => console.log(chalk.yellow(msg)),
5+
errorMsg: (msg) => console.log(chalk.red(msg)),
6+
infoMsg: (msg) => console.log(chalk.blue(msg)),
7+
successMsg: (msg) => console.log(chalk.green(msg))
8+
}

‎lib/files.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
4+
module.exports = {
5+
getCurrentDir: () => path.basename(process.cwd()),
6+
dirExists: (fpath) => fs.existsSync(fpath)
7+
}

‎lib/index.js

-1,280
This file was deleted.

‎lib/prompts.js

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const inquirer = require('inquirer')
2+
3+
const askForVimInfo = () => {
4+
const questions = [
5+
{
6+
name: 'vimpath',
7+
type: 'input',
8+
message: 'What is the path to your vim config file using vim-plug?',
9+
validate: (val) => {
10+
if (val.length) {
11+
return true
12+
} else {
13+
return 'Please enter a path to your vim config file'
14+
}
15+
}
16+
},
17+
{
18+
name: 'vimtype',
19+
type: 'list',
20+
message: 'Are you using neovim (nvim) or vim?',
21+
choices: ['nvim', 'vim'],
22+
default: 'vim'
23+
}
24+
]
25+
26+
return inquirer.prompt(questions)
27+
}
28+
29+
const askForQuery = () =>
30+
inquirer.prompt([
31+
{
32+
name: 'query',
33+
type: 'input',
34+
message: 'query',
35+
validate: (val) => {
36+
if (val.length === 0) {
37+
return 'Must supply a name'
38+
} else {
39+
return true
40+
}
41+
}
42+
}
43+
])
44+
45+
const askPluginSelection = (plugins) =>
46+
inquirer.prompt([
47+
{
48+
name: 'selection',
49+
type: 'list',
50+
choices: plugins.map((p) => ({
51+
name: `${p.name} - ${p.short_desc}`,
52+
value: p,
53+
short: `${p.name} - ${p.short_desc}`
54+
}))
55+
}
56+
])
57+
58+
const menuSelection = () =>
59+
inquirer.prompt([
60+
{
61+
name: 'command',
62+
type: 'list',
63+
choices: ['query', 'install', 'uninstall', 'list'],
64+
default: 'query'
65+
}
66+
])
67+
68+
module.exports = {
69+
askForVimInfo,
70+
askForQuery,
71+
askPluginSelection,
72+
menuSelection
73+
}

‎lib/store.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const Configstore = require('configstore')
2+
3+
const store = new Configstore('vaq')
4+
5+
module.exports = store

‎package-lock.json

+1,162-7,791
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
{
22
"name": "vaq",
33
"version": "1.0.0",
4-
"description": "",
4+
"description": "A cli for managing vim plugins through vim-plug",
55
"bin": {
6-
"vaq": "./lib/index.js"
6+
"vaq": "index.js"
77
},
88
"scripts": {
9-
"build": "rm -rf lib && parcel build src/vaq.js --target node --bundle-node-modules -d lib --no-source-maps --out-file index.js",
109
"test": "echo \"Error: no test specified\" && exit 1"
1110
},
12-
"keywords": [],
13-
"author": "",
11+
"keywords": [
12+
"node",
13+
"cli",
14+
"vim",
15+
"neovim",
16+
"nvim",
17+
"vim-plug",
18+
"automation"
19+
],
20+
"author": "Josh Waller",
1421
"license": "ISC",
1522
"devDependencies": {
16-
"@babel/node": "^7.10.5",
1723
"eslint": "^7.5.0",
1824
"eslint-config-standard": "^14.1.1",
1925
"eslint-plugin-import": "^2.22.0",
2026
"eslint-plugin-node": "^11.1.0",
2127
"eslint-plugin-promise": "^4.2.1",
22-
"eslint-plugin-standard": "^4.0.1",
23-
"parcel-bundler": "^1.12.4"
28+
"eslint-plugin-standard": "^4.0.1"
2429
},
2530
"dependencies": {
2631
"axios": "^0.19.2",

‎src/colorStates.js

-9
This file was deleted.

‎src/files.js

-6
This file was deleted.

‎src/prompts.js

-27
This file was deleted.

‎src/store.js

-5
This file was deleted.

‎src/vaq.js

-45
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.