-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
96 lines (91 loc) · 2.49 KB
/
index.js
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
// index.js
const inquirer = require('inquirer');
const fs = require('fs');
const path = require('path');
const generateMarkdown = require('./generateMarkdown');
const questions = [
{
type: 'input',
name: 'title',
message: 'Enter your project title:',
validate: (input) => input ? true : 'Project title cannot be empty.',
},
{
type: 'input',
name: 'description',
message: 'Enter your project description:',
validate: (input) => input ? true : 'Description cannot be empty.',
},
{
type: 'input',
name: 'installation',
message: 'Enter installation instructions:',
default: 'npm install',
},
{
type: 'input',
name: 'usage',
message: 'Enter usage information:',
validate: (input) => input ? true : 'Usage information cannot be empty.',
},
{
type: 'list',
name: 'license',
message: 'Choose a license for your project:',
choices: ['MIT', 'Apache 2.0', 'GPLv3', 'BSD 3-Clause', 'None'],
},
{
type: 'input',
name: 'contributing',
message: 'Enter contribution guidelines:',
default: 'Contributions are welcome! Please fork the repository and submit pull requests for enhancements.',
},
{
type: 'input',
name: 'tests',
message: 'Enter test instructions:',
default: 'npm test',
},
{
type: 'input',
name: 'github',
message: 'Enter your GitHub username:',
validate: (input) => input ? true : 'GitHub username cannot be empty.',
},
{
type: 'input',
name: 'email',
message: 'Enter your email address:',
validate: (input) => {
const valid = /\S+@\S+\.\S+/.test(input);
return valid ? true : 'Please enter a valid email address.';
},
},
{
type: 'input',
name: 'videoLink',
message: 'Enter the URL to your walkthrough video:',
validate: (input) => {
const valid = /^(ftp|http|https):\/\/[^ "]+$/.test(input);
return valid ? true : 'Please enter a valid URL.';
},
},
];
function writeToFile(fileName, data) {
return fs.writeFileSync(path.join(process.cwd(), fileName), data);
}
function init() {
console.log('Initializing ReadMePro...');
inquirer.prompt(questions)
.then((answers) => {
console.log('Generating README.md...');
const markdown = generateMarkdown(answers);
writeToFile('README.md', markdown);
console.log('Successfully created README.md');
})
.catch((error) => {
console.error('Error generating README.md:', error);
});
}
// Function call to initialize app
init();