Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
fix: set pluginType
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Feb 6, 2018
1 parent 7a9f531 commit 1ece4fb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface Command {
examples?: string[]
type?: string
pluginName?: string
pluginType?: string
flags: {[name: string]: Command.Flag}
args: {
name: string
Expand Down Expand Up @@ -80,6 +81,7 @@ export namespace Command {
description: c.description,
usage: c.usage,
pluginName: c.plugin && c.plugin.name,
pluginType: c.plugin && c.plugin.type,
hidden: c.hidden,
aliases: c.aliases || [],
examples: c.examples,
Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class Config extends Plugin.Plugin implements IConfig {
if (opts.devPlugins !== false) {
try {
const devPlugins = this.pjson.anycli.devPlugins
if (devPlugins) this.loadPlugins(this.root, devPlugins)
if (devPlugins) this.loadPlugins(this.root, 'dev', devPlugins)
} catch (err) {
process.emitWarning(err)
}
Expand All @@ -147,7 +147,7 @@ export class Config extends Plugin.Plugin implements IConfig {
const userPJSONPath = path.join(this.dataDir, 'package.json')
const pjson = this.userPJSON = loadJSONSync(userPJSONPath)
if (!pjson.anycli) pjson.anycli = {schema: 1}
this.loadPlugins(userPJSONPath, pjson.anycli.plugins)
this.loadPlugins(userPJSONPath, 'user', pjson.anycli.plugins)
} catch (err) {
if (err.code !== 'ENOENT') process.emitWarning(err)
}
Expand Down
7 changes: 3 additions & 4 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class Plugin implements IPlugin {
this.hooks = mapValues(this.pjson.anycli.hooks || {}, i => Array.isArray(i) ? i : [i])

this.manifest = this._manifest(!!opts.ignoreManifest)
this.loadPlugins(this.root, this.pjson.anycli.plugins || [])
this.loadPlugins(this.root, this.type, this.pjson.anycli.plugins || [])
this.addMissingTopics()
}

Expand Down Expand Up @@ -304,18 +304,17 @@ export class Plugin implements IPlugin {
}
}

protected loadPlugins(root: string, plugins: (string | PJSON.Plugin)[]) {
protected loadPlugins(root: string, type: string, plugins: (string | PJSON.Plugin)[]) {
if (!plugins.length) return
if (!plugins || !plugins.length) return
debug('loading plugins', plugins)
for (let plugin of plugins || []) {
try {
let opts: Options = {type: this.type, root}
let opts: Options = {type, root}
if (typeof plugin === 'string') {
opts.name = plugin
} else {
opts.name = plugin.name || opts.name
opts.type = plugin.type || opts.type
opts.tag = plugin.tag || opts.tag
opts.root = plugin.root || opts.root
}
Expand Down

0 comments on commit 1ece4fb

Please sign in to comment.