@hazeljs/cli 0.5.4 → 0.6.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/@template-ai-native/package.json +1 -1
- package/README.md +140 -588
- package/cli-manifest.json +940 -0
- package/dist/commands/add.d.ts +9 -0
- package/dist/commands/add.js +35 -126
- package/dist/commands/generate-app.js +17 -230
- package/dist/commands/generate-auth.d.ts +12 -0
- package/dist/commands/generate-auth.js +12 -0
- package/dist/commands/generate-crud.d.ts +12 -0
- package/dist/commands/generate-crud.js +12 -0
- package/dist/commands/generate-dto.d.ts +12 -0
- package/dist/commands/generate-dto.js +12 -0
- package/dist/commands/generate-module.d.ts +12 -0
- package/dist/commands/generate-module.js +12 -0
- package/dist/commands/generate-simple.d.ts +74 -0
- package/dist/commands/generate-simple.js +104 -0
- package/dist/commands/generate-simple.test.js +100 -0
- package/dist/commands/info.d.ts +12 -0
- package/dist/commands/info.js +12 -0
- package/dist/commands/templates.d.ts +34 -0
- package/dist/commands/templates.js +387 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +50 -48
- package/dist/index.list.test.js +8 -22
- package/dist/index.test.js +19 -56
- package/dist/utils/generator-registry.d.ts +5 -0
- package/dist/utils/generator-registry.js +34 -65
- package/dist/utils/generator.d.ts +0 -1
- package/dist/utils/generator.js +0 -22
- package/dist/utils/generator.test.js +0 -28
- package/dist/utils/packages-registry.d.ts +34 -0
- package/dist/utils/packages-registry.js +380 -0
- package/package.json +7 -7
- package/dist/commands/build.d.ts +0 -2
- package/dist/commands/build.js +0 -52
- package/dist/commands/generate-agent.d.ts +0 -4
- package/dist/commands/generate-agent.js +0 -64
- package/dist/commands/generate-agent.test.js +0 -36
- package/dist/commands/generate-ai-service.d.ts +0 -4
- package/dist/commands/generate-ai-service.js +0 -54
- package/dist/commands/generate-ai-service.test.d.ts +0 -1
- package/dist/commands/generate-ai-service.test.js +0 -41
- package/dist/commands/generate-cache.d.ts +0 -4
- package/dist/commands/generate-cache.js +0 -66
- package/dist/commands/generate-cache.test.d.ts +0 -1
- package/dist/commands/generate-cache.test.js +0 -36
- package/dist/commands/generate-config.d.ts +0 -4
- package/dist/commands/generate-config.js +0 -59
- package/dist/commands/generate-config.test.d.ts +0 -1
- package/dist/commands/generate-config.test.js +0 -35
- package/dist/commands/generate-controller.d.ts +0 -4
- package/dist/commands/generate-controller.js +0 -66
- package/dist/commands/generate-controller.test.d.ts +0 -1
- package/dist/commands/generate-controller.test.js +0 -48
- package/dist/commands/generate-cron.d.ts +0 -4
- package/dist/commands/generate-cron.js +0 -61
- package/dist/commands/generate-cron.test.d.ts +0 -1
- package/dist/commands/generate-cron.test.js +0 -42
- package/dist/commands/generate-discovery.d.ts +0 -4
- package/dist/commands/generate-discovery.js +0 -63
- package/dist/commands/generate-discovery.test.d.ts +0 -1
- package/dist/commands/generate-discovery.test.js +0 -36
- package/dist/commands/generate-exception-filter.d.ts +0 -4
- package/dist/commands/generate-exception-filter.js +0 -54
- package/dist/commands/generate-exception-filter.test.d.ts +0 -1
- package/dist/commands/generate-exception-filter.test.js +0 -43
- package/dist/commands/generate-guard.d.ts +0 -4
- package/dist/commands/generate-guard.js +0 -42
- package/dist/commands/generate-guard.test.d.ts +0 -1
- package/dist/commands/generate-guard.test.js +0 -41
- package/dist/commands/generate-interceptor.d.ts +0 -4
- package/dist/commands/generate-interceptor.js +0 -43
- package/dist/commands/generate-interceptor.test.d.ts +0 -1
- package/dist/commands/generate-interceptor.test.js +0 -41
- package/dist/commands/generate-middleware.d.ts +0 -4
- package/dist/commands/generate-middleware.js +0 -47
- package/dist/commands/generate-middleware.test.d.ts +0 -1
- package/dist/commands/generate-middleware.test.js +0 -41
- package/dist/commands/generate-pipe.d.ts +0 -4
- package/dist/commands/generate-pipe.js +0 -39
- package/dist/commands/generate-pipe.test.d.ts +0 -1
- package/dist/commands/generate-pipe.test.js +0 -35
- package/dist/commands/generate-rag.d.ts +0 -4
- package/dist/commands/generate-rag.js +0 -68
- package/dist/commands/generate-rag.test.d.ts +0 -1
- package/dist/commands/generate-rag.test.js +0 -35
- package/dist/commands/generate-repository.d.ts +0 -4
- package/dist/commands/generate-repository.js +0 -46
- package/dist/commands/generate-repository.test.d.ts +0 -1
- package/dist/commands/generate-repository.test.js +0 -41
- package/dist/commands/generate-serverless-handler.d.ts +0 -4
- package/dist/commands/generate-serverless-handler.js +0 -57
- package/dist/commands/generate-serverless-handler.test.d.ts +0 -1
- package/dist/commands/generate-serverless-handler.test.js +0 -42
- package/dist/commands/generate-service.d.ts +0 -4
- package/dist/commands/generate-service.js +0 -58
- package/dist/commands/generate-service.test.d.ts +0 -1
- package/dist/commands/generate-service.test.js +0 -41
- package/dist/commands/generate-setup.d.ts +0 -4
- package/dist/commands/generate-setup.js +0 -187
- package/dist/commands/generate-setup.test.d.ts +0 -1
- package/dist/commands/generate-setup.test.js +0 -50
- package/dist/commands/generate-websocket-gateway.d.ts +0 -4
- package/dist/commands/generate-websocket-gateway.js +0 -53
- package/dist/commands/generate-websocket-gateway.test.d.ts +0 -1
- package/dist/commands/generate-websocket-gateway.test.js +0 -41
- package/dist/commands/pdf-to-audio.d.ts +0 -2
- package/dist/commands/pdf-to-audio.js +0 -170
- package/dist/commands/pdf-to-audio.test.d.ts +0 -1
- package/dist/commands/pdf-to-audio.test.js +0 -92
- package/dist/commands/start.d.ts +0 -2
- package/dist/commands/start.js +0 -61
- package/dist/commands/test.d.ts +0 -2
- package/dist/commands/test.js +0 -63
- package/dist/commands/utility-commands.test.d.ts +0 -1
- package/dist/commands/utility-commands.test.js +0 -95
- /package/dist/commands/{generate-agent.test.d.ts → generate-simple.test.d.ts} +0 -0
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { GenerateResult, GenerateCLIOptions } from '../utils/generator';
|
|
3
|
+
/**
|
|
4
|
+
* Generate a complete feature module (5 files: module, controller, service, 2 DTOs).
|
|
5
|
+
*
|
|
6
|
+
* @param name - Feature name (e.g. 'users') — determines file and class names
|
|
7
|
+
* @param options - Standard CLI options (--path, --dry-run, --json)
|
|
8
|
+
* @returns GenerateResult with paths of all created files
|
|
9
|
+
*/
|
|
3
10
|
export declare function runModule(name: string, options: GenerateCLIOptions): Promise<GenerateResult>;
|
|
11
|
+
/**
|
|
12
|
+
* Register `hazel g module <name>` as a sub-command of the generate command.
|
|
13
|
+
*
|
|
14
|
+
* @param program - The Commander `generate` parent command
|
|
15
|
+
*/
|
|
4
16
|
export declare function generateModule(program: Command): void;
|
|
@@ -64,6 +64,13 @@ const UPDATE_DTO_TEMPLATE = `export class Update{{className}}Dto {
|
|
|
64
64
|
name?: string;
|
|
65
65
|
}
|
|
66
66
|
`;
|
|
67
|
+
/**
|
|
68
|
+
* Generate a complete feature module (5 files: module, controller, service, 2 DTOs).
|
|
69
|
+
*
|
|
70
|
+
* @param name - Feature name (e.g. 'users') — determines file and class names
|
|
71
|
+
* @param options - Standard CLI options (--path, --dry-run, --json)
|
|
72
|
+
* @returns GenerateResult with paths of all created files
|
|
73
|
+
*/
|
|
67
74
|
async function runModule(name, options) {
|
|
68
75
|
const className = (0, generator_1.toPascalCase)(name);
|
|
69
76
|
const fileName = (0, generator_1.toKebabCase)(name);
|
|
@@ -95,6 +102,11 @@ async function runModule(name, options) {
|
|
|
95
102
|
nextSteps: [`Import ${className}Module in your app module.`],
|
|
96
103
|
};
|
|
97
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Register `hazel g module <name>` as a sub-command of the generate command.
|
|
107
|
+
*
|
|
108
|
+
* @param program - The Commander `generate` parent command
|
|
109
|
+
*/
|
|
98
110
|
function generateModule(program) {
|
|
99
111
|
program
|
|
100
112
|
.command('module <name>')
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config-driven generator factory for simple single-file generators.
|
|
3
|
+
*
|
|
4
|
+
* Architecture:
|
|
5
|
+
* 1. Templates live in ./templates.ts (Mustache strings, one per generator type).
|
|
6
|
+
* 2. SIMPLE_GENERATORS is a declarative config array — each entry maps a CLI
|
|
7
|
+
* sub-command to a template, suffix, alias, and optional next-steps.
|
|
8
|
+
* 3. registerSimpleGenerators() loops over the config and registers each one
|
|
9
|
+
* as a Commander sub-command of `hazel generate`.
|
|
10
|
+
* 4. runSimpleGenerator() instantiates a lightweight SimpleGenerator (extends
|
|
11
|
+
* the base Generator class) and renders the template with the user's name.
|
|
12
|
+
*
|
|
13
|
+
* To add a new single-file generator:
|
|
14
|
+
* 1. Add a Mustache template in ./templates.ts
|
|
15
|
+
* 2. Add a SimpleGeneratorConfig entry to SIMPLE_GENERATORS below
|
|
16
|
+
* — that's it; the CLI, --list, --json, and --dry-run support are automatic.
|
|
17
|
+
*/
|
|
18
|
+
import { Command } from 'commander';
|
|
19
|
+
import { GenerateResult, GenerateCLIOptions } from '../utils/generator';
|
|
20
|
+
/**
|
|
21
|
+
* Declarative configuration for a single-file generator.
|
|
22
|
+
*
|
|
23
|
+
* Each entry in SIMPLE_GENERATORS produces one CLI sub-command under
|
|
24
|
+
* `hazel generate` (e.g. `hazel g controller <name>`).
|
|
25
|
+
*/
|
|
26
|
+
export interface SimpleGeneratorConfig {
|
|
27
|
+
/** Generator type used as the sub-command name (e.g. 'controller', 'agent') */
|
|
28
|
+
type: string;
|
|
29
|
+
/** Human-readable description shown in `hazel g --list` and `--help` */
|
|
30
|
+
description: string;
|
|
31
|
+
/** File suffix before .ts — e.g. 'controller' produces `name.controller.ts` */
|
|
32
|
+
suffix: string;
|
|
33
|
+
/** Mustache template string (imported from ./templates.ts) */
|
|
34
|
+
template: string;
|
|
35
|
+
/** Short alias for the sub-command (e.g. 'c' for controller) */
|
|
36
|
+
alias?: string;
|
|
37
|
+
/** Default output directory if --path is not provided (defaults to 'src') */
|
|
38
|
+
defaultPath?: string;
|
|
39
|
+
/** Whether the generator requires a <name> argument (false for config, etc.) */
|
|
40
|
+
nameRequired: boolean;
|
|
41
|
+
/** Factory function returning extra Mustache data merged into the template context */
|
|
42
|
+
extraData?: (name: string) => Record<string, string>;
|
|
43
|
+
/** Post-generation instructions printed to the user (e.g. 'npm install ...') */
|
|
44
|
+
nextSteps?: string[];
|
|
45
|
+
/** Additional CLI options beyond the standard --path, --dry-run, --json */
|
|
46
|
+
extraOptions?: string[];
|
|
47
|
+
}
|
|
48
|
+
export declare const SIMPLE_GENERATORS: SimpleGeneratorConfig[];
|
|
49
|
+
/**
|
|
50
|
+
* Execute a simple generator given its config, a name, and CLI options.
|
|
51
|
+
*
|
|
52
|
+
* @param config - The SimpleGeneratorConfig entry (from SIMPLE_GENERATORS)
|
|
53
|
+
* @param name - User-provided name (e.g. 'users') — used for file and class names
|
|
54
|
+
* @param options - Standard CLI options (--path, --dry-run, --json, --platform)
|
|
55
|
+
* @returns A GenerateResult with created file paths and optional next steps
|
|
56
|
+
*/
|
|
57
|
+
export declare function runSimpleGenerator(config: SimpleGeneratorConfig, name: string, options: GenerateCLIOptions): Promise<GenerateResult>;
|
|
58
|
+
/**
|
|
59
|
+
* Register all simple generators as sub-commands of the `hazel generate` command.
|
|
60
|
+
*
|
|
61
|
+
* Iterates over SIMPLE_GENERATORS and creates a Commander sub-command for each,
|
|
62
|
+
* wiring up aliases, options (--path, --dry-run, --json, plus any extraOptions),
|
|
63
|
+
* and the action handler that calls runSimpleGenerator.
|
|
64
|
+
*
|
|
65
|
+
* @param generateCommand - The Commander `generate` parent command to attach sub-commands to
|
|
66
|
+
*/
|
|
67
|
+
export declare function registerSimpleGenerators(generateCommand: Command): void;
|
|
68
|
+
/**
|
|
69
|
+
* Look up a SimpleGeneratorConfig by its type name (e.g. 'controller', 'agent').
|
|
70
|
+
*
|
|
71
|
+
* @param type - The generator type to find
|
|
72
|
+
* @returns The matching config, or undefined if no simple generator matches
|
|
73
|
+
*/
|
|
74
|
+
export declare function findSimpleGenerator(type: string): SimpleGeneratorConfig | undefined;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SIMPLE_GENERATORS = void 0;
|
|
4
|
+
exports.runSimpleGenerator = runSimpleGenerator;
|
|
5
|
+
exports.registerSimpleGenerators = registerSimpleGenerators;
|
|
6
|
+
exports.findSimpleGenerator = findSimpleGenerator;
|
|
7
|
+
const generator_1 = require("../utils/generator");
|
|
8
|
+
const templates_1 = require("./templates");
|
|
9
|
+
exports.SIMPLE_GENERATORS = [
|
|
10
|
+
{ type: 'controller', description: 'REST controller', suffix: 'controller', template: templates_1.CONTROLLER_TEMPLATE, alias: 'c', nameRequired: true },
|
|
11
|
+
{ type: 'service', description: 'Service class', suffix: 'service', template: templates_1.SERVICE_TEMPLATE, alias: 's', nameRequired: true },
|
|
12
|
+
{ type: 'guard', description: 'Guard (e.g. auth)', suffix: 'guard', template: templates_1.GUARD_TEMPLATE, alias: 'gu', nameRequired: true },
|
|
13
|
+
{ type: 'interceptor', description: 'Interceptor', suffix: 'interceptor', template: templates_1.INTERCEPTOR_TEMPLATE, alias: 'i', nameRequired: true },
|
|
14
|
+
{ type: 'middleware', description: 'Middleware', suffix: 'middleware', template: templates_1.MIDDLEWARE_TEMPLATE, alias: 'mw', defaultPath: 'src/middleware', nameRequired: true, nextSteps: ['Import the middleware in your module or apply it globally.'] },
|
|
15
|
+
{ type: 'pipe', description: 'Validation/transform pipe', suffix: 'pipe', template: templates_1.PIPE_TEMPLATE, nameRequired: true },
|
|
16
|
+
{ type: 'filter', description: 'Exception filter', suffix: 'filter', template: templates_1.EXCEPTION_FILTER_TEMPLATE, alias: 'f', nameRequired: true },
|
|
17
|
+
{ type: 'repository', description: 'Prisma repository', suffix: 'repository', template: templates_1.REPOSITORY_TEMPLATE, alias: 'repo', nameRequired: true },
|
|
18
|
+
{ type: 'gateway', description: 'WebSocket gateway', suffix: 'gateway', template: templates_1.WEBSOCKET_GATEWAY_TEMPLATE, alias: 'ws', nameRequired: true },
|
|
19
|
+
{ type: 'ai-service', description: 'AI service with decorators', suffix: 'ai-service', template: templates_1.AI_SERVICE_TEMPLATE, alias: 'ai', nameRequired: true },
|
|
20
|
+
{ type: 'agent', description: 'AI agent with @Agent and @Tool', suffix: 'agent', template: templates_1.AGENT_TEMPLATE, nameRequired: true, extraData: (name) => ({ description: `A ${name} agent` }) },
|
|
21
|
+
{ type: 'cache', description: 'Cache service with decorators', suffix: 'cache', template: templates_1.CACHE_SERVICE_TEMPLATE, nameRequired: true, nextSteps: ['npm install @hazeljs/cache', 'Add CacheModule to your module imports', 'Configure the cache strategy (memory, redis, or multi-tier)'] },
|
|
22
|
+
{ type: 'cron', description: 'Cron/scheduled job service', suffix: 'cron', template: templates_1.CRON_SERVICE_TEMPLATE, alias: 'job', nameRequired: true, nextSteps: ['npm install @hazeljs/cron', 'Add CronModule to your module imports', 'Register this service as a provider'] },
|
|
23
|
+
{ type: 'rag', description: 'RAG (Retrieval-Augmented Generation) service', suffix: 'rag', template: templates_1.RAG_SERVICE_TEMPLATE, nameRequired: true, nextSteps: ['npm install @hazeljs/rag', 'Register this service as a provider in your module', 'Configure your embedding provider and vector store'] },
|
|
24
|
+
{ type: 'discovery', description: 'Service discovery setup', suffix: 'discovery', template: templates_1.DISCOVERY_TEMPLATE, nameRequired: true, nextSteps: ['npm install @hazeljs/discovery', 'Register this service as a provider in your module', 'Configure your discovery backend (memory, redis, consul, or kubernetes)'] },
|
|
25
|
+
{ type: 'config', description: 'Config module setup', suffix: 'config', template: templates_1.CONFIG_TEMPLATE, nameRequired: false, nextSteps: ['npm install @hazeljs/config', 'Add ConfigModule.forRoot({ envFilePath: ".env" }) to your app module imports', 'Create a .env file in your project root'] },
|
|
26
|
+
{ type: 'serverless', description: 'Serverless handler (Lambda or Cloud Function)', suffix: 'handler', template: templates_1.SERVERLESS_LAMBDA_TEMPLATE, alias: 'sls', nameRequired: true, extraOptions: ['platform'] },
|
|
27
|
+
];
|
|
28
|
+
// ── Runner factory ───────────────────────────────────────────────────────────
|
|
29
|
+
class SimpleGenerator extends generator_1.Generator {
|
|
30
|
+
constructor(_suffix, _template) {
|
|
31
|
+
super();
|
|
32
|
+
this._suffix = _suffix;
|
|
33
|
+
this._template = _template;
|
|
34
|
+
this.suffix = _suffix;
|
|
35
|
+
}
|
|
36
|
+
getDefaultTemplate() {
|
|
37
|
+
return this._template;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Execute a simple generator given its config, a name, and CLI options.
|
|
42
|
+
*
|
|
43
|
+
* @param config - The SimpleGeneratorConfig entry (from SIMPLE_GENERATORS)
|
|
44
|
+
* @param name - User-provided name (e.g. 'users') — used for file and class names
|
|
45
|
+
* @param options - Standard CLI options (--path, --dry-run, --json, --platform)
|
|
46
|
+
* @returns A GenerateResult with created file paths and optional next steps
|
|
47
|
+
*/
|
|
48
|
+
async function runSimpleGenerator(config, name, options) {
|
|
49
|
+
// Handle serverless platform option
|
|
50
|
+
let template = config.template;
|
|
51
|
+
if (config.type === 'serverless' && options.platform === 'cloud-function') {
|
|
52
|
+
template = templates_1.SERVERLESS_CLOUD_FUNCTION_TEMPLATE;
|
|
53
|
+
}
|
|
54
|
+
const generator = new SimpleGenerator(config.suffix, template);
|
|
55
|
+
const effectiveName = config.nameRequired ? name : (name || 'app');
|
|
56
|
+
const result = await generator.generate({
|
|
57
|
+
name: effectiveName,
|
|
58
|
+
path: options.path || config.defaultPath,
|
|
59
|
+
dryRun: options.dryRun,
|
|
60
|
+
data: config.extraData ? config.extraData(effectiveName) : undefined,
|
|
61
|
+
});
|
|
62
|
+
if (config.nextSteps) {
|
|
63
|
+
result.nextSteps = [...(result.nextSteps ?? []), ...config.nextSteps];
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Register all simple generators as sub-commands of the `hazel generate` command.
|
|
69
|
+
*
|
|
70
|
+
* Iterates over SIMPLE_GENERATORS and creates a Commander sub-command for each,
|
|
71
|
+
* wiring up aliases, options (--path, --dry-run, --json, plus any extraOptions),
|
|
72
|
+
* and the action handler that calls runSimpleGenerator.
|
|
73
|
+
*
|
|
74
|
+
* @param generateCommand - The Commander `generate` parent command to attach sub-commands to
|
|
75
|
+
*/
|
|
76
|
+
function registerSimpleGenerators(generateCommand) {
|
|
77
|
+
for (const config of exports.SIMPLE_GENERATORS) {
|
|
78
|
+
const cmdStr = config.nameRequired ? `${config.type} <name>` : config.type;
|
|
79
|
+
const cmd = generateCommand.command(cmdStr).description(config.description);
|
|
80
|
+
if (config.alias)
|
|
81
|
+
cmd.alias(config.alias);
|
|
82
|
+
cmd.option('-p, --path <path>', 'Path where the file should be generated', config.defaultPath);
|
|
83
|
+
cmd.option('--dry-run', 'Preview files without writing them');
|
|
84
|
+
cmd.option('--json', 'Output result as JSON');
|
|
85
|
+
if (config.extraOptions?.includes('platform')) {
|
|
86
|
+
cmd.option('--platform <platform>', 'Platform: lambda or cloud-function', 'lambda');
|
|
87
|
+
}
|
|
88
|
+
cmd.action(async (nameOrOptions, maybeOptions) => {
|
|
89
|
+
const name = typeof nameOrOptions === 'string' ? nameOrOptions : '';
|
|
90
|
+
const opts = typeof nameOrOptions === 'string' ? (maybeOptions || {}) : nameOrOptions;
|
|
91
|
+
const result = await runSimpleGenerator(config, name, opts);
|
|
92
|
+
(0, generator_1.printGenerateResult)(result, { json: opts.json });
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Look up a SimpleGeneratorConfig by its type name (e.g. 'controller', 'agent').
|
|
98
|
+
*
|
|
99
|
+
* @param type - The generator type to find
|
|
100
|
+
* @returns The matching config, or undefined if no simple generator matches
|
|
101
|
+
*/
|
|
102
|
+
function findSimpleGenerator(type) {
|
|
103
|
+
return exports.SIMPLE_GENERATORS.find((g) => g.type === type);
|
|
104
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const generate_simple_1 = require("./generate-simple");
|
|
9
|
+
jest.mock('fs');
|
|
10
|
+
describe('generate-simple', () => {
|
|
11
|
+
const mockFs = fs_1.default;
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
jest.clearAllMocks();
|
|
14
|
+
mockFs.existsSync.mockReturnValue(true);
|
|
15
|
+
mockFs.writeFileSync.mockImplementation(() => { });
|
|
16
|
+
});
|
|
17
|
+
describe('SIMPLE_GENERATORS', () => {
|
|
18
|
+
it('should have at least 15 generator configs', () => {
|
|
19
|
+
expect(generate_simple_1.SIMPLE_GENERATORS.length).toBeGreaterThanOrEqual(15);
|
|
20
|
+
});
|
|
21
|
+
it('should have unique types', () => {
|
|
22
|
+
const types = generate_simple_1.SIMPLE_GENERATORS.map((g) => g.type);
|
|
23
|
+
expect(new Set(types).size).toBe(types.length);
|
|
24
|
+
});
|
|
25
|
+
it('should all have non-empty templates', () => {
|
|
26
|
+
for (const g of generate_simple_1.SIMPLE_GENERATORS) {
|
|
27
|
+
expect(g.template.length).toBeGreaterThan(0);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
describe('findSimpleGenerator', () => {
|
|
32
|
+
it('finds by type', () => {
|
|
33
|
+
const config = (0, generate_simple_1.findSimpleGenerator)('controller');
|
|
34
|
+
expect(config).toBeDefined();
|
|
35
|
+
expect(config.type).toBe('controller');
|
|
36
|
+
});
|
|
37
|
+
it('returns undefined for unknown type', () => {
|
|
38
|
+
expect((0, generate_simple_1.findSimpleGenerator)('nope')).toBeUndefined();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe('runSimpleGenerator', () => {
|
|
42
|
+
it('generates a controller file in dry-run', async () => {
|
|
43
|
+
const config = (0, generate_simple_1.findSimpleGenerator)('controller');
|
|
44
|
+
const result = await (0, generate_simple_1.runSimpleGenerator)(config, 'users', { dryRun: true });
|
|
45
|
+
expect(result.ok).toBe(true);
|
|
46
|
+
expect(result.dryRun).toBe(true);
|
|
47
|
+
expect(result.created[0]).toContain('users.controller.ts');
|
|
48
|
+
});
|
|
49
|
+
it('generates a guard file', async () => {
|
|
50
|
+
const config = (0, generate_simple_1.findSimpleGenerator)('guard');
|
|
51
|
+
const result = await (0, generate_simple_1.runSimpleGenerator)(config, 'auth', {});
|
|
52
|
+
expect(result.ok).toBe(true);
|
|
53
|
+
expect(result.created[0]).toContain('auth.guard.ts');
|
|
54
|
+
expect(mockFs.writeFileSync).toHaveBeenCalled();
|
|
55
|
+
});
|
|
56
|
+
it('generates agent with extra data', async () => {
|
|
57
|
+
const config = (0, generate_simple_1.findSimpleGenerator)('agent');
|
|
58
|
+
const result = await (0, generate_simple_1.runSimpleGenerator)(config, 'weather', { dryRun: true });
|
|
59
|
+
expect(result.ok).toBe(true);
|
|
60
|
+
expect(result.created[0]).toContain('weather.agent.ts');
|
|
61
|
+
});
|
|
62
|
+
it('appends nextSteps for cache generator', async () => {
|
|
63
|
+
const config = (0, generate_simple_1.findSimpleGenerator)('cache');
|
|
64
|
+
const result = await (0, generate_simple_1.runSimpleGenerator)(config, 'product', { dryRun: true });
|
|
65
|
+
expect(result.nextSteps).toBeDefined();
|
|
66
|
+
expect(result.nextSteps.some((s) => s.includes('@hazeljs/cache'))).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
it('handles config generator (no name required)', async () => {
|
|
69
|
+
const config = (0, generate_simple_1.findSimpleGenerator)('config');
|
|
70
|
+
const result = await (0, generate_simple_1.runSimpleGenerator)(config, '', { dryRun: true });
|
|
71
|
+
expect(result.ok).toBe(true);
|
|
72
|
+
expect(result.created[0]).toContain('app.config.ts');
|
|
73
|
+
});
|
|
74
|
+
it('handles serverless with cloud-function platform', async () => {
|
|
75
|
+
const config = (0, generate_simple_1.findSimpleGenerator)('serverless');
|
|
76
|
+
const result = await (0, generate_simple_1.runSimpleGenerator)(config, 'api', { dryRun: true, platform: 'cloud-function' });
|
|
77
|
+
expect(result.ok).toBe(true);
|
|
78
|
+
expect(result.created[0]).toContain('api.handler.ts');
|
|
79
|
+
});
|
|
80
|
+
it('generates with custom path', async () => {
|
|
81
|
+
const config = (0, generate_simple_1.findSimpleGenerator)('service');
|
|
82
|
+
const result = await (0, generate_simple_1.runSimpleGenerator)(config, 'order', { path: 'src/orders', dryRun: true });
|
|
83
|
+
expect(result.ok).toBe(true);
|
|
84
|
+
expect(result.created[0]).toContain('src/orders');
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
describe('registerSimpleGenerators', () => {
|
|
88
|
+
it('registers all simple generators as sub-commands', () => {
|
|
89
|
+
const program = new commander_1.Command();
|
|
90
|
+
(0, generate_simple_1.registerSimpleGenerators)(program);
|
|
91
|
+
const commandNames = program.commands.map((c) => c.name());
|
|
92
|
+
expect(commandNames).toContain('controller');
|
|
93
|
+
expect(commandNames).toContain('guard');
|
|
94
|
+
expect(commandNames).toContain('agent');
|
|
95
|
+
expect(commandNames).toContain('serverless');
|
|
96
|
+
expect(commandNames).toContain('config');
|
|
97
|
+
expect(commandNames.length).toBe(generate_simple_1.SIMPLE_GENERATORS.length);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
package/dist/commands/info.d.ts
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
/**
|
|
3
|
+
* Register the `hazel info` command.
|
|
4
|
+
*
|
|
5
|
+
* Reads the current directory's package.json and displays:
|
|
6
|
+
* - Project name, version, description
|
|
7
|
+
* - Installed @hazeljs/* packages with versions
|
|
8
|
+
* - src/ directory listing
|
|
9
|
+
* - Node.js version, platform, architecture
|
|
10
|
+
* - Detected configuration files (tsconfig, .env, eslint, etc.)
|
|
11
|
+
*
|
|
12
|
+
* @param program - The root Commander program instance
|
|
13
|
+
*/
|
|
2
14
|
export declare function infoCommand(program: Command): void;
|
package/dist/commands/info.js
CHANGED
|
@@ -7,6 +7,18 @@ exports.infoCommand = infoCommand;
|
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
+
/**
|
|
11
|
+
* Register the `hazel info` command.
|
|
12
|
+
*
|
|
13
|
+
* Reads the current directory's package.json and displays:
|
|
14
|
+
* - Project name, version, description
|
|
15
|
+
* - Installed @hazeljs/* packages with versions
|
|
16
|
+
* - src/ directory listing
|
|
17
|
+
* - Node.js version, platform, architecture
|
|
18
|
+
* - Detected configuration files (tsconfig, .env, eslint, etc.)
|
|
19
|
+
*
|
|
20
|
+
* @param program - The root Commander program instance
|
|
21
|
+
*/
|
|
10
22
|
function infoCommand(program) {
|
|
11
23
|
program
|
|
12
24
|
.command('info')
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mustache templates for all simple (single-file) generators.
|
|
3
|
+
*
|
|
4
|
+
* Each template uses three standard variables provided by the Generator base class:
|
|
5
|
+
* - {{className}} — PascalCase name (e.g. "Users")
|
|
6
|
+
* - {{fileName}} — kebab-case name (e.g. "users")
|
|
7
|
+
* - {{camelName}} — camelCase name (e.g. "users")
|
|
8
|
+
*
|
|
9
|
+
* Some templates accept additional data via `extraData` in SimpleGeneratorConfig:
|
|
10
|
+
* - AGENT_TEMPLATE — {{description}}
|
|
11
|
+
* - REPOSITORY_TEMPLATE — {{modelName}} (defaults to fileName)
|
|
12
|
+
*
|
|
13
|
+
* Templates are imported by generate-simple.ts and referenced in the
|
|
14
|
+
* SIMPLE_GENERATORS config array. To add a new generator, create a template
|
|
15
|
+
* here and add a config entry in generate-simple.ts.
|
|
16
|
+
*/
|
|
17
|
+
export declare const CONTROLLER_TEMPLATE = "import { Controller, Get, Post, Body, Param, Delete, Put } from '@hazeljs/core';\nimport { {{className}}Service } from './{{fileName}}.service';\nimport { Create{{className}}Dto } from './dto/create-{{fileName}}.dto';\nimport { Update{{className}}Dto } from './dto/update-{{fileName}}.dto';\n\n@Controller('{{fileName}}')\nexport class {{className}}Controller {\n constructor(private readonly {{camelName}}Service: {{className}}Service) {}\n\n @Get()\n findAll() {\n return this.{{camelName}}Service.findAll();\n }\n\n @Get(':id')\n findOne(@Param('id') id: string) {\n return this.{{camelName}}Service.findOne(id);\n }\n\n @Post()\n create(@Body(Create{{className}}Dto) createDto: Create{{className}}Dto) {\n return this.{{camelName}}Service.create(createDto);\n }\n\n @Put(':id')\n update(@Param('id') id: string, @Body(Update{{className}}Dto) updateDto: Update{{className}}Dto) {\n return this.{{camelName}}Service.update(id, updateDto);\n }\n\n @Delete(':id')\n remove(@Param('id') id: string) {\n return this.{{camelName}}Service.remove(id);\n }\n}\n";
|
|
18
|
+
export declare const SERVICE_TEMPLATE = "import { Service } from '@hazeljs/core';\n\n@Service()\nexport class {{className}}Service {\n constructor() {}\n\n async findAll() {\n return [];\n }\n\n async findOne(id: string) {\n return { id };\n }\n\n async create(createDto: any) {\n return createDto;\n }\n\n async update(id: string, updateDto: any) {\n return { id, ...updateDto };\n }\n\n async remove(id: string) {\n return { id };\n }\n}\n";
|
|
19
|
+
export declare const GUARD_TEMPLATE = "import { Injectable, type CanActivate, type ExecutionContext } from '@hazeljs/core';\n\n@Injectable()\nexport class {{className}}Guard implements CanActivate {\n canActivate(context: ExecutionContext): boolean {\n const request = context.switchToHttp().getRequest();\n // Add your guard logic here\n return true;\n }\n}\n";
|
|
20
|
+
export declare const INTERCEPTOR_TEMPLATE = "import { Injectable, Interceptor, type ExecutionContext } from '@hazeljs/core';\n\n@Injectable()\nexport class {{className}}Interceptor implements Interceptor {\n async intercept(context: ExecutionContext, next: () => Promise<unknown>): Promise<unknown> {\n // Pre-processing logic here (before handler execution)\n const result = await next();\n // Post-processing logic here (after handler execution)\n return result;\n }\n}\n";
|
|
21
|
+
export declare const MIDDLEWARE_TEMPLATE = "import { Injectable, type MiddlewareHandler, type Request, type Response, type NextFunction } from '@hazeljs/core';\n\n@Injectable()\nexport class {{className}}Middleware implements MiddlewareHandler {\n use(req: Request, res: Response, next: NextFunction) {\n // Add your middleware logic here\n console.log(`[{{className}}Middleware] ${req.method} ${req.url}`);\n \n // Continue to next middleware\n next();\n }\n}\n";
|
|
22
|
+
export declare const PIPE_TEMPLATE = "import { type PipeTransform, type RequestContext } from '@hazeljs/core';\n\nexport class {{className}}Pipe implements PipeTransform {\n transform(value: unknown, context: RequestContext): unknown {\n // Transform logic here\n return value;\n }\n}\n";
|
|
23
|
+
export declare const EXCEPTION_FILTER_TEMPLATE = "import { Catch, type ExceptionFilter, type ArgumentsHost, HttpError, logger } from '@hazeljs/core';\n\n@Catch(HttpError)\nexport class {{className}}ExceptionFilter implements ExceptionFilter<HttpError> {\n catch(exception: HttpError, host: ArgumentsHost): void {\n const ctx = host.switchToHttp();\n const response = ctx.getResponse();\n const request = ctx.getRequest();\n\n const status = exception.statusCode || 500;\n const message = exception.message || 'Internal server error';\n\n logger.error(`[${request.method}] ${request.url} - ${message} (${status})`);\n\n response.status(status).json({\n statusCode: status,\n message,\n timestamp: new Date().toISOString(),\n path: request.url,\n });\n }\n}\n";
|
|
24
|
+
export declare const REPOSITORY_TEMPLATE = "import { Repository, BaseRepository, PrismaService } from '@hazeljs/prisma';\n\n// @Repository implies @Injectable() \u2014 no need for both decorators\n@Repository({ model: '{{modelName}}' })\nexport class {{className}}Repository extends BaseRepository<any> {\n constructor(prisma: PrismaService) {\n super(prisma, '{{modelName}}');\n }\n\n // Add custom repository methods here\n async findByName(name: string) {\n return this.findMany({ where: { name } });\n }\n}\n";
|
|
25
|
+
export declare const WEBSOCKET_GATEWAY_TEMPLATE = "import { Realtime, OnConnect, OnDisconnect, OnMessage, Subscribe, Client, Data, WebSocketClient } from '@hazeljs/websocket';\n\n@Realtime('/{{fileName}}')\nexport class {{className}}Gateway {\n @OnConnect()\n handleConnection(@Client() client: WebSocketClient) {\n console.log('Client connected:', client.id);\n }\n\n @OnDisconnect()\n handleDisconnect(@Client() client: WebSocketClient) {\n console.log('Client disconnected:', client.id);\n }\n\n @Subscribe('message')\n @OnMessage('message')\n handleMessage(@Client() client: WebSocketClient, @Data() data: unknown) {\n console.log('Message received from', client.id, ':', data);\n // Handle message logic here\n }\n}\n";
|
|
26
|
+
export declare const AI_SERVICE_TEMPLATE = "import { Service } from '@hazeljs/core';\nimport { AIService, AIFunction, AIPrompt } from '@hazeljs/ai';\n\n@Service()\nexport class {{className}}AIService {\n constructor(private readonly aiService: AIService) {}\n\n @AIFunction({\n provider: 'openai',\n model: 'gpt-4',\n streaming: false,\n })\n async {{camelName}}Task(@AIPrompt() prompt: string): Promise<unknown> {\n const result = await this.aiService.complete({\n provider: 'openai',\n model: 'gpt-4',\n messages: [{ role: 'user', content: prompt }],\n });\n\n return result;\n }\n}\n";
|
|
27
|
+
export declare const AGENT_TEMPLATE = "import { Agent, Tool } from '@hazeljs/agent';\n\n@Agent({\n name: '{{fileName}}',\n description: '{{description}}',\n systemPrompt: 'You are a helpful {{className}} agent.',\n enableMemory: true,\n enableRAG: true,\n})\nexport class {{className}}Agent {\n @Tool({\n description: 'Example tool for {{fileName}}',\n parameters: [\n {\n name: 'input',\n type: 'string',\n description: 'Input parameter',\n required: true,\n },\n ],\n })\n async exampleTool(input: { input: string }): Promise<{ result: string }> {\n // Implement your tool logic here\n return {\n result: `Processed: ${input.input}`,\n };\n }\n}\n";
|
|
28
|
+
export declare const CACHE_SERVICE_TEMPLATE = "import { Service } from '@hazeljs/core';\nimport { CacheService, Cacheable, CacheEvict } from '@hazeljs/cache';\n\n@Service()\nexport class {{className}}CacheService {\n constructor(private readonly cacheService: CacheService) {}\n\n @Cacheable({ key: '{{fileName}}:all', ttl: 60 })\n async findAll() {\n // This result will be cached for 60 seconds\n return [];\n }\n\n @Cacheable({ key: '{{fileName}}:{{=<% %>=}}#{id}<%={{ }}=%>', ttl: 300 })\n async findOne(id: string) {\n // This result will be cached for 5 minutes\n return { id };\n }\n\n @CacheEvict({ key: '{{fileName}}:all' })\n async create(data: any) {\n // Creating a new item evicts the list cache\n return data;\n }\n\n async clearAll() {\n await this.cacheService.clear();\n }\n}\n";
|
|
29
|
+
export declare const CRON_SERVICE_TEMPLATE = "import { Service } from '@hazeljs/core';\nimport { Cron, CronExpression } from '@hazeljs/cron';\n\n@Service()\nexport class {{className}}CronService {\n @Cron(CronExpression.EVERY_MINUTE)\n handleEveryMinute() {\n console.log('[{{className}}Cron] Running every minute...');\n // Add your cron job logic here\n }\n\n @Cron('0 0 * * *') // Every day at midnight\n handleDaily() {\n console.log('[{{className}}Cron] Running daily task...');\n // Add your daily task logic here\n }\n\n @Cron(CronExpression.EVERY_HOUR)\n handleHourly() {\n console.log('[{{className}}Cron] Running hourly cleanup...');\n // Add your hourly task logic here\n }\n}\n";
|
|
30
|
+
export declare const RAG_SERVICE_TEMPLATE = "import { Service } from '@hazeljs/core';\nimport { RAGPipeline, MemoryVectorStore } from '@hazeljs/rag';\n\n@Service()\nexport class {{className}}RagService {\n private pipeline: RAGPipeline;\n\n constructor() {\n // Initialize with a memory vector store (swap for Pinecone, Qdrant, etc. in production)\n const vectorStore = new MemoryVectorStore();\n\n this.pipeline = new RAGPipeline({\n vectorStore,\n topK: 5,\n });\n }\n\n async addDocument(content: string, metadata?: Record<string, unknown>) {\n // Add a document to the vector store for retrieval\n await this.pipeline.addDocument({\n content,\n metadata: metadata || {},\n });\n }\n\n async query(question: string) {\n // Retrieve relevant documents and generate a response\n const results = await this.pipeline.query(question);\n return results;\n }\n}\n";
|
|
31
|
+
export declare const DISCOVERY_TEMPLATE = "import { Service } from '@hazeljs/core';\nimport { ServiceRegistry, DiscoveryClient } from '@hazeljs/discovery';\n\n@Service()\nexport class {{className}}DiscoveryService {\n constructor(\n private readonly registry: ServiceRegistry,\n private readonly client: DiscoveryClient,\n ) {}\n\n async registerService() {\n await this.registry.register({\n name: '{{fileName}}-service',\n host: 'localhost',\n port: 3000,\n metadata: {\n version: '1.0.0',\n },\n });\n }\n\n async discoverService(serviceName: string) {\n const instances = await this.client.getInstances(serviceName);\n return instances;\n }\n}\n";
|
|
32
|
+
export declare const CONFIG_TEMPLATE = "import { HazelModule } from '@hazeljs/core';\nimport { ConfigModule, ConfigService } from '@hazeljs/config';\n\n// Import ConfigModule.forRoot() in your app module:\n//\n// @HazelModule({\n// imports: [\n// ConfigModule.forRoot({\n// envFilePath: '.env',\n// }),\n// ],\n// })\n//\n// Then inject ConfigService wherever you need it:\n//\n// constructor(private readonly config: ConfigService) {}\n//\n// Usage:\n// this.config.get('DATABASE_URL');\n// this.config.get('PORT', '3000'); // with default value\n\nexport { ConfigModule, ConfigService };\n";
|
|
33
|
+
export declare const SERVERLESS_LAMBDA_TEMPLATE = "import { createLambdaHandler } from '@hazeljs/serverless';\nimport { AppModule } from './app.module';\n\nexport const handler = createLambdaHandler(AppModule);\n";
|
|
34
|
+
export declare const SERVERLESS_CLOUD_FUNCTION_TEMPLATE = "import { createCloudFunctionHandler } from '@hazeljs/serverless';\nimport { AppModule } from './app.module';\n\nexport const handler = createCloudFunctionHandler(AppModule);\n";
|