Skip to content

Commit ab9fa35

Browse files
committed
fix: category set to undefined if command file is not in category folder
1 parent d7b8335 commit ab9fa35

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/resolve.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import jiti from 'jiti'
2-
import { dirname } from 'pathe'
2+
import { resolve } from 'pathe'
33
import { filename } from 'pathe/utils'
44
import type {
55
ButtonConfig,
@@ -62,9 +62,14 @@ export const resolveCommand = (
6262
})
6363
const _cmdPath = _jiti.resolve(cmd)
6464
const command = _jiti(_cmdPath) as HarmonixCommand
65+
const relativePath = resolve(_cmdPath).replace(harmonixOptions.rootDir, '')
66+
const categoryMatch = relativePath.match(
67+
/\/commands\/(.+?)\/[^\/]+\.(ts|js)/
68+
)
69+
const category = categoryMatch ? categoryMatch[1] : undefined
6570
const config: CommandConfig = {
6671
name: command.config.name || filename(_cmdPath),
67-
category: command.config.category || filename(dirname(_cmdPath)),
72+
category: command.config.category ?? category,
6873
...command.config
6974
}
7075

0 commit comments

Comments
 (0)