Skip to content

Commit 70a90a0

Browse files
authored
Merge pull request #33 from ScaffoldAPI/dev
fix: Improve express-mongo/mysql templates and fix bugs
2 parents f862ae6 + 6ec0528 commit 70a90a0

File tree

11 files changed

+61
-44
lines changed

11 files changed

+61
-44
lines changed

package.json

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scaffold-api",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"description": "Scaffold CLI",
55
"main": "build/index.js",
66
"type": "module",
@@ -24,7 +24,32 @@
2424
"keywords": [
2525
"cli",
2626
"scaffold",
27-
"api"
27+
"api",
28+
"generator",
29+
"boilerplate",
30+
"nodejs",
31+
"typescript",
32+
"javascript",
33+
"backend",
34+
"framework",
35+
"express",
36+
"fastify",
37+
"mysql",
38+
"postgresql",
39+
"mongodb",
40+
"database",
41+
"rest-api",
42+
"developer-tools",
43+
"productivity",
44+
"automation",
45+
"template",
46+
"project-setup",
47+
"node",
48+
"node-js",
49+
"command-line",
50+
"command-line-tool",
51+
"command-line-interface",
52+
"open-source"
2853
],
2954
"license": "MIT",
3055
"dependencies": {

src/menus/helpers/messages/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ck from "chalk";
22

33
export const messages = {
44
"en-US": {
5-
mainMenuTitle: "⚙️ Scaffold CLI 📦 1.1.3",
5+
mainMenuTitle: "⚙️ Scaffold CLI 📦 1.1.4",
66
createProject: "◈ Create API Project",
77
settings: "☰ Settings",
88
quit: "✕ Quit",
@@ -30,7 +30,7 @@ export const messages = {
3030
byeMessage: "👋 Goodbye!"
3131
},
3232
"pt-BR": {
33-
mainMenuTitle: "⚙️ Scaffold CLI 📦 1.1.3",
33+
mainMenuTitle: "⚙️ Scaffold CLI 📦 1.1.4",
3434
createProject: "◈ Criar Projeto de API",
3535
settings: "☰ Configurações",
3636
quit: "✕ Sair",

templates/express-mongo/.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MONGO_URI=

templates/express-mongo/package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
"version": "1.0.0",
44
"type": "module",
55
"scripts": {
6-
"build": "tsc && node fix-imports.js",
7-
"start": "node build/app.js",
8-
"dev": "ts-node src/server.ts"
6+
"dev": "tsx watch src/server.ts"
97
},
108
"dependencies": {
119
"dotenv": "^16.3.1",
1210
"express": "^4.18.2",
13-
"mongoose": "^8.0.3"
11+
"mongoose": "^8.0.3",
12+
"cors": "^2.8.5"
1413
},
1514
"devDependencies": {
1615
"@types/express": "^4.17.21",

templates/express-mongo/src/app.ts

+23-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
11
import express from "express";
2+
import cors from "cors"
23
import routes from "./appModule.js";
3-
import connectDB from "./database/index.js";
4+
import connectDB from "./config/database.js";
45

5-
const app = express();
6+
class AppController {
7+
public app: express.Application;
68

7-
app.use(express.json());
9+
constructor() {
10+
this.app = express();
11+
this.database();
12+
this.middlewares();
13+
this.routes();
14+
}
815

9-
connectDB();
16+
private async database(): Promise<void> {
17+
await connectDB();
18+
}
1019

11-
app.use("/api", routes);
20+
private middlewares(): void {
21+
this.app.use(express.json());
22+
this.app.use(cors());
23+
}
1224

13-
export default app;
25+
private routes(): void {
26+
this.app.use(routes);
27+
}
28+
}
29+
30+
export default new AppController().app;

templates/express-mongo/src/database/index.ts renamed to templates/express-mongo/src/config/database.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import mongoose from "mongoose";
2-
import { config } from "dotenv";
2+
import dotenv from "dotenv";
33

4-
config();
4+
dotenv.config();
55

66
const MONGO_URI = process.env.MONGO_URI as string;
77

templates/express-mongo/src/fix-imports.js

-25
This file was deleted.

templates/express-mongo/src/server.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ config();
66
const PORT = process.env.PORT || 3000;
77

88
app.listen(PORT, () => {
9-
console.log(`Servidor rodando na porta ${PORT}`);
10-
});
9+
console.log(`Server running on port ${PORT}`);
10+
});

templates/express-mysql/src/app.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class AppController {
1515

1616
private async database(): Promise<void> {
1717
try {
18-
await pool.raw("SELECT 1");
18+
await pool.query("SELECT 1");
1919
console.log("📦 Banco de dados conectado com sucesso!");
2020
} catch (error) {
2121
console.error("❌ Erro ao conectar no banco de dados:", error);

0 commit comments

Comments
 (0)