-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.js
36 lines (30 loc) · 1 KB
/
setup.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
const fs = require("fs");
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const askProjectName = () => {
rl.question("Enter your project name: ", (projectName) => {
if (!projectName.trim()) {
console.error("Project name cannot be empty. Please try again.");
askProjectName();
} else {
const replacePlaceholders = (filePath, placeholders) => {
let content = fs.readFileSync(filePath, "utf8");
for (const [placeholder, value] of Object.entries(placeholders)) {
content = content.replace(new RegExp(placeholder, "g"), value);
}
fs.writeFileSync(filePath, content, "utf8");
};
const placeholders = {
__PROJECT_NAME__: projectName,
};
replacePlaceholders("package.json", placeholders);
replacePlaceholders("angular.json", placeholders);
console.log("Project setup complete!");
rl.close();
}
});
};
askProjectName();