Skip to content

Commit

Permalink
feat: show version after uninstalling
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Jun 1, 2018
1 parent de3bf4e commit c1c69ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/commands/plugins/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ Can be installed from npm or a git url.
async run() {
const {flags, argv} = this.parse(PluginsInstall)
if (flags.verbose) this.plugins.verbose = true
for (let plugin of argv) {
let p = parsePlugin(plugin)
for (let name of argv) {
let p = parsePlugin(name)
let plugin
if (p.type === 'npm') {
cli.action.start(`Installing plugin ${chalk.cyan(this.plugins.friendlyName(p.name))}`)
await this.plugins.install(p.name, p.tag)
plugin = await this.plugins.install(p.name, p.tag)
} else {
cli.action.start(`Installing plugin ${chalk.cyan(p.url)}`)
await this.plugins.install(p.url)
plugin = await this.plugins.install(p.url)
}
cli.action.stop()
cli.action.stop(`installed v${plugin.version}`)
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@ export default class Plugins {
return this.normalizePlugins(pjson.oclif.plugins)
}

async install(name: string, tag = 'latest') {
async install(name: string, tag = 'latest'): Promise<Config.IConfig> {
try {
const yarnOpts = {cwd: this.config.dataDir, verbose: this.verbose}
await this.createPJSON()
let plugin
if (name.includes(':')) {
// url
const url = name
await this.yarn.exec(['add', url], yarnOpts)
name = Object.entries((await this.pjson()).dependencies || {}).find(([, u]: any) => u === url)![0]
const plugin = await Config.load({devPlugins: false, userPlugins: false, root: path.join(this.config.dataDir, 'node_modules', name), name})
plugin = await Config.load({devPlugins: false, userPlugins: false, root: path.join(this.config.dataDir, 'node_modules', name), name})
await this.refresh(plugin.root)
if (!plugin.valid && !this.config.plugins.find(p => p.name === '@oclif/plugin-legacy')) {
throw new Error('plugin is invalid')
Expand All @@ -70,13 +71,14 @@ export default class Plugins {
name = unfriendly
}
await this.yarn.exec(['add', `${name}@${tag}`], yarnOpts)
const plugin = await Config.load({devPlugins: false, userPlugins: false, root: path.join(this.config.dataDir, 'node_modules', name), name})
plugin = await Config.load({devPlugins: false, userPlugins: false, root: path.join(this.config.dataDir, 'node_modules', name), name})
if (!plugin.valid && !this.config.plugins.find(p => p.name === '@oclif/plugin-legacy')) {
throw new Error('plugin is invalid')
}
await this.refresh(plugin.root)
await this.add({name, tag: range || tag, type: 'user'})
}
return plugin
} catch (err) {
await this.uninstall(name).catch(err => this.debug(err))
throw err
Expand Down

0 comments on commit c1c69ec

Please sign in to comment.