Skip to content

Commit d1d1a0e

Browse files
committed
md completed & fixed typos
1 parent 47ccc8f commit d1d1a0e

File tree

10 files changed

+114
-2
lines changed

10 files changed

+114
-2
lines changed

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
Readme.md
3+
./images

Readme.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# @s54a/init
2+
3+
I built this project cause I was didn't wanted to create templates times while starting a new project.
4+
5+
## Folder Structure
6+
7+
there is only 1 for testing which has three files
8+
I didn't add any more template cause I didn"t wanted to bloat the package
9+
10+
📁 init
11+
├── 🌅 images
12+
│ ├── 🖼️ article.png
13+
│ ├── 🖼️ init -a.png
14+
│ ├── 🖼️ init -c.png
15+
│ ├── 🖼️ init -h.png
16+
│ ├── 🖼️ init -r.png
17+
│ └── 🖼️ init.png
18+
├── 📁 templates
19+
│ └── 📁 templateTest
20+
│ ├── 📄 index.html
21+
│ ├── 📄 main.js
22+
│ └── 📄 style.css
23+
├── 📄 .gitignore
24+
├── 📄 .npmignore
25+
├── 📄 index.js
26+
├── 📜 LICENSE
27+
├── 📝 Readme.md
28+
├── 📋 package.json
29+
└── 📋 package-lock.json
30+
31+
###### (Note ChatGPT built this folder structure)
32+
33+
## How it Works
34+
35+
To begin, open a terminal at the desired project location and run this command
36+
37+
```bash
38+
init
39+
```
40+
41+
This displays all available templates from the template folder, listed by folder name. Choose a template and enter the desired folder name when prompted to create a new project with the selected template's contents.
42+
43+
**Users can also create templates themselves by running:**
44+
45+
```bash
46+
init -a "C:\Users\{User}\Desktop\Projects\Ongoing Projects"
47+
```
48+
49+
Upon execution, the tool generates a new folder path containing the contents of the user-created template. Subsequently, when the init command is invoked, it showcases the recently created template under the specified name.
50+
51+
_Tip_: For Windows users, you can quickly access the folder by selecting it and then pressing `ctrl + shift + c.`
52+
53+
**Templates can be removed using the following command:**
54+
55+
```bash
56+
init -r "template name"
57+
```
58+
59+
_(Note: The name must match exactly.)_
60+
61+
**Templates can also be added from GitHub with:**
62+
63+
```bash
64+
init -c "https://github.com/user/repoitoryName"
65+
```
66+
67+
This process involves cloning the repository into the current terminal directory, removing the .git folder from the cloned repository, executing the init -a "repoName" command to create a copy in the templates folder, and then deleting the cloned repository folder from the current terminal location.
68+
69+
The reason it performs all these steps is because I attempted to accomplish it in a simpler manner but couldn't find one.
70+
71+
## Resources
72+
73+
#### These are the YouTube Videos & Article which helped me build this
74+
75+
[![The Articel Link](./images/article.png)](https://medium.com/northcoders/creating-a-project-generator-with-node-29e13b3cd309)
76+
77+
[![The Video Link](https://img.youtube.com/vi/xYko2bHNgVA/0.jpg)](https://www.youtube.com/watch?v=xYko2bHNgVA)
78+
79+
[![The Video Link](https://img.youtube.com/vi/UxdSoefSxrA/sddefault.jpg)](https://www.youtube.com/watch?v=UxdSoefSxrA)
80+
81+
& ChatGPT
82+
83+
This a similer project built with Typescript
84+
https://github.com/pongsatt/mycli/blob/master/src/index.ts
85+
86+
Extra Resources
87+
https://github.com/lirantal/nodejs-cli-apps-best-practices
88+
89+
Take a look at https://yeoman.io/generators/

images/article.png

146 KB
Loading

images/html.png

21.7 KB
Loading

images/init -a.png

24.5 KB
Loading

images/init -c.png

55.1 KB
Loading

images/init -h.png

69.4 KB
Loading

images/init -r.png

22.3 KB
Loading

images/init.png

28.6 KB
Loading

index.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ if (!condition) {
204204
console.error("Error cloning repository:", error);
205205
process.exit(1); // Exit the script with an error status code
206206
});
207-
} else if (condition === "-h") {
207+
} else if (condition === "h") {
208208
// Clear the terminal by printing ANSI escape codes
209209
process.stdout.write("\u001b[2J\u001b[0;0H");
210210

@@ -217,7 +217,7 @@ ${chalk.bold.underline.white("Package Commands:")}
217217
${chalk.green("Add a Template:")}
218218
- Use the ${chalk.cyan("-a")} flag followed by the path in quotes.
219219
${chalk.yellow("Example:")} ${chalk.cyan("init -a")} ${chalk.yellow(
220-
'"C:Users\\{User}\\Desktop\\Projects\\Ongoing Projects"'
220+
'"C:\\Users\\{User}\\Desktop\\Projects\\Ongoing Projects"'
221221
)}
222222
223223
${chalk.green("Clone a Repository and Add as a Template:")}
@@ -241,4 +241,24 @@ ${chalk.bold.underline.white("Package Commands:")}
241241
`;
242242

243243
console.log(message);
244+
} else if (condition) {
245+
console.log(
246+
chalk.red(
247+
`
248+
Invalid command: "${condition}".
249+
250+
Please use one of the supported commands.
251+
252+
Run ${chalk.yellow("init -h")} to see help.
253+
254+
`
255+
)
256+
);
257+
} else {
258+
console.log(
259+
chalk.red(
260+
`An error occurred or an invalid command was provided.
261+
Run ${chalk.yellow("init -h")} to see help.`
262+
)
263+
);
244264
}

0 commit comments

Comments
 (0)