Skip to content

Commit

Permalink
fix: used nestjs logger & used ts-node to transpile & run ts file
Browse files Browse the repository at this point in the history
  • Loading branch information
Allan2000-Git committed Dec 5, 2024
1 parent 8b001a5 commit 3ba51a2
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 308 deletions.
26 changes: 26 additions & 0 deletions apps/api/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module'
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended'
],
root: true,
env: {
node: true,
jest: true
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': ['warn']
}
}
6 changes: 4 additions & 2 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "api",
"version": "1.0.0",
"description": "",
"type": "module",
"main": "index.js",
"scripts": {
"build": "nest build",
Expand All @@ -16,7 +17,7 @@
"db:format": "pnpm dlx prisma format --schema=src/prisma/schema.prisma",
"db:reset": "pnpm dlx dotenv-cli -e ../../.env -- pnpm dlx prisma migrate reset --force --schema=src/prisma/schema.prisma",
"sourcemaps": "sentry-cli sourcemaps inject ./dist && sentry-cli sourcemaps upload ./dist || echo 'Failed to upload source maps to Sentry'",
"e2e:prepare": "cd ../../ && docker compose down && docker compose -f docker-compose-test.yml up -d && sleep 3 && cd apps/api && pnpm db:generate-types && cross-env NODE_ENV='e2e' DATABASE_URL='postgresql://prisma:prisma@localhost:5432/tests' pnpm run db:deploy-migrations",
"e2e:prepare": "cd ../../ && docker compose down && docker compose -f docker-compose-test.yml up -d && cd apps/api && node --loader ts-node/esm src/common/cross-platform-sleep.ts && pnpm db:generate-types && cross-env NODE_ENV='e2e' DATABASE_URL='postgresql://prisma:prisma@localhost:5432/tests' pnpm run db:deploy-migrations",
"e2e": "pnpm run e2e:prepare && cross-env NODE_ENV='e2e' DATABASE_URL='postgresql://prisma:prisma@localhost:5432/tests' jest --runInBand --config=jest.e2e-config.ts && pnpm run e2e:teardown",
"e2e:teardown": "cd ../../ && docker compose -f docker-compose-test.yml down",
"unit": "pnpm db:generate-types && jest --config=jest.config.ts"
Expand Down Expand Up @@ -78,7 +79,8 @@
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3"
"ts-loader": "^9.4.3",
"ts-node": "^10.9.2"
},
"jest": {
"moduleFileExtensions": [
Expand Down
30 changes: 17 additions & 13 deletions apps/api/src/common/cross-platform-sleep.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import { execSync } from 'child_process';
import { platform } from 'os';
import { execSync } from 'child_process'
import { platform } from 'os'
import { Logger } from '@nestjs/common'

const seconds = 3;
const os = platform();
const logger = new Logger('SleepCommand')
const seconds = 3
const os = platform()

let command: string;
let command: string
if (os === 'win32') {
command = `powershell -command "Start-Sleep -s ${seconds}"`;
command = `powershell -command "Start-Sleep -s ${seconds}"`
} else if (os === 'darwin' || os === 'linux') {
command = `sleep ${seconds}`;
command = `sleep ${seconds}`
} else {
console.error('Unsupported operating system');
process.exit(1);
logger.error('Unsupported operating system')
process.exit(1)
}

try {
execSync(command);
logger.log(`Executing sleep command for ${seconds} seconds on ${os}`)
execSync(command)
logger.log('Sleep command executed successfully')
} catch (error) {
console.error(`Error executing sleep command: ${error}`);
process.exit(1);
}
logger.error(`Error executing sleep command: ${error}`)
process.exit(1)
}
Loading

0 comments on commit 3ba51a2

Please sign in to comment.