Skip to content

Commit b3a1112

Browse files
authored
Merge pull request #3 from bralegz/develop-netepscript
Configuracion de typeORM
2 parents 9164589 + f70c60f commit b3a1112

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

netepscript.sh

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ echo -e "${YELLOW}\n4) We generated the tsconfig.json with default options${NC}"
3434

3535
npx tsc --init
3636

37+
#Typescript config file modification
3738
sed -i.bak '
3839
s/\/\/ *"rootDir": *".\/"/"rootDir": "\.\/src"/g
3940
s/\/\/ *"outDir": *".\/"/"outDir": "\.\/dist"/g
@@ -146,6 +147,7 @@ module.exports = {
146147
};
147148
EOF
148149

150+
149151
# We set up the scripts in package.json
150152
echo -e "${YELLOW}\n11) We set up the scripts in package.json${NC}"
151153

@@ -155,8 +157,51 @@ npx json -I -f package.json -e 'this.scripts.build="tsc"'
155157
npx json -I -f package.json -e 'this.scripts.lint="eslint . --ext .ts"'
156158
npx json -I -f package.json -e 'this.scripts["lint:fix"]="eslint . --ext .ts --fix"'
157159

160+
echo -e "${YELLOW}\n12) Choose your database engine:${NC}"
161+
echo "1) PostgreSQL with Sequelize"
162+
echo "2) MySQL with Sequelize"
163+
echo "3) MongoDB with Mongoose"
164+
echo "4) typeORM with postgres"
165+
echo "5) No database engine"
166+
read -p "Enter your choice (1-5): " db_choice
167+
168+
case "$db_choice" in
169+
"1")
170+
echo "Installing PostgreSQL and Sequelize dependencies..."
171+
npm install pg sequelize
172+
npm install -D @types/pg @types/sequelize
173+
echo -e "\n# PostgreSQL Configuration\nDB_HOST=localhost\nDB_PORT=5432\nDB_NAME=your_database\nDB_USER=your_username\nDB_PASSWORD=your_password" >> .env
174+
;;
175+
"2")
176+
echo "Installing MySQL and Sequelize dependencies..."
177+
npm install mysql2 sequelize
178+
npm install -D @types/mysql @types/sequelize
179+
echo -e "\n# MySQL Configuration\nDB_HOST=localhost\nDB_PORT=3306\nDB_NAME=your_database\nDB_USER=your_username\nDB_PASSWORD=your_password" >> .env
180+
;;
181+
"3")
182+
echo "Installing MongoDB and Mongoose dependencies..."
183+
npm install mongodb mongoose
184+
npm install -D @types/mongodb @types/mongoose
185+
echo -e "\n# MongoDB Configuration\nMONGO_URI=mongodb://localhost:27017/your_database" >> .env
186+
;;
187+
"4")
188+
echo "Installing typeORM dependencies..."
189+
bash typeOrm.sh
190+
;;
191+
"5")
192+
echo "No database dependencies installed."
193+
;;
194+
*)
195+
echo "Invalid choice. No database dependencies installed."
196+
;;
197+
esac
198+
158199
PACKAGE_JSON="./package.json"
159-
sed -i 's/\^//g' "$PACKAGE_JSON"
200+
if [[ "$OSTYPE" == "darwin"* ]]; then
201+
sed -i '' 's/\^//g' "$PACKAGE_JSON"
202+
else
203+
sed -i 's/\^//g' "$PACKAGE_JSON"
204+
fi
160205

161206
echo -e "${GREEN}=========================================================${NC}"
162207
echo -e "${RED} ${BOLD}Follow us on GitHub:${NC}"

typeOrm.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
npm install typeorm reflect-metadata pg
2+
3+
4+
#Typescript config file modification
5+
sed -i.bak '
6+
s/\/\/ *"emitDecoratorMetadata": *true,/"emitDecoratorMetadata": true,/g
7+
s/\/\/ *"experimentalDecorators": *true,/"experimentalDecorators": true,/g
8+
s/\/\/ *"lib": *\[\],/"lib": ["ES6"],/g
9+
s/\/\/ *"strictPropertyInitialization": *true,/"strictPropertyInitialization": false,/g
10+
' tsconfig.json && rm tsconfig.json.bak
11+
12+
13+
cat << EOF > src/config/data-source.ts
14+
import { DataSource } from 'typeorm';
15+
16+
export const AppDataSource = new DataSource({
17+
type: 'postgres',
18+
host: 'localhost',
19+
port: 5432,
20+
username: 'postgres',
21+
password: 'postgres',
22+
database: 'new_database', //This database must be created before initialize the typeorm
23+
dropSchema: false, //Erase database content when the server starts
24+
synchronize: true,
25+
logging: false, // Don't log queries in the console
26+
entities: [],
27+
subscribers: [],
28+
migrations: [],
29+
});
30+
EOF

0 commit comments

Comments
 (0)