-
Notifications
You must be signed in to change notification settings - Fork 22
/
index.ts
61 lines (54 loc) · 1.76 KB
/
index.ts
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
import color from '@oclif/color'
import {Command, flags} from '@oclif/command'
import {Plugin} from '@oclif/config'
import {cli} from 'cli-ux'
import Plugins from '../../plugins'
import {sortBy} from '../../util'
export default class PluginsIndex extends Command {
static flags = {
core: flags.boolean({description: 'show core plugins'})
}
static description = 'list installed plugins'
static examples = ['$ <%- config.bin %> plugins']
plugins = new Plugins(this.config)
async run() {
const {flags} = this.parse(PluginsIndex)
let plugins = this.config.plugins
sortBy(plugins, p => this.plugins.friendlyName(p.name))
if (!flags.core) {
plugins = plugins.filter(p => p.type !== 'core' && p.type !== 'dev')
}
if (!plugins.length) {
this.log('no plugins installed')
return
}
this.display(plugins as Plugin[])
}
private display(plugins: Plugin[]) {
for (let plugin of plugins.filter((p: Plugin) => !p.parent)) {
this.log(this.formatPlugin(plugin))
if (plugin.children && plugin.children.length) {
let tree = this.createTree(plugin)
tree.display(this.log)
}
}
}
private createTree(plugin: Plugin) {
let tree = cli.tree()
for (let p of plugin.children) {
const name = this.formatPlugin(p)
tree.insert(name, this.createTree(p))
}
return tree
}
private formatPlugin(plugin: any): string {
let output = `${this.plugins.friendlyName(plugin.name)} ${color.dim(plugin.version)}`
if (plugin.type !== 'user')
output += color.dim(` (${plugin.type})`)
if (plugin.type === 'link')
output += ` ${plugin.root}`
else if (plugin.tag && plugin.tag !== 'latest')
output += color.dim(` (${String(plugin.tag)})`)
return output
}
}