@dauflo/nest-fixtures 1.2.0 → 1.3.1
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Connection } from 'mongoose';
|
|
2
2
|
import { CommandRunner } from 'nest-commander';
|
|
3
3
|
import { Fixtures } from './fixtures';
|
|
4
|
-
|
|
4
|
+
type FixturesObject = {
|
|
5
5
|
[key: string]: Fixtures;
|
|
6
6
|
};
|
|
7
7
|
export declare class FixturesCommand extends CommandRunner {
|
package/dist/fixtures.module.js
CHANGED
|
@@ -16,10 +16,11 @@ const fixtures_1 = require("./fixtures");
|
|
|
16
16
|
class FixturesModule {
|
|
17
17
|
static forRootAsync(fixturesPathPattern, entitiesPathPattern, discriminatorDir = 'discriminatorDir') {
|
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
var _a;
|
|
19
20
|
const fixturesPath = glob_1.glob.sync(fixturesPathPattern);
|
|
20
21
|
const fixturesRelativePath = fixturesPath.map((path) => path.replace('src/', `${process.cwd()}/dist/`)).map((path) => path.replace('.ts', ''));
|
|
21
22
|
const fixturesProviders = [];
|
|
22
|
-
const importedFixtures = yield Promise.all(fixturesRelativePath.map((path) => Promise.resolve().then(() => require(
|
|
23
|
+
const importedFixtures = yield Promise.all(fixturesRelativePath.map((path) => { var _a; return _a = path, Promise.resolve().then(() => require(_a)); }));
|
|
23
24
|
importedFixtures.forEach((fixture) => {
|
|
24
25
|
fixturesProviders.push(fixture[Object.keys(fixture)[0]]);
|
|
25
26
|
});
|
|
@@ -29,14 +30,14 @@ class FixturesModule {
|
|
|
29
30
|
const discriminatorsRelativePath = entitiesRelativePath.filter((e) => e.includes(discriminatorDir));
|
|
30
31
|
const entitiesProviders = [];
|
|
31
32
|
for (const entity of nonDiscriminatorsRelativePath) {
|
|
32
|
-
const importedEntity = yield Promise.resolve().then(() => require(
|
|
33
|
+
const importedEntity = yield (_a = entity, Promise.resolve().then(() => require(_a)));
|
|
33
34
|
const provider = {
|
|
34
35
|
name: importedEntity[Object.keys(importedEntity)[0]].name,
|
|
35
36
|
schema: importedEntity[Object.keys(importedEntity)[1]],
|
|
36
37
|
};
|
|
37
38
|
const discriminators = discriminatorsRelativePath.filter((e) => e.includes(entity.replace(/(.+)(\/.+)$/gm, '$1')));
|
|
38
39
|
if (discriminators.length !== 0) {
|
|
39
|
-
const importedDiscriminators = yield Promise.all(discriminators.map((path) => Promise.resolve().then(() => require(
|
|
40
|
+
const importedDiscriminators = yield Promise.all(discriminators.map((path) => { var _a; return _a = path, Promise.resolve().then(() => require(_a)); }));
|
|
40
41
|
provider['discriminators'] = importedDiscriminators.map((e) => {
|
|
41
42
|
return { name: e[Object.keys(e)[0]].name, schema: e[Object.keys(e)[1]] };
|
|
42
43
|
});
|
|
@@ -65,27 +66,32 @@ class FixturesModule {
|
|
|
65
66
|
}
|
|
66
67
|
static forRootAsyncMonorepo(fixturesPathPattern, entitiesPathPattern, discriminatorDir = 'discriminators', buildDir = 'dist') {
|
|
67
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
var _a;
|
|
68
70
|
const fixturesPath = glob_1.glob.sync(fixturesPathPattern);
|
|
69
|
-
const fixturesRelativePath = fixturesPath
|
|
71
|
+
const fixturesRelativePath = fixturesPath
|
|
72
|
+
.map((path) => `${process.cwd()}/${buildDir}/${path.split('/').slice(-2).join('/')}`)
|
|
73
|
+
.map((path) => path.replace('.ts', ''));
|
|
70
74
|
const fixturesProviders = [];
|
|
71
|
-
const importedFixtures = yield Promise.all(fixturesRelativePath.map((path) => Promise.resolve().then(() => require(
|
|
75
|
+
const importedFixtures = yield Promise.all(fixturesRelativePath.map((path) => { var _a; return _a = path, Promise.resolve().then(() => require(_a)); }));
|
|
72
76
|
importedFixtures.forEach((fixture) => {
|
|
73
77
|
fixturesProviders.push(fixture[Object.keys(fixture)[0]]);
|
|
74
78
|
});
|
|
75
79
|
const entitiesPath = glob_1.glob.sync(entitiesPathPattern);
|
|
76
|
-
const entitiesRelativePath = entitiesPath
|
|
80
|
+
const entitiesRelativePath = entitiesPath
|
|
81
|
+
.map((path) => `${process.cwd()}/${buildDir}/${path.split('/').slice(-3).join('/')}`)
|
|
82
|
+
.map((path) => path.replace('.ts', ''));
|
|
77
83
|
const nonDiscriminatorsRelativePath = entitiesRelativePath.filter((e) => !e.includes(discriminatorDir));
|
|
78
84
|
const discriminatorsRelativePath = entitiesRelativePath.filter((e) => e.includes(discriminatorDir));
|
|
79
85
|
const entitiesProviders = [];
|
|
80
86
|
for (const entity of nonDiscriminatorsRelativePath) {
|
|
81
|
-
const importedEntity = yield Promise.resolve().then(() => require(
|
|
87
|
+
const importedEntity = yield (_a = entity, Promise.resolve().then(() => require(_a)));
|
|
82
88
|
const provider = {
|
|
83
89
|
name: importedEntity[Object.keys(importedEntity)[0]].name,
|
|
84
90
|
schema: importedEntity[Object.keys(importedEntity)[1]],
|
|
85
91
|
};
|
|
86
92
|
const discriminators = discriminatorsRelativePath.filter((e) => e.includes(entity.replace(/(.+)(\/.+)$/gm, '$1')));
|
|
87
93
|
if (discriminators.length !== 0) {
|
|
88
|
-
const importedDiscriminators = yield Promise.all(discriminators.map((path) => Promise.resolve().then(() => require(
|
|
94
|
+
const importedDiscriminators = yield Promise.all(discriminators.map((path) => { var _a; return _a = path, Promise.resolve().then(() => require(_a)); }));
|
|
89
95
|
provider['discriminators'] = importedDiscriminators.map((e) => {
|
|
90
96
|
return { name: e[Object.keys(e)[0]].name, schema: e[Object.keys(e)[1]] };
|
|
91
97
|
});
|
package/package.json
CHANGED
package/src/fixtures.module.ts
CHANGED
|
@@ -72,7 +72,9 @@ export class FixturesModule {
|
|
|
72
72
|
): Promise<DynamicModule> {
|
|
73
73
|
// import fixtures
|
|
74
74
|
const fixturesPath = glob.sync(fixturesPathPattern)
|
|
75
|
-
const fixturesRelativePath = fixturesPath
|
|
75
|
+
const fixturesRelativePath = fixturesPath
|
|
76
|
+
.map((path) => `${process.cwd()}/${buildDir}/${path.split('/').slice(-2).join('/')}`)
|
|
77
|
+
.map((path) => path.replace('.ts', ''))
|
|
76
78
|
const fixturesProviders: any[] = []
|
|
77
79
|
const importedFixtures = await Promise.all(fixturesRelativePath.map((path) => import(path)))
|
|
78
80
|
|
|
@@ -82,7 +84,9 @@ export class FixturesModule {
|
|
|
82
84
|
|
|
83
85
|
// import entities
|
|
84
86
|
const entitiesPath = glob.sync(entitiesPathPattern)
|
|
85
|
-
const entitiesRelativePath = entitiesPath
|
|
87
|
+
const entitiesRelativePath = entitiesPath
|
|
88
|
+
.map((path) => `${process.cwd()}/${buildDir}/${path.split('/').slice(-3).join('/')}`)
|
|
89
|
+
.map((path) => path.replace('.ts', ''))
|
|
86
90
|
|
|
87
91
|
const nonDiscriminatorsRelativePath = entitiesRelativePath.filter((e) => !e.includes(discriminatorDir))
|
|
88
92
|
const discriminatorsRelativePath = entitiesRelativePath.filter((e) => e.includes(discriminatorDir))
|