Skip to content

Commit eccb3c5

Browse files
S
1 parent 01969e2 commit eccb3c5

File tree

10 files changed

+247
-42
lines changed

10 files changed

+247
-42
lines changed

Sources.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
https://www.robinwieruch.de/react-function-component
1+
https://www.robinwieruch.de/react-function-component
2+
3+
// if (args == null) {
4+
// args = { _fsPath: vscode.workspace.rootPath };
5+
// }
6+
// let incomingpath: string = args._fsPath;

package.json

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "create-reactjs-components",
33
"displayName": "create-reactjs-components",
4-
"description": "Options Menu",
5-
"version": "1.0.1",
4+
"description": "Create Component/Context Explorer Context",
5+
"version": "1.1.0",
66
"publisher": "canducci",
77
"icon": "images/logo-three.png",
88
"engines": {
@@ -29,7 +29,11 @@
2929
"onCommand:canducci.arrowFunctionComponentJs",
3030
"onCommand:canducci.functionComponentJs",
3131
"onCommand:canducci.arrowFunctionComponentJsx",
32-
"onCommand:canducci.functionComponentJsx"
32+
"onCommand:canducci.functionComponentJsx",
33+
"onCommand:canducci.createContextArrowFunctionJs",
34+
"onCommand:canducci.createContextFunctionJs",
35+
"onCommand:canducci.createContextArrowFunctionJsx",
36+
"onCommand:canducci.createContextFunctionJsx"
3337
],
3438
"main": "./out/extension.js",
3539
"contributes": {
@@ -42,34 +46,70 @@
4246
"command": "canducci.functionComponentJs",
4347
"title": "React Function Component (js)"
4448
},
49+
{
50+
"command": "canducci.createContextArrowFunctionJs",
51+
"title": "React Arrow Function Context (js)"
52+
},
53+
{
54+
"command": "canducci.createContextFunctionJs",
55+
"title": "React Function Context (js)"
56+
},
4557
{
4658
"command": "canducci.arrowFunctionComponentJsx",
4759
"title": "React Arrow Function Component (jsx)"
4860
},
4961
{
5062
"command": "canducci.functionComponentJsx",
5163
"title": "React Function Component (jsx)"
64+
},
65+
{
66+
"command": "canducci.createContextArrowFunctionJsx",
67+
"title": "React Arrow Function Context (jsx)"
68+
},
69+
{
70+
"command": "canducci.createContextFunctionJsx",
71+
"title": "React Function Context (jsx)"
5272
}
5373
],
5474
"menus": {
5575
"explorer/context": [
5676
{
5777
"command": "canducci.arrowFunctionComponentJs",
58-
"group": "2_modification",
78+
"group": "1_modification",
5979
"when": "explorerResourceIsFolder"
6080
},
6181
{
6282
"command": "canducci.functionComponentJs",
63-
"group": "2_modification",
83+
"group": "1_modification",
6484
"when": "explorerResourceIsFolder"
6585
},
6686
{
6787
"command": "canducci.arrowFunctionComponentJsx",
68-
"group": "2_modification",
88+
"group": "1_modification",
6989
"when": "explorerResourceIsFolder"
7090
},
7191
{
7292
"command": "canducci.functionComponentJsx",
93+
"group": "1_modification",
94+
"when": "explorerResourceIsFolder"
95+
},
96+
{
97+
"command": "canducci.createContextArrowFunctionJs",
98+
"group": "2_modification",
99+
"when": "explorerResourceIsFolder"
100+
},
101+
{
102+
"command": "canducci.createContextFunctionJs",
103+
"group": "2_modification",
104+
"when": "explorerResourceIsFolder"
105+
},
106+
{
107+
"command": "canducci.createContextArrowFunctionJsx",
108+
"group": "2_modification",
109+
"when": "explorerResourceIsFolder"
110+
},
111+
{
112+
"command": "canducci.createContextFunctionJsx",
73113
"group": "2_modification",
74114
"when": "explorerResourceIsFolder"
75115
}

src/extension.ts

Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,98 @@
11
import * as vscode from 'vscode';
2-
2+
import {
3+
arrowFunctionComponentJs,
4+
createContextArrowFunctionJs,
5+
createContextFunctionJs,
6+
functionComponentJs,
7+
} from './templates/js';
38
import {
49
arrowFunctionComponentJsx,
10+
createContextArrowFunctionJsx,
11+
createContextFunctionJsx,
512
functionComponentJsx,
6-
} from './templates/base/jsx';
7-
8-
import { functionComponentJs, arrowFunctionComponentJs } from './templates/js';
9-
13+
} from './templates/jsx';
1014
import createComponent from './utils/index';
15+
import {
16+
getProjectComponentFolder,
17+
getProjectContextFolder,
18+
} from './utils/operations';
1119

1220
export function activate(context: vscode.ExtensionContext) {
1321
const { registerCommand } = vscode.commands;
1422
let disposables = [
1523
/*Javascript*/
1624
registerCommand(
1725
'canducci.arrowFunctionComponentJs',
18-
async (args: any) => await createComponent(args, arrowFunctionComponentJs)
26+
async (args: any) =>
27+
await createComponent(
28+
args,
29+
arrowFunctionComponentJs,
30+
getProjectComponentFolder
31+
)
1932
),
2033
registerCommand(
2134
'canducci.functionComponentJs',
22-
async (args: any) => await createComponent(args, functionComponentJs)
35+
async (args: any) =>
36+
await createComponent(
37+
args,
38+
functionComponentJs,
39+
getProjectComponentFolder
40+
)
41+
),
42+
registerCommand(
43+
'canducci.createContextArrowFunctionJs',
44+
async (args: any) =>
45+
await createComponent(
46+
args,
47+
createContextArrowFunctionJs,
48+
getProjectContextFolder
49+
)
50+
),
51+
registerCommand(
52+
'canducci.createContextFunctionJs',
53+
async (args: any) =>
54+
await createComponent(
55+
args,
56+
createContextFunctionJs,
57+
getProjectContextFolder
58+
)
2359
),
2460
/*JavascriptReact*/
2561
registerCommand(
2662
'canducci.arrowFunctionComponentJsx',
2763
async (args: any) =>
28-
await createComponent(args, arrowFunctionComponentJsx)
64+
await createComponent(
65+
args,
66+
arrowFunctionComponentJsx,
67+
getProjectComponentFolder
68+
)
2969
),
3070
registerCommand(
3171
'canducci.functionComponentJsx',
32-
async (args: any) => await createComponent(args, functionComponentJsx)
72+
async (args: any) =>
73+
await createComponent(
74+
args,
75+
functionComponentJsx,
76+
getProjectComponentFolder
77+
)
78+
),
79+
registerCommand(
80+
'canducci.createContextArrowFunctionJsx',
81+
async (args: any) =>
82+
await createComponent(
83+
args,
84+
createContextArrowFunctionJsx,
85+
getProjectContextFolder
86+
)
87+
),
88+
registerCommand(
89+
'canducci.createContextFunctionJsx',
90+
async (args: any) =>
91+
await createComponent(
92+
args,
93+
createContextFunctionJsx,
94+
getProjectContextFolder
95+
)
3396
),
3497
];
3598

src/templates/base/index.ts

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { IComponentReturn } from './types';
22

3-
export function fctComponent(
3+
export function functionComponentBase(
44
name: string,
55
extension: string
66
): IComponentReturn {
77
return {
8+
title: 'Component',
89
extension: extension,
910
content: `
1011
import React from 'react';
@@ -20,11 +21,12 @@ export default ${name};
2021
};
2122
}
2223

23-
export function aFctComponent(
24+
export function arrowFunctionComponentBase(
2425
name: string,
2526
extension: string
2627
): IComponentReturn {
2728
return {
29+
title: 'Component',
2830
extension: extension,
2931
content: `
3032
import React from 'react';
@@ -39,3 +41,53 @@ export default ${name};
3941
`,
4042
};
4143
}
44+
45+
export function createContextArrowFunctionBase(
46+
name: string,
47+
extension: string
48+
): IComponentReturn {
49+
return {
50+
title: 'Context',
51+
extension: extension,
52+
content: `
53+
import React, { createContext } from "react";
54+
55+
const ${name}Context = createContext();
56+
57+
const ${name}ContextProvider = ({ children }) => {
58+
return (
59+
<${name}Context.Provider value={{ }}>
60+
{children}
61+
</${name}Context.Provider>
62+
);
63+
}
64+
65+
export default ${name}ContextProvider;
66+
`,
67+
};
68+
}
69+
70+
export function createContextFunctionBase(
71+
name: string,
72+
extension: string
73+
): IComponentReturn {
74+
return {
75+
title: 'Context',
76+
extension: extension,
77+
content: `
78+
import React, { createContext } from "react";
79+
80+
const ${name}Context = createContext();
81+
82+
function ${name}ContextProvider({ children }) {
83+
return (
84+
<${name}Context.Provider value={{ }}>
85+
{children}
86+
</${name}Context.Provider>
87+
);
88+
}
89+
90+
export default ${name}ContextProvider;
91+
`,
92+
};
93+
}

src/templates/base/jsx.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/templates/base/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface IComponentReturn {
22
content: string;
33
extension: string;
4+
title: string;
45
}

src/templates/js.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
1-
import { aFctComponent, fctComponent } from './base/index';
2-
const arrowFunctionComponentJs = (name: string) => aFctComponent(name, 'js');
3-
const functionComponentJs = (name: string) => fctComponent(name, 'js');
1+
import {
2+
arrowFunctionComponentBase,
3+
createContextArrowFunctionBase,
4+
createContextFunctionBase,
5+
functionComponentBase,
6+
} from './base/index';
7+
const arrowFunctionComponentJs = (name: string) =>
8+
arrowFunctionComponentBase(name, 'js');
9+
const functionComponentJs = (name: string) => functionComponentBase(name, 'js');
410

5-
export { functionComponentJs, arrowFunctionComponentJs };
11+
const createContextArrowFunctionJs = (name: string) =>
12+
createContextArrowFunctionBase(name, 'js');
13+
const createContextFunctionJs = (name: string) =>
14+
createContextFunctionBase(name, 'js');
15+
16+
export {
17+
functionComponentJs,
18+
arrowFunctionComponentJs,
19+
createContextArrowFunctionJs,
20+
createContextFunctionJs,
21+
};

src/templates/jsx.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {
2+
arrowFunctionComponentBase,
3+
createContextArrowFunctionBase,
4+
createContextFunctionBase,
5+
functionComponentBase,
6+
} from './base/index';
7+
8+
const arrowFunctionComponentJsx = (name: string) =>
9+
arrowFunctionComponentBase(name, 'jsx');
10+
const functionComponentJsx = (name: string) =>
11+
functionComponentBase(name, 'jsx');
12+
13+
const createContextArrowFunctionJsx = (name: string) =>
14+
createContextArrowFunctionBase(name, 'jsx');
15+
const createContextFunctionJsx = (name: string) =>
16+
createContextFunctionBase(name, 'jsx');
17+
18+
export {
19+
arrowFunctionComponentJsx,
20+
functionComponentJsx,
21+
createContextArrowFunctionJsx,
22+
createContextFunctionJsx,
23+
};

0 commit comments

Comments
 (0)