-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstaller.js
More file actions
100 lines (90 loc) · 3.63 KB
/
installer.js
File metadata and controls
100 lines (90 loc) · 3.63 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
#!/usr/bin/env node
import fsExtra from "fs-extra/esm";
import inquirer from "inquirer";
import { BackendOnly } from "./Configuration/BackendOnly.js";
import { execSync } from "child_process";
import path from "path";
import chalk from "chalk";
import { FrontendOnly } from "./Configuration/FrontendOnly.js";
const practice = async () => {
try {
console.clear();
console.log(chalk.greenBright("\n 🚀 Welcome to Rabee Node CLI v2.2.0\n"));
const answer = await inquirer.prompt([{
type: 'input',
name: 'ProjectName',
message: 'Write the Name of main Folder',
validate: (input) => {
if (input.trim() === '') {
return 'Project name cannot be empty';
} else if (input.includes(' ')) {
return 'Project name cannot contain spaces';
}
return true;
}
}, {
type: 'rawlist',
name: 'FrontendBackend',
message: 'What you want to create ?',
choices: [
'Frontend', 'Backend', 'Both'
]
}, {
type: 'rawlist',
name: 'BackendType',
message: 'Which Backend Template you want to use?',
choices: [
'MongoDB', 'Sqlite'
],
when: (answers) => answers.FrontendBackend !== 'Frontend'
}, {
type: 'rawlist',
name: 'OpenVsCode',
message: 'Do you want to open the project in VS Code After Creation?',
choices: [
'Yes', 'No'
]
}
]);
const newPath = path.join(process.cwd(), answer.ProjectName);
await fsExtra.pathExists(newPath).then (async exists => {
if (exists) {
await inquirer.prompt([{
type: 'confirm',
name: 'overwrite',
message: `\nA folder with the name "${answer.ProjectName}" already exists. Do you want to overwrite it?`
}]).then(async overwriteAnswer => {
if (overwriteAnswer.overwrite) {
await fsExtra.emptyDir(newPath);
} else {
console.log(chalk.redBright("\nProject creation cancelled. Please choose a different name or remove the existing folder."));
process.exit(0);
}
});
}
})
if (answer.FrontendBackend == 'Both') {
await FrontendOnly(newPath,"Redux", `${answer.ProjectName}`);
await BackendOnly(newPath, answer.BackendType, answer.ProjectName);
if (answer.OpenVsCode == 'Yes') {
execSync(`code ${newPath}/Frontend`, { stdio: 'inherit' });
execSync(`code ${newPath}/Backend`, { stdio: 'inherit' });
}
} else if (answer.FrontendBackend == 'Frontend') {
await FrontendOnly(newPath,"Redux", `${answer.ProjectName}`);
if (answer.OpenVsCode == 'Yes') {
execSync(`code ${newPath}/Frontend`, { stdio: 'inherit' });
}
} else {
await BackendOnly(newPath, answer.BackendType, answer.ProjectName);
if (answer.OpenVsCode == 'Yes') {
execSync(`code ${newPath}/Backend`, { stdio: 'inherit' });
}
}
console.log(chalk.greenBright("projects Created Successfully \n"));
} catch (error) {
console.log(chalk.bold.red.bgWhiteBright("\nGot the error While Creating Project : \n"), error);
process.exit(1);
}
}
practice();