11import { window , workspace , Uri } from 'vscode' ;
2- import { trim , capitalize , replace , split } from 'string-ts' ;
2+ import { trim , capitalize , replace , split , endsWith } from 'string-ts' ;
33import { existsSync , mkdirSync , readdirSync } from 'fs' ;
44import { join } from 'pathe' ;
55import { TextEncoder } from 'util' ;
@@ -36,7 +36,7 @@ export const createDirectoryAndFile = (componentName: any, commandType: string,
3636 createFile ( {
3737 fileName : componentName ,
3838 content,
39- fullPath : `${ projectSrcDirectory ( ) } /${ type . path } /${ name } /${ componentName } ${ type . extension } ` ,
39+ fullPath : `${ projectSrcDirectory ( ) } /${ type . path } /${ name } /${ normalizeFileExtension ( componentName , type . extension ) } ${ type . extension } ` ,
4040 } ) ;
4141 } else {
4242 window . showWarningMessage (
@@ -88,8 +88,10 @@ export const showSubFolderQuickPick = (args: {
8888 content : any
8989} ) => {
9090
91+
9192 const { type } = getCommandType ( args . commandType ) ;
9293
94+
9395 window
9496 . showQuickPick ( args . subFolders , { placeHolder : 'Select a subfolder' } )
9597 . then ( ( selection ) => {
@@ -98,18 +100,19 @@ export const showSubFolderQuickPick = (args: {
98100 }
99101 switch ( selection ) {
100102 case `Main ${ type . name . toLocaleLowerCase ( ) } folder` :
101- const path = `${ args . name } ${ type . extension } ` ;
103+ const path = `${ normalizeFileExtension ( args . name , type . extension ) } ${ type . extension } ` ;
102104 createFile ( {
103105 fileName : args . name ,
104106 content : args . content ,
105107 fullPath : `${ projectSrcDirectory ( ) } /${ type . path } /${ path } ` ,
106108 } ) ;
107109 break ;
108110 case 'Create new folder...' :
109- createDirectoryAndFile ( args . name , type . name , args . content ) ;
111+ createDirectoryAndFile ( normalizeFileExtension ( args . name , type . extension ) , type . name , args . content ) ;
110112 break ;
111113 default :
112- const fileNameAndPath = `${ selection } /${ args . name } ${ type . extension } ` ;
114+ const fileNameAndPath = `${ selection } /${ normalizeFileExtension ( args . name , type . extension ) } ${ type . extension } ` ;
115+
113116 createFile ( {
114117 fileName : args . name ,
115118 content : args . content ,
@@ -171,4 +174,6 @@ export const createVueTemplate = (content: string, type: string) => {
171174
172175} ;
173176
174- export const normalizeName = ( name : string , capital ?: boolean ) => split ( trim ( name ) , "-" ) . map ( capitalize ) . join ( '' ) ;
177+ export const normalizeName = ( name : string , capital ?: boolean ) => split ( trim ( split ( name , '.' ) [ 0 ] ) , "-" ) . map ( capitalize ) . join ( '' ) ;
178+
179+ export const normalizeFileExtension = ( name : string , extension : string ) => endsWith ( name , extension ) ? replace ( name , extension , '' ) : name
0 commit comments