@nestledjs/api 0.0.6 → 0.0.9
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/package.json +2 -2
- package/src/account/generator.d.ts +3 -0
- package/src/account/generator.js +19 -0
- package/src/account/generator.js.map +1 -0
- package/src/app/generator.d.ts +6 -0
- package/src/app/generator.js +96 -0
- package/src/app/generator.js.map +1 -0
- package/src/config/files/src/index.ts__tmpl__ +1 -0
- package/src/config/files/src/lib/config.modules.ts__tmpl__ +8 -0
- package/src/config/files/src/lib/config.service.ts__tmpl__ +3 -3
- package/src/config/generator.d.ts +3 -0
- package/src/config/generator.js +18 -0
- package/src/config/generator.js.map +1 -0
- package/src/core/files/models/src/lib/generate-models.ts__tmpl__ +36 -25
- package/src/core/generator.d.ts +3 -0
- package/src/core/generator.js +31 -0
- package/src/core/generator.js.map +1 -0
- package/src/custom/generator.d.ts +24 -0
- package/src/custom/generator.js +199 -0
- package/src/custom/generator.js.map +1 -0
- package/src/custom/schema.d.ts +5 -0
- package/src/custom/schema.js +3 -0
- package/src/custom/schema.js.map +1 -0
- package/src/extended/generator.d.ts +3 -0
- package/src/extended/generator.js +136 -0
- package/src/extended/generator.js.map +1 -0
- package/src/extended/index.d.ts +1 -0
- package/src/extended/index.js +7 -0
- package/src/extended/index.js.map +1 -0
- package/src/extended/{schema.ts → schema.d.ts} +2 -2
- package/src/extended/schema.js +3 -0
- package/src/extended/schema.js.map +1 -0
- package/src/generate-crud/generator.d.ts +50 -0
- package/src/generate-crud/generator.js +295 -0
- package/src/generate-crud/generator.js.map +1 -0
- package/src/generate-crud/schema.d.ts +8 -0
- package/src/generate-crud/schema.js +3 -0
- package/src/generate-crud/schema.js.map +1 -0
- package/src/index.d.ts +13 -0
- package/src/index.js +17 -0
- package/src/index.js.map +1 -0
- package/src/plugin/generator.d.ts +3 -0
- package/src/plugin/generator.js +74 -0
- package/src/plugin/generator.js.map +1 -0
- package/src/plugin/{schema.ts → schema.d.ts} +3 -3
- package/src/plugin/schema.js +3 -0
- package/src/plugin/schema.js.map +1 -0
- package/src/prisma/generator.d.ts +3 -0
- package/src/prisma/generator.js +61 -0
- package/src/prisma/generator.js.map +1 -0
- package/src/setup/generator.d.ts +3 -0
- package/src/setup/generator.js +104 -0
- package/src/setup/generator.js.map +1 -0
- package/src/smtp-mailer/generator.d.ts +2 -0
- package/src/smtp-mailer/generator.js +17 -0
- package/src/smtp-mailer/generator.js.map +1 -0
- package/src/user/generator.d.ts +2 -0
- package/src/user/generator.js +18 -0
- package/src/user/generator.js.map +1 -0
- package/src/utils/generator.d.ts +2 -0
- package/src/utils/generator.js +17 -0
- package/src/utils/generator.js.map +1 -0
- package/src/workspace-setup/generator.d.ts +1 -0
- package/src/workspace-setup/generator.js +42 -0
- package/src/workspace-setup/generator.js.map +1 -0
- package/src/workspace-setup/lib/helpers.d.ts +16 -0
- package/src/workspace-setup/lib/helpers.js +164 -0
- package/src/workspace-setup/lib/helpers.js.map +1 -0
- package/eslint.config.cjs +0 -28
- package/project.json +0 -47
- package/src/account/generator.spec.ts +0 -71
- package/src/account/generator.ts +0 -20
- package/src/app/generator.spec.ts +0 -112
- package/src/app/generator.ts +0 -105
- package/src/config/generator.spec.ts +0 -47
- package/src/config/generator.ts +0 -16
- package/src/core/generator.spec.ts +0 -85
- package/src/core/generator.ts +0 -35
- package/src/custom/generator.spec.ts +0 -75
- package/src/custom/generator.ts +0 -239
- package/src/custom/schema.ts +0 -5
- package/src/extended/generator.spec.ts +0 -95
- package/src/extended/generator.ts +0 -161
- package/src/extended/index.ts +0 -1
- package/src/generate-crud/generator.spec.ts +0 -84
- package/src/generate-crud/generator.ts +0 -354
- package/src/generate-crud/schema.ts +0 -8
- package/src/index.ts +0 -13
- package/src/plugin/generator.spec.ts +0 -18
- package/src/plugin/generator.ts +0 -74
- package/src/prisma/generator.spec.ts +0 -60
- package/src/prisma/generator.ts +0 -61
- package/src/setup/generator.spec.ts +0 -18
- package/src/setup/generator.ts +0 -107
- package/src/smtp-mailer/generator.spec.ts +0 -41
- package/src/smtp-mailer/generator.ts +0 -14
- package/src/user/generator.spec.ts +0 -41
- package/src/user/generator.ts +0 -15
- package/src/utils/generator.ts +0 -14
- package/src/workspace-setup/generator.spec.ts +0 -85
- package/src/workspace-setup/generator.ts +0 -57
- package/src/workspace-setup/lib/helpers.ts +0 -149
- package/tsconfig.json +0 -16
- package/tsconfig.lib.json +0 -23
- package/tsconfig.spec.json +0 -22
- package/vite.config.mts +0 -31
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestledjs/api",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"generators": "./generators.json",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -25,6 +25,6 @@
|
|
|
25
25
|
"pg": "^8.13.0"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@nestledjs/utils": "0.0.
|
|
28
|
+
"@nestledjs/utils": "0.0.9"
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = generateLibraries;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const utils_1 = require("@nestledjs/utils");
|
|
7
|
+
function generateLibraries(tree_1) {
|
|
8
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* (tree, options = {}) {
|
|
9
|
+
const templateRootPath = (0, devkit_1.joinPathFragments)(__dirname, './files');
|
|
10
|
+
const overwrite = options.overwrite === true;
|
|
11
|
+
yield (0, utils_1.apiLibraryGenerator)(tree, { name: 'account', overwrite }, templateRootPath, 'data-access');
|
|
12
|
+
yield (0, utils_1.apiLibraryGenerator)(tree, { name: 'account', overwrite }, templateRootPath, 'feature', true);
|
|
13
|
+
yield (0, devkit_1.formatFiles)(tree);
|
|
14
|
+
return () => {
|
|
15
|
+
(0, devkit_1.installPackagesTask)(tree);
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../generators/api/src/account/generator.ts"],"names":[],"mappings":";;AAIA,oCAeC;;AAnBD,uCAAyG;AACzG,4CAAsD;AAGtD,SAA8B,iBAAiB;iEAC7C,IAAU,EACV,UAAqC,EAAE;QAEvC,MAAM,gBAAgB,GAAG,IAAA,0BAAiB,EAAC,SAAS,EAAE,SAAS,CAAC,CAAA;QAChE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,KAAK,IAAI,CAAA;QAE5C,MAAM,IAAA,2BAAmB,EAAC,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,gBAAgB,EAAE,aAAa,CAAC,CAAA;QAChG,MAAM,IAAA,2BAAmB,EAAC,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,gBAAgB,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;QAElG,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAA;QAEvB,OAAO,GAAG,EAAE;YACV,IAAA,4BAAmB,EAAC,IAAI,CAAC,CAAA;QAC3B,CAAC,CAAA;IACH,CAAC;CAAA"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = default_1;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const child_process_1 = require("child_process");
|
|
7
|
+
const path = tslib_1.__importStar(require("path"));
|
|
8
|
+
const get_npm_scope_1 = require("@nx/js/src/utils/package-json/get-npm-scope");
|
|
9
|
+
/**
|
|
10
|
+
* Removes specific compiler options from tsconfig.app.json to use the settings from tsconfig.base.json
|
|
11
|
+
* @param tree The file system tree
|
|
12
|
+
*/
|
|
13
|
+
function updateAppTsConfig(tree) {
|
|
14
|
+
const tsConfigPath = 'apps/api/tsconfig.app.json';
|
|
15
|
+
if (tree.exists(tsConfigPath)) {
|
|
16
|
+
(0, devkit_1.updateJson)(tree, tsConfigPath, (json) => {
|
|
17
|
+
if (json.compilerOptions) {
|
|
18
|
+
// Remove specific options to use the ones from tsconfig.base.json
|
|
19
|
+
delete json.compilerOptions.module;
|
|
20
|
+
delete json.compilerOptions.moduleResolution;
|
|
21
|
+
delete json.compilerOptions.emitDecoratorMetadata;
|
|
22
|
+
delete json.compilerOptions.experimentalDecorators;
|
|
23
|
+
}
|
|
24
|
+
return json;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
console.warn(`tsconfig.app.json not found at: ${tsConfigPath}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function default_1(tree, schema) {
|
|
32
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
try {
|
|
34
|
+
// Get the workspace root directory
|
|
35
|
+
const workspaceRoot = tree.root;
|
|
36
|
+
// Create apps directory if it doesn't exist
|
|
37
|
+
if (!tree.exists('apps')) {
|
|
38
|
+
tree.write('apps/.gitkeep', '');
|
|
39
|
+
}
|
|
40
|
+
// Run the Nx generator command directly from the workspace root with proper workspace layout
|
|
41
|
+
(0, child_process_1.execSync)('nx g @nx/nest:application --name api --directory apps/api --no-interactive', {
|
|
42
|
+
stdio: 'inherit',
|
|
43
|
+
cwd: workspaceRoot,
|
|
44
|
+
});
|
|
45
|
+
// Wait a bit for files to be created
|
|
46
|
+
yield new Promise((resolve) => setTimeout(resolve, 2000));
|
|
47
|
+
// Update tsconfig.app.json to remove specific compiler options
|
|
48
|
+
updateAppTsConfig(tree);
|
|
49
|
+
// Generate all files according to the template folder structure
|
|
50
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, './files'), path.join('apps', 'api'), Object.assign(Object.assign({}, schema), { tmpl: '', npmScope: (0, get_npm_scope_1.getNpmScope)(tree) }));
|
|
51
|
+
// Add dev:api script to package.json
|
|
52
|
+
(0, devkit_1.updateJson)(tree, 'package.json', (json) => {
|
|
53
|
+
if (!json.scripts) {
|
|
54
|
+
json.scripts = {};
|
|
55
|
+
}
|
|
56
|
+
json.scripts['dev:api'] = 'nx serve api --skip-nx-cache';
|
|
57
|
+
return json;
|
|
58
|
+
});
|
|
59
|
+
// Update the build target in apps/api/project.json to use custom webpack command
|
|
60
|
+
const projectJsonPath = path.join('apps', 'api', 'project.json');
|
|
61
|
+
if (tree.exists(projectJsonPath)) {
|
|
62
|
+
(0, devkit_1.updateJson)(tree, projectJsonPath, (json) => {
|
|
63
|
+
json.targets = json.targets || {};
|
|
64
|
+
json.targets.build = {
|
|
65
|
+
executor: 'nx:run-commands',
|
|
66
|
+
options: {
|
|
67
|
+
command: 'NODE_ENV=production webpack-cli --config apps/api/webpack.config.js',
|
|
68
|
+
},
|
|
69
|
+
configurations: {
|
|
70
|
+
development: {
|
|
71
|
+
command: 'NODE_ENV=development webpack-cli --config apps/api/webpack.config.js',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
return json;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
console.warn(`project.json not found at: ${projectJsonPath}`);
|
|
80
|
+
}
|
|
81
|
+
// Optionally, delete the unused default app files if they exist
|
|
82
|
+
const targetPath = path.join('apps', 'api', 'src');
|
|
83
|
+
const filesToDelete = [path.join(targetPath, 'assets'), path.join(targetPath, 'app')];
|
|
84
|
+
filesToDelete.forEach((filePath) => {
|
|
85
|
+
if (tree.exists(filePath)) {
|
|
86
|
+
tree.delete(filePath);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
console.error('Error generating API app:', error);
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../generators/api/src/app/generator.ts"],"names":[],"mappings":";;AA+BA,4BAyEC;;AAxGD,uCAA+E;AAC/E,iDAAwC;AACxC,mDAA4B;AAC5B,+EAAyE;AAEzE;;;GAGG;AACH,SAAS,iBAAiB,CAAC,IAAU;IACnC,MAAM,YAAY,GAAG,4BAA4B,CAAA;IACjD,IAAI,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;QAC9B,IAAA,mBAAU,EAAC,IAAI,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE;YACtC,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;gBACzB,kEAAkE;gBAClE,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,CAAA;gBAClC,OAAO,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAA;gBAC5C,OAAO,IAAI,CAAC,eAAe,CAAC,qBAAqB,CAAA;gBACjD,OAAO,IAAI,CAAC,eAAe,CAAC,sBAAsB,CAAA;YACpD,CAAC;YACD,OAAO,IAAI,CAAA;QACb,CAAC,CAAC,CAAA;IACJ,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,IAAI,CAAC,mCAAmC,YAAY,EAAE,CAAC,CAAA;IACjE,CAAC;AACH,CAAC;AAMD,mBAA+B,IAAU,EAAE,MAAc;;QACvD,IAAI,CAAC;YACH,mCAAmC;YACnC,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAA;YAE/B,4CAA4C;YAC5C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;gBACzB,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE,EAAE,CAAC,CAAA;YACjC,CAAC;YAED,6FAA6F;YAC7F,IAAA,wBAAQ,EAAC,4EAA4E,EAAE;gBACrF,KAAK,EAAE,SAAS;gBAChB,GAAG,EAAE,aAAa;aACnB,CAAC,CAAA;YAEF,qCAAqC;YACrC,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAA;YAEzD,+DAA+D;YAC/D,iBAAiB,CAAC,IAAI,CAAC,CAAA;YAEvB,gEAAgE;YAChE,IAAA,sBAAa,EACX,IAAI,EACJ,IAAA,0BAAiB,EAAC,SAAS,EAAE,SAAS,CAAC,EACvC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,kCACnB,MAAM,KAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAA,2BAAW,EAAC,IAAI,CAAC,IACnD,CAAC;YAEF,qCAAqC;YACrC,IAAA,mBAAU,EAAC,IAAI,EAAE,cAAc,EAAE,CAAC,IAAI,EAAE,EAAE;gBACxC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;oBAClB,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;gBACnB,CAAC;gBACD,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,8BAA8B,CAAA;gBACxD,OAAO,IAAI,CAAA;YACb,CAAC,CAAC,CAAA;YAEF,iFAAiF;YACjF,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,cAAc,CAAC,CAAA;YAChE,IAAI,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,EAAE,CAAC;gBACjC,IAAA,mBAAU,EAAC,IAAI,EAAE,eAAe,EAAE,CAAC,IAAI,EAAE,EAAE;oBACzC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,EAAE,CAAA;oBACjC,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG;wBACnB,QAAQ,EAAE,iBAAiB;wBAC3B,OAAO,EAAE;4BACP,OAAO,EAAE,qEAAqE;yBAC/E;wBACD,cAAc,EAAE;4BACd,WAAW,EAAE;gCACX,OAAO,EAAE,sEAAsE;6BAChF;yBACF;qBACF,CAAA;oBACD,OAAO,IAAI,CAAA;gBACb,CAAC,CAAC,CAAA;YACJ,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,IAAI,CAAC,8BAA8B,eAAe,EAAE,CAAC,CAAA;YAC/D,CAAC;YAED,gEAAgE;YAChE,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;YAClD,MAAM,aAAa,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAA;YACrF,aAAa,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACjC,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;oBAC1B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;gBACvB,CAAC;YACH,CAAC,CAAC,CAAA;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAA;YACjD,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;CAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Injectable } from '@nestjs/common'
|
|
2
|
-
import { ConfigService } from '@nestjs/config'
|
|
2
|
+
import { ConfigService as NestConfigService } from '@nestjs/config'
|
|
3
3
|
import { CookieOptions } from 'express'
|
|
4
4
|
|
|
5
5
|
@Injectable()
|
|
6
|
-
export class
|
|
7
|
-
constructor(public readonly config:
|
|
6
|
+
export class ConfigService {
|
|
7
|
+
constructor(public readonly config: NestConfigService) {}
|
|
8
8
|
|
|
9
9
|
get apiUrl(): string {
|
|
10
10
|
return this.config.getOrThrow<string>('apiUrl')
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = generateLibraries;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const utils_1 = require("@nestledjs/utils");
|
|
7
|
+
function generateLibraries(tree_1) {
|
|
8
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* (tree, options = {}) {
|
|
9
|
+
const templateRootPath = (0, devkit_1.joinPathFragments)(__dirname, './files');
|
|
10
|
+
const overwrite = options.overwrite === true;
|
|
11
|
+
yield (0, utils_1.apiLibraryGenerator)(tree, { name: 'config', overwrite }, templateRootPath);
|
|
12
|
+
yield (0, devkit_1.formatFiles)(tree);
|
|
13
|
+
return () => {
|
|
14
|
+
(0, devkit_1.installPackagesTask)(tree);
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../generators/api/src/config/generator.ts"],"names":[],"mappings":";;AAIA,oCAWC;;AAfD,uCAAsF;AACtF,4CAAsD;AAGtD,SAA8B,iBAAiB;iEAAC,IAAU,EAAE,UAAoC,EAAE;QAChG,MAAM,gBAAgB,GAAG,IAAA,0BAAiB,EAAC,SAAS,EAAE,SAAS,CAAC,CAAA;QAChE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,KAAK,IAAI,CAAA;QAE5C,MAAM,IAAA,2BAAmB,EAAC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,gBAAgB,CAAC,CAAA;QAEhF,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAA;QAEvB,OAAO,GAAG,EAAE;YACV,IAAA,4BAAmB,EAAC,IAAI,CAAC,CAAA;QAC3B,CAAC,CAAA;IACH,CAAC;CAAA"}
|
|
@@ -30,7 +30,10 @@ function getPrismaImportPath(): string {
|
|
|
30
30
|
const schemaPathSetting = packageJson.prisma?.schema || ''
|
|
31
31
|
|
|
32
32
|
// Updated logic: if the schema path includes 'libs/api/prisma' (or similar new structure)
|
|
33
|
-
if (
|
|
33
|
+
if (
|
|
34
|
+
schemaPathSetting.includes('libs/api/prisma') ||
|
|
35
|
+
schemaPathSetting.includes('prisma/src/lib')
|
|
36
|
+
) {
|
|
34
37
|
return '@<%= npmScope %>/api/prisma'
|
|
35
38
|
}
|
|
36
39
|
|
|
@@ -101,7 +104,7 @@ async function main() {
|
|
|
101
104
|
|
|
102
105
|
// Read and parse all schema files for DMMF
|
|
103
106
|
console.log('Reading Prisma schema files for DMMF generation...')
|
|
104
|
-
const schemaFiles = readdirSync(schemaDir).filter(
|
|
107
|
+
const schemaFiles = readdirSync(schemaDir).filter(file => file.endsWith('.prisma'))
|
|
105
108
|
|
|
106
109
|
if (schemaFiles.length === 0) {
|
|
107
110
|
console.error(`Error: No .prisma files found in directory ${schemaDir}`)
|
|
@@ -142,21 +145,25 @@ async function main() {
|
|
|
142
145
|
|
|
143
146
|
function generateModels(models: readonly any[], enums: readonly any[]): string {
|
|
144
147
|
// Check if any model field uses Float
|
|
145
|
-
const usesFloat = models.some(model =>
|
|
148
|
+
const usesFloat = models.some(model =>
|
|
149
|
+
model.fields.some((field: { type: string }) => field.type === 'Float'),
|
|
150
|
+
)
|
|
146
151
|
let output = `import { Field, ObjectType${usesFloat ? ', Float' : ''}, Int } from '@nestjs/graphql';\n`
|
|
147
152
|
output += `import { GraphQLJSONObject } from 'graphql-type-json';\n`
|
|
148
153
|
|
|
149
154
|
// Check if any model field uses Decimal
|
|
150
|
-
const usesDecimal = models.some(model =>
|
|
155
|
+
const usesDecimal = models.some(model =>
|
|
156
|
+
model.fields.some((field: { type: string }) => field.type === 'Decimal'),
|
|
157
|
+
)
|
|
151
158
|
if (usesDecimal) {
|
|
152
|
-
output += `import { Decimal } from '@prisma/client/runtime/library';\n
|
|
153
|
-
output += `import { GraphQLDecimal } from 'prisma-graphql-type-decimal';\n
|
|
159
|
+
output += `import { Decimal } from '@prisma/client/runtime/library';\n`
|
|
160
|
+
output += `import { GraphQLDecimal } from 'prisma-graphql-type-decimal';\n`
|
|
154
161
|
}
|
|
155
162
|
// Ensure Prisma and enums are imported correctly
|
|
156
|
-
const enumNames = enums.map(
|
|
163
|
+
const enumNames = enums.map(e => e.name)
|
|
157
164
|
output += `import { Prisma } from '${prismaImportPath}';\n`
|
|
158
165
|
if (enumNames.length > 0) {
|
|
159
|
-
output += `import { ${enumNames.join(', ')} } from './enums';\n
|
|
166
|
+
output += `import { ${enumNames.join(', ')} } from './enums';\n`
|
|
160
167
|
}
|
|
161
168
|
output += `\n`
|
|
162
169
|
|
|
@@ -168,6 +175,7 @@ function generateModels(models: readonly any[], enums: readonly any[]): string {
|
|
|
168
175
|
const isEnum = field.kind === 'enum'
|
|
169
176
|
const isRelation = field.kind === 'object'
|
|
170
177
|
const originalType = field.type
|
|
178
|
+
const isFieldRequired = isRelation ? false : field.isRequired
|
|
171
179
|
// const isRequired = field.isRequired // Natively supported by DMMF
|
|
172
180
|
|
|
173
181
|
// ALWAYS LOG: Print every field processed for debugging
|
|
@@ -178,7 +186,7 @@ function generateModels(models: readonly any[], enums: readonly any[]): string {
|
|
|
178
186
|
type: field.type,
|
|
179
187
|
isList: field.isList,
|
|
180
188
|
isRequired: field.isRequired,
|
|
181
|
-
})
|
|
189
|
+
})
|
|
182
190
|
|
|
183
191
|
let tsType = originalType
|
|
184
192
|
|
|
@@ -208,8 +216,10 @@ function generateModels(models: readonly any[], enums: readonly any[]): string {
|
|
|
208
216
|
|
|
209
217
|
let decorator = '@Field('
|
|
210
218
|
const options: string[] = []
|
|
211
|
-
//
|
|
212
|
-
|
|
219
|
+
// Only add nullable: true for optional fields
|
|
220
|
+
if (!isFieldRequired) {
|
|
221
|
+
options.push('nullable: true')
|
|
222
|
+
}
|
|
213
223
|
|
|
214
224
|
// Always declare the type in the decorator
|
|
215
225
|
let decoratorType = ''
|
|
@@ -238,26 +248,26 @@ function generateModels(models: readonly any[], enums: readonly any[]): string {
|
|
|
238
248
|
else if (isEnum || isRelation) decoratorType = `() => ${originalType}`
|
|
239
249
|
else if (originalType === 'DateTime') decoratorType = '() => Date'
|
|
240
250
|
else if (originalType === 'Boolean') decoratorType = '() => Boolean'
|
|
241
|
-
else if (originalType.toLowerCase() === 'string' || originalType === 'ID')
|
|
251
|
+
else if (originalType.toLowerCase() === 'string' || originalType === 'ID')
|
|
252
|
+
decoratorType = '() => String'
|
|
242
253
|
else decoratorType = `() => ${originalType}`
|
|
243
254
|
}
|
|
244
255
|
|
|
245
256
|
decorator += decoratorType
|
|
246
|
-
|
|
257
|
+
if (options.length > 0) {
|
|
258
|
+
decorator += `, { ${options.join(', ')} }`
|
|
259
|
+
}
|
|
247
260
|
decorator += ')'
|
|
248
261
|
|
|
249
262
|
output += ` ${decorator}\n`
|
|
250
|
-
//
|
|
251
|
-
const
|
|
263
|
+
// Add optional marker (?) for non-required fields, or ! for required fields
|
|
264
|
+
const typeMarker = isFieldRequired ? '!' : '?'
|
|
252
265
|
|
|
253
266
|
// For relations, use Partial<Type> only if it's not required and can be partially loaded
|
|
254
|
-
// Otherwise, if it's a relation, it's either the full Type or Type[] or null/undefined.
|
|
255
|
-
// For simplicity, let's assume if it's a relation object, it's the Type itself.
|
|
256
|
-
// Partial is useful for inputs or update DTOs, less so for GQL ObjectTypes unless specifically designed.
|
|
257
267
|
let finalTsType = tsType
|
|
258
268
|
if (isRelation) {
|
|
259
269
|
// For relations, always use Partial<Type> (for both single and list)
|
|
260
|
-
finalTsType = `Partial<${tsType}
|
|
270
|
+
finalTsType = `Partial<${tsType}>`
|
|
261
271
|
// DEBUG: Log relation fields
|
|
262
272
|
console.log('DEBUG: Relation field detected:', {
|
|
263
273
|
model: model.name,
|
|
@@ -266,11 +276,12 @@ function generateModels(models: readonly any[], enums: readonly any[]): string {
|
|
|
266
276
|
type: field.type,
|
|
267
277
|
isList: field.isList,
|
|
268
278
|
isRequired: field.isRequired,
|
|
269
|
-
})
|
|
279
|
+
})
|
|
270
280
|
}
|
|
271
281
|
|
|
272
|
-
//
|
|
273
|
-
|
|
282
|
+
// Add null union type only for non-required fields
|
|
283
|
+
const nullUnion = isFieldRequired ? '' : ' | null'
|
|
284
|
+
output += ` ${field.name}${typeMarker}: ${finalTsType}${isList ? '[]' : ''}${nullUnion};\n\n`
|
|
274
285
|
}
|
|
275
286
|
output += `}\n\n`
|
|
276
287
|
}
|
|
@@ -282,11 +293,11 @@ function generateEnums(enums: readonly any[]): string {
|
|
|
282
293
|
output += "import { registerEnumType } from '@nestjs/graphql';\n"
|
|
283
294
|
|
|
284
295
|
if (enums.length > 0) {
|
|
285
|
-
const enumNames = enums.map(
|
|
296
|
+
const enumNames = enums.map(e => e.name).join(', ')
|
|
286
297
|
output += `import { ${enumNames} } from '${prismaImportPath}';\n\n`
|
|
287
298
|
output += `export { ${enumNames} };\n\n`
|
|
288
299
|
|
|
289
|
-
enums.forEach(
|
|
300
|
+
enums.forEach(enumType => {
|
|
290
301
|
output += `registerEnumType(${enumType.name}, { name: '${enumType.name}' });\n\n`
|
|
291
302
|
})
|
|
292
303
|
} else {
|
|
@@ -304,7 +315,7 @@ export * from './core-paging.model'
|
|
|
304
315
|
`
|
|
305
316
|
}
|
|
306
317
|
|
|
307
|
-
main().catch(
|
|
318
|
+
main().catch(e => {
|
|
308
319
|
console.error('Error during generation:', e)
|
|
309
320
|
process.exit(1)
|
|
310
321
|
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = generateLibraries;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const utils_1 = require("@nestledjs/utils");
|
|
7
|
+
function generateLibraries(tree_1) {
|
|
8
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* (tree, options = {}) {
|
|
9
|
+
const templateRootPath = (0, devkit_1.joinPathFragments)(__dirname, './files');
|
|
10
|
+
const overwrite = options.overwrite === true;
|
|
11
|
+
const dependencies = {
|
|
12
|
+
'graphql-type-json': '^0.3.2',
|
|
13
|
+
'@nestjs/graphql': '^12.0.0',
|
|
14
|
+
'@nestjs/common': '^10.0.0',
|
|
15
|
+
'@nestjs/passport': '^10.0.0',
|
|
16
|
+
'@nestjs/axios': '^3.0.0',
|
|
17
|
+
'@prisma/client': '^6.9.0',
|
|
18
|
+
'@apollo/server': '^4.9.0',
|
|
19
|
+
};
|
|
20
|
+
const devDependencies = {};
|
|
21
|
+
yield (0, utils_1.installPlugins)(tree, dependencies, devDependencies);
|
|
22
|
+
yield (0, utils_1.apiLibraryGenerator)(tree, { name: 'core', overwrite }, templateRootPath, 'data-access');
|
|
23
|
+
yield (0, utils_1.apiLibraryGenerator)(tree, { name: 'core', overwrite }, templateRootPath, 'feature', true);
|
|
24
|
+
yield (0, utils_1.apiLibraryGenerator)(tree, { name: 'core', overwrite }, templateRootPath, 'models');
|
|
25
|
+
yield (0, devkit_1.formatFiles)(tree);
|
|
26
|
+
return () => {
|
|
27
|
+
(0, devkit_1.installPackagesTask)(tree);
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../generators/api/src/core/generator.ts"],"names":[],"mappings":";;AAIA,oCA8BC;;AAlCD,uCAAyG;AACzG,4CAAsE;AAGtE,SAA8B,iBAAiB;iEAC7C,IAAU,EACV,UAAkC,EAAE;QAEpC,MAAM,gBAAgB,GAAG,IAAA,0BAAiB,EAAC,SAAS,EAAE,SAAS,CAAC,CAAA;QAChE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,KAAK,IAAI,CAAA;QAE5C,MAAM,YAAY,GAAG;YACnB,mBAAmB,EAAE,QAAQ;YAC7B,iBAAiB,EAAE,SAAS;YAC5B,gBAAgB,EAAE,SAAS;YAC3B,kBAAkB,EAAE,SAAS;YAC7B,eAAe,EAAE,QAAQ;YACzB,gBAAgB,EAAE,QAAQ;YAC1B,gBAAgB,EAAE,QAAQ;SAC3B,CAAA;QAED,MAAM,eAAe,GAAG,EAAE,CAAA;QAE1B,MAAM,IAAA,sBAAc,EAAC,IAAI,EAAE,YAAY,EAAE,eAAe,CAAC,CAAA;QAEzD,MAAM,IAAA,2BAAmB,EAAC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,gBAAgB,EAAE,aAAa,CAAC,CAAA;QAC7F,MAAM,IAAA,2BAAmB,EAAC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,gBAAgB,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;QAC/F,MAAM,IAAA,2BAAmB,EAAC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,gBAAgB,EAAE,QAAQ,CAAC,CAAA;QAExF,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAA;QAEvB,OAAO,GAAG,EAAE;YACV,IAAA,4BAAmB,EAAC,IAAI,CAAC,CAAA;QAC3B,CAAC,CAAA;IACH,CAAC;CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { formatFiles, installPackagesTask, Tree } from '@nx/devkit';
|
|
2
|
+
import { getDMMF } from '@prisma/internals';
|
|
3
|
+
import { addToModules, apiLibraryGenerator, getPrismaSchemaPath, readPrismaSchema } from '@nestledjs/utils';
|
|
4
|
+
import { GenerateCustomGeneratorSchema } from './schema';
|
|
5
|
+
import { execSync } from 'child_process';
|
|
6
|
+
import { getNpmScope } from '@nx/js/src/utils/package-json/get-npm-scope';
|
|
7
|
+
import pluralize from 'pluralize';
|
|
8
|
+
declare const defaultDependencies: {
|
|
9
|
+
formatFiles: typeof formatFiles;
|
|
10
|
+
installPackagesTask: typeof installPackagesTask;
|
|
11
|
+
getDMMF: typeof getDMMF;
|
|
12
|
+
addToModules: typeof addToModules;
|
|
13
|
+
apiLibraryGenerator: typeof apiLibraryGenerator;
|
|
14
|
+
getPrismaSchemaPath: typeof getPrismaSchemaPath;
|
|
15
|
+
readPrismaSchema: typeof readPrismaSchema;
|
|
16
|
+
execSync: typeof execSync;
|
|
17
|
+
getNpmScope: typeof getNpmScope;
|
|
18
|
+
pluralize: typeof pluralize;
|
|
19
|
+
join: (...paths: string[]) => string;
|
|
20
|
+
};
|
|
21
|
+
export type CustomGeneratorDependencies = typeof defaultDependencies;
|
|
22
|
+
export declare function customGeneratorLogic(tree: Tree, schema: GenerateCustomGeneratorSchema, dependencies?: CustomGeneratorDependencies): Promise<() => void>;
|
|
23
|
+
export default function (tree: Tree, schema: GenerateCustomGeneratorSchema): Promise<() => void>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.customGeneratorLogic = customGeneratorLogic;
|
|
4
|
+
exports.default = default_1;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const devkit_1 = require("@nx/devkit");
|
|
7
|
+
const internals_1 = require("@prisma/internals");
|
|
8
|
+
const utils_1 = require("@nestledjs/utils");
|
|
9
|
+
const child_process_1 = require("child_process");
|
|
10
|
+
const get_npm_scope_1 = require("@nx/js/src/utils/package-json/get-npm-scope");
|
|
11
|
+
const pluralize_1 = tslib_1.__importDefault(require("pluralize"));
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
// Group all dependencies into a single object
|
|
14
|
+
const defaultDependencies = {
|
|
15
|
+
formatFiles: devkit_1.formatFiles,
|
|
16
|
+
installPackagesTask: devkit_1.installPackagesTask,
|
|
17
|
+
getDMMF: internals_1.getDMMF,
|
|
18
|
+
addToModules: utils_1.addToModules,
|
|
19
|
+
apiLibraryGenerator: utils_1.apiLibraryGenerator,
|
|
20
|
+
getPrismaSchemaPath: utils_1.getPrismaSchemaPath,
|
|
21
|
+
readPrismaSchema: utils_1.readPrismaSchema,
|
|
22
|
+
execSync: child_process_1.execSync,
|
|
23
|
+
getNpmScope: get_npm_scope_1.getNpmScope,
|
|
24
|
+
pluralize: pluralize_1.default,
|
|
25
|
+
join: path_1.join,
|
|
26
|
+
};
|
|
27
|
+
function getAllPrismaModels(tree, dependencies) {
|
|
28
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const prismaPath = dependencies.getPrismaSchemaPath(tree);
|
|
30
|
+
const prismaSchema = dependencies.readPrismaSchema(tree, prismaPath);
|
|
31
|
+
if (!prismaSchema) {
|
|
32
|
+
console.error(`No Prisma schema found at ${prismaPath}`);
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const dmmf = yield dependencies.getDMMF({ datamodel: prismaSchema });
|
|
37
|
+
return dmmf.datamodel.models.map((model) => {
|
|
38
|
+
var _a;
|
|
39
|
+
const singularPropertyName = model.name.charAt(0).toLowerCase() + model.name.slice(1);
|
|
40
|
+
const pluralPropertyName = dependencies.pluralize(singularPropertyName);
|
|
41
|
+
// Create a properly typed fields array
|
|
42
|
+
const fields = model.fields.map((field) => (Object.assign({ name: field.name, type: field.type, isId: field.isId, isRequired: field.isRequired, isList: field.isList, isUnique: field.isUnique, isReadOnly: field.isReadOnly, isGenerated: field.isGenerated, isUpdatedAt: field.isUpdatedAt, documentation: field.documentation }, field)));
|
|
43
|
+
// Create and return the model
|
|
44
|
+
const modelData = {
|
|
45
|
+
name: model.name,
|
|
46
|
+
pluralName: dependencies.pluralize(model.name),
|
|
47
|
+
fields,
|
|
48
|
+
primaryField: ((_a = model.fields.find((f) => !f.isId && f.type === 'String')) === null || _a === void 0 ? void 0 : _a.name) || 'name',
|
|
49
|
+
modelName: model.name,
|
|
50
|
+
modelPropertyName: singularPropertyName,
|
|
51
|
+
pluralModelName: dependencies.pluralize(model.name),
|
|
52
|
+
pluralModelPropertyName: pluralPropertyName,
|
|
53
|
+
};
|
|
54
|
+
return modelData;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.error('Error parsing Prisma schema:', error);
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function ensureDirExists(tree, path) {
|
|
64
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
if (!tree.exists(path)) {
|
|
66
|
+
// Only create the directory, do not write .gitkeep
|
|
67
|
+
// Directory will be created when a file is written into it
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function toKebabCase(str) {
|
|
72
|
+
return str
|
|
73
|
+
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
74
|
+
.replace(/([A-Z])([A-Z][a-z])/g, '$1-$2')
|
|
75
|
+
.toLowerCase();
|
|
76
|
+
}
|
|
77
|
+
function generateCustomFiles(tree, customLibraryRoot, models, npmScope, dependencies) {
|
|
78
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
const defaultDir = dependencies.join(customLibraryRoot, 'src/lib/default');
|
|
80
|
+
const pluginsDir = dependencies.join(customLibraryRoot, 'src/lib/plugins');
|
|
81
|
+
yield ensureDirExists(tree, defaultDir);
|
|
82
|
+
yield ensureDirExists(tree, pluginsDir);
|
|
83
|
+
// Only write .gitkeep in pluginsDir
|
|
84
|
+
tree.write(dependencies.join(pluginsDir, '.gitkeep'), '');
|
|
85
|
+
for (const model of models) {
|
|
86
|
+
const kebabModel = toKebabCase(model.modelName);
|
|
87
|
+
const modelFolder = dependencies.join(defaultDir, kebabModel);
|
|
88
|
+
if (tree.exists(modelFolder)) {
|
|
89
|
+
// Skip if model folder already exists
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
yield ensureDirExists(tree, modelFolder);
|
|
93
|
+
// Generate service.ts
|
|
94
|
+
const serviceContent = `import { Injectable } from '@nestjs/common'
|
|
95
|
+
|
|
96
|
+
@Injectable()
|
|
97
|
+
export class ${model.modelName}Service {
|
|
98
|
+
// Empty for now; will override or extend later if needed
|
|
99
|
+
}
|
|
100
|
+
`;
|
|
101
|
+
tree.write(dependencies.join(modelFolder, `${kebabModel}.service.ts`), serviceContent);
|
|
102
|
+
// Generate resolver.ts
|
|
103
|
+
const resolverContent = `
|
|
104
|
+
import { ApiCrudDataAccessService } from '${npmScope}/api/generated-crud/data-access'
|
|
105
|
+
import { Generated${model.modelName}Resolver } from '${npmScope}/api/generated-crud/feature'
|
|
106
|
+
import { Injectable } from '@nestjs/common'
|
|
107
|
+
import { Resolver } from '@nestjs/graphql'
|
|
108
|
+
import { ${model.modelName} } from '${npmScope}/api/core/models'
|
|
109
|
+
|
|
110
|
+
@Resolver(() => ${model.modelName})
|
|
111
|
+
@Injectable()
|
|
112
|
+
export class ${model.modelName}Resolver extends Generated${model.modelName}Resolver {
|
|
113
|
+
constructor(
|
|
114
|
+
// private readonly customService: ${model.modelName}Service,
|
|
115
|
+
generatedService: ApiCrudDataAccessService,
|
|
116
|
+
) {
|
|
117
|
+
super(generatedService)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
`;
|
|
121
|
+
tree.write(dependencies.join(modelFolder, `${kebabModel}.resolver.ts`), resolverContent);
|
|
122
|
+
// Generate module.ts
|
|
123
|
+
const moduleContent = `import { Module } from '@nestjs/common'
|
|
124
|
+
import { ${model.modelName}Service } from './${kebabModel}.service'
|
|
125
|
+
import { ${model.modelName}Resolver } from './${kebabModel}.resolver'
|
|
126
|
+
import { ApiCrudDataAccessModule } from '${npmScope}/api/generated-crud/data-access'
|
|
127
|
+
|
|
128
|
+
@Module({
|
|
129
|
+
imports: [ApiCrudDataAccessModule],
|
|
130
|
+
providers: [${model.modelName}Service, ${model.modelName}Resolver],
|
|
131
|
+
exports: [${model.modelName}Service, ${model.modelName}Resolver],
|
|
132
|
+
})
|
|
133
|
+
export class ${model.modelName}Module {}
|
|
134
|
+
`;
|
|
135
|
+
tree.write(dependencies.join(modelFolder, `${kebabModel}.module.ts`), moduleContent);
|
|
136
|
+
// Add to defaultModules in app.module.ts__tmpl__
|
|
137
|
+
dependencies.addToModules({
|
|
138
|
+
tree,
|
|
139
|
+
modulePath: 'apps/api/src/app.module.ts',
|
|
140
|
+
moduleArrayName: 'defaultModules',
|
|
141
|
+
moduleToAdd: `${model.modelName}Module`,
|
|
142
|
+
importPath: `${npmScope}/api/custom`,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
// Update index.ts to export all model modules
|
|
146
|
+
const modelFolders = models.map((m) => toKebabCase(m.modelName));
|
|
147
|
+
const indexContent = modelFolders.map((m) => `export * from './lib/default/${m}/${m}.module'`).join('\n');
|
|
148
|
+
tree.write(dependencies.join(customLibraryRoot, 'src/index.ts'), indexContent);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function customGeneratorLogic(tree_1, schema_1) {
|
|
152
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* (tree, schema, dependencies = defaultDependencies) {
|
|
153
|
+
try {
|
|
154
|
+
const name = schema.name || 'custom';
|
|
155
|
+
const customLibraryRoot = schema.directory ? `libs/api/${schema.directory}/${name}` : `libs/api/${name}`;
|
|
156
|
+
const projectName = schema.directory ? `api-${schema.directory.replace(/\//g, '-')}-${name}` : `api-${name}`;
|
|
157
|
+
// Overwrite logic
|
|
158
|
+
if (schema.overwrite && tree.exists(customLibraryRoot)) {
|
|
159
|
+
try {
|
|
160
|
+
dependencies.execSync(`nx g @nx/workspace:remove ${projectName} --forceRemove`, {
|
|
161
|
+
stdio: 'inherit',
|
|
162
|
+
cwd: tree.root,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
console.warn(`Failed to remove existing library ${projectName}:`, error);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// Use the shared apiLibraryGenerator
|
|
170
|
+
yield dependencies.apiLibraryGenerator(tree, { name }, '', undefined, false);
|
|
171
|
+
yield ensureDirExists(tree, dependencies.join(customLibraryRoot, 'src/lib/default'));
|
|
172
|
+
yield ensureDirExists(tree, dependencies.join(customLibraryRoot, 'src/lib/plugins'));
|
|
173
|
+
// Get all Prisma models
|
|
174
|
+
const models = yield getAllPrismaModels(tree, dependencies);
|
|
175
|
+
if (models.length === 0) {
|
|
176
|
+
console.error('No Prisma models found');
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
// Generate custom files per model
|
|
180
|
+
const npmScope = `@${dependencies.getNpmScope(tree)}`;
|
|
181
|
+
yield generateCustomFiles(tree, customLibraryRoot, models, npmScope, dependencies);
|
|
182
|
+
// Format files
|
|
183
|
+
yield dependencies.formatFiles(tree);
|
|
184
|
+
return () => {
|
|
185
|
+
dependencies.installPackagesTask(tree);
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
console.error('Error in Custom generator:', error);
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
function default_1(tree, schema) {
|
|
195
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
196
|
+
return customGeneratorLogic(tree, schema);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=generator.js.map
|