Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/commands/CreateReactHOC.command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as vscode from 'vscode';
import * as fs from 'fs';
import * as fspath from 'path';
import { reactHOCFactory } from '../factory/ReactHOC.factory';

export const createReactHOCCommand = (uri: vscode.Uri) => {
const path = uri.fsPath;

vscode.window.showInputBox({
prompt: 'Enter React hoc name',
placeHolder: 'withMyHOC',
}).then((hocName) => {
if (hocName) {
const hocFileContent = reactHOCFactory(hocName);

fs.writeFileSync(
fspath.join(path, `${hocName}.hoc.tsx`),
hocFileContent,
);
}
});
};
5 changes: 5 additions & 0 deletions src/factory/Commands.factory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from 'vscode';
import { createReactComponentCommand } from "../commands/CreateReactComponent.command";
import { createReactHookCommand } from '../commands/CreateReactHook.factory';
import { createReactHOCCommand } from '../commands/CreateReactHOC.command';

export const commandsFactory = (context: vscode.ExtensionContext) => {
commands.forEach((command) => {
Expand All @@ -13,6 +14,10 @@ const commands = [
'vscode-react-developer-toolkit.createReactComponent',
createReactComponentCommand,
),
vscode.commands.registerCommand(
'vscode-react-developer-toolkit.createReactHOC',
createReactHOCCommand,
),
vscode.commands.registerCommand(
'vscode-react-developer-toolkit.createReactHook',
createReactHookCommand,
Expand Down
16 changes: 16 additions & 0 deletions src/factory/ReactHOC.factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const reactHOCFactory = (hocName: string) => `import { ComponentType } from 'react';

export type IComponentRequiredProps = {
// Write required props.
};

export function ${hocName}<P = IComponentRequiredProps>(Component: ComponentType<P>) {
return function(props: P) {
return (
<Component { ...props as any } />
);
};
};

export default ${hocName};
`;