Skip to content

Commit 1e56691

Browse files
committed
.
1 parent b2aa5cf commit 1e56691

File tree

2 files changed

+160
-0
lines changed

2 files changed

+160
-0
lines changed

netepScript.v0-8-9.sh

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
#!/bin/bash
2+
3+
VERDE='\033[0;32m'
4+
AZUL='\033[0;34m'
5+
AMARILLO='\033[1;33m'
6+
ROJO='\033[0;31m'
7+
NEGRITA='\033[1m'
8+
NC='\033[0m' # No Color (para resetear)
9+
10+
echo -e "${VERDE}=========================================================${NC}"
11+
echo -e "${AZUL} ${NEGRITA}netepScript - V 0.8.9${NC}"
12+
echo -e "${AZUL} Script de instalación para servidor Node.js${NC}"
13+
echo -e "${AMARILLO} Incluye: Express.js, TypeScript, ESLint y Prettier${NC}"
14+
echo -e "${ROJO}${NEGRITA} Autores: Marcelo Robin / Jesús García${NC}"
15+
echo -e "${VERDE}=========================================================${NC}"
16+
echo ""
17+
18+
echo -e "${AZUL}\n1) Inicializamos el proyecto de NodeJS (si no existe)${NC}"
19+
20+
if [ ! -f "package.json" ]; then
21+
npm init -y
22+
fi
23+
24+
echo -e "${AZUL}\n2) Instalamos dependencias${NC}"
25+
26+
npm install express dotenv
27+
28+
echo -e "${AZUL}\n3) Instalamos dependencias de desarrollo${NC}"
29+
30+
npm install -D morgan @types/morgan nodemon [email protected] @typescript-eslint/[email protected] @typescript-eslint/[email protected] [email protected] @types/node @types/express ts-node prettier eslint-plugin-prettier eslint-config-prettier
31+
32+
echo -e "${AZUL}\n4) Generamos el tsconfig.json con las opciones por defecto${NC}"
33+
34+
npx tsc --init
35+
36+
# Función para agregar líneas al final del archivo antes de la última llave
37+
add_lines_before_last_brace() {
38+
file=$1
39+
tmpfile=$(mktemp)
40+
# Verificar si las líneas ya existen antes de agregarlas
41+
if ! grep -q '"include": \["src/\*\*/\*.ts"\]' "$file" || ! grep -q '"exclude": \["node_modules"\]' "$file"; then
42+
awk '
43+
BEGIN {
44+
include_added = 0
45+
exclude_added = 0
46+
}
47+
{
48+
if ($0 ~ /}$/ && !include_added && !exclude_added) {
49+
sub(/}$/, "},")
50+
print
51+
print " \"include\": [\"src/**/*.ts\"],"
52+
print " \"exclude\": [\"node_modules\"]"
53+
include_added = 1
54+
exclude_added = 1
55+
} else if ($0 ~ /}$/ && include_added && !exclude_added) {
56+
sub(/}$/, "},")
57+
print
58+
print " \"exclude\": [\"node_modules\"]"
59+
exclude_added = 1
60+
} else {
61+
print
62+
}
63+
}
64+
' "$file" > "$tmpfile"
65+
mv "$tmpfile" "$file"
66+
fi
67+
}
68+
69+
# Ajustamos el tsconfig.json
70+
add_lines_before_last_brace "tsconfig.json"
71+
72+
echo -e "${AZUL}\n5) Creamos el nodemon.json con su configuración correspondiente${NC}"
73+
74+
cat << EOF > nodemon.json
75+
{
76+
"watch": ["src"],
77+
"ext": "ts,json",
78+
"ignore": ["src/tests/*", "node_modules"],
79+
"exec": "ts-node src/index.ts"
80+
}
81+
EOF
82+
83+
echo -e "${AZUL}\n6) Creamos el archivo .gitignore${NC}"
84+
85+
cat <<EOF > .gitignore
86+
node_modules
87+
.env
88+
dist
89+
EOF
90+
91+
echo -e "${AZUL}\n7) Creamos la estructura de carpetas del proyecto${NC}"
92+
93+
mkdir -p src/{routes,controllers,config,interfaces,models,middlewares,services}
94+
touch src/config/envs.ts
95+
touch src/routes/indexRouter.ts
96+
touch src/routes/userRouter.ts
97+
touch src/routes/appointmentRouter.ts
98+
touch src/controllers/userRouter.ts
99+
touch src/controllers/appointmentRouter.ts
100+
101+
echo -e "${AZUL}\n8) Agregamos los archivos index.ts y server.ts${NC}"
102+
103+
touch src/index.ts
104+
touch src/server.ts
105+
106+
echo -e "${AZUL}\n9) Agregamos el archivo .prettierrc con su configuración${NC}"
107+
108+
touch ./.prettierrc
109+
cat << EOF > .prettierrc
110+
{
111+
"singleQuote": true,
112+
"trailingComma": "all",
113+
"semi": true,
114+
"tabWidth": 2,
115+
"bracketSpacing": true,
116+
"arrowParens": "always",
117+
"endOfLine": "lf"
118+
}
119+
EOF
120+
121+
echo -e "${AZUL}\n10) Agregamos el archivo .eslintrc.js y su configuración${NC}"
122+
123+
touch ./.eslintrc.js
124+
cat << EOF > .eslintrc.js
125+
module.exports = {
126+
parser: "@typescript-eslint/parser",
127+
plugins: ["@typescript-eslint", "prettier"],
128+
extends: [
129+
"eslint:recommended",
130+
"plugin:@typescript-eslint/recommended",
131+
"plugin:prettier/recommended"
132+
],
133+
parserOptions: {
134+
ecmaVersion: "latest",
135+
},
136+
env: {
137+
es6: true,
138+
},
139+
rules: {
140+
"prettier/prettier": "error"
141+
}
142+
};
143+
EOF
144+
145+
# Configuramos los scripts en package.json
146+
echo -e "${AZUL}\n11) Configuramos los scripts en package.json${NC}"
147+
148+
npx json -I -f package.json -e 'this.scripts.start="nodemon"'
149+
npx json -I -f package.json -e 'this.scripts.build="tsc"'
150+
npx json -I -f package.json -e 'this.scripts.lint="eslint . --ext .ts"'
151+
npx json -I -f package.json -e 'this.scripts["lint:fix"]="eslint . --ext .ts --fix"'
152+
153+
echo -e "${VERDE}=========================================================${NC}"
154+
echo -e "${ROJO} ${NEGRITA}Seguinos en Github:${NC}"
155+
echo -e "${ROJO} ${NEGRITA}https://github.com/mnibor${NC}"
156+
echo -e "${ROJO} ${NEGRITA}https://github.com/JAJesusGarcia${NC}"
157+
echo -e "${VERDE}=========================================================${NC}"
158+
159+
echo -e "${VERDE}\n${NEGRITA}LISTO!!! PROYECTO CONFIGURADO!!! A PROGRAMAR!!!${NC}"
160+
echo ""

netepScript.v0-8-9.zip

-1.78 KB
Binary file not shown.

0 commit comments

Comments
 (0)