1
1
import { window , workspace , Uri } from 'vscode' ;
2
- import { trim , capitalize , replace , split } from 'string-ts' ;
2
+ import { trim , capitalize , replace , split , endsWith } from 'string-ts' ;
3
3
import { existsSync , mkdirSync , readdirSync } from 'fs' ;
4
4
import { join } from 'pathe' ;
5
5
import { TextEncoder } from 'util' ;
@@ -36,7 +36,7 @@ export const createDirectoryAndFile = (componentName: any, commandType: string,
36
36
createFile ( {
37
37
fileName : componentName ,
38
38
content,
39
- fullPath : `${ projectSrcDirectory ( ) } /${ type . path } /${ name } /${ componentName } ${ type . extension } ` ,
39
+ fullPath : `${ projectSrcDirectory ( ) } /${ type . path } /${ name } /${ normalizeFileExtension ( componentName , type . extension ) } ${ type . extension } ` ,
40
40
} ) ;
41
41
} else {
42
42
window . showWarningMessage (
@@ -88,8 +88,10 @@ export const showSubFolderQuickPick = (args: {
88
88
content : any
89
89
} ) => {
90
90
91
+
91
92
const { type } = getCommandType ( args . commandType ) ;
92
93
94
+
93
95
window
94
96
. showQuickPick ( args . subFolders , { placeHolder : 'Select a subfolder' } )
95
97
. then ( ( selection ) => {
@@ -98,18 +100,19 @@ export const showSubFolderQuickPick = (args: {
98
100
}
99
101
switch ( selection ) {
100
102
case `Main ${ type . name . toLocaleLowerCase ( ) } folder` :
101
- const path = `${ args . name } ${ type . extension } ` ;
103
+ const path = `${ normalizeFileExtension ( args . name , type . extension ) } ${ type . extension } ` ;
102
104
createFile ( {
103
105
fileName : args . name ,
104
106
content : args . content ,
105
107
fullPath : `${ projectSrcDirectory ( ) } /${ type . path } /${ path } ` ,
106
108
} ) ;
107
109
break ;
108
110
case 'Create new folder...' :
109
- createDirectoryAndFile ( args . name , type . name , args . content ) ;
111
+ createDirectoryAndFile ( normalizeFileExtension ( args . name , type . extension ) , type . name , args . content ) ;
110
112
break ;
111
113
default :
112
- const fileNameAndPath = `${ selection } /${ args . name } ${ type . extension } ` ;
114
+ const fileNameAndPath = `${ selection } /${ normalizeFileExtension ( args . name , type . extension ) } ${ type . extension } ` ;
115
+
113
116
createFile ( {
114
117
fileName : args . name ,
115
118
content : args . content ,
@@ -171,4 +174,6 @@ export const createVueTemplate = (content: string, type: string) => {
171
174
172
175
} ;
173
176
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