forked from AntonScheving/README-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
123 lines (118 loc) · 4.93 KB
/
index.js
File metadata and controls
123 lines (118 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
console.log(
"\n\n This is a README.md file generator. Please read the included README file before using this application. \n\n Please type your answers to the questions below to generate your own README.md file.\n To type your answers press \n- 'Enter' \n- Then press 'i' \n- Press Ctrl v (Windows) - command v (Mac OS) to paste your text or start typing directly into the editor\n- Press 'escape' \n- Press colon ':' \n- Press 'wq' and 'Enter'\n\n"
);
// fs is the Node.js File System module, which is used to read and write files, and inquirer is a package that provides a way to prompt users for input in the command line using the prompt() method below.
const fs = require("fs");
const inquirer = require("inquirer");
const generateMarkdown = require("./utils/generateMarkdown.js");
inquirer
.prompt(
// The prompt() method takes an array of question objects that define the questions to ask the user. Each question object has a type, a name, a message, and sometimes a choices property. The type property specifies the type of question to ask (e.g., input, editor, list, etc.), the name property is used to store the user's answer to the question, and the message property is the prompt that is displayed to the user. The choices property is used for list questions to provide a list of options for the user to choose from.
[
{
type: "input",
name: "title",
message: "What is the title of your project?\n",
},
{
type: "input",
name: "repoTitle",
message: "What is the exact title of your repository?\n",
},
{
type: "editor",
name: "description",
message:
"\nPlease enter a description of your project: \nExplain the what, why, and how of your project. \nUse the following questions as a guide: \n\t- What was your motivation? \n\t- Why did you build this project? \n\t- What problem does it solve? \n\t- What did you learn?\n",
},
{
type: "input",
name: "deployedWebsite",
message: "Please enter deployed website URL:\n",
},
{
type: "input",
name: "imgAlt",
message: "Please enter your screenshot Alt:\n",
},
{
type: "input",
name: "screenshot",
message: "Please enter relative path to screenshot:\n",
},
{
type: "input",
name: "screenshotSubtitle",
message: "Please enter screenshot subtitle:\n",
},
{
type: "editor",
name: "installation",
message: "Please enter installation instructions for your project:\n",
},
{
type: "input",
name: "librariesAndTools",
message:
"Please enter libraries and tools used for your project. Write them in a list like this: \n<li>First item</li> <li>Second item</li> <li>Third item</li>:\n",
},
{
type: "editor",
name: "usage",
message: "Please enter usage information for your project:\n",
},
{
type: "list",
name: "license",
message:
"\n Please choose a license for your project\n (Visit https://choosealicense.com/ if you are unsure, which license to choose):",
choices: [
"MIT",
"GPL-3-0",
"apache-2-0",
"BSD-3-clause",
"ISC",
"0bsd",
],
},
{
type: "editor",
name: "contribution",
message: "\nPlease enter contribution guidelines for your project:\n",
},
{
type: "editor",
name: "tests",
message: "Please enter test instructions for your project:\n",
},
{
type: "input",
name: "github",
message: "What is your GitHub username?\n",
},
{
type: "input",
name: "website",
message: "What is your website URL?\n",
},
{
type: "input",
name: "webLinkPlaceholder",
message: "What is the placeholder for the website URL?\n",
},
{
type: "input",
name: "email",
message: "What is your email address?\n",
},
]
)
// The then() method is used to process the answers and generate the README.md file. The then() method takes a callback function that is passed the answers as an argument. The callback function uses the fs module's writeFile() method to write the contents of the README.md file to disk. The first argument to writeFile() is the name of the file to write (in this case, README.md), the second argument is the content of the file (which is generated by calling the generateMarkdown() function with the user's answers), and the third argument is a callback function that is called when the file has been written to disk.
.then((answers) => {
console.log(answers);
fs.writeFile(`README.md`, generateMarkdown(answers), (error) =>
error
? console.error(error)
: console.log(`Success! You have now created a README.md `)
);
});