-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
executable file
·65 lines (56 loc) · 1.76 KB
/
script.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
import { intro, outro, text, confirm, log, note } from "@clack/prompts";
import color from "picocolors";
import fs from "fs";
import path from "path";
import createHTMLBoilerplate from "./html_boilerplate.js";
import readmeContents from "./readme.js";
import { stylesContent, tailwindConfigContent } from "./css_bp.js";
async function main() {
intro(color.inverse("Welcome!"));
let projectName = await text({
message: "Enter your project name",
placeholder: "my-project",
defaultValue: "my-project",
});
const rootPath = path.resolve();
const folderPath = path.join(rootPath, `${projectName}`);
const createDir = await confirm({
message: `Do you want to create ${projectName} directory?`,
initialValue: true,
});
if (!createDir) {
outro("Well alright then! Bye👋");
return;
}
if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath);
log.success(`Directory '${color.cyan(projectName)}' created successfully.`);
} else {
log.warn(`Directory '${color.cyan(projectName)}' already exists.`);
log.info("Exiting...");
// outro("Goodbye👋!");
return;
}
[
["index.html", createHTMLBoilerplate(projectName)],
["style.css", ""],
["in.css", stylesContent],
["tailwind.config.js", tailwindConfigContent],
["script.js", ""],
["README.md", readmeContents(projectName)],
].forEach((file) => {
writeFile(path.join(folderPath, file[0]), file[1]);
log.success(`${color.green(file[0])} created successfully.`);
});
note(`Your project ${color.cyan(projectName)} is ready!`);
outro("Happy Coding!🚀");
}
main();
function writeFile(filePath, contents) {
fs.writeFile(filePath, contents, (err) => {
if (err) {
console.error("Error creating file:", err);
} else {
}
});
}