Skip to content

Commit

Permalink
feat(cli): support object/function plugin type
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 18, 2020
1 parent 34ebc6e commit 37e4bdd
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/koishi-cli/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function loadEcosystem (type: string, name: string) {
throw new Error(`cannot resolve ${type} ${name}`)
}

export type PluginConfig = (string | [string | Plugin, any?])[]
export type PluginConfig = (string | Plugin | [string | Plugin, any?])[]

export interface AppConfig extends AppOptions {
plugins?: PluginConfig | Record<string, PluginConfig>
Expand All @@ -54,11 +54,13 @@ export interface AppConfig extends AppOptions {
function loadPlugins (ctx: Context, plugins: PluginConfig) {
for (const item of plugins) {
let plugin: Plugin, options
if (typeof item === 'string') {
plugin = loadEcosystem('plugin', item)
} else {
if (Array.isArray(item)) {
plugin = typeof item[0] === 'string' ? loadEcosystem('plugin', item[0]) : item[0]
options = item[1]
} else if (typeof item === 'string') {
plugin = loadEcosystem('plugin', item)
} else {
plugin = item
}
ctx.plugin(plugin, options)
if (plugin.name) logger.info(`apply plugin ${cyan(plugin.name)}`, baseLogLevel)
Expand Down

0 comments on commit 37e4bdd

Please sign in to comment.