File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ import * as vscode from 'vscode' ;
2
+ import * as fs from 'fs' ;
3
+ import * as fspath from 'path' ;
4
+ import { reactHOCFactory } from '../factory/ReactHOC.factory' ;
5
+
6
+ export const createReactHOCCommand = ( uri : vscode . Uri ) => {
7
+ const path = uri . fsPath ;
8
+
9
+ vscode . window . showInputBox ( {
10
+ prompt : 'Enter React hoc name' ,
11
+ placeHolder : 'withMyHOC' ,
12
+ } ) . then ( ( hocName ) => {
13
+ if ( hocName ) {
14
+ const hocFileContent = reactHOCFactory ( hocName ) ;
15
+
16
+ fs . writeFileSync (
17
+ fspath . join ( path , `${ hocName } .hoc.tsx` ) ,
18
+ hocFileContent ,
19
+ ) ;
20
+ }
21
+ } ) ;
22
+ } ;
Original file line number Diff line number Diff line change 1
1
import * as vscode from 'vscode' ;
2
2
import { createReactComponentCommand } from "../commands/CreateReactComponent.command" ;
3
3
import { createReactHookCommand } from '../commands/CreateReactHook.factory' ;
4
+ import { createReactHOCCommand } from '../commands/CreateReactHOC.command' ;
4
5
5
6
export const commandsFactory = ( context : vscode . ExtensionContext ) => {
6
7
commands . forEach ( ( command ) => {
@@ -13,6 +14,10 @@ const commands = [
13
14
'vscode-react-developer-toolkit.createReactComponent' ,
14
15
createReactComponentCommand ,
15
16
) ,
17
+ vscode . commands . registerCommand (
18
+ 'vscode-react-developer-toolkit.createReactHOC' ,
19
+ createReactHOCCommand ,
20
+ ) ,
16
21
vscode . commands . registerCommand (
17
22
'vscode-react-developer-toolkit.createReactHook' ,
18
23
createReactHookCommand ,
Original file line number Diff line number Diff line change
1
+ export const reactHOCFactory = ( hocName : string ) => `import { ComponentType } from 'react';
2
+
3
+ export type IComponentRequiredProps = {
4
+ // Write required props.
5
+ };
6
+
7
+ export function ${ hocName } <P = IComponentRequiredProps>(Component: ComponentType<P>) {
8
+ return function(props: P) {
9
+ return (
10
+ <Component { ...props as any } />
11
+ );
12
+ };
13
+ };
14
+
15
+ export default ${ hocName } ;
16
+ ` ;
You can’t perform that action at this time.
0 commit comments