Skip to content

Commit a5a6d14

Browse files
authored
Merge pull request #21 from amosproj/setup-nest
Initialized Project and Setup Files
2 parents fa6824d + 29f663d commit a5a6d14

File tree

95 files changed

+24145
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+24145
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,11 @@ bin/
3434

3535
# MacOS
3636
.DS_Store
37+
38+
# Local env files
39+
apps/*/.env
40+
41+
.nx/cache
42+
.nx/workspace-data
43+
**/vite.config.{js,ts,mjs,mts,cjs,cts}.timestamp*
44+
.angular

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=true

.prettierignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Add files here to ignore them from prettier formatting
2+
/dist
3+
/coverage
4+
/.nx/cache
5+
/.nx/workspace-data
6+
.angular

.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"singleQuote": true
3+
}

Documentation/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,21 @@
11
Build, user, and technical documentation
22
Software architecture description
3+
4+
basic setup:
5+
6+
- `npm ci`: dependency install
7+
- copy `.env.example` file and rename to `.env` (adjust database properties according to database setup if necessary)
8+
9+
running the code locally:
10+
11+
- `npm run be`: run backend individually
12+
- `npm run fe`: run frontend individually
13+
- `npm run both`: run backend and frontend
14+
15+
generating database migrations:
16+
17+
- the entity files need to be annotated with `@Entity(<table-name>)`
18+
- append the entity file to the `entities` array in `db-config.service.ts`
19+
- run the following command to generate a migration file:
20+
- `nx run metadata-analyzer-backend:migrations:generate --name <migration-name>`
21+
- append the generated file to the `migrations` array in `db-config.service.ts`

apps/backend-e2e/eslint.config.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const baseConfig = require('../../eslint.config.cjs');
2+
3+
module.exports = [...baseConfig];

apps/backend-e2e/jest.config.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export default {
2+
displayName: "metadata-analyzer-backend-e2e",
3+
preset: "../../jest.preset.cjs",
4+
globalSetup: "<rootDir>/src/support/global-setup.ts",
5+
globalTeardown: "<rootDir>/src/support/global-teardown.ts",
6+
setupFiles: ["<rootDir>/src/support/test-setup.ts"],
7+
testEnvironment: "node",
8+
transform: {
9+
"^.+\\.[tj]s$": [
10+
"ts-jest",
11+
{
12+
tsconfig: "<rootDir>/tsconfig.spec.json",
13+
},
14+
],
15+
},
16+
moduleFileExtensions: ["ts", "js", "html"],
17+
coverageDirectory: "../../coverage/metadata-analyzer-backend-e2e",
18+
};

apps/backend-e2e/project.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "metadata-analyzer-backend-e2e",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"projectType": "application",
5+
"implicitDependencies": ["metadata-analyzer-backend"],
6+
"targets": {
7+
"e2e": {
8+
"executor": "@nx/jest:jest",
9+
"outputs": ["{workspaceRoot}/coverage/{e2eProjectRoot}"],
10+
"options": {
11+
"jestConfig": "apps/backend-e2e/jest.config.ts",
12+
"passWithNoTests": true
13+
},
14+
"dependsOn": ["metadata-analyzer-backend:build"]
15+
}
16+
}
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import axios from 'axios';
2+
3+
describe('GET /api', () => {
4+
it('should return a message', async () => {
5+
const res = await axios.get(`/api`);
6+
7+
expect(res.status).toBe(200);
8+
expect(res.data).toEqual({ message: 'Hello API' });
9+
});
10+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* eslint-disable */
2+
var __TEARDOWN_MESSAGE__: string;
3+
4+
module.exports = async function () {
5+
// Start services that that the app needs to run (e.g. database, docker-compose, etc.).
6+
console.log('\nSetting up...\n');
7+
8+
// Hint: Use `globalThis` to pass variables to global teardown.
9+
globalThis.__TEARDOWN_MESSAGE__ = '\nTearing down...\n';
10+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* eslint-disable */
2+
3+
module.exports = async function () {
4+
// Put clean up logic here (e.g. stopping services, docker-compose, etc.).
5+
// Hint: `globalThis` is shared between setup and teardown.
6+
console.log(globalThis.__TEARDOWN_MESSAGE__);
7+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* eslint-disable */
2+
3+
import axios from 'axios';
4+
5+
module.exports = async function () {
6+
// Configure axios for tests to use.
7+
const host = process.env.HOST ?? 'localhost';
8+
const port = process.env.PORT ?? '3000';
9+
axios.defaults.baseURL = `http://${host}:${port}`;
10+
};

apps/backend-e2e/tsconfig.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"files": [],
4+
"include": [],
5+
"references": [
6+
{
7+
"path": "./tsconfig.spec.json"
8+
}
9+
],
10+
"compilerOptions": {
11+
"esModuleInterop": true
12+
}
13+
}

apps/backend-e2e/tsconfig.spec.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc",
5+
"module": "ESNext",
6+
"types": ["jest", "node"]
7+
},
8+
"include": ["jest.config.ts", "src/**/*.ts"]
9+
}

apps/backend/.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
DATABASE_HOST="localhost"
2+
DATABASE_PORT=5433
3+
DATABASE_USER="postgres"
4+
DATABASE_PASSWORD="postgres"
5+
DATABASE_DATABASE="postgres"

apps/backend/esbuild.config.cjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const esbuildPluginTsc = require('esbuild-plugin-tsc');
2+
const path = require('node:path');
3+
4+
/** @type {import('esbuild').BuildOptions} */
5+
module.exports = {
6+
keepNames: true,
7+
plugins: [
8+
esbuildPluginTsc({
9+
tsconfigPath: path.join(__dirname, 'tsconfig.app.json'),
10+
}),
11+
],
12+
};

apps/backend/eslint.config.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const baseConfig = require('../../eslint.config.cjs');
2+
3+
module.exports = [...baseConfig];

apps/backend/jest.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
displayName: 'metadata-analyzer-backend',
3+
preset: '../../jest.preset.cjs',
4+
testEnvironment: 'node',
5+
transform: {
6+
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
7+
},
8+
moduleFileExtensions: ['ts', 'js', 'html'],
9+
coverageDirectory: '../../coverage/apps/backend',
10+
};

apps/backend/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "metadata-analyzer-backend",
3+
"type": "module",
4+
"version": "0.0.1"
5+
}

apps/backend/project.json

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"name": "metadata-analyzer-backend",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "apps/backend/src",
5+
"projectType": "application",
6+
"tags": [],
7+
"targets": {
8+
"serve": {
9+
"executor": "@nx/js:node",
10+
"defaultConfiguration": "development",
11+
"options": {
12+
"buildTarget": "metadata-analyzer-backend:build"
13+
},
14+
"configurations": {
15+
"development": {
16+
"buildTarget": "metadata-analyzer-backend:build:development"
17+
},
18+
"production": {
19+
"buildTarget": "metadata-analyzer-backend:build:production"
20+
}
21+
}
22+
},
23+
"preview": {
24+
"dependsOn": [
25+
"build"
26+
],
27+
"executor": "@nx/vite:preview-server",
28+
"defaultConfiguration": "development",
29+
"options": {
30+
"buildTarget": "metadata-analyzer-backend:build"
31+
},
32+
"configurations": {
33+
"development": {
34+
"buildTarget": "metadata-analyzer-backend:build:development",
35+
"hmr": true
36+
},
37+
"production": {
38+
"buildTarget": "metadata-analyzer-backend:build:production",
39+
"hmr": true
40+
}
41+
}
42+
},
43+
"build": {
44+
"executor": "@nx/esbuild:esbuild",
45+
"outputs": [
46+
"{options.outputPath}"
47+
],
48+
"defaultConfiguration": "production",
49+
"options": {
50+
"main": "apps/backend/src/main.ts",
51+
"outputPath": "dist/apps/backend",
52+
"tsConfig": "apps/backend/tsconfig.app.json",
53+
"assets": [],
54+
"platform": "node",
55+
"additionalEntryPoints": [
56+
"{projectRoot}/src/migrations.main.ts"
57+
]
58+
},
59+
"configurations": {
60+
"development": {
61+
"minify": false
62+
},
63+
"production": {
64+
"minify": true
65+
}
66+
}
67+
},
68+
"migrations": {
69+
"executor": "nx:run-commands",
70+
"dependsOn": [
71+
"build"
72+
],
73+
"configurations": {
74+
"run": {
75+
"command": "npx typeorm-ts-node-esm -d dist/apps/backend/migrations.main.js migration:run"
76+
},
77+
"generate": {
78+
"command": "npx typeorm-ts-node-esm -d dist/apps/backend/migrations.main.js migration:generate apps/backend/src/app/migrations/{args.name}"
79+
},
80+
"revert": {
81+
"command": "npx typeorm-ts-node-esm -d dist/apps/backend/migrations.main.js migration:revert"
82+
}
83+
}
84+
}
85+
}
86+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Test, TestingModule } from '@nestjs/testing';
2+
3+
import { AppController } from './app.controller';
4+
import { AppService } from './app.service';
5+
6+
describe('AppController', () => {
7+
let app: TestingModule;
8+
9+
beforeAll(async () => {
10+
app = await Test.createTestingModule({
11+
controllers: [AppController],
12+
providers: [AppService],
13+
}).compile();
14+
});
15+
16+
describe('getData', () => {
17+
it('should return "Hello API"', () => {
18+
const appController = app.get<AppController>(AppController);
19+
expect(appController.getData()).toEqual({ message: 'Hello API' });
20+
});
21+
});
22+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {Controller, Get} from '@nestjs/common';
2+
3+
import {AppService} from './app.service';
4+
import {ApiOperation} from '@nestjs/swagger';
5+
6+
@Controller()
7+
export class AppController {
8+
constructor(
9+
private readonly appService: AppService) {
10+
}
11+
12+
@ApiOperation({
13+
summary: 'Dummy Endpoint for testing basic setup',
14+
})
15+
@Get('data')
16+
getData() {
17+
return this.appService.getData();
18+
}
19+
}

apps/backend/src/app/app.module.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {Module} from '@nestjs/common';
2+
import {ConfigModule} from '@nestjs/config';
3+
4+
import {AppController} from './app.controller';
5+
import {AppService} from './app.service';
6+
import {TypeOrmModule} from '@nestjs/typeorm';
7+
import {DbConfigService} from "./db-config.service";
8+
import {DemoModule} from "./demo/demo.module";
9+
10+
@Module({
11+
imports: [
12+
ConfigModule.forRoot({
13+
isGlobal: true,
14+
}),
15+
TypeOrmModule.forRootAsync({
16+
imports: [ConfigModule],
17+
useClass: DbConfigService,
18+
}),
19+
DemoModule
20+
],
21+
controllers: [AppController],
22+
providers: [AppService],
23+
})
24+
export class AppModule {
25+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Test } from '@nestjs/testing';
2+
3+
import { AppService } from './app.service';
4+
5+
describe('AppService', () => {
6+
let service: AppService;
7+
8+
beforeAll(async () => {
9+
const app = await Test.createTestingModule({
10+
providers: [AppService],
11+
}).compile();
12+
13+
service = app.get<AppService>(AppService);
14+
});
15+
16+
describe('getData', () => {
17+
it('should return "Hello API"', () => {
18+
expect(service.getData()).toEqual({ message: 'Hello API' });
19+
});
20+
});
21+
});

apps/backend/src/app/app.service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Injectable } from '@nestjs/common';
2+
3+
@Injectable()
4+
export class AppService {
5+
getData(): { message: string } {
6+
return { message: 'Hello API' };
7+
}
8+
}

0 commit comments

Comments
 (0)