Skip to content

Commit

Permalink
feat(manager): use group@name for plugin groups
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jun 8, 2022
1 parent 36f4ed8 commit 104b942
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/cli/src/worker/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ export default class Loader extends ConfigLoader<App.Config> {
const { context } = fork.runtime
for (const name in plugins || {}) {
if (name.startsWith('~') || name.startsWith('$')) continue
if (name.startsWith('+')) {
record[name] = this.loadGroup(name.slice(1), plugins[name], context)
if (name.startsWith('group@')) {
record[name] = this.loadGroup(name.slice(6), plugins[name], context)
} else {
this.reloadPlugin(fork.runtime, name, plugins[name])
}
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/worker/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class Watcher {
for (const name in { ...old, ...neo }) {
if (name.startsWith('~') || name.startsWith('$')) continue
const fork = runtime[Loader.kRecord][name]
if (name.startsWith('+')) {
if (name.startsWith('group@')) {
// handle group config changes
if (!fork) {
// load new group
Expand All @@ -153,7 +153,7 @@ class Watcher {
} else {
fork.dispose()
delete runtime[Loader.kRecord][name]
this.ctx.logger('app').info(`unload group %c`, name.slice(1))
this.ctx.logger('app').info(`unload group %c`, name.slice(6))
}
} else {
// handle plugin config changes
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"dependencies": {
"@koishijs/utils": "^5.4.5",
"cordis": "^1.3.1",
"cordis": "^1.3.2",
"fastest-levenshtein": "^1.0.12",
"minato": "^1.1.0"
}
Expand Down
1 change: 1 addition & 0 deletions plugins/frontend/client/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface RouteMetaExtension {

export interface PageOptions extends RouteMetaExtension, PageExtension {
path: string
strict?: boolean
component: Component
}

Expand Down
1 change: 1 addition & 0 deletions plugins/frontend/manager/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default (ctx: Context) => {
icon: 'cog',
order: 630,
authority: 4,
strict: true,
fields: ['config', 'packages', 'services', 'dependencies'],
component: Settings,
})
Expand Down
2 changes: 1 addition & 1 deletion plugins/frontend/manager/client/settings/group.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const props = defineProps<{
function addPlugin() {
const tree: Tree = {
label: '',
path: props.current.path ? props.current.path + '/$' : '$',
path: props.current.path + '$',
config: {},
disabled: true,
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/frontend/manager/client/settings/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ import GroupSettings from './group.vue'
import TreeView from './tree.vue'
import PluginSettings from './plugin.vue'
function join(source: string | string[]) {
return Array.isArray(source) ? source.join('/') : source || ''
function join(source: string | string[], trailing = false) {
return Array.isArray(source) ? source.join('/') + (trailing ? '/' : '') : source || ''
}
const route = useRoute()
const router = useRouter()
const path = computed<string>({
get() {
const name = join(route.params.name)
const name = join(route.params.name, route.fullPath.endsWith('/'))
return name in plugins.value.paths ? name : '@global'
},
set(name) {
Expand Down
4 changes: 3 additions & 1 deletion plugins/frontend/manager/client/settings/tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ function handleDrop(source: Node, target: Node, position: 'before' | 'after' | '
const oldPath = source.data.path
const ctxPath = parent.data.path
const index = parent.childNodes.findIndex(node => node.data.path === oldPath)
send('manager/teleport', oldPath, ctxPath, index)
if (!oldPath.endsWith('$')) {
send('manager/teleport', oldPath, ctxPath, index)
}
const segments1 = oldPath.split('/')
const segments2 = ctxPath ? ctxPath.split('/') : []
segments2.push(segments1.pop())
Expand Down
7 changes: 4 additions & 3 deletions plugins/frontend/manager/client/settings/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Dict } from 'koishi'
import { computed, reactive, watch } from 'vue'
import { computed } from 'vue'
import { PackageJson } from '@koishijs/market'
import { MarketProvider } from '@koishijs/plugin-manager'
import { store } from '@koishijs/client'
Expand Down Expand Up @@ -115,8 +115,9 @@ function getTree(prefix: string, plugins: any): Tree[] {
if (key.startsWith('~')) {
node.disabled = true
}
if (key.startsWith('+')) {
node.label = '分组:' + label.slice(1)
if (key.startsWith('group@')) {
node.path += '/'
node.label = '分组:' + label.slice(6)
node.children = getTree(path + '/', config)
}
trees.push(node)
Expand Down

0 comments on commit 104b942

Please sign in to comment.