-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (59 loc) · 2.3 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
const vorpal = require('vorpal')()
const inquirer = require('inquirer')
const fs = require('fs-extra')
const yaml = require('js-yaml')
vorpal
.command('init', 'Initializes the process of packages selection')
.action((args, cb) => {
// Role selection from command line
roleList = inquirer.prompt([
{
type: 'list',
message: 'Select your role:',
name: 'role',
choices: [
'Developer',
'Designer'
],
filter: val => val.toLowerCase()
}
], (result) => {
// Load json files
let role = result.role
const base = fs.readJsonSync('./roles/base.json')
const common = fs.readJsonSync('./roles/common.json')
const roleList = fs.readJsonSync(`./roles/${role}.json`)
// Generate system packages
let systemList = roleList.system.concat(base.system)
systemList = systemList.map(item => ({ checked: true, name: item, type: 'system' }))
systemList.unshift(new inquirer.Separator(' = System packages = '))
// Generate cask packages
let caskList = roleList.cask.concat(base.cask)
caskList = caskList.map(item => ({ checked: true, name: item, type: 'cask' }))
caskList.unshift(new inquirer.Separator(' = Applications = '))
// Complete package list to show to the user
const packagesList = (role == 'designer') ? caskList : caskList.concat(systemList)
// Package selection from command line
SoftwareList = inquirer.prompt([
{
type: 'checkbox',
message: `As a ${role} we think this software could be useful for you, after the selection press <Enter> to start the installation:\n`,
name: 'software',
choices: packagesList
}
], (result) => {
// Remove deselected packages
let userSystemList = systemList.filter(item => result.software.includes(item.name))
let userCaskList = caskList.filter(item => result.software.includes(item.name))
// Generate install.yml file
let tasks = common[0].tasks
tasks[0].homebrew.name = userSystemList.map(item => item.name)
tasks[2].homebrew_cask.name = userCaskList.map(item => item.name)
fs.writeFile('./install.yml', yaml.dump(common))
})
})
})
vorpal
.delimiter('sloth$')
.show()
.parse(process.argv)