Skip to content

Commit 6aa5d94

Browse files
committed
Refactor Makefile to add production, development, and debug environment commands
1 parent 631295c commit 6aa5d94

File tree

4 files changed

+71
-2
lines changed

4 files changed

+71
-2
lines changed

Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,33 @@ help:
1414
build: ## Build the container
1515
@docker build --platform $(PLATFORM) -t $(IMG_NAME) .
1616

17+
prod: ## Start production environment
18+
@docker run --rm -it \
19+
-e NODE_ENV=development \
20+
-e NODE_TLS_REJECT_UNAUTHORIZED=0 \
21+
--add-host host.docker.internal:host-gateway \
22+
--platform $(PLATFORM) \
23+
--network dev \
24+
--name $(APP_NAME) \
25+
-p $(APP_PORT):4000 \
26+
-p 9229:9229 \
27+
-v $(CURDIR):/data \
28+
$(IMG_NAME) yarn start:prod
29+
1730
dev: ## Start development environment
31+
@docker run --rm -it \
32+
-e NODE_ENV=development \
33+
-e NODE_TLS_REJECT_UNAUTHORIZED=0 \
34+
--add-host host.docker.internal:host-gateway \
35+
--platform $(PLATFORM) \
36+
--network dev \
37+
--name $(APP_NAME) \
38+
-p $(APP_PORT):4000 \
39+
-p 9229:9229 \
40+
-v $(CURDIR):/data \
41+
$(IMG_NAME) yarn start:dev
42+
43+
debug: ## Start debug environment
1844
@docker run --rm -it \
1945
-e NODE_ENV=development \
2046
-e NODE_TLS_REJECT_UNAUTHORIZED=0 \

src/app.module.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { MailerModule } from '@nestjs-modules/mailer';
2020
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';
2121
import { MailadmService } from '~/settings/mailadm.service';
2222
import { FactorydriveModule } from '@the-software-compagny/nestjs_module_factorydrive';
23+
import { MigrationsService } from './migrations.service';
2324

2425
@Module({
2526
imports: [
@@ -39,7 +40,7 @@ import { FactorydriveModule } from '@the-software-compagny/nestjs_module_factory
3940
},
4041
template: {
4142
dir: __dirname + '/../templates',
42-
adapter: new HandlebarsAdapter(),
43+
// adapter: new HandlebarsAdapter(),
4344
options: {
4445
strict: true,
4546
},
@@ -96,6 +97,7 @@ import { FactorydriveModule } from '@the-software-compagny/nestjs_module_factory
9697
controllers: [AppController],
9798
providers: [
9899
AppService,
100+
MigrationsService,
99101
{
100102
provide: APP_GUARD,
101103
useClass: AuthGuard('jwt'),
@@ -114,4 +116,4 @@ import { FactorydriveModule } from '@the-software-compagny/nestjs_module_factory
114116
},
115117
],
116118
})
117-
export class AppModule {}
119+
export class AppModule { }

src/migrations.service.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Injectable, OnModuleInit } from '@nestjs/common'
2+
import { InjectModel } from '@nestjs/mongoose'
3+
import { readdir } from 'fs/promises'
4+
import { Model } from 'mongoose'
5+
6+
@Injectable()
7+
export class MigrationsService implements OnModuleInit {
8+
public constructor() { }
9+
10+
public async onModuleInit() {
11+
await this.runMigrations()
12+
}
13+
14+
public async runMigrations() {
15+
try {
16+
await this.loadMigrationsFiles()
17+
} catch { }
18+
}
19+
20+
private async loadMigrationsFiles() {
21+
let files: string[] = []
22+
try {
23+
console.log('Loading migrations files')
24+
console.log(process.cwd())
25+
console.log(__dirname)
26+
console.log(__filename)
27+
files = await readdir('./migrations')
28+
} catch { }
29+
30+
console.log(files)
31+
32+
for (const file of files) {
33+
const migration = await import(`./migrations/${file}`)
34+
console.log(migration)
35+
}
36+
}
37+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export function up() {
2+
console.log('1316027432511-employee-number up')
3+
4+
}

0 commit comments

Comments
 (0)