@@ -31,7 +31,6 @@ const RULES_SUBDIR = OutputSubdirectories.RULES
3131const GLOBAL_RULE_FILE = OutputFileNames . CURSOR_GLOBAL_RULE
3232const SKILLS_CURSOR_SUBDIR = OutputSubdirectories . CURSOR_SKILLS
3333const SKILLS_PROJECT_SUBDIR = 'skills'
34- const SKILL_FILE_NAME = OutputFileNames . SKILL
3534const PRESERVED_SKILLS = PreservedSkills . CURSOR
3635
3736type CursorOutputSource
@@ -201,47 +200,23 @@ export class CursorOutputPlugin extends AbstractOutputPlugin {
201200 ) : void => {
202201 const skillsSubDir
203202 = scope === 'global' ? SKILLS_CURSOR_SUBDIR : SKILLS_PROJECT_SUBDIR
204- for ( const skill of filteredSkills ) {
205- const skillName = this . getSkillName ( skill )
206- if ( this . isPreservedSkill ( skillName ) ) continue
207-
208- const skillDir = path . join ( baseDir , skillsSubDir , skillName )
209- declarations . push ( {
210- path : path . join ( skillDir , SKILL_FILE_NAME ) ,
211- scope,
212- source : { kind : 'skill' , skill} satisfies CursorOutputSource
213- } )
214-
215- if ( skill . childDocs != null ) {
216- for ( const childDoc of skill . childDocs ) {
217- declarations . push ( {
218- path : path . join (
219- skillDir ,
220- childDoc . relativePath . replace ( / \. m d x $ / , '.md' )
221- ) ,
222- scope,
223- source : {
224- kind : 'skillChildDoc' ,
225- content : childDoc . content as string
226- } satisfies CursorOutputSource
227- } )
228- }
229- }
230-
231- if ( skill . resources != null ) {
232- for ( const resource of skill . resources ) {
233- declarations . push ( {
234- path : path . join ( skillDir , resource . relativePath ) ,
235- scope,
236- source : {
237- kind : 'skillResource' ,
238- content : resource . content ,
239- encoding : resource . encoding
240- } satisfies CursorOutputSource
241- } )
242- }
203+ const writableSkills = filteredSkills . filter (
204+ skill => ! this . isPreservedSkill ( this . getSkillName ( skill ) )
205+ )
206+ this . appendSkillDeclarations (
207+ declarations ,
208+ baseDir ,
209+ scope ,
210+ writableSkills ,
211+ {
212+ skillSubDir : skillsSubDir ,
213+ buildSkillMainSource : skill => ( { kind : 'skill' , skill} ) ,
214+ buildSkillReferenceSource : childDoc => ( {
215+ kind : 'skillChildDoc' ,
216+ content : childDoc . content as string
217+ } )
243218 }
244- }
219+ )
245220 }
246221
247222 const pushSkillMcpDeclarations = (
@@ -251,23 +226,16 @@ export class CursorOutputPlugin extends AbstractOutputPlugin {
251226 ) : void => {
252227 const skillsSubDir
253228 = scope === 'global' ? SKILLS_CURSOR_SUBDIR : SKILLS_PROJECT_SUBDIR
254- for ( const skill of filteredMcpSkills ) {
255- if ( skill . mcpConfig == null ) continue
256-
257- const skillDir = path . join (
258- baseDir ,
259- skillsSubDir ,
260- this . getSkillName ( skill )
261- )
262- declarations . push ( {
263- path : path . join ( skillDir , MCP_CONFIG_FILE ) ,
264- scope,
265- source : {
266- kind : 'skillMcpConfig' ,
267- rawContent : skill . mcpConfig . rawContent
268- } satisfies CursorOutputSource
269- } )
270- }
229+ this . appendSkillMcpDeclarations (
230+ declarations ,
231+ baseDir ,
232+ scope ,
233+ filteredMcpSkills ,
234+ {
235+ skillSubDir : skillsSubDir ,
236+ fileName : MCP_CONFIG_FILE
237+ }
238+ )
271239 }
272240
273241 const pushMcpDeclaration = (
@@ -356,17 +324,13 @@ export class CursorOutputPlugin extends AbstractOutputPlugin {
356324 project . projectConfig ,
357325 'commands'
358326 )
359- for ( const command of filteredCommands ) {
360- declarations . push ( {
361- path : path . join (
362- baseDir ,
363- COMMANDS_SUBDIR ,
364- this . transformCommandName ( command , transformOptions )
365- ) ,
366- scope : 'project' ,
367- source : { kind : 'command' , command} satisfies CursorOutputSource
368- } )
369- }
327+ this . appendCommandDeclarations (
328+ declarations ,
329+ baseDir ,
330+ 'project' ,
331+ filteredCommands ,
332+ transformOptions
333+ )
370334 }
371335 }
372336
@@ -376,17 +340,13 @@ export class CursorOutputPlugin extends AbstractOutputPlugin {
376340 promptSourceProjectConfig ,
377341 'commands'
378342 )
379- for ( const command of filteredCommands ) {
380- declarations . push ( {
381- path : path . join (
382- globalDir ,
383- COMMANDS_SUBDIR ,
384- this . transformCommandName ( command , transformOptions )
385- ) ,
386- scope : 'global' ,
387- source : { kind : 'command' , command} satisfies CursorOutputSource
388- } )
389- }
343+ this . appendCommandDeclarations (
344+ declarations ,
345+ globalDir ,
346+ 'global' ,
347+ filteredCommands ,
348+ transformOptions
349+ )
390350 }
391351
392352 if ( rules != null && rules . length > 0 ) {
0 commit comments