24
24
25
25
echo -e " ${YELLOW} \n2) We installed dependencies${NC} "
26
26
27
- npm install express dotenv typeorm reflect-metadata pg
27
+ npm install express dotenv
28
28
29
29
echo -e " ${YELLOW} \n3) We installed development dependencies${NC} "
30
30
@@ -38,10 +38,6 @@ npx tsc --init
38
38
sed -i.bak '
39
39
s/\/\/ *"rootDir": *".\/"/"rootDir": "\.\/src"/g
40
40
s/\/\/ *"outDir": *".\/"/"outDir": "\.\/dist"/g
41
- s/\/\/ *"emitDecoratorMetadata": *true,/"emitDecoratorMetadata": true,/g
42
- s/\/\/ *"experimentalDecorators": *true,/"experimentalDecorators": true,/g
43
- s/\/\/ *"lib": *\[\],/"lib": ["ES6"],/g
44
- s/\/\/ *"strictPropertyInitialization": *true,/"strictPropertyInitialization": false,/g
45
41
' tsconfig.json && rm tsconfig.json.bak
46
42
47
43
# Function to add lines to the end of the file before the last curly brace
@@ -151,36 +147,55 @@ module.exports = {
151
147
};
152
148
EOF
153
149
154
- echo -e " ${YELLOW} \n11) We configured data-source.ts ${NC} "
155
-
156
- cat << EOF > src/config/data-source.ts
157
- import { DataSource } from 'typeorm';
158
-
159
- export const AppDataSource = new DataSource({
160
- type: 'postgres',
161
- host: 'localhost',
162
- port: 5432,
163
- username: 'postgres',
164
- password: 'postgres',
165
- database: 'new_database', //This database must be created before initialize the typeorm
166
- dropSchema: false, //Erase database content when the server starts
167
- synchronize: true,
168
- logging: false, // Don't log queries in the console
169
- entities: [],
170
- subscribers: [],
171
- migrations: [],
172
- });
173
- EOF
174
150
175
151
# We set up the scripts in package.json
176
- echo -e " ${YELLOW} \n12 ) We set up the scripts in package.json${NC} "
152
+ echo -e " ${YELLOW} \n11 ) We set up the scripts in package.json${NC} "
177
153
178
154
npx json -I -f package.json -e ' this.main="./dist/index.js"'
179
155
npx json -I -f package.json -e ' this.scripts.start="nodemon"'
180
156
npx json -I -f package.json -e ' this.scripts.build="tsc"'
181
157
npx json -I -f package.json -e ' this.scripts.lint="eslint . --ext .ts"'
182
158
npx json -I -f package.json -e ' this.scripts["lint:fix"]="eslint . --ext .ts --fix"'
183
159
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
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
+
184
199
PACKAGE_JSON=" ./package.json"
185
200
sed -i ' s/\^//g' " $PACKAGE_JSON "
186
201
0 commit comments