From c78af3f7dc984d0099b139e9b8d035fd375356c8 Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Mon, 22 Aug 2022 21:23:25 +0300 Subject: [PATCH] typeorm command with ts-node --- .vscode/settings.json | 9 ++++++++- ormconfig.js | 19 ------------------- package.json | 3 ++- src/datasource.ts | 9 +++++---- 4 files changed, 15 insertions(+), 25 deletions(-) delete mode 100644 ormconfig.js diff --git a/.vscode/settings.json b/.vscode/settings.json index 8599e60..4d4be98 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,8 +2,15 @@ "editor.formatOnSave": true, "files.insertFinalNewline": true, "editor.defaultFormatter": "esbenp.prettier-vscode", - "eslint.validate": ["typescript", "typescriptreact", "html"], + "eslint.validate": [ + "typescript", + "typescriptreact", + "html" + ], "editor.codeActionsOnSave": { "source.fixAll.eslint": true + }, + "[sql]": { + "editor.defaultFormatter": "adpyke.vscode-sql-formatter" } } diff --git a/ormconfig.js b/ormconfig.js deleted file mode 100644 index 1bc00ba..0000000 --- a/ormconfig.js +++ /dev/null @@ -1,19 +0,0 @@ -/* eslint-disable @typescript-eslint/no-var-requires */ -const { join } = require('path'); -const dotenv = require('dotenv'); -const { readFileSync } = require('fs'); -const toml = require('toml'); - -dotenv.config(); - -const CONFIG_ENV = process.env.NODE_ENV === 'production' ? 'prod' : 'dev'; -const CONFIG_FILENAME = process.env.CONFIG || `config.${CONFIG_ENV}.toml`; -const CONFIG_PATH = join(process.cwd(), CONFIG_FILENAME); - -// toml.parse returns an object that doesn't have the correct prototype, -// thus this JSON workaround is used. -const config = JSON.parse( - JSON.stringify(toml.parse(readFileSync(CONFIG_PATH, { encoding: 'utf-8' }))), -); - -module.exports = config.database; diff --git a/package.json b/package.json index 8813d79..dc9ab96 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "start:debug": "nest start --debug --watch", "start:prod": "node dist/main", "start:fe": "rimraf public/css public/js && webpack --mode=development -w", + "typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "test": "jest", "test:watch": "jest --watch", @@ -23,7 +24,7 @@ "test:e2e": "jest --config ./test/jest-e2e.json" }, "dependencies": { - "@icynet/oauth2-provider": "git+ssh://git@gitlab.icynet.eu:IcyNetwork/oauth2-provider.git", + "@icynet/oauth2-provider": "git+https://gitlab.icynet.eu/IcyNetwork/oauth2-provider.git", "@nestjs/common": "^9.0.11", "@nestjs/core": "^9.0.11", "@nestjs/platform-express": "^9.0.11", diff --git a/src/datasource.ts b/src/datasource.ts index d6cf2f2..8b77e39 100644 --- a/src/datasource.ts +++ b/src/datasource.ts @@ -1,10 +1,11 @@ -/* eslint-disable @typescript-eslint/no-var-requires */ import { join } from 'path'; -import * as dotenv from 'dotenv'; import { readFileSync } from 'fs'; -import * as toml from 'toml'; + import { DataSource } from 'typeorm'; +import * as toml from 'toml'; +import * as dotenv from 'dotenv'; + dotenv.config(); const CONFIG_ENV = process.env.NODE_ENV === 'production' ? 'prod' : 'dev'; @@ -17,4 +18,4 @@ const config = JSON.parse( JSON.stringify(toml.parse(readFileSync(CONFIG_PATH, { encoding: 'utf-8' }))), ); -export default new DataSource({ ...config.database }); +export const AppDataSource = new DataSource(config.database);