MCPcopy Index your code
hub / github.com/codeaashu/claude-code / getCommandNameFromFile

Function getCommandNameFromFile

src/utils/plugins/loadPluginCommands.ts:60–97  ·  view source on GitHub ↗

* Get command name from file path, handling both regular files and skills

(
  filePath: string,
  baseDir: string,
  pluginName: string,
)

Source from the content-addressed store, hash-verified

58 * Get command name from file path, handling both regular files and skills
59 */
60function getCommandNameFromFile(
61 filePath: string,
62 baseDir: string,
63 pluginName: string,
64): string {
65 const isSkill = isSkillFile(filePath)
66
67 if (isSkill) {
68 // For skills, use the parent directory name
69 const skillDirectory = dirname(filePath)
70 const parentOfSkillDir = dirname(skillDirectory)
71 const commandBaseName = basename(skillDirectory)
72
73 // Build namespace from parent of skill directory
74 const relativePath = parentOfSkillDir.startsWith(baseDir)
75 ? parentOfSkillDir.slice(baseDir.length).replace(/^\//, '')
76 : ''
77 const namespace = relativePath ? relativePath.split('/').join(':') : ''
78
79 return namespace
80 ? `${pluginName}:${namespace}:${commandBaseName}`
81 : `${pluginName}:${commandBaseName}`
82 } else {
83 // For regular files, use filename without .md
84 const fileDirectory = dirname(filePath)
85 const commandBaseName = basename(filePath).replace(/\.md$/, '')
86
87 // Build namespace from file directory
88 const relativePath = fileDirectory.startsWith(baseDir)
89 ? fileDirectory.slice(baseDir.length).replace(/^\//, '')
90 : ''
91 const namespace = relativePath ? relativePath.split('/').join(':') : ''
92
93 return namespace
94 ? `${pluginName}:${namespace}:${commandBaseName}`
95 : `${pluginName}:${commandBaseName}`
96 }
97}
98
99/**
100 * Recursively collects all markdown files from a directory

Callers 1

Calls 1

isSkillFileFunction · 0.70

Tested by

no test coverage detected