-
Notifications
You must be signed in to change notification settings - Fork 0
/
designa-create.sh
101 lines (80 loc) · 2.61 KB
/
designa-create.sh
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
#!/bin/bash
# Pergunta o nome do projeto
read -p "Digite o nome do projeto: " project_name
# Cria o diretório com o nome do projeto e acessa-o
mkdir "$project_name"
cd "$project_name"
# Inicializa o projeto em TypeScript usando o yarn
yarn init -y
# Cria a estrutura de diretórios sugerida
mkdir src
mkdir src/controllers
mkdir src/models
mkdir src/services
mkdir src/routes
mkdir src/middlewares
mkdir src/utils
mkdir environment
# Define o nome do projeto e do ambiente
project_name=$(echo "$project_name" | tr '[:upper:]' '[:lower:]')
environment_names=("development" "production" "internal" "staging")
# Loop para criar os arquivos de ambiente com os respectivos valores
for environment_index in "${!environment_names[@]}"; do
environment_name="${environment_names[$environment_index]}"
environment_file="environment/environment.$environment_name.ts"
is_production=false
if [[ $environment_index == 1 ]]; then
is_production=true
fi
echo "export const environment = {
apiUrl: \"http://localhost:3000\",
name: \"$project_name\",
env: \"$environment_name\",
production: $is_production
};" > "$environment_file"
done
mv environment/environment.development.ts environment/environment.ts
# Cria o arquivo tsconfig.json
echo '{
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"outDir": "dist",
"strict": true,
"esModuleInterop": true
},
"include": [
"src",
"environment"
],
"files": [
"environment/environment.ts"
]
}' > tsconfig.json
# Baixa o Dockerfile
curl -sS https://raw.githubusercontent.com/designa/node-scaffold/main/Dockerfile -o Dockerfile
# Baixa o arquivo docker-compose.yaml
curl -sS https://raw.githubusercontent.com/designa/node-scaffold/main/docker-compose.yml -o docker-compose.yaml
echo 'import express, { Request, Response } from "express";
import { environment } from "../environment/environment";
const port = 3000;
const app = express();
const { name, env, production, apiUrl } = environment
app.get("/", (_: Request, res: Response) => {
res.json({ name, env, production, apiUrl, status: 200 });
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});' > src/index.ts
# Instala as dependências necessárias
yarn add express prisma fastify ts-node-dev typescript
# Adiciona os scripts ao package.json
cat package.json | jq '.scripts += {
"start": "node dist/index.js",
"dev": "ts-node-dev --respawn --transpile-only src/index.ts",
"build": "tsc",
"test": "echo \"No tests yet\""
}' > temp.json && mv temp.json package.json
echo "Projeto $project_name criado com sucesso!"
cd "$project_name"
yarn dev