Skip to content

Commit a6560cf

Browse files
committed
feat: add dynamic readme generator based on user's selection
1 parent f722b0a commit a6560cf

File tree

3 files changed

+188
-1
lines changed

3 files changed

+188
-1
lines changed

src/index.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import logger from "@/utils/logger";
2525
import i18nAdder from "@/operation/i18n";
2626
import { pluginDependencyAdder } from "@/utils/file";
2727
import initGitRepo from "@/operation/initGit";
28-
import { absolutePathConfigAdderInReact } from "./operation/projectGenerator/projectGenerator";
28+
import { absolutePathConfigAdderInReact } from "@/operation/projectGenerator/projectGenerator";
29+
import readmeGenerator from "@/operation/readme";
2930

3031
/**
3132
* 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
@@ -102,6 +103,20 @@ async function main() {
102103
//install dependencies of the plugins
103104
await pluginDependencyAdder();
104105

106+
//generating readme file
107+
await readmeGenerator({
108+
currentProjectType: selectedProjectType,
109+
cachingOption: cachingOption,
110+
currentPackageManager: currentPackageManager,
111+
eslint: true,
112+
husky: addHusky,
113+
i18n: addI18n,
114+
language: selectedLanguage,
115+
prettier: addPrettier,
116+
selectedLibrary: selectedLibrary,
117+
storybook: addPrettier,
118+
});
119+
105120
logger("green", "\n ☺️ Happy Coding !");
106121
} catch (e: unknown) {
107122
logger("green", "\n ☺️ Happy Coding !");

src/operation/readme/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from "./readme";

src/operation/readme/readme.ts

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
import {
2+
NodePackageManager,
3+
SupportedLanguage,
4+
SupportedProjectGenerator,
5+
SupportedStateManagementAndCachingSol,
6+
SupportedUILibrary,
7+
} from "@/types";
8+
import { writeFile } from "@/utils/file";
9+
10+
type ReadmeGen = {
11+
prettier?: boolean;
12+
husky?: boolean;
13+
eslint?: boolean;
14+
storybook?: boolean;
15+
language?: SupportedLanguage;
16+
currentPackageManager?: NodePackageManager;
17+
cachingOption?: SupportedStateManagementAndCachingSol;
18+
selectedLibrary?: SupportedUILibrary;
19+
i18n?: boolean;
20+
currentProjectType: SupportedProjectGenerator;
21+
};
22+
23+
export default async function readmeGenerator({
24+
currentProjectType,
25+
cachingOption,
26+
currentPackageManager,
27+
eslint,
28+
husky,
29+
i18n,
30+
language,
31+
prettier,
32+
selectedLibrary,
33+
storybook,
34+
}: ReadmeGen) {
35+
// ======== Logo ========== //
36+
const readme = [
37+
`![Logo](https://www.simform.com/wp-content/uploads/2022/12/logo.svg)`,
38+
];
39+
40+
//=========== Heading ==========//
41+
readme.push(
42+
`# ${currentProjectType === "next" ? "Next Js" : "React Js"} Boilerplate`
43+
);
44+
45+
readme.push(
46+
`This boilerplate is starting point of any project with all batteries included. you can directly start development without spending time on project setup.`
47+
);
48+
49+
//======== TECH STACK ===========//
50+
readme.push("## Tech Stack");
51+
52+
readme.push(`**Client:** [React](react.dev), ${
53+
language === "ts" ? "[Typescript](https://www.typescriptlang.org)," : ""
54+
} ${
55+
currentProjectType === "next"
56+
? "[Next Js](https://nextjs.org/),"
57+
: currentProjectType === "react-cra"
58+
? "[Create-React-App](https://create-react-app.dev/),"
59+
: "[Vite](https://vitejs.dev/),"
60+
} ${
61+
cachingOption === "graphql"
62+
? "[Apollo Client](https://www.apollographql.com/docs/react/),"
63+
: cachingOption === "react-query"
64+
? "[React-Query](https://tanstack.com/query/latest),"
65+
: cachingOption === "rtk-query-redux"
66+
? "[Redux (RTK-Query)](https://redux.js.org/),"
67+
: ""
68+
} ${
69+
currentProjectType !== "next"
70+
? "[React Router](https://reactrouter.com/en/main),"
71+
: ""
72+
} \n
73+
`);
74+
75+
(selectedLibrary || storybook) &&
76+
readme.push(
77+
`**Styling:** ${
78+
selectedLibrary === "antd"
79+
? "[Antd](https://ant.design/),"
80+
: selectedLibrary === "mui"
81+
? "[Material UI](https://mui.com/material-ui/),"
82+
: ""
83+
} ${storybook ? "[Storybook](https://storybook.js.org/)," : ""} \n`
84+
);
85+
86+
cachingOption === "react-query" &&
87+
readme.push(`**HTTP Client:** [axios](https://axios-http.com/) \n`);
88+
89+
i18n &&
90+
readme.push(
91+
`**Internationalization:** [i18next](https://react.i18next.com/) \n`
92+
);
93+
94+
readme.push(
95+
`**Code Formatter:** ${
96+
prettier ? "[Prettier](https://prettier.io/)," : ""
97+
} ${
98+
husky ? "[Husky](https://typicode.github.io/husky)," : ""
99+
} [Eslint](https://eslint.org/) \n`
100+
);
101+
102+
//========= Developer Guide =========//
103+
readme.push(`
104+
### Developer Guide
105+
106+
1. To begin, set your Git username and email using the following commands:
107+
- \`git config user.name "{username}"\`
108+
- \`git config user.email "{email}"\`
109+
110+
2. Avoid pushing or committing directly to the \`main\` branch.
111+
112+
3. When creating a new branch, use one of the following naming conventions:
113+
- \`feature/feature-name\`
114+
- \`bug/bug-details\`
115+
- \`design/design-details\`
116+
117+
4. Format your commit messages as \`Ticket number : Title\` only. For example: \`T-101 : Deploy site on production environment.\`
118+
119+
5. Prior to committing, ensure you verify and resolve linting issues by running the following commands:
120+
- \`npm run lint\`
121+
- \`npm run lint:fix\`
122+
123+
6. Each Pull Request (PR) should contain only a single commit. If you've made multiple commits, rebase them into a single commit before submitting the PR.
124+
125+
7. Add comments when necessary for better understanding, and make further improvements as needed.
126+
127+
8. Customize the ESLint rules in the .eslintrc.cjs file to meet your project's specific requirements.
128+
`);
129+
130+
// ======= Useful scripts ==========//
131+
const prefix =
132+
currentPackageManager === "npm"
133+
? "npm run"
134+
: currentPackageManager === "pnpm"
135+
? "pnpm"
136+
: "yarn";
137+
138+
readme.push(`### Other useful scripts`);
139+
140+
readme.push(`- \`${prefix} build\` to build a project`);
141+
142+
readme.push(
143+
`- \`${prefix} ${
144+
currentProjectType === "next"
145+
? "dev"
146+
: currentProjectType === "react-cra"
147+
? "start"
148+
: "dev"
149+
}\` to run (dev) a project`
150+
);
151+
152+
readme.push(`- \`${prefix} build\` to build a project`);
153+
154+
readme.push(`- \`${prefix} preview\` to run preview a project`);
155+
156+
readme.push(
157+
`- \`${prefix} lint\` to lint a project \n - \`${prefix} lint:fix\` to lint:fix a project`
158+
);
159+
160+
prettier && readme.push(`- \`${prefix} format\` to format a project`);
161+
162+
storybook &&
163+
readme.push(
164+
`- \`${prefix} storybook\` to start storybook dev server \n - \`${prefix} build-storybook\` to build storybook`
165+
);
166+
167+
const readmeContent = readme.join("\n");
168+
169+
//writing readme file with the dynamically generated readme content
170+
writeFile("README.md", readmeContent);
171+
}

0 commit comments

Comments
 (0)