Skip to content

Commit

Permalink
feat: add plugins:post* hooks (#932)
Browse files Browse the repository at this point in the history
* feat: add `plugins:post`* hooks

* fix: handle multiple uninstalls
  • Loading branch information
cristiand391 committed Aug 1, 2024
1 parent b72147e commit 53725d5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/commands/plugins/install.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-await-in-loop */
import {Args, Command, Errors, Flags, Interfaces, ux} from '@oclif/core'
import {Args, Command, Errors, Flags, Interfaces, Plugin, ux} from '@oclif/core'
import {bold, cyan} from 'ansis'
import validate from 'validate-npm-package-name'

Expand Down Expand Up @@ -195,6 +195,12 @@ Use the <%= config.scopedEnvVarKey('NPM_REGISTRY') %> environment variable to se
throw error
}

const pluginInstance = new Plugin(plugin)
await pluginInstance.load()
this.config.plugins.set(pluginInstance.name, pluginInstance)

await this.config.runHook('plugins:postinstall', {})

ux.action.stop(`installed v${plugin.version}`)
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/commands/plugins/uninstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export default class PluginsUninstall extends Command {
logLevel: determineLogLevel(this.config, flags, 'silent'),
})

const pluginNameToDelete: string[] = []

if (argv.length === 0) argv.push('.')
for (const plugin of argv as string[]) {
const friendly = removeTags(plugins.friendlyName(plugin))
Expand All @@ -64,15 +66,22 @@ export default class PluginsUninstall extends Command {

try {
const {name} = unfriendly
const displayName = friendly === '.' ? name : friendly ?? name
const displayName = friendly === '.' ? name : (friendly ?? name)
ux.action.start(`${this.config.name}: Uninstalling ${displayName}`)
await plugins.uninstall(name)
pluginNameToDelete.push(name)
} catch (error) {
ux.action.stop(bold.red('failed'))
throw error
}

ux.action.stop()
}

for (const p of pluginNameToDelete) {
this.config.plugins.delete(p)
}

await this.config.runHook('plugins:postuninstall', {})
}
}

0 comments on commit 53725d5

Please sign in to comment.