Skip to content

Commit 6bb656e

Browse files
committed
Refactor package.json to add glob dependency
1 parent e01a11d commit 6bb656e

File tree

4 files changed

+66
-14
lines changed

4 files changed

+66
-14
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"class-validator": "^0.14.1",
7373
"cookie-parser": "^1.4.6",
7474
"fast-password-entropy": "^1.1.1",
75+
"glob": "^11.0.0",
7576
"handlebars": "^4.7.8",
7677
"helmet": "^7.1.0",
7778
"hibp": "^14.1.2",

src/migrations.service.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Injectable, OnModuleInit } from '@nestjs/common'
22
import { InjectModel } from '@nestjs/mongoose'
33
import { readdir } from 'fs/promises'
44
import { Model } from 'mongoose'
5+
import { glob } from 'glob'
56

67
@Injectable()
78
export class MigrationsService implements OnModuleInit {
@@ -18,20 +19,22 @@ export class MigrationsService implements OnModuleInit {
1819
}
1920

2021
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)
22+
const files = await glob(`./migrations/*.js`, {
23+
cwd: __dirname,
24+
root: __dirname,
25+
})
3126

3227
for (const file of files) {
33-
const migration = await import(`./migrations/${file}`)
34-
console.log(migration)
28+
console.log('file', file)
29+
const migration = await import(`${__dirname}/${file}`)
30+
31+
if (migration.default) {
32+
const instance = new migration.default()
33+
34+
if (typeof instance.up === 'function') {
35+
await instance.up()
36+
}
37+
}
3538
}
3639
}
3740
}
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
export function up() {
2-
console.log('1316027432511-employee-number up')
1+
export default class EmployeeNumber1616027432511 {
2+
// public constructor(@InjectConnection() private connection: Connection) {
33

4+
// }
5+
6+
public async up(): Promise<void> {
7+
console.log('EmployeeNumber1616027432511 up')
8+
}
9+
10+
public async down(): Promise<void> {
11+
console.log('EmployeeNumber1616027432511 down')
12+
}
413
}

yarn.lock

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7232,6 +7232,18 @@ glob@^10.3.10, glob@^10.3.3:
72327232
package-json-from-dist "^1.0.0"
72337233
path-scurry "^1.11.1"
72347234

7235+
glob@^11.0.0:
7236+
version "11.0.0"
7237+
resolved "https://registry.yarnpkg.com/glob/-/glob-11.0.0.tgz#6031df0d7b65eaa1ccb9b29b5ced16cea658e77e"
7238+
integrity sha512-9UiX/Bl6J2yaBbxKoEBRm4Cipxgok8kQYcOPEhScPwebu2I0HoQOuYdIO6S3hLuWoZgpDpwQZMzTFxgpkyT76g==
7239+
dependencies:
7240+
foreground-child "^3.1.0"
7241+
jackspeak "^4.0.1"
7242+
minimatch "^10.0.0"
7243+
minipass "^7.1.2"
7244+
package-json-from-dist "^1.0.0"
7245+
path-scurry "^2.0.0"
7246+
72357247
glob@^7.1.3, glob@^7.1.4:
72367248
version "7.2.3"
72377249
resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b"
@@ -8126,6 +8138,13 @@ jackspeak@^3.1.2:
81268138
optionalDependencies:
81278139
"@pkgjs/parseargs" "^0.11.0"
81288140

8141+
jackspeak@^4.0.1:
8142+
version "4.0.2"
8143+
resolved "https://registry.yarnpkg.com/jackspeak/-/jackspeak-4.0.2.tgz#11f9468a3730c6ff6f56823a820d7e3be9bef015"
8144+
integrity sha512-bZsjR/iRjl1Nk1UkjGpAzLNfQtzuijhn2g+pbZb98HQ1Gk8vM9hfbxeMBP+M2/UUdwj0RqGG3mlvk2MsAqwvEw==
8145+
dependencies:
8146+
"@isaacs/cliui" "^8.0.2"
8147+
81298148
jake@^10.8.5:
81308149
version "10.9.2"
81318150
resolved "https://registry.yarnpkg.com/jake/-/jake-10.9.2.tgz#6ae487e6a69afec3a5e167628996b59f35ae2b7f"
@@ -8913,6 +8932,11 @@ lru-cache@^10.2.0:
89138932
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.2.2.tgz#48206bc114c1252940c41b25b41af5b545aca878"
89148933
integrity sha512-9hp3Vp2/hFQUiIwKo8XCeFVnrg8Pk3TYNPIR7tJADKi5YfcF7vEaK7avFHTlSy3kOKYaJQaalfEo6YuXdceBOQ==
89158934

8935+
lru-cache@^11.0.0:
8936+
version "11.0.1"
8937+
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-11.0.1.tgz#3a732fbfedb82c5ba7bca6564ad3f42afcb6e147"
8938+
integrity sha512-CgeuL5uom6j/ZVrg7G/+1IXqRY8JXX4Hghfy5YE0EhoYQWvndP1kufu58cmZLNIDKnRhZrXfdS9urVWx98AipQ==
8939+
89168940
lru-cache@^4.0.1:
89178941
version "4.1.5"
89188942
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.5.tgz#8bbe50ea85bed59bc9e33dcab8235ee9bcf443cd"
@@ -9191,6 +9215,13 @@ minimatch@9.0.1:
91919215
dependencies:
91929216
brace-expansion "^2.0.1"
91939217

9218+
minimatch@^10.0.0:
9219+
version "10.0.1"
9220+
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-10.0.1.tgz#ce0521856b453c86e25f2c4c0d03e6ff7ddc440b"
9221+
integrity sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ==
9222+
dependencies:
9223+
brace-expansion "^2.0.1"
9224+
91949225
minimatch@^3.0.4, minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2:
91959226
version "3.1.2"
91969227
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b"
@@ -10535,6 +10566,14 @@ path-scurry@^1.10.2, path-scurry@^1.11.1:
1053510566
lru-cache "^10.2.0"
1053610567
minipass "^5.0.0 || ^6.0.2 || ^7.0.0"
1053710568

10569+
path-scurry@^2.0.0:
10570+
version "2.0.0"
10571+
resolved "https://registry.yarnpkg.com/path-scurry/-/path-scurry-2.0.0.tgz#9f052289f23ad8bf9397a2a0425e7b8615c58580"
10572+
integrity sha512-ypGJsmGtdXUOeM5u93TyeIEfEhM6s+ljAhrk5vAvSx8uyY/02OvrZnA0YNGUrPXfpJMgI1ODd3nwz8Npx4O4cg==
10573+
dependencies:
10574+
lru-cache "^11.0.0"
10575+
minipass "^7.1.2"
10576+
1053810577
path-to-regexp@0.1.7:
1053910578
version "0.1.7"
1054010579
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c"

0 commit comments

Comments
 (0)