Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: display nested plugins as a tree #65

Merged
merged 11 commits into from
Jan 2, 2019
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@oclif/color": "^0.0.0",
"@oclif/command": "^1.5.4",
"chalk": "^2.4.1",
"cli-ux": "^4.9.3",
"cli-ux": "^5.0.0",
"debug": "^4.1.0",
"fs-extra": "^7.0.1",
"http-call": "^5.2.2",
Expand All @@ -19,7 +19,7 @@
"yarn": "^1.12.3"
},
"devDependencies": {
"@oclif/config": "^1.9.0",
"@oclif/config": "^1.10.3",
"@oclif/dev-cli": "^1.19.4",
"@oclif/errors": "^1.2.2",
"@oclif/plugin-help": "^2.1.4",
Expand Down
38 changes: 32 additions & 6 deletions src/commands/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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'
Expand All @@ -24,12 +26,36 @@ export default class PluginsIndex extends Command {
this.log('no plugins installed')
return
}
for (let plugin of plugins) {
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)})`)
this.log(output)
this.display(plugins)
}

private display(plugins: Plugin[]) {
for (let plugin of plugins.filter((p: Plugin) => !p.parent)) {
this.log(this.formatPlugin(plugin))
if (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
}
}
2 changes: 2 additions & 0 deletions src/commands/plugins/uninstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export default class PluginsUninstall extends Command {
cli.action.start(`Uninstalling ${friendly}`)
const unfriendly = await this.plugins.hasPlugin(plugin)
if (!unfriendly) {
const p = this.config.plugins.find(p => p.name === plugin)
if (p && p.parent) return this.error(`${friendly} is installed via plugin ${p.parent!.name}, uninstall ${p.parent!.name} instead`)
return this.error(`${friendly} is not installed`)
}
await this.plugins.uninstall(unfriendly.name)
Expand Down
55 changes: 41 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@
debug "^3.1.0"
semver "^5.5.0"

"@oclif/command@^1.5.1":
version "1.5.8"
resolved "https://registry.yarnpkg.com/@oclif/command/-/command-1.5.8.tgz#cd09d4f3183123548cb25d1b12b92e41277ac3e9"
integrity sha512-+Xuqp7by9jmB+GvR2r450wUXkCpZVdeOXQD0mLSEm3h+Mxhp0NPHuhzXZQvLI0/2fXR+cmJLv1CfpaCYaflL/g==
dependencies:
"@oclif/errors" "^1.2.2"
"@oclif/parser" "^3.7.2"
debug "^4.1.0"
semver "^5.6.0"

"@oclif/command@^1.5.4":
version "1.5.4"
resolved "https://registry.yarnpkg.com/@oclif/command/-/command-1.5.4.tgz#659456def965454e1c0115e8265533980eefb200"
Expand All @@ -63,18 +73,18 @@
debug "^4.1.0"
semver "^5.6.0"

"@oclif/config@^1.8.7":
version "1.8.7"
resolved "https://registry.yarnpkg.com/@oclif/config/-/config-1.8.7.tgz#b42cf0a2b5eaee14fb2eb80a26a903c747f5421f"
integrity sha512-2pMMOC4gL/vkxXskhqFwoS7Cs3qZ5yXgrUd6GGQ3kkaJiz+8Y8bM80CTBiC2SuraZYPO/1GWtqUQzkXn9I0khg==
"@oclif/config@^1.10.3":
version "1.10.3"
resolved "https://registry.yarnpkg.com/@oclif/config/-/config-1.10.3.tgz#401c12bd40e1073d2c2051aa1c991cdc5fb9fca3"
integrity sha512-F3G4kZZ4kMHlyOcNZiztT4E6E7LzFGlTfxyXIOax+D+3drK5fFkZXLr1Bjs5otdtd2jDFT3CpO7Qrkc9hYZUmA==
dependencies:
debug "^4.1.0"
tslib "^1.9.3"

"@oclif/config@^1.9.0":
version "1.9.0"
resolved "https://registry.yarnpkg.com/@oclif/config/-/config-1.9.0.tgz#f0df483bad3988f24cddd4d85fdc8eafa9eb7ff2"
integrity sha512-R9HJvS7x4Ff/VFGlg8b7hxFnuC77y7znr1iXwRay4Jhd/EFJyZRT9d9SHzA6TS8lz9vDTW93xOFakT9AXld4Kg==
"@oclif/config@^1.8.7":
version "1.8.7"
resolved "https://registry.yarnpkg.com/@oclif/config/-/config-1.8.7.tgz#b42cf0a2b5eaee14fb2eb80a26a903c747f5421f"
integrity sha512-2pMMOC4gL/vkxXskhqFwoS7Cs3qZ5yXgrUd6GGQ3kkaJiz+8Y8bM80CTBiC2SuraZYPO/1GWtqUQzkXn9I0khg==
dependencies:
debug "^4.1.0"
tslib "^1.9.3"
Expand Down Expand Up @@ -107,7 +117,7 @@
strip-ansi "^4.0.0"
wrap-ansi "^3.0.1"

"@oclif/errors@^1.2.2":
"@oclif/errors@^1.2.1", "@oclif/errors@^1.2.2":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@oclif/errors/-/errors-1.2.2.tgz#9d8f269b15f13d70aa93316fed7bebc24688edc2"
integrity sha512-Eq8BFuJUQcbAPVofDxwdE0bL14inIiwt5EaKRVY9ZDIG11jwdXZqiQEECJx0VfnLyUZdYfRd/znDI/MytdJoKg==
Expand All @@ -132,6 +142,15 @@
chalk "^2.4.1"
tslib "^1.9.3"

"@oclif/parser@^3.7.2":
version "3.7.2"
resolved "https://registry.yarnpkg.com/@oclif/parser/-/parser-3.7.2.tgz#b06c73377a1f027f10444109a8a4a6cc31ffd8ba"
integrity sha512-ssYXztaf9TuOGCJQOYMg62L1Q4y2lB4wZORWng+Iy0ckP2A6IUnQy97V8YjAJkkohYZOu3Mga8LGfQcf+xdIIw==
dependencies:
"@oclif/linewrap" "^1.0.0"
chalk "^2.4.1"
tslib "^1.9.3"

"@oclif/plugin-help@^2.1.2":
version "2.1.2"
resolved "https://registry.yarnpkg.com/@oclif/plugin-help/-/plugin-help-2.1.2.tgz#b6639e95157f563225a29b4329ce62e2e162afe9"
Expand Down Expand Up @@ -548,12 +567,13 @@ cli-ux@^4.9.0:
supports-hyperlinks "^1.0.1"
treeify "^1.1.0"

cli-ux@^4.9.3:
version "4.9.3"
resolved "https://registry.yarnpkg.com/cli-ux/-/cli-ux-4.9.3.tgz#4c3e070c1ea23eef010bbdb041192e0661be84ce"
integrity sha512-/1owvF0SZ5Gn54cgrikJ0QskgTzeg30HGjkmjFoaHDJzAqFpuX1DBpFR8aLvsE1J5s9MgeYRENQK4BFwOag5VA==
cli-ux@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/cli-ux/-/cli-ux-5.0.0.tgz#62dd504d92cb5e4d03c63b67bf76f049046e8bdc"
integrity sha512-oW3MsKNPYG3PT2DUEs+dAMaackpzO0bof6JTdqk2SEch+pww93C+3hpXKvSycMPBEgjGPkJ3tl39VkebrkckAA==
dependencies:
"@oclif/errors" "^1.2.2"
"@oclif/command" "^1.5.1"
"@oclif/errors" "^1.2.1"
"@oclif/linewrap" "^1.0.0"
"@oclif/screen" "^1.0.3"
ansi-escapes "^3.1.0"
Expand All @@ -567,8 +587,10 @@ cli-ux@^4.9.3:
indent-string "^3.2.0"
is-wsl "^1.1.0"
lodash "^4.17.11"
natural-orderby "^1.0.2"
password-prompt "^1.0.7"
semver "^5.6.0"
string-width "^2.1.1"
strip-ansi "^5.0.0"
supports-color "^5.5.0"
supports-hyperlinks "^1.0.1"
Expand Down Expand Up @@ -1499,6 +1521,11 @@ nanomatch@^1.2.9:
snapdragon "^0.8.1"
to-regex "^3.0.1"

natural-orderby@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/natural-orderby/-/natural-orderby-1.0.2.tgz#287a4778217fbf6af0d704129d55ae90450f7a88"
integrity sha512-V2CMcGpkL078lsYpUUjuZrFsYzdvL0eETYvw9N4dwQsz2gV8QMbKyJBgGdF6Xwg9OuZBzCvfbKu8ex2JXp8Cbw==

nice-try@^1.0.4:
version "1.0.5"
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
Expand Down