-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·134 lines (112 loc) · 3.4 KB
/
cli.js
File metadata and controls
executable file
·134 lines (112 loc) · 3.4 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
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
#!/usr/bin/env node
import figlet from "figlet";
import { program } from "commander";
import chalk from "chalk";
import shell from "shelljs";
import path from "path";
import useGradient from "./src/utils/useGradient.js";
import { createBackendProject } from "./src/utils/create-backend-project.js";
import {
promptBackendFramework,
promptDatabase,
promptFrontendFramework,
promptFrontendLanguage,
promptInitDatabase,
promptOrm,
promptProjectName,
promptProjectStack,
promptDependenciesInstall,
promptInitializeGit
} from "./src/utils/prompts.js";
import { createFrontendProject } from "./src/utils/create-frontend-project.js";
import { validateProjectName } from "./src/utils/helper.js";
import { sendQueuedStats } from "./src/utils/stat.js";
import ora from "ora";
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;
let initializeGit;
const initialMsg = `Simplify Project Setup with the. ${chalk.green(
toolName,
)} CLI Tool.`;
// render cli title
renderTitle();
console.log(chalk.white(initialMsg));
projectName = await promptProjectName();
validateProjectName(projectName);
projectStack = await promptProjectStack();
// process sending of stats in background
sendQueuedStats();
/**
* start prompts
*/
if (projectStack === "frontend") {
language = await promptFrontendLanguage();
framework = await promptFrontendFramework();
initializeGit = await promptInitializeGit();
if (framework === "html-x-css-x-javascript") {
return await createFrontendProject(projectName, framework, "javascript");
}
await createFrontendProject(projectName, framework, language);
} else if (projectStack === "backend") {
framework = await promptBackendFramework();
initDB = await promptInitDatabase();
if (initDB) {
database = await promptDatabase(framework);
if (jsBackendStacks.includes(framework)) {
orm = await promptOrm(database);
}
}
installDependencies = await promptDependenciesInstall();
initializeGit = await promptInitializeGit();
await createBackendProject(projectName, framework, database, orm, installDependencies);
}
if (initializeGit) {
if (shell.which("git")) {
const destinationPath = path.join(
process.cwd(),
projectName ?? `project-starter-${framework}-template`,
);
// initialize git for the final source
const spinner = ora();
spinner.succeed();
spinner.start("Initializing git ...");
shell.cd(`${destinationPath}`);
shell.exec(`git init`, { silent: true });
shell.exec(`git add .`, { silent: true });
shell.exec(`git commit -m "Initial commit"`, { silent: true });
shell.cd("-");
spinner.succeed("Project ready!🚀");
}
}
}
/**
* Render cli title
*/
function renderTitle() {
const figletConfig = {
font: "Big",
horizontalLayout: "default",
verticalLayout: "default",
width: 80,
whitespaceBreak: true,
};
useGradient({
title: figlet.textSync("StartEase", figletConfig),
});
}