Skip to content

Commit ff953ed

Browse files
committed
feat: Add initial entry layout for React project generation
This commit introduces the initial entry layout for the generated React project. It also includes an example adder configuration in all React plugins. These changes provide a solid starting point for working with the generated projects.
1 parent 7a76195 commit ff953ed

File tree

12 files changed

+337
-31
lines changed

12 files changed

+337
-31
lines changed

src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
//=============== main executer ==============//
44

5-
import GlobalStateUtility from "./global";
5+
import GlobalStateUtility from "@/global";
66
import getCurrentPackageManager from "@/operation/getPackageManager";
77
import getProjectName from "@/operation/getProjectName";
88
import getCurrentProject from "@/operation/getProjectType";
@@ -27,6 +27,7 @@ import { pluginDependencyAdder } from "@/utils/file";
2727
import initGitRepo from "@/operation/initGit";
2828
import { absolutePathConfigAdderInReact } from "@/operation/projectGenerator/projectGenerator";
2929
import readmeGenerator from "@/operation/readme";
30+
import cmdRunner from "@/utils/cmdRunner";
3031

3132
/**
3233
* current we are storing the config with code but if we increase the number of features then we can have plugin dir that has it's own config file
@@ -117,6 +118,13 @@ async function main() {
117118
storybook: addPrettier,
118119
});
119120

121+
//formatting the code if prettier is available
122+
if (addPrettier) {
123+
const formatCmd =
124+
currentPackageManager === "npm" ? ["run", "format"] : ["format"];
125+
await cmdRunner(currentPackageManager, formatCmd);
126+
}
127+
120128
logger("green", "\n ☺️ Happy Coding !");
121129
} catch (e: unknown) {
122130
logger("green", "\n ☺️ Happy Coding !");

src/plugins/react/antd/config.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,17 @@ const AntDReactPlugin: PluginConfigType = {
7878
},
7979
{
8080
content: getExampleComponent,
81-
fileName: "Buttons",
81+
fileName: "AntDExample",
8282
fileType: "component",
83-
path: ["src", "components", "AntdExample"],
83+
path: ["src", "components", "antDExample"],
8484
},
8585
],
8686
fileModification: {
87-
App: {},
87+
App: {
88+
importStatement: `import AntDExample from "src/components/antDExample/AntDExample"`,
89+
name: "Ant Design",
90+
component: "<AntDExample/>",
91+
},
8892
Index: {
8993
importStatements: `import { ConfigProvider } from "antd";
9094
import theme from "src/theme/themeAntd";`,

src/plugins/react/graphql/config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ const GraphQlReactPlugin: PluginConfigType = {
9797
],
9898
dependencies: "@apollo/client graphql",
9999
fileModification: {
100-
App: {},
100+
App: {
101+
importStatement: `import Characters from "src/components/character/Character"`,
102+
name: "Apollo GraphQL",
103+
component: "<Characters/>",
104+
},
101105
Index: {
102106
importStatements: `import { ApolloProvider } from "@apollo/client";
103107
import client from "src/config/client";`,

src/plugins/react/i18n/config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ const i18NReactPlugin: PluginConfigType = {
124124
},
125125
],
126126
fileModification: {
127-
App: {},
127+
App: {
128+
importStatement: `import I18Example from "src/components/i18Example/I18Example";`,
129+
name: "I18n",
130+
component: "<I18Example />",
131+
},
128132
Index: {
129133
importStatements: `import "src/utils/i18n";`,
130134
addAfterMatch: "",

src/plugins/react/mui/config.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,51 @@ const theme = createTheme({
2929
3030
export default theme;`;
3131

32+
//gives react example components based on project type
33+
const getExampleComponent = (
34+
isTsProject: boolean
35+
) => `import { Box, Button, Rating, TextField, Typography } from "@mui/material";
36+
import { useState } from "react";
37+
38+
function MuiExample() {
39+
const [ratingValue, setRatingValue] = useState${
40+
isTsProject ? "<number | null>" : ""
41+
}(null);
42+
const [comment, setComment] = useState("");
43+
const isDisabled = ratingValue === null || comment === "";
44+
return (
45+
<Box
46+
sx={{
47+
width: "300px",
48+
display: "flex",
49+
flexDirection: "column",
50+
alignItems: "center",
51+
}}
52+
>
53+
<Typography variant="h2" color="primary.main">
54+
How would you rate this experience ?
55+
</Typography>
56+
<Rating
57+
value={ratingValue}
58+
onChange={(_, val) => setRatingValue(val)}
59+
sx={{ m: 2 }}
60+
/>
61+
<Typography>Tell us how it went</Typography>
62+
<TextField
63+
multiline
64+
maxRows={4}
65+
value={comment}
66+
onChange={e => setComment(e.target.value)}
67+
/>
68+
<Button disabled={isDisabled} sx={{ mt: 1 }} variant="contained">
69+
Submit
70+
</Button>
71+
</Box>
72+
);
73+
}
74+
export default MuiExample;
75+
`;
76+
3277
const MuiReactPlugin: PluginConfigType = {
3378
initializingMessage: "Adding Material UI ! Please Wait !",
3479
files: [
@@ -38,6 +83,12 @@ const MuiReactPlugin: PluginConfigType = {
3883
fileName: "theme",
3984
fileType: "native",
4085
},
86+
{
87+
path: ["src", "components", "muiExample"],
88+
content: getExampleComponent,
89+
fileName: "MuiExample",
90+
fileType: "component",
91+
},
4192
],
4293
dependencies: "@mui/material",
4394
fileModification: {
@@ -46,7 +97,11 @@ const MuiReactPlugin: PluginConfigType = {
4697
addBeforeMatch: "<ThemeProvider theme={theme}>",
4798
addAfterMatch: "</ThemeProvider>",
4899
},
49-
App: {},
100+
App: {
101+
importStatement: `import MuiExample from "src/components/muiExample/MuiExample"`,
102+
name: "Material UI",
103+
component: "<MuiExample/>",
104+
},
50105
},
51106
successMessage: "Successfully added Material UI with theme config !",
52107
};

src/plugins/react/reactQuery/config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ const reactQueryExample = `import { useQuery } from "@tanstack/react-query";
156156
import { getPosts } from "src/utils/api";
157157
158158
const ReactQueryExample = () => {
159-
const { data, error, isLoading } = useQuery(["posts"], getPosts);
159+
const { data, error, isLoading } = useQuery({ queryKey: ["posts"], queryFn: getPosts });
160160
161161
if (error) return <div>An error occurred</div>;
162162
@@ -214,7 +214,11 @@ const ReactQueryReactPlugin: PluginConfigType = {
214214
},
215215
],
216216
fileModification: {
217-
App: {},
217+
App: {
218+
importStatement: `import ReactQueryExample from "src/components/reactQueryExample/ReactQueryExample"`,
219+
name: "React Query",
220+
component: "<ReactQueryExample />",
221+
},
218222
Index: {
219223
importStatements: `import { QueryClientProvider } from "@tanstack/react-query";
220224
import queryClient from "src/client/queryClient";

src/plugins/react/reactRouterDom/config.ts

Lines changed: 87 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,69 @@ export default App;`;
1111

1212
export const LayoutReact = (isTsProject: boolean) => `import React from "react";
1313
import { Link } from "react-router-dom";
14+
import styles from "./Layout.module.css";
1415
1516
${!isTsProject ? "// eslint-disable-next-line react/prop-types" : ""}
1617
const Layout = ({ children }${
1718
isTsProject ? ": { children: React.ReactNode }" : ""
1819
}) => {
1920
return (
20-
<>
21-
<div style={{ margin: "1rem" }}>
21+
<main className={styles.main}>
22+
<nav className={styles.nav}>
2223
<div>
23-
<ul>
24-
<li>
25-
<Link to={"/"}>Home</Link>
26-
</li>
27-
<li>
28-
<Link to={"/contact"}>Contact</Link>
29-
</li>
30-
<li>
31-
<Link to={"/about"}>About</Link>
32-
</li>
33-
</ul>
24+
<img src="https://ik.imagekit.io/ashishkk22/simform_logo.svg?updatedAt=1697020836220" alt="simform_logo" />
3425
</div>
35-
</div>
26+
<div>
27+
<div>
28+
<ul className={styles.nav_ul}>
29+
<li>
30+
<Link to={"/"} className={styles.nav_link}>
31+
Home
32+
</Link>
33+
</li>
34+
<li>
35+
<Link to={"/contact"} className={styles.nav_link}>
36+
Contact
37+
</Link>
38+
</li>
39+
<li>
40+
<Link to={"/about"} className={styles.nav_link}>
41+
About
42+
</Link>
43+
</li>
44+
</ul>
45+
</div>
46+
</div>
47+
</nav>
3648
{children}
37-
</>
49+
</main>
3850
);
3951
};
4052
4153
export default Layout;
4254
`;
4355

56+
const layoutCss = `.nav {
57+
background-color: #ea495c;
58+
display: flex;
59+
justify-content: space-around;
60+
align-items: center;
61+
padding: 1rem 0;
62+
}
63+
64+
.nav_ul {
65+
list-style-type: none;
66+
display: flex;
67+
justify-content: space-around;
68+
width: 20rem;
69+
}
70+
71+
.nav_link {
72+
text-decoration: none;
73+
color: white;
74+
}
75+
`;
76+
4477
export const getPagesComponentReact = (
4578
name: string
4679
) => `import React from "react";
@@ -259,6 +292,33 @@ export class SuspenseErrorBoundary extends React.Component${
259292
}
260293
`;
261294

295+
const indexCssReset = `@import url("https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,300;1,400;1,500;1,600;1,700;1,800&family=Poppins:wght@200;300;400;500&family=Roboto:wght@300;400;500&display=swap");
296+
297+
*,
298+
*::before,
299+
*::after {
300+
box-sizing: border-box;
301+
}
302+
303+
* {
304+
margin: 0;
305+
padding: 0;
306+
font-family: "Poppins";
307+
}
308+
309+
html,
310+
body {
311+
height: 100%;
312+
}
313+
314+
input,
315+
button,
316+
textarea,
317+
select {
318+
font: inherit;
319+
}
320+
`;
321+
262322
const ReactRouterDomReactPlugin: PluginConfigType = {
263323
initializingMessage: "Adding React Router Dom ! Please Wait !",
264324
dependencies: "react-router-dom",
@@ -275,6 +335,12 @@ const ReactRouterDomReactPlugin: PluginConfigType = {
275335
fileName: "Layout",
276336
fileType: "component",
277337
},
338+
{
339+
path: ["src", "components", "layout"],
340+
content: layoutCss,
341+
fileName: "Layout.module.css",
342+
fileType: "simple",
343+
},
278344
{
279345
path: ["src", "components", "about"],
280346
content: getPagesComponentReact("About"),
@@ -329,6 +395,12 @@ const ReactRouterDomReactPlugin: PluginConfigType = {
329395
fileName: "SuspenseErrorBoundary",
330396
fileType: "component",
331397
},
398+
{
399+
path: ["src"],
400+
content: indexCssReset,
401+
fileName: "index.css",
402+
fileType: "simple",
403+
},
332404
],
333405
successMessage: "Successfully added React Router Dom !",
334406
};

src/plugins/react/rtkQueryRedux/config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,11 @@ const RtkReduxReactPlugin: PluginConfigType = {
275275
}`;
276276
},
277277
fileModification: {
278-
App: {},
278+
App: {
279+
importStatement: `import RtkQueryExample from "src/components/rtkQueryExample/RtkQueryExample"`,
280+
name: "RTK Query",
281+
component: "<RtkQueryExample/>",
282+
},
279283
Index: {
280284
importStatements: `import { Provider } from "react-redux";
281285
import { store } from "src/store";`,

src/questions/questions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ export async function getSelectedUiLibrary(
137137

138138
const dependencies = `${
139139
selectStylingEngine === "emotion"
140-
? "@emotion/react @emotion/styled"
140+
? "@emotion/styled"
141141
: "@mui/styled-engine-sc styled-components"
142-
} ${addMuiIcons ? "@mui/icons-material" : ""}`;
142+
} @emotion/react ${addMuiIcons ? "@mui/icons-material" : ""}`;
143143

144144
GlobalStateUtility.getInstance().setDependencies(dependencies);
145145
}

src/types/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ export type SupportedStateManagementAndCachingSol =
1919
export type StylingEngineInMui = "emotion" | "styled-components";
2020

2121
export type ReactAppConfig = {
22-
import?: string[];
22+
importStatement?: string;
23+
name?: string;
2324
localImport?: string[];
2425
relativeImport?: string[];
2526
afterImport?: string[];
2627
innerHooks?: string[];
2728
inner?: string[];
28-
component?: string[];
29+
component?: string;
2930
};
3031

3132
export type ReactIndexConfig = {

0 commit comments

Comments
 (0)