forked from susthitsoft/orango
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (43 loc) · 1.2 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
const fs = require('fs')
const inquirer = require('inquirer')
const di = require('./helpers/di')
const setup = require('./setup')
const config = require('./config')
require('colors')
function humanize(str) {
var frags = str.split('_')
for (i = 0; i < frags.length; i++) {
frags[i] = frags[i].charAt(0).toUpperCase() + frags[i].slice(1)
}
return frags.join(' ')
}
console.log('🍊 Welcome to Orango examples!')
inquirer
.prompt([
{
type: 'list',
name: 'snippet',
message: 'Choose a snippet to run:',
choices() {
let files = fs.readdirSync(__dirname + '/snippets')
let choices = []
for (let i = 0; i < files.length; i++) {
let option = {
name: humanize(files[i].replace(/.\w+$/gi, '')),
value: files[i]
}
choices[i] = option
}
return choices
}
}
])
.then(async ({ snippet }) => {
if (snippet.match(/connect/gi)) {
const orango = require('../lib')
di.injectFile(__dirname + '/snippets/' + snippet, { orango, config })
} else {
const orango = await setup(config)
di.injectFile(__dirname + '/snippets/' + snippet, { orango, config })
}
})