@nest-extended/cli 0.0.2-beta-7 → 0.0.2-beta-10
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/README.md +16 -4
- package/package.json +13 -1
- package/src/commands/generate-app.js +62 -56
- package/src/commands/generate-app.js.map +1 -1
- package/src/commands/generate-auth.d.ts +1 -0
- package/src/commands/generate-auth.js +77 -0
- package/src/commands/generate-auth.js.map +1 -0
- package/src/commands/generate-service.js +2 -1
- package/src/commands/generate-service.js.map +1 -1
- package/src/commands/generate.js +5 -0
- package/src/commands/generate.js.map +1 -1
- package/src/lib/generate-auth-services.d.ts +1 -0
- package/src/lib/generate-auth-services.js +33 -0
- package/src/lib/generate-auth-services.js.map +1 -0
- package/src/templates/schema.template.d.ts +1 -1
- package/src/templates/schema.template.js +17 -14
- package/src/templates/schema.template.js.map +1 -1
package/README.md
CHANGED
|
@@ -25,14 +25,14 @@ yarn add -D @nest-extended/cli
|
|
|
25
25
|
### Generate Application (`g app`)
|
|
26
26
|
|
|
27
27
|
Generates a fully configured NestJS application with standard best-practices built right in.
|
|
28
|
-
It
|
|
28
|
+
It interactively prompts for your choice of database (currently supporting MongoDB) and handles scaffolding the app. It also prompts whether you want to automatically generate authentication modules.
|
|
29
29
|
|
|
30
30
|
**Includes:**
|
|
31
31
|
- Running `@nestjs/cli`'s `nest new` command internally
|
|
32
32
|
- `Mongoose` schema integration out of the box
|
|
33
33
|
- Context-mapping out of the box using `nestjs-cls`
|
|
34
|
-
- Built-in `AuthModule` with JSON Web Token (JWT) handling via `@nestjs/jwt` and password hashing with `bcrypt`
|
|
35
|
-
- Fully functional `UsersModule` equipped with standard fields and authentication logic implementations.
|
|
34
|
+
- Built-in `AuthModule` with JSON Web Token (JWT) handling via `@nestjs/jwt` and password hashing with `bcrypt` (opt-in)
|
|
35
|
+
- Fully functional `UsersModule` equipped with standard fields and authentication logic implementations. (opt-in)
|
|
36
36
|
- Pre-configured `NestExtendedModule` context for soft deletes functionality
|
|
37
37
|
|
|
38
38
|
**Usage:**
|
|
@@ -49,13 +49,25 @@ nest-cli generate app <app-name>
|
|
|
49
49
|
nest-cli g app e-commerce-dashboard
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
+
### Generate Authentication (`g auth`)
|
|
53
|
+
|
|
54
|
+
If you generated a NestJS application without the authentication modules and want to add them later, use the `auth` command. This will scaffold out the `Auth` and `Users` modules, install `@nestjs/jwt` and `bcrypt`, and hook them into your `app.module.ts`.
|
|
55
|
+
|
|
56
|
+
**Usage:**
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
nest-cli g auth
|
|
60
|
+
# or
|
|
61
|
+
nest-cli generate auth
|
|
62
|
+
```
|
|
63
|
+
|
|
52
64
|
### Generate Service (`g service`)
|
|
53
65
|
|
|
54
66
|
Generates a complete resource bundle including:
|
|
55
67
|
- **Module**: Registers the controller and service.
|
|
56
68
|
- **Service**: Extends `NestService` from `@nest-extended/mongoose`.
|
|
57
69
|
- **Controller**: Extends `NestController` from `@nest-extended/core`.
|
|
58
|
-
- **Schema**: Mongoose schema with `timestamps` and soft delete fields.
|
|
70
|
+
- **Schema**: Mongoose schema with `timestamps` and soft delete fields (only injects `createdBy`, `updatedBy`, `deletedBy` mapping if Auth was generated).
|
|
59
71
|
- **DTO**: Data Transfer Object with validation.
|
|
60
72
|
- **Specs**: Unit tests for service and controller.
|
|
61
73
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-extended/cli",
|
|
3
|
-
"version": "0.0.2-beta-
|
|
3
|
+
"version": "0.0.2-beta-10",
|
|
4
4
|
"private": false,
|
|
5
|
+
"contributors": [
|
|
6
|
+
{
|
|
7
|
+
"name": "Soubhik Kumar Gon",
|
|
8
|
+
"email": "soubhikgon2004@gmail.com",
|
|
9
|
+
"url": "https://github.com/zakhaev26"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"name": "Santanu Prasad Sahoo",
|
|
13
|
+
"email": "sahoosantanu92@gmail.com",
|
|
14
|
+
"url": "https://github.com/santanup"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
5
17
|
"main": "./src/index.js",
|
|
6
18
|
"types": "./src/index.d.ts",
|
|
7
19
|
"bin": {
|
|
@@ -7,30 +7,41 @@ const chalk = require("chalk");
|
|
|
7
7
|
const path = require("path");
|
|
8
8
|
const fs = require("fs-extra");
|
|
9
9
|
const child_process_1 = require("child_process");
|
|
10
|
-
const
|
|
11
|
-
const dto_template_1 = require("../templates/dto.template");
|
|
12
|
-
const auth_template_1 = require("../templates/auth.template");
|
|
13
|
-
const users_template_1 = require("../templates/users.template");
|
|
10
|
+
const generate_auth_services_1 = require("../lib/generate-auth-services");
|
|
14
11
|
const generateAppAction = (appName) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
15
12
|
const questions = [
|
|
13
|
+
{
|
|
14
|
+
type: 'list',
|
|
15
|
+
name: 'pkgManager',
|
|
16
|
+
message: 'Which package manager would you like to use?',
|
|
17
|
+
choices: ['npm', 'yarn', 'pnpm'],
|
|
18
|
+
default: 'yarn',
|
|
19
|
+
},
|
|
16
20
|
{
|
|
17
21
|
type: 'list',
|
|
18
22
|
name: 'database',
|
|
19
23
|
message: 'Which database would you like to use?',
|
|
20
|
-
choices: ['
|
|
24
|
+
choices: ['mongoose', 'sqlite', 'prisma'],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
type: 'confirm',
|
|
28
|
+
name: 'generateAuth',
|
|
29
|
+
message: 'Would you like to generate authentication (Users and Auth services)?',
|
|
30
|
+
default: true,
|
|
21
31
|
},
|
|
22
32
|
];
|
|
23
33
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
24
34
|
// @ts-expect-error
|
|
25
35
|
const answers = yield inquirer.prompt(questions);
|
|
26
36
|
const database = answers['database'];
|
|
27
|
-
|
|
28
|
-
|
|
37
|
+
const pkgManager = answers['pkgManager'];
|
|
38
|
+
const generateAuth = answers['generateAuth'];
|
|
39
|
+
if (database === 'sqlite' || database === 'prisma') {
|
|
40
|
+
console.error(chalk.red(`Error: We are not supporting ${database} now`));
|
|
29
41
|
process.exit(1);
|
|
30
42
|
}
|
|
31
43
|
console.log(chalk.blue(`Generating NestJS app: ${appName}`));
|
|
32
44
|
const appDir = path.join(process.cwd(), appName);
|
|
33
|
-
const pkgManager = fs.existsSync(path.join(process.cwd(), 'yarn.lock')) ? 'yarn' : 'npm';
|
|
34
45
|
// 1. Run nest new
|
|
35
46
|
yield new Promise((resolve, reject) => {
|
|
36
47
|
const child = (0, child_process_1.spawn)('npx', ['@nestjs/cli', 'new', appName, '--package-manager', pkgManager], {
|
|
@@ -49,19 +60,23 @@ const generateAppAction = (appName) => tslib_1.__awaiter(void 0, void 0, void 0,
|
|
|
49
60
|
console.log(chalk.blue('Installing additional dependencies...'));
|
|
50
61
|
// 2. Install dependencies
|
|
51
62
|
yield new Promise((resolve, reject) => {
|
|
52
|
-
const installArgs = pkgManager === '
|
|
53
|
-
const
|
|
54
|
-
...installArgs,
|
|
63
|
+
const installArgs = pkgManager === 'npm' ? ['install'] : ['add'];
|
|
64
|
+
const baseDeps = [
|
|
55
65
|
'@nestjs/mongoose',
|
|
56
66
|
'mongoose',
|
|
57
67
|
'@nestjs/config',
|
|
58
68
|
'nestjs-cls',
|
|
59
|
-
'@nestjs/jwt',
|
|
60
|
-
'bcrypt',
|
|
61
69
|
`@nest-extended/core@${nestExtendedVersion}`,
|
|
62
70
|
`@nest-extended/mongoose@${nestExtendedVersion}`,
|
|
63
71
|
`@nest-extended/decorators@${nestExtendedVersion}`,
|
|
64
72
|
'zod'
|
|
73
|
+
];
|
|
74
|
+
if (generateAuth) {
|
|
75
|
+
baseDeps.push('@nestjs/jwt', 'bcrypt');
|
|
76
|
+
}
|
|
77
|
+
const child = (0, child_process_1.spawn)(pkgManager, [
|
|
78
|
+
...installArgs,
|
|
79
|
+
...baseDeps
|
|
65
80
|
], {
|
|
66
81
|
stdio: 'inherit',
|
|
67
82
|
cwd: appDir,
|
|
@@ -75,35 +90,43 @@ const generateAppAction = (appName) => tslib_1.__awaiter(void 0, void 0, void 0,
|
|
|
75
90
|
});
|
|
76
91
|
});
|
|
77
92
|
// 3. Install Dev dependencies
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
93
|
+
if (generateAuth) {
|
|
94
|
+
yield new Promise((resolve, reject) => {
|
|
95
|
+
const devArgs = pkgManager === 'npm' ? ['install', '-D'] : ['add', '-D'];
|
|
96
|
+
const child = (0, child_process_1.spawn)(pkgManager, [...devArgs, '@types/bcrypt'], {
|
|
97
|
+
stdio: 'inherit',
|
|
98
|
+
cwd: appDir,
|
|
99
|
+
shell: true,
|
|
100
|
+
});
|
|
101
|
+
child.on('close', (code) => {
|
|
102
|
+
if (code === 0)
|
|
103
|
+
resolve();
|
|
104
|
+
else
|
|
105
|
+
reject(new Error(`${pkgManager} dev install failed with code ${code}`));
|
|
106
|
+
});
|
|
84
107
|
});
|
|
85
|
-
|
|
86
|
-
if (code === 0)
|
|
87
|
-
resolve();
|
|
88
|
-
else
|
|
89
|
-
reject(new Error(`${pkgManager} dev install failed with code ${code}`));
|
|
90
|
-
});
|
|
91
|
-
});
|
|
108
|
+
}
|
|
92
109
|
console.log(chalk.blue('Configuring project...'));
|
|
93
110
|
// 4. Update app.module.ts
|
|
94
111
|
const appModulePath = path.join(appDir, 'src/app.module.ts');
|
|
95
112
|
let appModuleContent = fs.readFileSync(appModulePath, 'utf8');
|
|
113
|
+
const authImports = generateAuth ? `
|
|
114
|
+
import { AuthModule } from './services/auth/auth.module';
|
|
115
|
+
import { UsersModule } from './services/users/users.module';` : '';
|
|
96
116
|
const importsToAdd = `
|
|
97
117
|
import { APP_FILTER, APP_INTERCEPTOR } from '@nestjs/core';
|
|
98
118
|
import { GlobalExceptionFilter } from '@nest-extended/mongoose';
|
|
99
119
|
import { ConfigModule } from '@nestjs/config';
|
|
100
120
|
import { ClsModule } from 'nestjs-cls';
|
|
101
121
|
import { NestExtendedModule, NullResponseInterceptor } from '@nest-extended/core';
|
|
102
|
-
import { MongooseModule } from '@nestjs/mongoose'
|
|
103
|
-
import { AuthModule } from './services/auth/auth.module';
|
|
104
|
-
import { UsersModule } from './services/users/users.module';
|
|
122
|
+
import { MongooseModule } from '@nestjs/mongoose';${authImports}
|
|
105
123
|
`;
|
|
106
124
|
appModuleContent = importsToAdd + appModuleContent;
|
|
125
|
+
const deletedByProp = generateAuth ? `
|
|
126
|
+
deletedBy: user?._id,` : '';
|
|
127
|
+
const authModuleImports = generateAuth ? `
|
|
128
|
+
AuthModule,
|
|
129
|
+
UsersModule,` : '';
|
|
107
130
|
const nestImports = `
|
|
108
131
|
ConfigModule.forRoot({
|
|
109
132
|
envFilePath: ['.env'],
|
|
@@ -117,16 +140,14 @@ import { UsersModule } from './services/users/users.module';
|
|
|
117
140
|
softDelete: {
|
|
118
141
|
getQuery: () => ({ deleted: { $ne: true } }),
|
|
119
142
|
getData: (user: { _id?: string } | null) => ({
|
|
120
|
-
deleted: true
|
|
121
|
-
deletedBy: user?._id,
|
|
143
|
+
deleted: true,${deletedByProp}
|
|
122
144
|
deletedAt: new Date(),
|
|
123
145
|
}),
|
|
124
146
|
},
|
|
125
147
|
}),
|
|
126
|
-
MongooseModule.forRoot(process.env.MONGODB_URI || 'mongodb://localhost:27017/test')
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
appModuleContent = appModuleContent.replace(/imports:\s*\[/, `imports: [\n${nestImports}`);
|
|
148
|
+
MongooseModule.forRoot(process.env.MONGODB_URI || 'mongodb://localhost:27017/test'),${authModuleImports}`;
|
|
149
|
+
appModuleContent = appModuleContent.replace(/imports:\s*\[/, `imports: [
|
|
150
|
+
${nestImports}`);
|
|
130
151
|
const appProviders = `providers: [
|
|
131
152
|
AppService,
|
|
132
153
|
{
|
|
@@ -141,27 +162,12 @@ import { UsersModule } from './services/users/users.module';
|
|
|
141
162
|
appModuleContent = appModuleContent.replace(/providers:\s*\[AppService\],?/, appProviders);
|
|
142
163
|
fs.writeFileSync(appModulePath, appModuleContent);
|
|
143
164
|
// Write .env file
|
|
144
|
-
fs.writeFileSync(path.join(appDir, '.env'),
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
fs.writeFileSync(path.join(schemasDir, 'users.schema.ts'), (0, users_template_1.getUsersSchema)());
|
|
151
|
-
fs.writeFileSync(path.join(usersDir, 'users.module.ts'), (0, module_template_1.getModule)('Users', 'users'));
|
|
152
|
-
fs.writeFileSync(path.join(usersDir, 'users.service.ts'), (0, users_template_1.getUsersService)());
|
|
153
|
-
fs.writeFileSync(path.join(usersDir, 'users.controller.ts'), (0, users_template_1.getUsersController)());
|
|
154
|
-
fs.ensureDirSync(path.join(usersDir, 'dto'));
|
|
155
|
-
fs.writeFileSync(path.join(usersDir, 'dto/users.dto.ts'), (0, dto_template_1.getDto)('Users'));
|
|
156
|
-
// 6. Generate Auth Service
|
|
157
|
-
const authDir = path.join(appDir, 'src/services/auth');
|
|
158
|
-
fs.ensureDirSync(authDir);
|
|
159
|
-
fs.ensureDirSync(path.join(authDir, 'constants'));
|
|
160
|
-
fs.writeFileSync(path.join(authDir, 'auth.module.ts'), (0, auth_template_1.getAuthModule)());
|
|
161
|
-
fs.writeFileSync(path.join(authDir, 'auth.service.ts'), (0, auth_template_1.getAuthService)());
|
|
162
|
-
fs.writeFileSync(path.join(authDir, 'auth.controller.ts'), (0, auth_template_1.getAuthController)());
|
|
163
|
-
fs.writeFileSync(path.join(authDir, 'auth.guard.ts'), (0, auth_template_1.getAuthGuard)());
|
|
164
|
-
fs.writeFileSync(path.join(authDir, 'constants/jwt-constants.ts'), (0, auth_template_1.getJwtConstants)());
|
|
165
|
+
fs.writeFileSync(path.join(appDir, '.env'), `MONGODB_URI=mongodb://localhost:27017/test
|
|
166
|
+
JWT_SECRET=super-secret-jwt-key
|
|
167
|
+
`);
|
|
168
|
+
if (generateAuth) {
|
|
169
|
+
(0, generate_auth_services_1.generateAuthServices)(appDir);
|
|
170
|
+
}
|
|
165
171
|
console.log(chalk.blue('Running lint...'));
|
|
166
172
|
yield new Promise((resolve) => {
|
|
167
173
|
const lintChild = (0, child_process_1.spawn)(pkgManager, ['run', 'lint'], {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-app.js","sourceRoot":"","sources":["../../../../../packages/cli/src/commands/generate-app.ts"],"names":[],"mappings":";;;;AAAA,qCAAqC;AACrC,+BAA+B;AAC/B,6BAA6B;AAC7B,+BAA+B;AAC/B,iDAAsC;
|
|
1
|
+
{"version":3,"file":"generate-app.js","sourceRoot":"","sources":["../../../../../packages/cli/src/commands/generate-app.ts"],"names":[],"mappings":";;;;AAAA,qCAAqC;AACrC,+BAA+B;AAC/B,6BAA6B;AAC7B,+BAA+B;AAC/B,iDAAsC;AAItC,0EAAqE;AAE9D,MAAM,iBAAiB,GAAG,CAAO,OAAe,EAAE,EAAE;IACvD,MAAM,SAAS,GAAG;QACd;YACI,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,8CAA8C;YACvD,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC;YAChC,OAAO,EAAE,MAAM;SAClB;QACD;YACI,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE,uCAAuC;YAChD,OAAO,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAC;SAC5C;QACD;YACI,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,cAAc;YACpB,OAAO,EAAE,sEAAsE;YAC/E,OAAO,EAAE,IAAI;SAChB;KACJ,CAAC;IACF,6DAA6D;IAC7D,mBAAmB;IACnB,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACjD,MAAM,QAA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C/D,WAAW,EAAE,CAAC,CAAC;IAEb,MAAM,YAAY,GAAG;;;;;;;;;;KAUpB,CAAC;IACF,gBAAgB,GAAG,gBAAgB,CAAC,OAAO,CAAC,+BAA+B,EAAE,YAAY,CAAC,CAAC;IAE3F,EAAE,CAAC,aAAa,CAAC,aAAa,EAAE,gBAAgB,CAAC,CAAC;IAElD,kBAAkB;IAClB,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;;CAE/C,CAAC,CAAC;IAEC,IAAI,YAAY,EAAE,CAAC;QACf,IAAA,6CAAoB,EAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC3C,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QAChC,MAAM,SAAS,GAAG,IAAA,qBAAK,EAAC,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE;YACjD,KAAK,EAAE,SAAS;YAChB,GAAG,EAAE,MAAM;YACX,KAAK,EAAE,IAAI;SACd,CAAC,CAAC;QACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC,CAAC;AAC5D,CAAC,CAAA,CAAC;AA7LW,QAAA,iBAAiB,qBA6L5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const generateAuthAction: () => Promise<void>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateAuthAction = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const fs = require("fs-extra");
|
|
8
|
+
const child_process_1 = require("child_process");
|
|
9
|
+
const update_app_module_1 = require("../lib/update-app-module");
|
|
10
|
+
const generate_auth_services_1 = require("../lib/generate-auth-services");
|
|
11
|
+
const generateAuthAction = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
const projectDir = process.cwd();
|
|
13
|
+
const appDir = projectDir;
|
|
14
|
+
const authDir = path.join(appDir, 'src/services/auth');
|
|
15
|
+
if (fs.existsSync(authDir)) {
|
|
16
|
+
console.error(chalk.red('Error: Authentication is already generated in this project.'));
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
console.log(chalk.blue('Generating authentication (Auth & Users services)...'));
|
|
20
|
+
const pkgManager = fs.existsSync(path.join(projectDir, 'yarn.lock')) ? 'yarn' : fs.existsSync(path.join(projectDir, 'pnpm-lock.yaml')) ? 'pnpm' : 'npm';
|
|
21
|
+
console.log(chalk.blue('Installing additional dependencies...'));
|
|
22
|
+
yield new Promise((resolve, reject) => {
|
|
23
|
+
const installArgs = pkgManager === 'npm' ? ['install'] : ['add'];
|
|
24
|
+
const child = (0, child_process_1.spawn)(pkgManager, [...installArgs, '@nestjs/jwt', 'bcrypt'], { stdio: 'inherit', cwd: appDir, shell: true });
|
|
25
|
+
child.on('close', (code) => {
|
|
26
|
+
if (code === 0)
|
|
27
|
+
resolve();
|
|
28
|
+
else
|
|
29
|
+
reject(new Error(`${pkgManager} install failed with code ${code}`));
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
console.log(chalk.blue('Installing dev dependencies...'));
|
|
33
|
+
yield new Promise((resolve, reject) => {
|
|
34
|
+
const devArgs = pkgManager === 'npm' ? ['install', '-D'] : ['add', '-D'];
|
|
35
|
+
const child = (0, child_process_1.spawn)(pkgManager, [...devArgs, '@types/bcrypt'], {
|
|
36
|
+
stdio: 'inherit', cwd: appDir, shell: true
|
|
37
|
+
});
|
|
38
|
+
child.on('close', (code) => {
|
|
39
|
+
if (code === 0)
|
|
40
|
+
resolve();
|
|
41
|
+
else
|
|
42
|
+
reject(new Error(`${pkgManager} dev install failed with code ${code}`));
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
console.log(chalk.blue('Configuring project...'));
|
|
46
|
+
(0, generate_auth_services_1.generateAuthServices)(appDir);
|
|
47
|
+
// Update app.module.ts to add modules
|
|
48
|
+
yield (0, update_app_module_1.updateAppModule)('Auth', 'auth');
|
|
49
|
+
yield (0, update_app_module_1.updateAppModule)('Users', 'users');
|
|
50
|
+
// Update app.module.ts to add deletedBy to softDelete config
|
|
51
|
+
const appModulePath = path.join(appDir, 'src/app.module.ts');
|
|
52
|
+
if (fs.existsSync(appModulePath)) {
|
|
53
|
+
let content = fs.readFileSync(appModulePath, 'utf8');
|
|
54
|
+
// Check if softDelete config exists and doesn't have deletedBy yet
|
|
55
|
+
if (content.includes(`getData: (user: { _id?: string } | null) => ({
|
|
56
|
+
deleted: true,`) && !content.includes('deletedBy: user?._id')) {
|
|
57
|
+
content = content.replace(`getData: (user: { _id?: string } | null) => ({
|
|
58
|
+
deleted: true,`, `getData: (user: { _id?: string } | null) => ({
|
|
59
|
+
deleted: true,
|
|
60
|
+
deletedBy: user?._id,`);
|
|
61
|
+
fs.writeFileSync(appModulePath, content);
|
|
62
|
+
console.log(chalk.green('Updated softDelete configuration in app.module.ts with deletedBy'));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
console.log(chalk.blue('Running lint...'));
|
|
66
|
+
yield new Promise((resolve) => {
|
|
67
|
+
const lintChild = (0, child_process_1.spawn)(pkgManager, ['run', 'lint'], {
|
|
68
|
+
stdio: 'inherit',
|
|
69
|
+
cwd: projectDir,
|
|
70
|
+
shell: true,
|
|
71
|
+
});
|
|
72
|
+
lintChild.on('close', () => resolve());
|
|
73
|
+
});
|
|
74
|
+
console.log(chalk.green('Authentication generated successfully!'));
|
|
75
|
+
});
|
|
76
|
+
exports.generateAuthAction = generateAuthAction;
|
|
77
|
+
//# sourceMappingURL=generate-auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-auth.js","sourceRoot":"","sources":["../../../../../packages/cli/src/commands/generate-auth.ts"],"names":[],"mappings":";;;;AAAA,+BAA+B;AAC/B,6BAA6B;AAC7B,+BAA+B;AAC/B,iDAAsC;AACtC,gEAA2D;AAC3D,0EAAqE;AAE9D,MAAM,kBAAkB,GAAG,GAAS,EAAE;IACzC,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IACjC,MAAM,MAAM,GAAG,UAAU,CAAC;IAC1B,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IAEvD,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACzB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,6DAA6D,CAAC,CAAC,CAAC;QACxF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,sDAAsD,CAAC,CAAC,CAAC;IAEhF,MAAM,UAAU,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;IAExJ,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC,CAAC;IACjE,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACxC,MAAM,WAAW,GAAG,UAAU,KAAK,KAAK,CA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AAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAC,CAAC;AACvE,CAAC,CAAA,CAAC;AA9EW,QAAA,kBAAkB,sBA8E7B"}
|
|
@@ -24,7 +24,8 @@ const generateServiceAction = (rawName) => tslib_1.__awaiter(void 0, void 0, voi
|
|
|
24
24
|
const Name = argArray.join(''); // PascalCase
|
|
25
25
|
const name = Name[0].toLowerCase() + Name.slice(1); // camelCase
|
|
26
26
|
console.log(`Generating service for: ${Name} (${name})`);
|
|
27
|
-
|
|
27
|
+
const isAuthGenerated = fs.existsSync(path.join(process.cwd(), 'src/services/auth'));
|
|
28
|
+
(0, create_file_1.createFileWithContent)(`src/schemas/${name}.schema.ts`, (0, schema_template_1.getSchema)(Name, 'Users', isAuthGenerated));
|
|
28
29
|
(0, create_file_1.createFileWithContent)(`src/services/${name}/${name}.module.ts`, (0, module_template_1.getModule)(Name, name));
|
|
29
30
|
(0, create_file_1.createFileWithContent)(`src/services/${name}/${name}.service.ts`, (0, service_template_1.getService)(Name, name));
|
|
30
31
|
(0, create_file_1.createFileWithContent)(`src/services/${name}/${name}.controller.ts`, (0, controller_template_1.getController)(Name, name, rawName));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-service.js","sourceRoot":"","sources":["../../../../../packages/cli/src/commands/generate-service.ts"],"names":[],"mappings":";;;;AAAA,+BAA+B;AAC/B,6BAA6B;AAC7B,+BAA+B;AAC/B,iDAAsC;AACtC,oDAA2D;AAC3D,gEAA2D;AAC3D,kEAAyD;AACzD,oEAA2D;AAC3D,0EAAiE;AACjE,4DAAmD;AACnD,kEAAyD;AACzD,8EAAoE;AACpE,oFAA0E;AAEnE,MAAM,qBAAqB,GAAG,CAAO,OAAe,EAAE,EAAE;IAC3D,qEAAqE;IACrE,MA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,CAC7B,CAAC;IACF,IAAA,mCAAqB,EACjB,gBAAgB,IAAI,IAAI,IAAI,qBAAqB,EACjD,IAAA,4CAAiB,EAAC,IAAI,EAAE,IAAI,CAAC,CAChC,CAAC;IAEF,MAAM,IAAA,mCAAe,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAElC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC3C,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IACjC,MAAM,UAAU,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;IACtF,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QAChC,MAAM,SAAS,GAAG,IAAA,qBAAK,EAAC,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE;YACjD,KAAK,EAAE,SAAS;YAChB,GAAG,EAAE,UAAU;YACf,KAAK,EAAE,IAAI;SACd,CAAC,CAAC;QACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACP,CAAC,CAAA,CAAC;AA3CW,QAAA,qBAAqB,yBA2ChC"}
|
package/src/commands/generate.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.generateCommand = void 0;
|
|
|
4
4
|
const commander_1 = require("commander");
|
|
5
5
|
const generate_service_1 = require("./generate-service");
|
|
6
6
|
const generate_app_1 = require("./generate-app");
|
|
7
|
+
const generate_auth_1 = require("./generate-auth");
|
|
7
8
|
exports.generateCommand = new commander_1.Command('generate')
|
|
8
9
|
.alias('g')
|
|
9
10
|
.description('Generate a new element');
|
|
@@ -15,4 +16,8 @@ exports.generateCommand
|
|
|
15
16
|
.command('app <name>')
|
|
16
17
|
.description('Generate a new application')
|
|
17
18
|
.action(generate_app_1.generateAppAction);
|
|
19
|
+
exports.generateCommand
|
|
20
|
+
.command('auth')
|
|
21
|
+
.description('Generate authentication (Auth and Users services)')
|
|
22
|
+
.action(generate_auth_1.generateAuthAction);
|
|
18
23
|
//# sourceMappingURL=generate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../../../packages/cli/src/commands/generate.ts"],"names":[],"mappings":";;;AACA,yCAAoC;AACpC,yDAA2D;AAC3D,iDAAmD;
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../../../packages/cli/src/commands/generate.ts"],"names":[],"mappings":";;;AACA,yCAAoC;AACpC,yDAA2D;AAC3D,iDAAmD;AACnD,mDAAqD;AAExC,QAAA,eAAe,GAAG,IAAI,mBAAO,CAAC,UAAU,CAAC;KACjD,KAAK,CAAC,GAAG,CAAC;KACV,WAAW,CAAC,wBAAwB,CAAC,CAAC;AAE3C,uBAAe;KACV,OAAO,CAAC,gBAAgB,CAAC;KACzB,WAAW,CAAC,wBAAwB,CAAC;KACrC,MAAM,CAAC,wCAAqB,CAAC,CAAC;AAEnC,uBAAe;KACV,OAAO,CAAC,YAAY,CAAC;KACrB,WAAW,CAAC,4BAA4B,CAAC;KACzC,MAAM,CAAC,gCAAiB,CAAC,CAAC;AAE/B,uBAAe;KACV,OAAO,CAAC,MAAM,CAAC;KACf,WAAW,CAAC,mDAAmD,CAAC;KAChE,MAAM,CAAC,kCAAkB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const generateAuthServices: (appDir: string) => void;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateAuthServices = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const fs = require("fs-extra");
|
|
6
|
+
const module_template_1 = require("../templates/module.template");
|
|
7
|
+
const auth_template_1 = require("../templates/auth.template");
|
|
8
|
+
const users_template_1 = require("../templates/users.template");
|
|
9
|
+
const dto_template_1 = require("../templates/dto.template");
|
|
10
|
+
const generateAuthServices = (appDir) => {
|
|
11
|
+
// 5. Generate Users Service
|
|
12
|
+
const usersDir = path.join(appDir, 'src/services/users');
|
|
13
|
+
const schemasDir = path.join(appDir, 'src/schemas');
|
|
14
|
+
fs.ensureDirSync(usersDir);
|
|
15
|
+
fs.ensureDirSync(schemasDir);
|
|
16
|
+
fs.writeFileSync(path.join(schemasDir, 'users.schema.ts'), (0, users_template_1.getUsersSchema)());
|
|
17
|
+
fs.writeFileSync(path.join(usersDir, 'users.module.ts'), (0, module_template_1.getModule)('Users', 'users'));
|
|
18
|
+
fs.writeFileSync(path.join(usersDir, 'users.service.ts'), (0, users_template_1.getUsersService)());
|
|
19
|
+
fs.writeFileSync(path.join(usersDir, 'users.controller.ts'), (0, users_template_1.getUsersController)());
|
|
20
|
+
fs.ensureDirSync(path.join(usersDir, 'dto'));
|
|
21
|
+
fs.writeFileSync(path.join(usersDir, 'dto/users.dto.ts'), (0, dto_template_1.getDto)('Users'));
|
|
22
|
+
// 6. Generate Auth Service
|
|
23
|
+
const authDir = path.join(appDir, 'src/services/auth');
|
|
24
|
+
fs.ensureDirSync(authDir);
|
|
25
|
+
fs.ensureDirSync(path.join(authDir, 'constants'));
|
|
26
|
+
fs.writeFileSync(path.join(authDir, 'auth.module.ts'), (0, auth_template_1.getAuthModule)());
|
|
27
|
+
fs.writeFileSync(path.join(authDir, 'auth.service.ts'), (0, auth_template_1.getAuthService)());
|
|
28
|
+
fs.writeFileSync(path.join(authDir, 'auth.controller.ts'), (0, auth_template_1.getAuthController)());
|
|
29
|
+
fs.writeFileSync(path.join(authDir, 'auth.guard.ts'), (0, auth_template_1.getAuthGuard)());
|
|
30
|
+
fs.writeFileSync(path.join(authDir, 'constants/jwt-constants.ts'), (0, auth_template_1.getJwtConstants)());
|
|
31
|
+
};
|
|
32
|
+
exports.generateAuthServices = generateAuthServices;
|
|
33
|
+
//# sourceMappingURL=generate-auth-services.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-auth-services.js","sourceRoot":"","sources":["../../../../../packages/cli/src/lib/generate-auth-services.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,+BAA+B;AAC/B,kEAAyD;AACzD,8DAMoC;AACpC,gEAAkG;AAClG,4DAAmD;AAE5C,MAAM,oBAAoB,GAAG,CAAC,MAAc,EAAE,EAAE;IACnD,4BAA4B;IAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;IACzD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACpD,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC3B,EAAE,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAE7B,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,iBAAiB,CAAC,EAAE,IAAA,+BAAc,GAAE,CAAC,CAAC;IAC7E,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,iBAAiB,CAAC,EAAE,IAAA,2BAAS,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IACtF,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,kBAAkB,CAAC,EAAE,IAAA,gCAAe,GAAE,CAAC,CAAC;IAC7E,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,qBAAqB,CAAC,EAAE,IAAA,mCAAkB,GAAE,CAAC,CAAC;IACnF,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;IAC7C,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,kBAAkB,CAAC,EAAE,IAAA,qBAAM,EAAC,OAAO,CAAC,CAAC,CAAC;IAE3E,2BAA2B;IAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IACvD,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAC1B,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC;IAElD,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,gBAAgB,CAAC,EAAE,IAAA,6BAAa,GAAE,CAAC,CAAC;IACxE,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,iBAAiB,CAAC,EAAE,IAAA,8BAAc,GAAE,CAAC,CAAC;IAC1E,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,oBAAoB,CAAC,EAAE,IAAA,iCAAiB,GAAE,CAAC,CAAC;IAChF,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,eAAe,CAAC,EAAE,IAAA,4BAAY,GAAE,CAAC,CAAC;IACtE,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,4BAA4B,CAAC,EAAE,IAAA,+BAAe,GAAE,CAAC,CAAC;AAC1F,CAAC,CAAC;AAxBW,QAAA,oBAAoB,wBAwB/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const getSchema: (Name: string, UserEntity?: string) => string;
|
|
1
|
+
export declare const getSchema: (Name: string, UserEntity?: string, isAuthGenerated?: boolean) => string;
|
|
@@ -1,20 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getSchema = void 0;
|
|
4
|
-
const getSchema = (Name, UserEntity = 'Users'
|
|
5
|
-
|
|
6
|
-
import { ${UserEntity} } from './users.schema';
|
|
7
|
-
import { EnsureObjectId } from '@nest-extended/mongoose';
|
|
8
|
-
|
|
9
|
-
export type ${Name}Document = HydratedDocument<${Name}>;
|
|
10
|
-
|
|
11
|
-
@Schema({
|
|
12
|
-
timestamps: true,
|
|
13
|
-
})
|
|
14
|
-
export class ${Name} {
|
|
15
|
-
@Prop({ trim: true })
|
|
16
|
-
name?: string;
|
|
17
|
-
|
|
4
|
+
const getSchema = (Name, UserEntity = 'Users', isAuthGenerated = true) => {
|
|
5
|
+
const authFields = isAuthGenerated ? `
|
|
18
6
|
@Prop({
|
|
19
7
|
type: Types.ObjectId,
|
|
20
8
|
ref: ${UserEntity}.name,
|
|
@@ -35,7 +23,21 @@ export class ${Name} {
|
|
|
35
23
|
default: null
|
|
36
24
|
})
|
|
37
25
|
deletedBy?: Types.ObjectId;
|
|
26
|
+
` : '';
|
|
27
|
+
return `import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
|
28
|
+
import { HydratedDocument, Types } from 'mongoose';
|
|
29
|
+
import { ${UserEntity} } from './users.schema';
|
|
30
|
+
import { EnsureObjectId } from '@nest-extended/mongoose';
|
|
38
31
|
|
|
32
|
+
export type ${Name}Document = HydratedDocument<${Name}>;
|
|
33
|
+
|
|
34
|
+
@Schema({
|
|
35
|
+
timestamps: true,
|
|
36
|
+
})
|
|
37
|
+
export class ${Name} {
|
|
38
|
+
@Prop({ trim: true })
|
|
39
|
+
name?: string;
|
|
40
|
+
${authFields}
|
|
39
41
|
@Prop({
|
|
40
42
|
type: Boolean,
|
|
41
43
|
default: null
|
|
@@ -52,5 +54,6 @@ export class ${Name} {
|
|
|
52
54
|
|
|
53
55
|
export const ${Name}Schema = SchemaFactory.createForClass(${Name});
|
|
54
56
|
`;
|
|
57
|
+
};
|
|
55
58
|
exports.getSchema = getSchema;
|
|
56
59
|
//# sourceMappingURL=schema.template.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/schema.template.ts"],"names":[],"mappings":";;;AACO,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,aAAqB,OAAO,EAAU,EAAE,CAAC;;
|
|
1
|
+
{"version":3,"file":"schema.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/schema.template.ts"],"names":[],"mappings":";;;AACO,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,aAAqB,OAAO,EAAE,kBAA2B,IAAI,EAAU,EAAE;IAC/G,MAAM,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC;;;WAG5B,UAAU;;;;;;;WAOV,UAAU;;;;;;;WAOV,UAAU;;;;CAIpB,CAAC,CAAC,CAAC,EAAE,CAAC;IAEL,OAAO;;WAEE,UAAU;;;cAGP,IAAI,+BAA+B,IAAI;;;;;eAKtC,IAAI;;;IAGf,UAAU;;;;;;;;;;;;;;;eAeC,IAAI,yCAAyC,IAAI;CAC/D,CAAC;AACF,CAAC,CAAC;AAtDW,QAAA,SAAS,aAsDpB"}
|