-
Notifications
You must be signed in to change notification settings - Fork 25
/
cli.js
executable file
·126 lines (105 loc) · 3.07 KB
/
cli.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
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
#!/usr/bin/env node
import figlet from "figlet";
import { program } from "commander";
import chalk from "chalk";
import useGradient from "./src/core/utils/useGradient.js";
import { createBackendProject } from "./src/core/create-backend-project.js";
import {
promptBackendFramework,
promptDatabase,
promptFrontendFramework,
promptFrontendLanguage,
promptInitDatabase,
promptOrm,
promptProjectName,
promptProjectStack,
promptDependenciesInstall,
promptBackendLanguage,
} from "./src/core/prompts.js";
import { createFrontendProject } from "./src/core/create-frontend-project.js";
import {
checkForUpdate,
validateProjectName,
} from "./src/core/utils/helper.js";
import { sendQueuedStats } from "./src/core/stat.js";
const toolName = "StartEase";
const jsBackendStacks = ["expressjs", "nestjs"];
program.version("1.0.0").description("StartEase CLI");
program
.description("Scaffold a new project with StartEase")
.action(async () => {
await startProject();
});
program.parse(process.argv);
async function startProject() {
let framework;
let projectName;
let projectStack;
let initDB;
let database;
let orm;
let language;
let installDependencies;
const initialMsg = `Simplify Project Setup with the. ${chalk.green(
toolName,
)} CLI Tool.`;
// check for update
await checkForUpdate();
// render cli title
renderTitle();
console.log(chalk.white(initialMsg));
projectName = await promptProjectName();
validateProjectName(projectName);
projectStack = await promptProjectStack();
// process sending of stats in background
await sendQueuedStats();
/**
* start prompts
*/
if (projectStack === "frontend") {
language = await promptFrontendLanguage();
framework = await promptFrontendFramework();
if (framework === "html-x-css-x-javascript") {
return await createFrontendProject(projectName, framework, "javascript");
}
return await createFrontendProject(projectName, framework, language);
} else if (projectStack === "backend") {
language = await promptBackendLanguage();
framework = await promptBackendFramework(language);
// note: this is done because there is no other database and orm for typescript except mongoose and mongodb
// the default template for typescript is express-ts, and it ships with mongoose and mongodb by default
if (language !== "typescript") {
initDB = await promptInitDatabase();
if (initDB) {
database = await promptDatabase(framework);
if (jsBackendStacks.includes(framework)) {
orm = await promptOrm(database);
}
}
}
installDependencies = await promptDependenciesInstall();
await createBackendProject({
projectName,
framework,
database,
orm,
installDependencies,
language,
});
}
}
/**
* Render cli title
*/
function renderTitle() {
const figletConfig = {
font: "Big",
horizontalLayout: "default",
verticalLayout: "default",
width: 80,
whitespaceBreak: true,
};
useGradient({
title: figlet.textSync("StartEase", figletConfig),
});
}