-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
138 lines (105 loc) · 3.5 KB
/
main.ts
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import { existsSync } from "https://deno.land/std@0.197.0/fs/mod.ts";
import { Command } from "npm:commander@11";
import { join } from "node:path";
const program = new Command();
program
.name("readme")
.description("Create a README.md boilerplate for your project")
.version("23.08") // august 2023
.option("-f, --force", "overwrite existing README")
.option("-b, --backup", "Backup existing README")
.option("-p, --path <string>", "Path to save the generated README")
.option("-t, --title <string>", "The project title")
.option("-d, --description <string>", "The project description");
if (import.meta.main) {
program.parse();
const options = program.opts();
const path = options?.path ? join(options.path, "README.md") : "./README.md";
// overwrite existing readme
if (readmeExists(path) && options.backup) {
await Deno.rename(join(path), join(options?.path, "README.md.bak"));
await generateReadme(options.title, options.description);
} else if (options.force && readmeExists(path)) {
Deno.removeSync("./README.md");
await generateReadme(options.title, options.description);
} else if (options.force && !readmeExists) {
await generateReadme(options.title, options.description);
} else if (readmeExists(path)) {
console.log("%cREADME already exist ❌", "color:#FFCCCC");
Deno.exit(1); // quit the program if readme exists
} else {
await generateReadme(options.title, options.description, path);
}
}
async function generateReadme(
title = "Project Title",
description = "Simple overview of use/purpose.",
path = "./README.md",
) {
// create the readme otherwise
await Deno.writeTextFile(
path,
`# ${
title.replace(/(^\w{1})|(\s+\w{1})/g, (letter: string) =>
letter.toUpperCase())
}
${description}
- [Description](#description)
- [Getting Started](#getting-started)
- [Dependencies](#dependencies)
- [Installing](#installing)
- [Executing program](#executing-program)
- [Documentation](#documentation)
- [Help](#help)
- [Authors](#authors)
- [Version History](#version-history)
- [License](#license)
- [Acknowledgments](#acknowledgments)
## Description
An in-depth paragraph about your project and overview of use.
## Getting Started
### Dependencies
- Describe any prerequisites, libraries, OS version, etc., needed before installing program.
- ex. Windows 10
### Installing
- How/where to download your program
- Any modifications needed to be made to files/folders
### Executing program
- How to run the program
- Step-by-step bullets
\`\`\`
code blocks for commands
\`\`\`
## Documentation
Describe any special instructions that are necessary to install a software package on your computer (if applicable).
## Help
Any advise for common problems or issues.
\`\`\`
command to run if program contains helper info
\`\`\`
## Authors
Contributors names and contact info
ex. Dominique Pizzie
ex. [@DomPizzie](https://twitter.com/dompizzie)
## Version History
- 0.2
- Various bug fixes and optimizations
- See [commit change]() or See [release history]()
- 0.1
- Initial Release
## License
This project is licensed under the [NAME HERE] License - see the LICENSE.md file for details
## Acknowledgments
Inspiration, code snippets, etc.
`,
);
console.log("%cREADME successfully added ✅", "color:#E6FFCC");
}
// see if the file already in the provided directory
function readmeExists(path: string): boolean {
const fileExistInPath = existsSync(path.trim(), {
isReadable: true,
isFile: true,
});
return fileExistInPath;
}