@dauflo/nest-fixtures 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fixtures.module.js +9 -3
- package/package.json +4 -2
- package/src/fixtures.module.ts +9 -3
- package/tsconfig.json +1 -1
package/dist/fixtures.module.js
CHANGED
|
@@ -12,30 +12,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.FixturesModule = void 0;
|
|
13
13
|
const mongoose_1 = require("@nestjs/mongoose");
|
|
14
14
|
const glob_1 = require("glob");
|
|
15
|
+
const fixtures_1 = require("./fixtures");
|
|
15
16
|
class FixturesModule {
|
|
16
17
|
static forRootAsync(fixturesPathPattern, entitiesPathPattern) {
|
|
17
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
19
|
const fixturesPath = glob_1.glob.sync(fixturesPathPattern);
|
|
19
|
-
const fixturesRelativePath = fixturesPath.map((path) => path.replace('src/', '
|
|
20
|
+
const fixturesRelativePath = fixturesPath.map((path) => path.replace('src/', './dist/')).map((path) => path.replace('.ts', ''));
|
|
20
21
|
const fixturesProviders = [];
|
|
22
|
+
console.log(fixturesPath);
|
|
23
|
+
console.log(glob_1.glob.sync('./dist/datafixtures/*'));
|
|
24
|
+
console.log(glob_1.glob.sync('dist/datafixtures/*'));
|
|
21
25
|
const importedFixtures = yield Promise.all(fixturesRelativePath.map((path) => Promise.resolve().then(() => require(path))));
|
|
22
26
|
importedFixtures.forEach((fixture) => {
|
|
23
27
|
fixturesProviders.push(fixture[Object.keys(fixture)[0]]);
|
|
24
28
|
});
|
|
25
29
|
const entitiesPath = glob_1.glob.sync(entitiesPathPattern);
|
|
26
|
-
const entitiesRelativePath = entitiesPath.map((path) => path.replace('src/', '
|
|
30
|
+
const entitiesRelativePath = entitiesPath.map((path) => path.replace('src/', 'dist/')).map((path) => path.replace('.ts', ''));
|
|
27
31
|
const entitiesProviders = [];
|
|
28
32
|
const importedEntities = yield Promise.all(entitiesRelativePath.map((path) => Promise.resolve().then(() => require(path))));
|
|
29
33
|
importedEntities.forEach((entity) => {
|
|
30
34
|
entitiesProviders.push({
|
|
31
35
|
name: entity[Object.keys(entity)[0]].name,
|
|
32
|
-
schema: entity[Object.keys(entity)[
|
|
36
|
+
schema: entity[Object.keys(entity)[1]],
|
|
33
37
|
});
|
|
34
38
|
});
|
|
35
39
|
return {
|
|
36
40
|
module: FixturesModule,
|
|
37
41
|
imports: [mongoose_1.MongooseModule.forFeature(importedEntities)],
|
|
38
42
|
providers: [
|
|
43
|
+
fixtures_1.ReferenceRepository,
|
|
39
44
|
...fixturesProviders,
|
|
40
45
|
{
|
|
41
46
|
provide: 'FIXTURES',
|
|
@@ -44,6 +49,7 @@ class FixturesModule {
|
|
|
44
49
|
args.forEach((arg) => (providersObject[arg.constructor.name] = arg));
|
|
45
50
|
return providersObject;
|
|
46
51
|
},
|
|
52
|
+
inject: fixturesProviders
|
|
47
53
|
},
|
|
48
54
|
],
|
|
49
55
|
exports: ['FIXTURES'],
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dauflo/nest-fixtures",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "",
|
|
5
|
+
"main": "./dist/index.js",
|
|
5
6
|
"scripts": {
|
|
6
7
|
"build": "tsc"
|
|
7
8
|
},
|
|
@@ -15,7 +16,8 @@
|
|
|
15
16
|
"@types/glob": "^8.0.0",
|
|
16
17
|
"glob": "^8.0.3",
|
|
17
18
|
"mongoose": "^6.6.1",
|
|
18
|
-
"nest-commander": "^3.1.0"
|
|
19
|
+
"nest-commander": "^3.1.0",
|
|
20
|
+
"reflect-metadata": "^0.1.13"
|
|
19
21
|
},
|
|
20
22
|
"devDependencies": {
|
|
21
23
|
"typescript": "^4.8.3"
|
package/src/fixtures.module.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { DynamicModule } from '@nestjs/common'
|
|
2
2
|
import { MongooseModule } from '@nestjs/mongoose'
|
|
3
3
|
import { glob } from 'glob'
|
|
4
|
+
import { ReferenceRepository } from './fixtures'
|
|
4
5
|
|
|
5
6
|
export class FixturesModule {
|
|
6
7
|
static async forRootAsync(fixturesPathPattern: string, entitiesPathPattern: string): Promise<DynamicModule> {
|
|
7
8
|
// import fixtures
|
|
8
9
|
const fixturesPath = glob.sync(fixturesPathPattern)
|
|
9
|
-
const fixturesRelativePath = fixturesPath.map((path) => path.replace('src/', '
|
|
10
|
+
const fixturesRelativePath = fixturesPath.map((path) => path.replace('src/', './../../../../')).map((path) => path.replace('.ts', ''))
|
|
10
11
|
const fixturesProviders: any[] = []
|
|
12
|
+
console.log(fixturesPath)
|
|
13
|
+
console.log(glob.sync('./dist/datafixtures/*'))
|
|
14
|
+
console.log(glob.sync('dist/datafixtures/*'))
|
|
11
15
|
const importedFixtures = await Promise.all(fixturesRelativePath.map((path) => import(path)))
|
|
12
16
|
|
|
13
17
|
importedFixtures.forEach((fixture) => {
|
|
@@ -16,14 +20,14 @@ export class FixturesModule {
|
|
|
16
20
|
|
|
17
21
|
// import entities
|
|
18
22
|
const entitiesPath = glob.sync(entitiesPathPattern)
|
|
19
|
-
const entitiesRelativePath = entitiesPath.map((path) => path.replace('src/', '
|
|
23
|
+
const entitiesRelativePath = entitiesPath.map((path) => path.replace('src/', './../../../../')).map((path) => path.replace('.ts', ''))
|
|
20
24
|
const entitiesProviders: any[] = []
|
|
21
25
|
const importedEntities = await Promise.all(entitiesRelativePath.map((path) => import(path)))
|
|
22
26
|
|
|
23
27
|
importedEntities.forEach((entity) => {
|
|
24
28
|
entitiesProviders.push({
|
|
25
29
|
name: entity[Object.keys(entity)[0]].name,
|
|
26
|
-
schema: entity[Object.keys(entity)[
|
|
30
|
+
schema: entity[Object.keys(entity)[1]],
|
|
27
31
|
})
|
|
28
32
|
})
|
|
29
33
|
|
|
@@ -31,6 +35,7 @@ export class FixturesModule {
|
|
|
31
35
|
module: FixturesModule,
|
|
32
36
|
imports: [MongooseModule.forFeature(importedEntities)],
|
|
33
37
|
providers: [
|
|
38
|
+
ReferenceRepository,
|
|
34
39
|
...fixturesProviders,
|
|
35
40
|
{
|
|
36
41
|
provide: 'FIXTURES',
|
|
@@ -39,6 +44,7 @@ export class FixturesModule {
|
|
|
39
44
|
args.forEach((arg) => (providersObject[arg.constructor.name] = arg))
|
|
40
45
|
return providersObject
|
|
41
46
|
},
|
|
47
|
+
inject: fixturesProviders
|
|
42
48
|
},
|
|
43
49
|
],
|
|
44
50
|
exports: ['FIXTURES'],
|