typeorm command with ts-node

This commit is contained in:
Evert Prants 2022-08-22 21:23:25 +03:00
parent ac41a4668f
commit c78af3f7dc
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
4 changed files with 15 additions and 25 deletions

View File

@ -2,8 +2,15 @@
"editor.formatOnSave": true, "editor.formatOnSave": true,
"files.insertFinalNewline": true, "files.insertFinalNewline": true,
"editor.defaultFormatter": "esbenp.prettier-vscode", "editor.defaultFormatter": "esbenp.prettier-vscode",
"eslint.validate": ["typescript", "typescriptreact", "html"], "eslint.validate": [
"typescript",
"typescriptreact",
"html"
],
"editor.codeActionsOnSave": { "editor.codeActionsOnSave": {
"source.fixAll.eslint": true "source.fixAll.eslint": true
},
"[sql]": {
"editor.defaultFormatter": "adpyke.vscode-sql-formatter"
} }
} }

View File

@ -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;

View File

@ -15,6 +15,7 @@
"start:debug": "nest start --debug --watch", "start:debug": "nest start --debug --watch",
"start:prod": "node dist/main", "start:prod": "node dist/main",
"start:fe": "rimraf public/css public/js && webpack --mode=development -w", "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", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest", "test": "jest",
"test:watch": "jest --watch", "test:watch": "jest --watch",
@ -23,7 +24,7 @@
"test:e2e": "jest --config ./test/jest-e2e.json" "test:e2e": "jest --config ./test/jest-e2e.json"
}, },
"dependencies": { "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/common": "^9.0.11",
"@nestjs/core": "^9.0.11", "@nestjs/core": "^9.0.11",
"@nestjs/platform-express": "^9.0.11", "@nestjs/platform-express": "^9.0.11",

View File

@ -1,10 +1,11 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import { join } from 'path'; import { join } from 'path';
import * as dotenv from 'dotenv';
import { readFileSync } from 'fs'; import { readFileSync } from 'fs';
import * as toml from 'toml';
import { DataSource } from 'typeorm'; import { DataSource } from 'typeorm';
import * as toml from 'toml';
import * as dotenv from 'dotenv';
dotenv.config(); dotenv.config();
const CONFIG_ENV = process.env.NODE_ENV === 'production' ? 'prod' : 'dev'; 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' }))), JSON.stringify(toml.parse(readFileSync(CONFIG_PATH, { encoding: 'utf-8' }))),
); );
export default new DataSource({ ...config.database }); export const AppDataSource = new DataSource(config.database);