@@ -4,15 +4,26 @@ import * as fs from 'fs';
44import { reactComponentFactory } from '../factory/ReactComponent.factory' ;
55import { barrelFileFactory } from '../factory/BarrelFile.factory' ;
66
7- export const createReactComponent = ( dirPath : string , componentName : string ) => {
8- vscode . window . showInformationMessage ( dirPath , componentName ) ;
7+ export const createReactComponentCommand = ( uri : vscode . Uri ) => {
8+ if ( uri && uri . fsPath ) {
9+ const dirPath = uri . fsPath ;
910
10- const componentDir = path . join ( dirPath , componentName ) ;
11- fs . mkdirSync ( componentDir ) ;
11+ vscode . window . showInputBox ( {
12+ prompt : 'Enter React component name' ,
13+ placeHolder : 'MyComponent'
14+ } ) . then ( componentName => {
15+ if ( componentName ) {
16+ vscode . window . showInformationMessage ( dirPath , componentName ) ;
1217
13- const componentContent = reactComponentFactory ( componentName ) ;
14- const barrelFileContent = barrelFileFactory ( componentName ) ;
15-
16- fs . writeFileSync ( path . join ( componentDir , `${ componentName } .tsx` ) , componentContent ) ;
17- fs . writeFileSync ( path . join ( componentDir , `index.ts` ) , barrelFileContent ) ;
18+ const componentDir = path . join ( dirPath , componentName ) ;
19+ fs . mkdirSync ( componentDir ) ;
20+
21+ const componentContent = reactComponentFactory ( componentName ) ;
22+ const barrelFileContent = barrelFileFactory ( componentName ) ;
23+
24+ fs . writeFileSync ( path . join ( componentDir , `${ componentName } .tsx` ) , componentContent ) ;
25+ fs . writeFileSync ( path . join ( componentDir , `index.ts` ) , barrelFileContent ) ;
26+ }
27+ } ) ;
28+ }
1829} ;
0 commit comments