@nest-extended/cli 0.0.2-beta-3 → 0.0.2-beta-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nest-extended/cli",
3
- "version": "0.0.2-beta-3",
3
+ "version": "0.0.2-beta-5",
4
4
  "private": false,
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -0,0 +1 @@
1
+ export declare const generateAppAction: (appName: string) => Promise<void>;
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateAppAction = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const inquirer = require("inquirer");
6
+ const chalk = require("chalk");
7
+ const path = require("path");
8
+ const fs = require("fs-extra");
9
+ const child_process_1 = require("child_process");
10
+ const module_template_1 = require("../templates/module.template");
11
+ const controller_template_1 = require("../templates/controller.template");
12
+ const dto_template_1 = require("../templates/dto.template");
13
+ const auth_template_1 = require("../templates/auth.template");
14
+ const users_template_1 = require("../templates/users.template");
15
+ const generateAppAction = (appName) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
16
+ const questions = [
17
+ {
18
+ type: 'list',
19
+ name: 'database',
20
+ message: 'Which database would you like to use?',
21
+ choices: ['mongo', 'sql'],
22
+ },
23
+ ];
24
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
25
+ // @ts-expect-error
26
+ const answers = yield inquirer.prompt(questions);
27
+ const database = answers['database'];
28
+ if (database === 'sql') {
29
+ console.error(chalk.red('Error: We are not supporting sql now'));
30
+ process.exit(1);
31
+ }
32
+ console.log(chalk.blue(`Generating NestJS app: ${appName}`));
33
+ const appDir = path.join(process.cwd(), appName);
34
+ const pkgManager = fs.existsSync(path.join(process.cwd(), 'yarn.lock')) ? 'yarn' : 'npm';
35
+ // 1. Run nest new
36
+ yield new Promise((resolve, reject) => {
37
+ const child = (0, child_process_1.spawn)('npx', ['@nestjs/cli', 'new', appName, '--package-manager', pkgManager], {
38
+ stdio: 'inherit',
39
+ shell: true,
40
+ });
41
+ child.on('close', (code) => {
42
+ if (code === 0)
43
+ resolve();
44
+ else
45
+ reject(new Error(`nest new failed with code ${code}`));
46
+ });
47
+ });
48
+ const pkg = require('../../package.json');
49
+ const nestExtendedVersion = pkg.version;
50
+ console.log(chalk.blue('Installing additional dependencies...'));
51
+ // 2. Install dependencies
52
+ yield new Promise((resolve, reject) => {
53
+ const installArgs = pkgManager === 'yarn' ? ['add'] : ['install'];
54
+ const child = (0, child_process_1.spawn)(pkgManager, [
55
+ ...installArgs,
56
+ '@nestjs/mongoose',
57
+ 'mongoose',
58
+ '@nestjs/config',
59
+ 'nestjs-cls',
60
+ '@nestjs/jwt',
61
+ 'bcrypt',
62
+ `@nest-extended/core@${nestExtendedVersion}`,
63
+ `@nest-extended/mongoose@${nestExtendedVersion}`,
64
+ `@nest-extended/decorators@${nestExtendedVersion}`,
65
+ 'zod'
66
+ ], {
67
+ stdio: 'inherit',
68
+ cwd: appDir,
69
+ shell: true,
70
+ });
71
+ child.on('close', (code) => {
72
+ if (code === 0)
73
+ resolve();
74
+ else
75
+ reject(new Error(`${pkgManager} install failed with code ${code}`));
76
+ });
77
+ });
78
+ // 3. Install Dev dependencies
79
+ yield new Promise((resolve, reject) => {
80
+ const devArgs = pkgManager === 'yarn' ? ['add', '-D'] : ['install', '-D'];
81
+ const child = (0, child_process_1.spawn)(pkgManager, [...devArgs, '@types/bcrypt'], {
82
+ stdio: 'inherit',
83
+ cwd: appDir,
84
+ shell: true,
85
+ });
86
+ child.on('close', (code) => {
87
+ if (code === 0)
88
+ resolve();
89
+ else
90
+ reject(new Error(`${pkgManager} dev install failed with code ${code}`));
91
+ });
92
+ });
93
+ console.log(chalk.blue('Configuring project...'));
94
+ // 4. Update app.module.ts
95
+ const appModulePath = path.join(appDir, 'src/app.module.ts');
96
+ let appModuleContent = fs.readFileSync(appModulePath, 'utf8');
97
+ const importsToAdd = `
98
+ import { ConfigModule } from '@nestjs/config';
99
+ import { ClsModule } from 'nestjs-cls';
100
+ import { NestExtendedModule } from '@nest-extended/core';
101
+ import { MongooseModule } from '@nestjs/mongoose';
102
+ import { AuthModule } from './services/auth/auth.module';
103
+ import { UsersModule } from './services/users/users.module';
104
+ `;
105
+ appModuleContent = importsToAdd + appModuleContent;
106
+ const nestImports = `
107
+ ConfigModule.forRoot({
108
+ envFilePath: ['.env'],
109
+ isGlobal: true,
110
+ }),
111
+ ClsModule.forRoot({
112
+ global: true,
113
+ middleware: { mount: true },
114
+ }),
115
+ NestExtendedModule.forRoot({
116
+ softDelete: {
117
+ getQuery: () => ({ deleted: { $ne: true } }),
118
+ getData: (user: { _id?: string } | null) => ({
119
+ deleted: true,
120
+ deletedBy: user?._id,
121
+ deletedAt: new Date(),
122
+ }),
123
+ },
124
+ }),
125
+ MongooseModule.forRoot(process.env.MONGODB_URI || 'mongodb://localhost:27017/test'),
126
+ AuthModule,
127
+ UsersModule,`;
128
+ appModuleContent = appModuleContent.replace(/imports:\s*\[/, `imports: [\n${nestImports}`);
129
+ fs.writeFileSync(appModulePath, appModuleContent);
130
+ // Write .env file
131
+ fs.writeFileSync(path.join(appDir, '.env'), 'MONGODB_URI=mongodb://localhost:27017/test\nJWT_SECRET=super-secret-jwt-key\n');
132
+ // 5. Generate Users Service
133
+ const usersDir = path.join(appDir, 'src/services/users');
134
+ const schemasDir = path.join(appDir, 'src/schemas');
135
+ fs.ensureDirSync(usersDir);
136
+ fs.ensureDirSync(schemasDir);
137
+ fs.writeFileSync(path.join(schemasDir, 'users.schema.ts'), (0, users_template_1.getUsersSchema)());
138
+ fs.writeFileSync(path.join(usersDir, 'users.module.ts'), (0, module_template_1.getModule)('Users', 'users'));
139
+ fs.writeFileSync(path.join(usersDir, 'users.service.ts'), (0, users_template_1.getUsersService)());
140
+ fs.writeFileSync(path.join(usersDir, 'users.controller.ts'), (0, controller_template_1.getController)('Users', 'users', 'users'));
141
+ fs.ensureDirSync(path.join(usersDir, 'dto'));
142
+ fs.writeFileSync(path.join(usersDir, 'dto/users.dto.ts'), (0, dto_template_1.getDto)('Users'));
143
+ // 6. Generate Auth Service
144
+ const authDir = path.join(appDir, 'src/services/auth');
145
+ fs.ensureDirSync(authDir);
146
+ fs.ensureDirSync(path.join(authDir, 'constants'));
147
+ fs.writeFileSync(path.join(authDir, 'auth.module.ts'), (0, auth_template_1.getAuthModule)());
148
+ fs.writeFileSync(path.join(authDir, 'auth.service.ts'), (0, auth_template_1.getAuthService)());
149
+ fs.writeFileSync(path.join(authDir, 'auth.controller.ts'), (0, auth_template_1.getAuthController)());
150
+ fs.writeFileSync(path.join(authDir, 'auth.guard.ts'), (0, auth_template_1.getAuthGuard)());
151
+ fs.writeFileSync(path.join(authDir, 'constants/jwt-constants.ts'), (0, auth_template_1.getJwtConstants)());
152
+ console.log(chalk.blue('Running lint...'));
153
+ yield new Promise((resolve) => {
154
+ const lintChild = (0, child_process_1.spawn)(pkgManager, ['run', 'lint'], {
155
+ stdio: 'inherit',
156
+ cwd: appDir,
157
+ shell: true,
158
+ });
159
+ lintChild.on('close', () => resolve());
160
+ });
161
+ console.log(chalk.green('App generated successfully!'));
162
+ });
163
+ exports.generateAppAction = generateAppAction;
164
+ //# sourceMappingURL=generate-app.js.map
@@ -0,0 +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;AACtC,kEAAyD;AACzD,0EAAiE;AACjE,4DAAmD;AACnD,8DAMoC;AACpC,gEAA8E;AAEvE,MAAM,iBAAiB,GAAG,CAAO,OAAe,EAAE,EAAE;IACvD,MAAM,SAAS,GAAG;QACd;YACI,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE,uCAAuC;YA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ineProperty(exports, "__esModule", { value: true });
3
+ exports.generateServiceAction = 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 create_file_1 = require("../lib/create-file");
10
+ const update_app_module_1 = require("../lib/update-app-module");
11
+ const module_template_1 = require("../templates/module.template");
12
+ const service_template_1 = require("../templates/service.template");
13
+ const controller_template_1 = require("../templates/controller.template");
14
+ const dto_template_1 = require("../templates/dto.template");
15
+ const schema_template_1 = require("../templates/schema.template");
16
+ const service_spec_template_1 = require("../templates/service.spec.template");
17
+ const controller_spec_template_1 = require("../templates/controller.spec.template");
18
+ const generateServiceAction = (rawName) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
19
+ // if arg have '-' change to camelCase (Logic from original index.js)
20
+ const argArray = rawName.split('-');
21
+ argArray.forEach((arg, index) => {
22
+ argArray[index] = arg[0].toUpperCase() + arg.slice(1).toLowerCase();
23
+ });
24
+ const Name = argArray.join(''); // PascalCase
25
+ const name = Name[0].toLowerCase() + Name.slice(1); // camelCase
26
+ console.log(`Generating service for: ${Name} (${name})`);
27
+ (0, create_file_1.createFileWithContent)(`src/schemas/${name}.schema.ts`, (0, schema_template_1.getSchema)(Name));
28
+ (0, create_file_1.createFileWithContent)(`src/services/${name}/${name}.module.ts`, (0, module_template_1.getModule)(Name, name));
29
+ (0, create_file_1.createFileWithContent)(`src/services/${name}/${name}.service.ts`, (0, service_template_1.getService)(Name, name));
30
+ (0, create_file_1.createFileWithContent)(`src/services/${name}/${name}.controller.ts`, (0, controller_template_1.getController)(Name, name, rawName));
31
+ (0, create_file_1.createFileWithContent)(`src/services/${name}/dto/${name}.dto.ts`, (0, dto_template_1.getDto)(Name));
32
+ (0, create_file_1.createFileWithContent)(`src/services/${name}/${name}.service.spec.ts`, (0, service_spec_template_1.getServiceSpec)(Name, name));
33
+ (0, create_file_1.createFileWithContent)(`src/services/${name}/${name}.controller.spec.ts`, (0, controller_spec_template_1.getControllerSpec)(Name, name));
34
+ yield (0, update_app_module_1.updateAppModule)(Name, name);
35
+ console.log(chalk.blue('Running lint...'));
36
+ const projectDir = process.cwd();
37
+ const pkgManager = fs.existsSync(path.join(projectDir, 'yarn.lock')) ? 'yarn' : 'npm';
38
+ yield new Promise((resolve) => {
39
+ const lintChild = (0, child_process_1.spawn)(pkgManager, ['run', 'lint'], {
40
+ stdio: 'inherit',
41
+ cwd: projectDir,
42
+ shell: true,
43
+ });
44
+ lintChild.on('close', () => resolve());
45
+ });
46
+ });
47
+ exports.generateServiceAction = generateServiceAction;
48
+ //# sourceMappingURL=generate-service.js.map
@@ -0,0 +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,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpC,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QAC5B,QAAQ,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IACxE,CAAC,CAAC,CAAC;IACH,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa;IAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,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U,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;AAzCW,QAAA,qBAAqB,yBAyChC"}
@@ -1,208 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateCommand = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const commander_1 = require("commander");
6
- const inquirer = require("inquirer");
7
- const chalk = require("chalk");
8
- const path = require("path");
9
- const fs = require("fs-extra");
10
- const child_process_1 = require("child_process");
11
- const create_file_1 = require("../lib/create-file");
12
- const update_app_module_1 = require("../lib/update-app-module");
13
- const module_template_1 = require("../templates/module.template");
14
- const service_template_1 = require("../templates/service.template");
15
- const controller_template_1 = require("../templates/controller.template");
16
- const dto_template_1 = require("../templates/dto.template");
17
- const schema_template_1 = require("../templates/schema.template");
18
- const service_spec_template_1 = require("../templates/service.spec.template");
19
- const controller_spec_template_1 = require("../templates/controller.spec.template");
20
- const auth_template_1 = require("../templates/auth.template");
21
- const users_template_1 = require("../templates/users.template");
5
+ const generate_service_1 = require("./generate-service");
6
+ const generate_app_1 = require("./generate-app");
22
7
  exports.generateCommand = new commander_1.Command('generate')
23
8
  .alias('g')
24
9
  .description('Generate a new element');
25
10
  exports.generateCommand
26
11
  .command('service <name>')
27
12
  .description('Generate a new service')
28
- .action((rawName) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
29
- // if arg have '-' change to camelCase (Logic from original index.js)
30
- const argArray = rawName.split('-');
31
- argArray.forEach((arg, index) => {
32
- argArray[index] = arg[0].toUpperCase() + arg.slice(1).toLowerCase();
33
- });
34
- const Name = argArray.join(''); // PascalCase
35
- const name = Name[0].toLowerCase() + Name.slice(1); // camelCase
36
- console.log(`Generating service for: ${Name} (${name})`);
37
- (0, create_file_1.createFileWithContent)(`src/schemas/${name}.schema.ts`, (0, schema_template_1.getSchema)(Name));
38
- (0, create_file_1.createFileWithContent)(`src/services/${name}/${name}.module.ts`, (0, module_template_1.getModule)(Name, name));
39
- (0, create_file_1.createFileWithContent)(`src/services/${name}/${name}.service.ts`, (0, service_template_1.getService)(Name, name));
40
- (0, create_file_1.createFileWithContent)(`src/services/${name}/${name}.controller.ts`, (0, controller_template_1.getController)(Name, name, rawName));
41
- (0, create_file_1.createFileWithContent)(`src/services/${name}/dto/${name}.dto.ts`, (0, dto_template_1.getDto)(Name));
42
- (0, create_file_1.createFileWithContent)(`src/services/${name}/${name}.service.spec.ts`, (0, service_spec_template_1.getServiceSpec)(Name, name));
43
- (0, create_file_1.createFileWithContent)(`src/services/${name}/${name}.controller.spec.ts`, (0, controller_spec_template_1.getControllerSpec)(Name, name));
44
- yield (0, update_app_module_1.updateAppModule)(Name, name);
45
- console.log(chalk.blue('Running lint...'));
46
- const projectDir = process.cwd();
47
- const pkgManager = fs.existsSync(path.join(projectDir, 'yarn.lock')) ? 'yarn' : 'npm';
48
- yield new Promise((resolve) => {
49
- const lintChild = (0, child_process_1.spawn)(pkgManager, ['run', 'lint'], {
50
- stdio: 'inherit',
51
- cwd: projectDir,
52
- shell: true,
53
- });
54
- lintChild.on('close', () => resolve());
55
- });
56
- }));
13
+ .action(generate_service_1.generateServiceAction);
57
14
  exports.generateCommand
58
15
  .command('app <name>')
59
16
  .description('Generate a new application')
60
- .action((appName) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
61
- const questions = [
62
- {
63
- type: 'list',
64
- name: 'database',
65
- message: 'Which database would you like to use?',
66
- choices: ['mongo', 'sql'],
67
- },
68
- ];
69
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
70
- // @ts-expect-error
71
- const answers = yield inquirer.prompt(questions);
72
- const database = answers['database'];
73
- if (database === 'sql') {
74
- console.error(chalk.red('Error: We are not supporting sql now'));
75
- process.exit(1);
76
- }
77
- console.log(chalk.blue(`Generating NestJS app: ${appName}`));
78
- const appDir = path.join(process.cwd(), appName);
79
- const pkgManager = fs.existsSync(path.join(process.cwd(), 'yarn.lock')) ? 'yarn' : 'npm';
80
- // 1. Run nest new
81
- yield new Promise((resolve, reject) => {
82
- const child = (0, child_process_1.spawn)('npx', ['@nestjs/cli', 'new', appName, '--package-manager', pkgManager], {
83
- stdio: 'inherit',
84
- shell: true,
85
- });
86
- child.on('close', (code) => {
87
- if (code === 0)
88
- resolve();
89
- else
90
- reject(new Error(`nest new failed with code ${code}`));
91
- });
92
- });
93
- const pkg = require('../../package.json');
94
- const nestExtendedVersion = pkg.version;
95
- console.log(chalk.blue('Installing additional dependencies...'));
96
- // 2. Install dependencies
97
- yield new Promise((resolve, reject) => {
98
- const installArgs = pkgManager === 'yarn' ? ['add'] : ['install'];
99
- const child = (0, child_process_1.spawn)(pkgManager, [
100
- ...installArgs,
101
- '@nestjs/mongoose',
102
- 'mongoose',
103
- '@nestjs/config',
104
- 'nestjs-cls',
105
- '@nestjs/jwt',
106
- 'bcrypt',
107
- `@nest-extended/core@${nestExtendedVersion}`,
108
- `@nest-extended/mongoose@${nestExtendedVersion}`,
109
- `@nest-extended/decorators@${nestExtendedVersion}`,
110
- 'zod'
111
- ], {
112
- stdio: 'inherit',
113
- cwd: appDir,
114
- shell: true,
115
- });
116
- child.on('close', (code) => {
117
- if (code === 0)
118
- resolve();
119
- else
120
- reject(new Error(`${pkgManager} install failed with code ${code}`));
121
- });
122
- });
123
- // 3. Install Dev dependencies
124
- yield new Promise((resolve, reject) => {
125
- const devArgs = pkgManager === 'yarn' ? ['add', '-D'] : ['install', '-D'];
126
- const child = (0, child_process_1.spawn)(pkgManager, [...devArgs, '@types/bcrypt'], {
127
- stdio: 'inherit',
128
- cwd: appDir,
129
- shell: true,
130
- });
131
- child.on('close', (code) => {
132
- if (code === 0)
133
- resolve();
134
- else
135
- reject(new Error(`${pkgManager} dev install failed with code ${code}`));
136
- });
137
- });
138
- console.log(chalk.blue('Configuring project...'));
139
- // 4. Update app.module.ts
140
- const appModulePath = path.join(appDir, 'src/app.module.ts');
141
- let appModuleContent = fs.readFileSync(appModulePath, 'utf8');
142
- const importsToAdd = `
143
- import { ConfigModule } from '@nestjs/config';
144
- import { ClsModule } from 'nestjs-cls';
145
- import { NestExtendedModule } from '@nest-extended/core';
146
- import { MongooseModule } from '@nestjs/mongoose';
147
- import { AuthModule } from './services/auth/auth.module';
148
- import { UsersModule } from './services/users/users.module';
149
- `;
150
- appModuleContent = importsToAdd + appModuleContent;
151
- const nestImports = `
152
- ConfigModule.forRoot({
153
- envFilePath: ['.env'],
154
- isGlobal: true,
155
- }),
156
- ClsModule.forRoot({
157
- global: true,
158
- middleware: { mount: true },
159
- }),
160
- NestExtendedModule.forRoot({
161
- softDelete: {
162
- getQuery: () => ({ deleted: { $ne: true } }),
163
- getData: (user: { _id?: string } | null) => ({
164
- deleted: true,
165
- deletedBy: user?._id,
166
- deletedAt: new Date(),
167
- }),
168
- },
169
- }),
170
- MongooseModule.forRoot(process.env.MONGODB_URI || 'mongodb://localhost:27017/test'),
171
- AuthModule,
172
- UsersModule,`;
173
- appModuleContent = appModuleContent.replace(/imports:\s*\[/, `imports: [\n${nestImports}`);
174
- fs.writeFileSync(appModulePath, appModuleContent);
175
- // 5. Generate Users Service
176
- const usersDir = path.join(appDir, 'src/services/users');
177
- const schemasDir = path.join(appDir, 'src/schemas');
178
- fs.ensureDirSync(usersDir);
179
- fs.ensureDirSync(schemasDir);
180
- fs.writeFileSync(path.join(schemasDir, 'users.schema.ts'), (0, users_template_1.getUsersSchema)());
181
- fs.writeFileSync(path.join(usersDir, 'users.module.ts'), (0, module_template_1.getModule)('Users', 'users'));
182
- fs.writeFileSync(path.join(usersDir, 'users.service.ts'), (0, users_template_1.getUsersService)());
183
- fs.writeFileSync(path.join(usersDir, 'users.controller.ts'), (0, controller_template_1.getController)('Users', 'users', 'users'));
184
- fs.ensureDirSync(path.join(usersDir, 'dto'));
185
- fs.writeFileSync(path.join(usersDir, 'dto/users.dto.ts'), (0, dto_template_1.getDto)('Users'));
186
- // 6. Generate Auth Service
187
- const authDir = path.join(appDir, 'src/services/auth');
188
- fs.ensureDirSync(authDir);
189
- fs.ensureDirSync(path.join(authDir, 'constants'));
190
- fs.ensureDirSync(path.join(authDir, 'decorators'));
191
- fs.writeFileSync(path.join(authDir, 'auth.module.ts'), (0, auth_template_1.getAuthModule)());
192
- fs.writeFileSync(path.join(authDir, 'auth.service.ts'), (0, auth_template_1.getAuthService)());
193
- fs.writeFileSync(path.join(authDir, 'auth.controller.ts'), (0, auth_template_1.getAuthController)());
194
- fs.writeFileSync(path.join(authDir, 'auth.guard.ts'), (0, auth_template_1.getAuthGuard)());
195
- fs.writeFileSync(path.join(authDir, 'constants/jwt-constants.ts'), (0, auth_template_1.getJwtConstants)());
196
- fs.writeFileSync(path.join(authDir, 'decorators/public.decorator.ts'), (0, auth_template_1.getPublicDecorator)());
197
- console.log(chalk.blue('Running lint...'));
198
- yield new Promise((resolve) => {
199
- const lintChild = (0, child_process_1.spawn)(pkgManager, ['run', 'lint'], {
200
- stdio: 'inherit',
201
- cwd: appDir,
202
- shell: true,
203
- });
204
- lintChild.on('close', () => resolve());
205
- });
206
- console.log(chalk.green('App generated successfully!'));
207
- }));
17
+ .action(generate_app_1.generateAppAction);
208
18
  //# 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,qCAAqC;AACrC,+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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,CAAC"}
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../../../packages/cli/src/commands/generate.ts"],"names":[],"mappings":";;;AACA,yCAAoC;AACpC,yDAA2D;AAC3D,iDAAmD;AAEtC,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"}
@@ -2,5 +2,4 @@ export declare const getAuthController: () => string;
2
2
  export declare const getAuthService: () => string;
3
3
  export declare const getAuthModule: () => string;
4
4
  export declare const getAuthGuard: () => string;
5
- export declare const getPublicDecorator: () => string;
6
5
  export declare const getJwtConstants: () => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getJwtConstants = exports.getPublicDecorator = exports.getAuthGuard = exports.getAuthModule = exports.getAuthService = exports.getAuthController = void 0;
3
+ exports.getJwtConstants = exports.getAuthGuard = exports.getAuthModule = exports.getAuthService = exports.getAuthController = void 0;
4
4
  const getAuthController = () => `import {
5
5
  Body,
6
6
  Controller,
@@ -12,7 +12,7 @@ const getAuthController = () => `import {
12
12
  BadRequestException,
13
13
  } from '@nestjs/common';
14
14
  import { AuthService } from './auth.service';
15
- import { Public } from './decorators/public.decorator';
15
+ import { Public } from '@nest-extended/decorators';
16
16
  import { UsersService } from '../users/users.service';
17
17
  import { UsersDocument } from '../../schemas/users.schema';
18
18
 
@@ -55,32 +55,36 @@ export class AuthService {
55
55
  private jwtService: JwtService,
56
56
  ) { }
57
57
 
58
- async signInLocal(email: string, pass: string): Promise<Record<string, unknown>> {
59
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
60
- const [user] = (await this.usersService._find({
61
- email,
62
- $limit: 1,
63
- $select: [
64
- '_id',
65
- 'firstName',
66
- 'lastName',
67
- 'email',
68
- 'password',
69
- 'createdAt',
70
- 'updatedAt',
71
- ],
72
- }, { pagination: false })) as Array<Record<string, any>>;
58
+ async signInLocal(
59
+ email: string,
60
+ pass: string,
61
+ ): Promise<Record<string, unknown>> {
62
+ const [user] = await this.usersService._find(
63
+ {
64
+ email,
65
+ $limit: 1,
66
+ $select: [
67
+ '_id',
68
+ 'firstName',
69
+ 'lastName',
70
+ 'email',
71
+ 'password',
72
+ 'createdAt',
73
+ 'updatedAt',
74
+ ],
75
+ },
76
+ { pagination: false },
77
+ );
73
78
 
74
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
75
79
  if (!user) throw new UnauthorizedException();
76
80
 
77
- const passwordValid = await bcrypt.compare(pass, user.password as string);
81
+ const passwordValid = await bcrypt.compare(pass, user.password);
78
82
  if (!passwordValid) {
79
83
  throw new UnauthorizedException();
80
84
  }
81
85
 
82
86
  const sanitizedUser = this.usersService.sanitizeUser(user);
83
- const payload = { sub: { id: user._id as string }, user };
87
+ const payload = { sub: { id: user._id as unknown as string }, user };
84
88
  return {
85
89
  accessToken: await this.jwtService.signAsync(payload),
86
90
  user: sanitizedUser,
@@ -128,7 +132,7 @@ const getAuthGuard = () => `import {
128
132
  } from '@nestjs/common';
129
133
  import { Reflector } from '@nestjs/core';
130
134
  import { JwtService } from '@nestjs/jwt';
131
- import { IS_PUBLIC_KEY } from './decorators/public.decorator';
135
+ import { IS_PUBLIC_KEY } from '@nest-extended/decorators';
132
136
  import { UsersService } from '../users/users.service';
133
137
  import { jwtConstants } from './constants/jwt-constants';
134
138
  import { ClsService } from 'nestjs-cls';
@@ -159,7 +163,9 @@ export class AuthGuard implements CanActivate {
159
163
  const payload = await this.jwtService.verifyAsync<{ sub: { id: string } }>(token, {
160
164
  secret: jwtConstants.secret,
161
165
  });
162
- const user = (await this.usersService._get(payload.sub.id)) as Record<string, unknown>;
166
+ const user = (await this.usersService._get(
167
+ payload.sub.id,
168
+ )) as unknown as Record<string, unknown>;
163
169
  if (user) {
164
170
  request.user = user;
165
171
  this.cls.set('user', user);
@@ -178,11 +184,6 @@ export class AuthGuard implements CanActivate {
178
184
  }
179
185
  `;
180
186
  exports.getAuthGuard = getAuthGuard;
181
- const getPublicDecorator = () => `import { SetMetadata } from '@nestjs/common';
182
- export const IS_PUBLIC_KEY = 'isPublic';
183
- export const Public = () => SetMetadata(IS_PUBLIC_KEY, true);
184
- `;
185
- exports.getPublicDecorator = getPublicDecorator;
186
187
  const getJwtConstants = () => `import { randomBytes } from 'crypto';
187
188
  // NOTE: For a real application, consider using a more secure way to inject the secret (like ConfigService)
188
189
  export const jwtConstants = {
@@ -1 +1 @@
1
- {"version":3,"file":"auth.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/auth.template.ts"],"names":[],"mappings":";;;AAAO,MAAM,iBAAiB,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwC9C,CAAC;AAxCW,QAAA,iBAAiB,qBAwC5B;AAEK,MAAM,cAAc,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4C3C,CAAC;AA5CW,QAAA,cAAc,kBA4CzB;AAEK,MAAM,aAAa,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6B1C,CAAC;AA7BW,QAAA,aAAa,iBA6BxB;AAEK,MAAM,YAAY,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwDzC,CAAC;AAxDW,QAAA,YAAY,gBAwDvB;AAEK,MAAM,kBAAkB,GAAG,GAAW,EAAE,CAAC;;;CAG/C,CAAC;AAHW,QAAA,kBAAkB,sBAG7B;AAEK,MAAM,eAAe,GAAG,GAAW,EAAE,CAAC;;;;;CAK5C,CAAC;AALW,QAAA,eAAe,mBAK1B"}
1
+ {"version":3,"file":"auth.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/auth.template.ts"],"names":[],"mappings":";;;AAAO,MAAM,iBAAiB,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwC9C,CAAC;AAxCW,QAAA,iBAAiB,qBAwC5B;AAEK,MAAM,cAAc,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgD3C,CAAC;AAhDW,QAAA,cAAc,kBAgDzB;AAEK,MAAM,aAAa,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6B1C,CAAC;AA7BW,QAAA,aAAa,iBA6BxB;AAEK,MAAM,YAAY,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0DzC,CAAC;AA1DW,QAAA,YAAY,gBA0DvB;AAEK,MAAM,eAAe,GAAG,GAAW,EAAE,CAAC;;;;;CAK5C,CAAC;AALW,QAAA,eAAe,mBAK1B"}
@@ -49,7 +49,7 @@ export class UsersService extends NestService<Users, UsersDocument> {
49
49
  }
50
50
 
51
51
  sanitizeUser(user: UsersDocument) {
52
- const sanitized = user.toObject() as Record<string, unknown>;
52
+ const sanitized = user.toObject() as unknown as Record<string, unknown>
53
53
  delete sanitized['password'];
54
54
  return sanitized;
55
55
  }