@hazeljs/cli 0.2.0-rc.7 → 0.2.0
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/@template/src/hello.controller.ts +1 -1
- package/README.md +40 -3
- package/dist/commands/generate-agent.d.ts +2 -0
- package/dist/commands/generate-agent.js +13 -7
- package/dist/commands/generate-ai-service.d.ts +2 -0
- package/dist/commands/generate-ai-service.js +8 -2
- package/dist/commands/generate-app.d.ts +7 -0
- package/dist/commands/generate-app.interactive-packages.test.d.ts +1 -0
- package/dist/commands/generate-app.interactive-packages.test.js +107 -0
- package/dist/commands/generate-app.js +141 -0
- package/dist/commands/generate-app.new-command.test.d.ts +1 -0
- package/dist/commands/generate-app.new-command.test.js +86 -0
- package/dist/commands/generate-app.skeleton.test.d.ts +1 -0
- package/dist/commands/generate-app.skeleton.test.js +51 -0
- package/dist/commands/generate-auth.d.ts +2 -0
- package/dist/commands/generate-auth.js +39 -40
- package/dist/commands/generate-cache.d.ts +2 -0
- package/dist/commands/generate-cache.js +14 -12
- package/dist/commands/generate-config.d.ts +2 -0
- package/dist/commands/generate-config.js +14 -12
- package/dist/commands/generate-controller.d.ts +2 -0
- package/dist/commands/generate-controller.js +8 -2
- package/dist/commands/generate-cron.d.ts +2 -0
- package/dist/commands/generate-cron.js +14 -12
- package/dist/commands/generate-crud.d.ts +2 -0
- package/dist/commands/generate-crud.js +44 -33
- package/dist/commands/generate-discovery.d.ts +2 -0
- package/dist/commands/generate-discovery.js +14 -12
- package/dist/commands/generate-dto.d.ts +2 -0
- package/dist/commands/generate-dto.js +15 -6
- package/dist/commands/generate-exception-filter.d.ts +2 -0
- package/dist/commands/generate-exception-filter.js +8 -2
- package/dist/commands/generate-guard.d.ts +2 -0
- package/dist/commands/generate-guard.js +8 -2
- package/dist/commands/generate-interceptor.d.ts +2 -0
- package/dist/commands/generate-interceptor.js +8 -2
- package/dist/commands/generate-middleware.d.ts +2 -0
- package/dist/commands/generate-middleware.js +11 -10
- package/dist/commands/generate-module.d.ts +2 -0
- package/dist/commands/generate-module.js +35 -31
- package/dist/commands/generate-pipe.d.ts +2 -0
- package/dist/commands/generate-pipe.js +8 -2
- package/dist/commands/generate-rag.d.ts +2 -0
- package/dist/commands/generate-rag.js +14 -12
- package/dist/commands/generate-repository.d.ts +2 -0
- package/dist/commands/generate-repository.js +8 -2
- package/dist/commands/generate-serverless-handler.d.ts +2 -0
- package/dist/commands/generate-serverless-handler.js +14 -3
- package/dist/commands/generate-service.d.ts +2 -0
- package/dist/commands/generate-service.js +8 -2
- package/dist/commands/generate-setup.d.ts +4 -0
- package/dist/commands/generate-setup.js +187 -0
- package/dist/commands/generate-setup.test.d.ts +1 -0
- package/dist/commands/generate-setup.test.js +50 -0
- package/dist/commands/generate-websocket-gateway.d.ts +2 -0
- package/dist/commands/generate-websocket-gateway.js +8 -2
- package/dist/commands/info.test.d.ts +1 -0
- package/dist/commands/info.test.js +58 -0
- package/dist/commands/pdf-to-audio.test.d.ts +1 -0
- package/dist/commands/pdf-to-audio.test.js +92 -0
- package/dist/commands/utility-commands.test.d.ts +1 -0
- package/dist/commands/utility-commands.test.js +95 -0
- package/dist/index.js +32 -3
- package/dist/index.list.test.d.ts +0 -0
- package/dist/index.list.test.js +70 -0
- package/dist/utils/generator-registry.d.ts +15 -0
- package/dist/utils/generator-registry.js +97 -0
- package/dist/utils/generator-registry.test.d.ts +1 -0
- package/dist/utils/generator-registry.test.js +10 -0
- package/dist/utils/generator.d.ts +21 -1
- package/dist/utils/generator.js +23 -4
- package/dist/utils/generator.test.js +5 -4
- package/package.json +2 -2
|
@@ -3,10 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runAuth = runAuth;
|
|
6
7
|
exports.generateAuth = generateAuth;
|
|
7
8
|
const fs_1 = __importDefault(require("fs"));
|
|
8
9
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
10
10
|
const generator_1 = require("../utils/generator");
|
|
11
11
|
const AUTH_MODULE_TEMPLATE = `import { HazelModule } from '@hazeljs/core';
|
|
12
12
|
import { AuthController } from './auth.controller';
|
|
@@ -145,50 +145,49 @@ export class LoginDto {
|
|
|
145
145
|
password: string;
|
|
146
146
|
}
|
|
147
147
|
`;
|
|
148
|
+
async function runAuth(_name, options) {
|
|
149
|
+
const basePath = path_1.default.join(process.cwd(), options.path || 'src/auth');
|
|
150
|
+
const data = {};
|
|
151
|
+
const files = [
|
|
152
|
+
{ file: 'auth.module.ts', template: AUTH_MODULE_TEMPLATE },
|
|
153
|
+
{ file: 'auth.service.ts', template: AUTH_SERVICE_TEMPLATE },
|
|
154
|
+
{ file: 'auth.controller.ts', template: AUTH_CONTROLLER_TEMPLATE },
|
|
155
|
+
{ file: 'jwt-auth.guard.ts', template: JWT_GUARD_TEMPLATE },
|
|
156
|
+
{ file: 'dto/register.dto.ts', template: REGISTER_DTO_TEMPLATE },
|
|
157
|
+
{ file: 'dto/login.dto.ts', template: LOGIN_DTO_TEMPLATE },
|
|
158
|
+
];
|
|
159
|
+
const created = [];
|
|
160
|
+
for (const { file, template } of files) {
|
|
161
|
+
const filePath = path_1.default.join(basePath, file);
|
|
162
|
+
created.push(filePath);
|
|
163
|
+
if (options.dryRun)
|
|
164
|
+
continue;
|
|
165
|
+
const dir = path_1.default.dirname(filePath);
|
|
166
|
+
if (!fs_1.default.existsSync(dir))
|
|
167
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
168
|
+
fs_1.default.writeFileSync(filePath, (0, generator_1.renderTemplate)(template, data));
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
ok: true,
|
|
172
|
+
created,
|
|
173
|
+
dryRun: options.dryRun,
|
|
174
|
+
nextSteps: [
|
|
175
|
+
'Import AuthModule in your app module',
|
|
176
|
+
'Configure JwtModule.forRoot() in your app module: JwtModule.forRoot({ secret: "your-secret", expiresIn: "1d" })',
|
|
177
|
+
'Install bcryptjs: npm install bcryptjs @types/bcryptjs',
|
|
178
|
+
'Implement database integration in AuthService',
|
|
179
|
+
],
|
|
180
|
+
};
|
|
181
|
+
}
|
|
148
182
|
function generateAuth(command) {
|
|
149
183
|
command
|
|
150
184
|
.command('auth')
|
|
151
185
|
.description('Generate an auth module with JWT guard, service, controller, and DTOs')
|
|
152
186
|
.option('-p, --path <path>', 'Specify the path', 'src/auth')
|
|
153
187
|
.option('--dry-run', 'Preview files without writing them')
|
|
154
|
-
.
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
{ file: 'auth.module.ts', template: AUTH_MODULE_TEMPLATE },
|
|
159
|
-
{ file: 'auth.service.ts', template: AUTH_SERVICE_TEMPLATE },
|
|
160
|
-
{ file: 'auth.controller.ts', template: AUTH_CONTROLLER_TEMPLATE },
|
|
161
|
-
{ file: 'jwt-auth.guard.ts', template: JWT_GUARD_TEMPLATE },
|
|
162
|
-
{ file: 'dto/register.dto.ts', template: REGISTER_DTO_TEMPLATE },
|
|
163
|
-
{ file: 'dto/login.dto.ts', template: LOGIN_DTO_TEMPLATE },
|
|
164
|
-
];
|
|
165
|
-
try {
|
|
166
|
-
for (const { file, template } of files) {
|
|
167
|
-
const filePath = path_1.default.join(basePath, file);
|
|
168
|
-
if (options.dryRun) {
|
|
169
|
-
console.log(chalk_1.default.blue(`[dry-run] Would create ${filePath}`));
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
|
-
const dir = path_1.default.dirname(filePath);
|
|
173
|
-
if (!fs_1.default.existsSync(dir)) {
|
|
174
|
-
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
175
|
-
}
|
|
176
|
-
fs_1.default.writeFileSync(filePath, (0, generator_1.renderTemplate)(template, data));
|
|
177
|
-
console.log(chalk_1.default.green(`\u2713 Generated ${filePath}`));
|
|
178
|
-
}
|
|
179
|
-
if (!options.dryRun) {
|
|
180
|
-
console.log(chalk_1.default.blue('\n\uD83D\uDD10 Auth module generated successfully!'));
|
|
181
|
-
console.log(chalk_1.default.gray('\nNext steps:'));
|
|
182
|
-
console.log(chalk_1.default.gray(' 1. Import AuthModule in your app module'));
|
|
183
|
-
console.log(chalk_1.default.gray(' 2. Configure JwtModule.forRoot() in your app module:'));
|
|
184
|
-
console.log(chalk_1.default.gray(' JwtModule.forRoot({ secret: "your-secret", expiresIn: "1d" })'));
|
|
185
|
-
console.log(chalk_1.default.gray(' 3. Install bcryptjs: npm install bcryptjs @types/bcryptjs'));
|
|
186
|
-
console.log(chalk_1.default.gray(' 4. Implement database integration in AuthService'));
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
catch (error) {
|
|
190
|
-
console.error(chalk_1.default.red('Error generating auth module:'), error);
|
|
191
|
-
process.exit(1);
|
|
192
|
-
}
|
|
188
|
+
.option('--json', 'Output result as JSON')
|
|
189
|
+
.action(async (options) => {
|
|
190
|
+
const result = await runAuth('auth', options);
|
|
191
|
+
(0, generator_1.printGenerateResult)(result, { json: options.json });
|
|
193
192
|
});
|
|
194
193
|
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
import { GenerateResult, GenerateCLIOptions } from '../utils/generator';
|
|
3
|
+
export declare function runCache(name: string, options: GenerateCLIOptions): Promise<GenerateResult>;
|
|
2
4
|
export declare function generateCache(command: Command): void;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runCache = runCache;
|
|
6
4
|
exports.generateCache = generateCache;
|
|
7
5
|
const generator_1 = require("../utils/generator");
|
|
8
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
9
6
|
const CACHE_SERVICE_TEMPLATE = `import { Service } from '@hazeljs/core';
|
|
10
7
|
import { CacheService, Cacheable, CacheEvict } from '@hazeljs/cache';
|
|
11
8
|
|
|
@@ -45,20 +42,25 @@ class CacheServiceGenerator extends generator_1.Generator {
|
|
|
45
42
|
return CACHE_SERVICE_TEMPLATE;
|
|
46
43
|
}
|
|
47
44
|
}
|
|
45
|
+
async function runCache(name, options) {
|
|
46
|
+
const generator = new CacheServiceGenerator();
|
|
47
|
+
const result = await generator.generate({ name, path: options.path, dryRun: options.dryRun });
|
|
48
|
+
result.nextSteps = [
|
|
49
|
+
'npm install @hazeljs/cache',
|
|
50
|
+
'Add CacheModule to your module imports',
|
|
51
|
+
'Configure the cache strategy (memory, redis, or multi-tier)',
|
|
52
|
+
];
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
48
55
|
function generateCache(command) {
|
|
49
56
|
command
|
|
50
57
|
.command('cache <name>')
|
|
51
58
|
.description('Generate a cache service with decorators')
|
|
52
59
|
.option('-p, --path <path>', 'Specify the path')
|
|
53
60
|
.option('--dry-run', 'Preview files without writing them')
|
|
61
|
+
.option('--json', 'Output result as JSON')
|
|
54
62
|
.action(async (name, options) => {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
if (!options.dryRun) {
|
|
58
|
-
console.log(chalk_1.default.gray('\nNext steps:'));
|
|
59
|
-
console.log(chalk_1.default.gray(' 1. npm install @hazeljs/cache'));
|
|
60
|
-
console.log(chalk_1.default.gray(' 2. Add CacheModule to your module imports'));
|
|
61
|
-
console.log(chalk_1.default.gray(' 3. Configure the cache strategy (memory, redis, or multi-tier)'));
|
|
62
|
-
}
|
|
63
|
+
const result = await runCache(name, options);
|
|
64
|
+
(0, generator_1.printGenerateResult)(result, { json: options.json });
|
|
63
65
|
});
|
|
64
66
|
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
import { GenerateResult, GenerateCLIOptions } from '../utils/generator';
|
|
3
|
+
export declare function runConfig(_name: string, options: GenerateCLIOptions): Promise<GenerateResult>;
|
|
2
4
|
export declare function generateConfig(command: Command): void;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runConfig = runConfig;
|
|
6
4
|
exports.generateConfig = generateConfig;
|
|
7
5
|
const generator_1 = require("../utils/generator");
|
|
8
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
9
6
|
const CONFIG_TEMPLATE = `import { HazelModule } from '@hazeljs/core';
|
|
10
7
|
import { ConfigModule, ConfigService } from '@hazeljs/config';
|
|
11
8
|
|
|
@@ -38,20 +35,25 @@ class ConfigGenerator extends generator_1.Generator {
|
|
|
38
35
|
return CONFIG_TEMPLATE;
|
|
39
36
|
}
|
|
40
37
|
}
|
|
38
|
+
async function runConfig(_name, options) {
|
|
39
|
+
const generator = new ConfigGenerator();
|
|
40
|
+
const result = await generator.generate({ name: 'app', path: options.path, dryRun: options.dryRun });
|
|
41
|
+
result.nextSteps = [
|
|
42
|
+
'npm install @hazeljs/config',
|
|
43
|
+
'Add ConfigModule.forRoot({ envFilePath: ".env" }) to your app module imports',
|
|
44
|
+
'Create a .env file in your project root',
|
|
45
|
+
];
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
41
48
|
function generateConfig(command) {
|
|
42
49
|
command
|
|
43
50
|
.command('config')
|
|
44
51
|
.description('Generate a config module setup')
|
|
45
52
|
.option('-p, --path <path>', 'Specify the path', 'src')
|
|
46
53
|
.option('--dry-run', 'Preview files without writing them')
|
|
54
|
+
.option('--json', 'Output result as JSON')
|
|
47
55
|
.action(async (options) => {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
if (!options.dryRun) {
|
|
51
|
-
console.log(chalk_1.default.gray('\nNext steps:'));
|
|
52
|
-
console.log(chalk_1.default.gray(' 1. npm install @hazeljs/config'));
|
|
53
|
-
console.log(chalk_1.default.gray(' 2. Add ConfigModule.forRoot({ envFilePath: ".env" }) to your app module imports'));
|
|
54
|
-
console.log(chalk_1.default.gray(' 3. Create a .env file in your project root'));
|
|
55
|
-
}
|
|
56
|
+
const result = await runConfig('app', options);
|
|
57
|
+
(0, generator_1.printGenerateResult)(result, { json: options.json });
|
|
56
58
|
});
|
|
57
59
|
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
import { GenerateResult, GenerateCLIOptions } from '../utils/generator';
|
|
3
|
+
export declare function runController(name: string, options: GenerateCLIOptions): Promise<GenerateResult>;
|
|
2
4
|
export declare function generateController(program: Command): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runController = runController;
|
|
3
4
|
exports.generateController = generateController;
|
|
4
5
|
const generator_1 = require("../utils/generator");
|
|
5
6
|
const CONTROLLER_TEMPLATE = `import { Controller, Get, Post, Body, Param, Delete, Put } from '@hazeljs/core';
|
|
@@ -46,6 +47,10 @@ class ControllerGenerator extends generator_1.Generator {
|
|
|
46
47
|
return CONTROLLER_TEMPLATE;
|
|
47
48
|
}
|
|
48
49
|
}
|
|
50
|
+
async function runController(name, options) {
|
|
51
|
+
const generator = new ControllerGenerator();
|
|
52
|
+
return generator.generate({ name, path: options.path, dryRun: options.dryRun });
|
|
53
|
+
}
|
|
49
54
|
function generateController(program) {
|
|
50
55
|
program
|
|
51
56
|
.command('controller <name>')
|
|
@@ -53,8 +58,9 @@ function generateController(program) {
|
|
|
53
58
|
.alias('c')
|
|
54
59
|
.option('-p, --path <path>', 'Path where the controller should be generated')
|
|
55
60
|
.option('--dry-run', 'Preview files without writing them')
|
|
61
|
+
.option('--json', 'Output result as JSON')
|
|
56
62
|
.action(async (name, options) => {
|
|
57
|
-
const
|
|
58
|
-
|
|
63
|
+
const result = await runController(name, options);
|
|
64
|
+
(0, generator_1.printGenerateResult)(result, { json: options.json });
|
|
59
65
|
});
|
|
60
66
|
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
import { GenerateResult, GenerateCLIOptions } from '../utils/generator';
|
|
3
|
+
export declare function runCron(name: string, options: GenerateCLIOptions): Promise<GenerateResult>;
|
|
2
4
|
export declare function generateCron(command: Command): void;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runCron = runCron;
|
|
6
4
|
exports.generateCron = generateCron;
|
|
7
5
|
const generator_1 = require("../utils/generator");
|
|
8
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
9
6
|
const CRON_SERVICE_TEMPLATE = `import { Service } from '@hazeljs/core';
|
|
10
7
|
import { Cron, CronExpression } from '@hazeljs/cron';
|
|
11
8
|
|
|
@@ -39,6 +36,16 @@ class CronServiceGenerator extends generator_1.Generator {
|
|
|
39
36
|
return CRON_SERVICE_TEMPLATE;
|
|
40
37
|
}
|
|
41
38
|
}
|
|
39
|
+
async function runCron(name, options) {
|
|
40
|
+
const generator = new CronServiceGenerator();
|
|
41
|
+
const result = await generator.generate({ name, path: options.path, dryRun: options.dryRun });
|
|
42
|
+
result.nextSteps = [
|
|
43
|
+
'npm install @hazeljs/cron',
|
|
44
|
+
'Add CronModule to your module imports',
|
|
45
|
+
'Register this service as a provider',
|
|
46
|
+
];
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
42
49
|
function generateCron(command) {
|
|
43
50
|
command
|
|
44
51
|
.command('cron <name>')
|
|
@@ -46,14 +53,9 @@ function generateCron(command) {
|
|
|
46
53
|
.alias('job')
|
|
47
54
|
.option('-p, --path <path>', 'Specify the path')
|
|
48
55
|
.option('--dry-run', 'Preview files without writing them')
|
|
56
|
+
.option('--json', 'Output result as JSON')
|
|
49
57
|
.action(async (name, options) => {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
if (!options.dryRun) {
|
|
53
|
-
console.log(chalk_1.default.gray('\nNext steps:'));
|
|
54
|
-
console.log(chalk_1.default.gray(' 1. npm install @hazeljs/cron'));
|
|
55
|
-
console.log(chalk_1.default.gray(' 2. Add CronModule to your module imports'));
|
|
56
|
-
console.log(chalk_1.default.gray(' 3. Register this service as a provider'));
|
|
57
|
-
}
|
|
58
|
+
const result = await runCron(name, options);
|
|
59
|
+
(0, generator_1.printGenerateResult)(result, { json: options.json });
|
|
58
60
|
});
|
|
59
61
|
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
import { GenerateResult, GenerateCLIOptions } from '../utils/generator';
|
|
3
|
+
export declare function runCrud(name: string, options: GenerateCLIOptions): Promise<GenerateResult>;
|
|
2
4
|
export declare function generateCrud(command: Command): void;
|
|
@@ -3,10 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runCrud = runCrud;
|
|
6
7
|
exports.generateCrud = generateCrud;
|
|
7
8
|
const fs_1 = __importDefault(require("fs"));
|
|
8
9
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
10
10
|
const generator_1 = require("../utils/generator");
|
|
11
11
|
const controllerTemplate = `import { Controller, Get, Post, Put, Delete, Body, Param } from '@hazeljs/core';
|
|
12
12
|
import { {{className}}Service } from './{{fileName}}.service';
|
|
@@ -127,14 +127,8 @@ import { {{className}}Service } from './{{fileName}}.service';
|
|
|
127
127
|
})
|
|
128
128
|
export class {{className}}Module {}
|
|
129
129
|
`;
|
|
130
|
-
function
|
|
131
|
-
|
|
132
|
-
.command('crud <name>')
|
|
133
|
-
.description('Generate a complete CRUD resource (controller, service, module, DTOs)')
|
|
134
|
-
.option('-p, --path <path>', 'Specify the path', 'src')
|
|
135
|
-
.option('-r, --route <route>', 'Specify the route path')
|
|
136
|
-
.option('--dry-run', 'Preview files without writing them')
|
|
137
|
-
.action((name, options) => {
|
|
130
|
+
async function runCrud(name, options) {
|
|
131
|
+
try {
|
|
138
132
|
const className = (0, generator_1.toPascalCase)(name);
|
|
139
133
|
const fileName = (0, generator_1.toKebabCase)(name);
|
|
140
134
|
const camelName = (0, generator_1.toCamelCase)(name);
|
|
@@ -147,31 +141,48 @@ function generateCrud(command) {
|
|
|
147
141
|
{ file: `dto/${fileName}.dto.ts`, template: dtoTemplate },
|
|
148
142
|
{ file: `${fileName}.module.ts`, template: moduleTemplate },
|
|
149
143
|
];
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
fs_1.default.writeFileSync(filePath, (0, generator_1.renderTemplate)(template, data));
|
|
162
|
-
console.log(chalk_1.default.green(`\u2713 Generated ${filePath}`));
|
|
163
|
-
}
|
|
164
|
-
if (!options.dryRun) {
|
|
165
|
-
console.log(chalk_1.default.blue('\n\uD83D\uDCE6 CRUD resource generated successfully!'));
|
|
166
|
-
console.log(chalk_1.default.gray(`\nNext steps:`));
|
|
167
|
-
console.log(chalk_1.default.gray(`1. Import ${className}Module in your app module`));
|
|
168
|
-
console.log(chalk_1.default.gray(`2. Customize the DTOs`));
|
|
169
|
-
console.log(chalk_1.default.gray(`3. Implement your business logic in the service`));
|
|
170
|
-
}
|
|
144
|
+
const created = [];
|
|
145
|
+
for (const { file, template } of files) {
|
|
146
|
+
const filePath = path_1.default.join(basePath, file);
|
|
147
|
+
created.push(filePath);
|
|
148
|
+
if (options.dryRun)
|
|
149
|
+
continue;
|
|
150
|
+
const dir = path_1.default.dirname(filePath);
|
|
151
|
+
if (!fs_1.default.existsSync(dir))
|
|
152
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
153
|
+
fs_1.default.writeFileSync(filePath, (0, generator_1.renderTemplate)(template, data));
|
|
171
154
|
}
|
|
172
|
-
|
|
173
|
-
|
|
155
|
+
return {
|
|
156
|
+
ok: true,
|
|
157
|
+
created,
|
|
158
|
+
dryRun: options.dryRun,
|
|
159
|
+
nextSteps: [
|
|
160
|
+
`Import ${className}Module in your app module`,
|
|
161
|
+
'Customize the DTOs',
|
|
162
|
+
'Implement your business logic in the service',
|
|
163
|
+
],
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
return {
|
|
168
|
+
ok: false,
|
|
169
|
+
created: [],
|
|
170
|
+
error: error instanceof Error ? error.message : String(error),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function generateCrud(command) {
|
|
175
|
+
command
|
|
176
|
+
.command('crud <name>')
|
|
177
|
+
.description('Generate a complete CRUD resource (controller, service, module, DTOs)')
|
|
178
|
+
.option('-p, --path <path>', 'Specify the path', 'src')
|
|
179
|
+
.option('-r, --route <route>', 'Specify the route path')
|
|
180
|
+
.option('--dry-run', 'Preview files without writing them')
|
|
181
|
+
.option('--json', 'Output result as JSON')
|
|
182
|
+
.action(async (name, options) => {
|
|
183
|
+
const result = await runCrud(name, options);
|
|
184
|
+
(0, generator_1.printGenerateResult)(result, { json: options.json });
|
|
185
|
+
if (!result.ok)
|
|
174
186
|
process.exit(1);
|
|
175
|
-
}
|
|
176
187
|
});
|
|
177
188
|
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
import { GenerateResult, GenerateCLIOptions } from '../utils/generator';
|
|
3
|
+
export declare function runDiscovery(name: string, options: GenerateCLIOptions): Promise<GenerateResult>;
|
|
2
4
|
export declare function generateDiscovery(command: Command): void;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runDiscovery = runDiscovery;
|
|
6
4
|
exports.generateDiscovery = generateDiscovery;
|
|
7
5
|
const generator_1 = require("../utils/generator");
|
|
8
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
9
6
|
const DISCOVERY_TEMPLATE = `import { Service } from '@hazeljs/core';
|
|
10
7
|
import { ServiceRegistry, DiscoveryClient } from '@hazeljs/discovery';
|
|
11
8
|
|
|
@@ -42,20 +39,25 @@ class DiscoveryGenerator extends generator_1.Generator {
|
|
|
42
39
|
return DISCOVERY_TEMPLATE;
|
|
43
40
|
}
|
|
44
41
|
}
|
|
42
|
+
async function runDiscovery(name, options) {
|
|
43
|
+
const generator = new DiscoveryGenerator();
|
|
44
|
+
const result = await generator.generate({ name, path: options.path, dryRun: options.dryRun });
|
|
45
|
+
result.nextSteps = [
|
|
46
|
+
'npm install @hazeljs/discovery',
|
|
47
|
+
'Register this service as a provider in your module',
|
|
48
|
+
'Configure your discovery backend (memory, redis, consul, or kubernetes)',
|
|
49
|
+
];
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
45
52
|
function generateDiscovery(command) {
|
|
46
53
|
command
|
|
47
54
|
.command('discovery <name>')
|
|
48
55
|
.description('Generate a service discovery setup')
|
|
49
56
|
.option('-p, --path <path>', 'Specify the path')
|
|
50
57
|
.option('--dry-run', 'Preview files without writing them')
|
|
58
|
+
.option('--json', 'Output result as JSON')
|
|
51
59
|
.action(async (name, options) => {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
if (!options.dryRun) {
|
|
55
|
-
console.log(chalk_1.default.gray('\nNext steps:'));
|
|
56
|
-
console.log(chalk_1.default.gray(' 1. npm install @hazeljs/discovery'));
|
|
57
|
-
console.log(chalk_1.default.gray(' 2. Register this service as a provider in your module'));
|
|
58
|
-
console.log(chalk_1.default.gray(' 3. Configure your discovery backend (memory, redis, consul, or kubernetes)'));
|
|
59
|
-
}
|
|
60
|
+
const result = await runDiscovery(name, options);
|
|
61
|
+
(0, generator_1.printGenerateResult)(result, { json: options.json });
|
|
60
62
|
});
|
|
61
63
|
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
import { GenerateResult, GenerateCLIOptions } from '../utils/generator';
|
|
3
|
+
export declare function runDto(name: string, options: GenerateCLIOptions): Promise<GenerateResult>;
|
|
2
4
|
export declare function generateDto(program: Command): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runDto = runDto;
|
|
3
4
|
exports.generateDto = generateDto;
|
|
4
5
|
const generator_1 = require("../utils/generator");
|
|
5
6
|
const CREATE_DTO_TEMPLATE = `import { IsString, IsOptional } from 'class-validator';
|
|
@@ -35,7 +36,7 @@ class DtoGenerator extends generator_1.Generator {
|
|
|
35
36
|
}
|
|
36
37
|
async generate(options) {
|
|
37
38
|
// Generate create DTO
|
|
38
|
-
await super.generate({
|
|
39
|
+
const r1 = await super.generate({
|
|
39
40
|
...options,
|
|
40
41
|
template: CREATE_DTO_TEMPLATE,
|
|
41
42
|
path: options.path ? `${options.path}/dto` : 'src/dto',
|
|
@@ -49,12 +50,19 @@ class DtoGenerator extends generator_1.Generator {
|
|
|
49
50
|
template: UPDATE_DTO_TEMPLATE,
|
|
50
51
|
path: options.path ? `${options.path}/dto` : 'src/dto',
|
|
51
52
|
};
|
|
52
|
-
|
|
53
|
-
// so the file is update-<name>.dto.ts rather than <name>.dto.ts (which would conflict)
|
|
54
|
-
await super.generate(updateOptions);
|
|
53
|
+
const r2 = await super.generate(updateOptions);
|
|
55
54
|
this.suffix = origSuffix;
|
|
55
|
+
return {
|
|
56
|
+
ok: r1.ok && r2.ok,
|
|
57
|
+
created: [...(r1.created ?? []), ...(r2.created ?? [])],
|
|
58
|
+
dryRun: r1.dryRun ?? r2.dryRun,
|
|
59
|
+
};
|
|
56
60
|
}
|
|
57
61
|
}
|
|
62
|
+
async function runDto(name, options) {
|
|
63
|
+
const generator = new DtoGenerator();
|
|
64
|
+
return generator.generate({ name, path: options.path, dryRun: options.dryRun });
|
|
65
|
+
}
|
|
58
66
|
function generateDto(program) {
|
|
59
67
|
program
|
|
60
68
|
.command('dto <name>')
|
|
@@ -62,8 +70,9 @@ function generateDto(program) {
|
|
|
62
70
|
.alias('d')
|
|
63
71
|
.option('-p, --path <path>', 'Path where the DTOs should be generated')
|
|
64
72
|
.option('--dry-run', 'Preview files without writing them')
|
|
73
|
+
.option('--json', 'Output result as JSON')
|
|
65
74
|
.action(async (name, options) => {
|
|
66
|
-
const
|
|
67
|
-
|
|
75
|
+
const result = await runDto(name, options);
|
|
76
|
+
(0, generator_1.printGenerateResult)(result, { json: options.json });
|
|
68
77
|
});
|
|
69
78
|
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
import { GenerateResult, GenerateCLIOptions } from '../utils/generator';
|
|
3
|
+
export declare function runExceptionFilter(name: string, options: GenerateCLIOptions): Promise<GenerateResult>;
|
|
2
4
|
export declare function generateExceptionFilter(program: Command): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runExceptionFilter = runExceptionFilter;
|
|
3
4
|
exports.generateExceptionFilter = generateExceptionFilter;
|
|
4
5
|
const generator_1 = require("../utils/generator");
|
|
5
6
|
const EXCEPTION_FILTER_TEMPLATE = `import { Catch, type ExceptionFilter, type ArgumentsHost, HttpError, logger } from '@hazeljs/core';
|
|
@@ -34,6 +35,10 @@ class ExceptionFilterGenerator extends generator_1.Generator {
|
|
|
34
35
|
return EXCEPTION_FILTER_TEMPLATE;
|
|
35
36
|
}
|
|
36
37
|
}
|
|
38
|
+
async function runExceptionFilter(name, options) {
|
|
39
|
+
const generator = new ExceptionFilterGenerator();
|
|
40
|
+
return generator.generate({ name, path: options.path, dryRun: options.dryRun });
|
|
41
|
+
}
|
|
37
42
|
function generateExceptionFilter(program) {
|
|
38
43
|
program
|
|
39
44
|
.command('filter <name>')
|
|
@@ -41,8 +46,9 @@ function generateExceptionFilter(program) {
|
|
|
41
46
|
.alias('f')
|
|
42
47
|
.option('-p, --path <path>', 'Path where the filter should be generated')
|
|
43
48
|
.option('--dry-run', 'Preview files without writing them')
|
|
49
|
+
.option('--json', 'Output result as JSON')
|
|
44
50
|
.action(async (name, options) => {
|
|
45
|
-
const
|
|
46
|
-
|
|
51
|
+
const result = await runExceptionFilter(name, options);
|
|
52
|
+
(0, generator_1.printGenerateResult)(result, { json: options.json });
|
|
47
53
|
});
|
|
48
54
|
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
import { GenerateResult, GenerateCLIOptions } from '../utils/generator';
|
|
3
|
+
export declare function runGuard(name: string, options: GenerateCLIOptions): Promise<GenerateResult>;
|
|
2
4
|
export declare function generateGuard(program: Command): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runGuard = runGuard;
|
|
3
4
|
exports.generateGuard = generateGuard;
|
|
4
5
|
const generator_1 = require("../utils/generator");
|
|
5
6
|
const GUARD_TEMPLATE = `import { Injectable, type CanActivate, type ExecutionContext } from '@hazeljs/core';
|
|
@@ -22,6 +23,10 @@ class GuardGenerator extends generator_1.Generator {
|
|
|
22
23
|
return GUARD_TEMPLATE;
|
|
23
24
|
}
|
|
24
25
|
}
|
|
26
|
+
async function runGuard(name, options) {
|
|
27
|
+
const generator = new GuardGenerator();
|
|
28
|
+
return generator.generate({ name, path: options.path, dryRun: options.dryRun });
|
|
29
|
+
}
|
|
25
30
|
function generateGuard(program) {
|
|
26
31
|
program
|
|
27
32
|
.command('guard <name>')
|
|
@@ -29,8 +34,9 @@ function generateGuard(program) {
|
|
|
29
34
|
.alias('gu')
|
|
30
35
|
.option('-p, --path <path>', 'Path where the guard should be generated')
|
|
31
36
|
.option('--dry-run', 'Preview files without writing them')
|
|
37
|
+
.option('--json', 'Output result as JSON')
|
|
32
38
|
.action(async (name, options) => {
|
|
33
|
-
const
|
|
34
|
-
|
|
39
|
+
const result = await runGuard(name, options);
|
|
40
|
+
(0, generator_1.printGenerateResult)(result, { json: options.json });
|
|
35
41
|
});
|
|
36
42
|
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
import { GenerateResult, GenerateCLIOptions } from '../utils/generator';
|
|
3
|
+
export declare function runInterceptor(name: string, options: GenerateCLIOptions): Promise<GenerateResult>;
|
|
2
4
|
export declare function generateInterceptor(program: Command): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runInterceptor = runInterceptor;
|
|
3
4
|
exports.generateInterceptor = generateInterceptor;
|
|
4
5
|
const generator_1 = require("../utils/generator");
|
|
5
6
|
const INTERCEPTOR_TEMPLATE = `import { Injectable, Interceptor, type ExecutionContext } from '@hazeljs/core';
|
|
@@ -23,6 +24,10 @@ class InterceptorGenerator extends generator_1.Generator {
|
|
|
23
24
|
return INTERCEPTOR_TEMPLATE;
|
|
24
25
|
}
|
|
25
26
|
}
|
|
27
|
+
async function runInterceptor(name, options) {
|
|
28
|
+
const generator = new InterceptorGenerator();
|
|
29
|
+
return generator.generate({ name, path: options.path, dryRun: options.dryRun });
|
|
30
|
+
}
|
|
26
31
|
function generateInterceptor(program) {
|
|
27
32
|
program
|
|
28
33
|
.command('interceptor <name>')
|
|
@@ -30,8 +35,9 @@ function generateInterceptor(program) {
|
|
|
30
35
|
.alias('i')
|
|
31
36
|
.option('-p, --path <path>', 'Path where the interceptor should be generated')
|
|
32
37
|
.option('--dry-run', 'Preview files without writing them')
|
|
38
|
+
.option('--json', 'Output result as JSON')
|
|
33
39
|
.action(async (name, options) => {
|
|
34
|
-
const
|
|
35
|
-
|
|
40
|
+
const result = await runInterceptor(name, options);
|
|
41
|
+
(0, generator_1.printGenerateResult)(result, { json: options.json });
|
|
36
42
|
});
|
|
37
43
|
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
import { GenerateResult, GenerateCLIOptions } from '../utils/generator';
|
|
3
|
+
export declare function runMiddleware(name: string, options: GenerateCLIOptions): Promise<GenerateResult>;
|
|
2
4
|
export declare function generateMiddleware(command: Command): void;
|