@hazeljs/cli 0.2.0-beta.1 → 0.2.0-beta.14
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/.eslintrc.js +36 -0
- package/@template/.lintstagedrc +6 -0
- package/@template/jest.config.js +28 -0
- package/@template/jest.setup.js +81 -0
- package/@template/package.json +14 -32
- package/@template/src/hello.controller.ts +3 -3
- package/@template/src/index.ts +10 -2
- package/@template/tsconfig.json +30 -0
- package/LICENSE +21 -0
- package/dist/commands/add.js +58 -40
- package/dist/commands/generate-agent.js +9 -7
- package/dist/commands/generate-ai-service.js +8 -9
- package/dist/commands/generate-app.js +115 -10
- package/dist/commands/generate-auth.d.ts +2 -0
- package/dist/commands/generate-auth.js +194 -0
- package/dist/commands/generate-cache.d.ts +2 -0
- package/dist/commands/generate-cache.js +64 -0
- package/dist/commands/generate-config.d.ts +2 -0
- package/dist/commands/generate-config.js +57 -0
- package/dist/commands/generate-controller.js +15 -14
- package/dist/commands/generate-cron.d.ts +2 -0
- package/dist/commands/generate-cron.js +59 -0
- package/dist/commands/generate-crud.js +31 -57
- package/dist/commands/generate-discovery.d.ts +2 -0
- package/dist/commands/generate-discovery.js +61 -0
- package/dist/commands/generate-dto.js +28 -15
- package/dist/commands/generate-exception-filter.js +7 -9
- package/dist/commands/generate-guard.js +8 -7
- package/dist/commands/generate-interceptor.js +8 -8
- package/dist/commands/generate-middleware.js +18 -51
- package/dist/commands/generate-module.js +39 -29
- package/dist/commands/generate-pipe.js +7 -7
- package/dist/commands/generate-rag.d.ts +2 -0
- package/dist/commands/generate-rag.js +66 -0
- package/dist/commands/generate-repository.js +13 -10
- package/dist/commands/generate-serverless-handler.js +9 -9
- package/dist/commands/generate-service.js +11 -10
- package/dist/commands/generate-websocket-gateway.js +6 -6
- package/dist/index.js +12 -0
- package/dist/utils/generator.d.ts +13 -2
- package/dist/utils/generator.js +45 -17
- package/package.json +7 -2
- package/src/commands/add.ts +0 -101
- package/src/commands/build.ts +0 -56
- package/src/commands/generate-agent.ts +0 -58
- package/src/commands/generate-ai-service.ts +0 -52
- package/src/commands/generate-app.ts +0 -270
- package/src/commands/generate-controller.ts +0 -61
- package/src/commands/generate-crud.ts +0 -214
- package/src/commands/generate-dto.ts +0 -61
- package/src/commands/generate-exception-filter.ts +0 -53
- package/src/commands/generate-guard.ts +0 -37
- package/src/commands/generate-interceptor.ts +0 -39
- package/src/commands/generate-middleware.ts +0 -86
- package/src/commands/generate-module.ts +0 -102
- package/src/commands/generate-pipe.ts +0 -36
- package/src/commands/generate-repository.ts +0 -41
- package/src/commands/generate-serverless-handler.ts +0 -53
- package/src/commands/generate-service.ts +0 -53
- package/src/commands/generate-websocket-gateway.ts +0 -50
- package/src/commands/info.ts +0 -106
- package/src/commands/start.ts +0 -61
- package/src/commands/test.ts +0 -70
- package/src/index.ts +0 -68
- package/src/utils/generator.ts +0 -93
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
parser: '@typescript-eslint/parser',
|
|
4
|
+
parserOptions: {
|
|
5
|
+
ecmaVersion: 'latest',
|
|
6
|
+
sourceType: 'module',
|
|
7
|
+
project: './tsconfig.json',
|
|
8
|
+
},
|
|
9
|
+
plugins: ['@typescript-eslint', 'prettier'],
|
|
10
|
+
extends: [
|
|
11
|
+
'eslint:recommended',
|
|
12
|
+
'plugin:@typescript-eslint/recommended',
|
|
13
|
+
'plugin:prettier/recommended',
|
|
14
|
+
],
|
|
15
|
+
env: {
|
|
16
|
+
node: true,
|
|
17
|
+
es6: true,
|
|
18
|
+
jest: true,
|
|
19
|
+
},
|
|
20
|
+
rules: {
|
|
21
|
+
'@typescript-eslint/explicit-function-return-type': 'error',
|
|
22
|
+
'@typescript-eslint/no-explicit-any': 'error',
|
|
23
|
+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
|
24
|
+
'no-console': ['error', { allow: ['warn', 'error'] }],
|
|
25
|
+
'prettier/prettier': 'error',
|
|
26
|
+
},
|
|
27
|
+
overrides: [
|
|
28
|
+
{
|
|
29
|
+
files: ['**/*.test.ts'],
|
|
30
|
+
rules: {
|
|
31
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
32
|
+
'no-console': 'off',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
2
|
+
module.exports = {
|
|
3
|
+
preset: 'ts-jest',
|
|
4
|
+
testEnvironment: 'node',
|
|
5
|
+
roots: ['<rootDir>/src'],
|
|
6
|
+
testMatch: ['**/*.test.ts'],
|
|
7
|
+
transform: {
|
|
8
|
+
'^.+\\.tsx?$': 'ts-jest',
|
|
9
|
+
},
|
|
10
|
+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
|
11
|
+
collectCoverageFrom: [
|
|
12
|
+
'src/**/*.ts',
|
|
13
|
+
'!src/**/*.d.ts',
|
|
14
|
+
'!src/**/*.test.ts',
|
|
15
|
+
'!src/**/__tests__/**'
|
|
16
|
+
],
|
|
17
|
+
coverageThreshold: {
|
|
18
|
+
global: {
|
|
19
|
+
branches: 30,
|
|
20
|
+
functions: 30,
|
|
21
|
+
lines: 30,
|
|
22
|
+
statements: 30
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
coverageDirectory: 'coverage',
|
|
26
|
+
coverageReporters: ['text', 'lcov', 'clover'],
|
|
27
|
+
verbose: true,
|
|
28
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const winston = require('winston');
|
|
2
|
+
|
|
3
|
+
// Create a custom logger for tests
|
|
4
|
+
const logger = winston.createLogger({
|
|
5
|
+
level: 'info',
|
|
6
|
+
format: winston.format.combine(
|
|
7
|
+
winston.format.timestamp(),
|
|
8
|
+
winston.format.colorize(),
|
|
9
|
+
winston.format.printf(({ level, message, timestamp }) => {
|
|
10
|
+
const now = new Date();
|
|
11
|
+
return `[${now.toLocaleDateString()} ${now.toLocaleTimeString()}] ${level}: ${message}`;
|
|
12
|
+
})
|
|
13
|
+
),
|
|
14
|
+
transports: [
|
|
15
|
+
new winston.transports.Console()
|
|
16
|
+
]
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// Add custom matchers
|
|
20
|
+
expect.extend({
|
|
21
|
+
toBeWithinRange(received, floor, ceiling) {
|
|
22
|
+
const pass = received >= floor && received <= ceiling;
|
|
23
|
+
if (pass) {
|
|
24
|
+
return {
|
|
25
|
+
message: () =>
|
|
26
|
+
`expected ${received} not to be within range ${floor} - ${ceiling}`,
|
|
27
|
+
pass: true,
|
|
28
|
+
};
|
|
29
|
+
} else {
|
|
30
|
+
return {
|
|
31
|
+
message: () =>
|
|
32
|
+
`expected ${received} to be within range ${floor} - ${ceiling}`,
|
|
33
|
+
pass: false,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Add custom test utilities
|
|
40
|
+
global.testUtils = {
|
|
41
|
+
async waitFor(condition, timeout = 5000) {
|
|
42
|
+
const start = Date.now();
|
|
43
|
+
while (Date.now() - start < timeout) {
|
|
44
|
+
if (await condition()) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
48
|
+
}
|
|
49
|
+
throw new Error(`Condition not met within ${timeout}ms`);
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
// Add test lifecycle hooks
|
|
53
|
+
beforeAll(() => {
|
|
54
|
+
const now = new Date();
|
|
55
|
+
logger.info('\n' + '='.repeat(80));
|
|
56
|
+
logger.info(`Test Suite Started at: ${now.toLocaleString()}`);
|
|
57
|
+
logger.info(`Date: ${now.toLocaleDateString()}`);
|
|
58
|
+
logger.info(`Time: ${now.toLocaleTimeString()}`);
|
|
59
|
+
logger.info('='.repeat(80) + '\n');
|
|
60
|
+
logger.info('🚀 Starting test suite...');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
afterAll(() => {
|
|
64
|
+
const now = new Date();
|
|
65
|
+
logger.info('\n' + '='.repeat(80));
|
|
66
|
+
logger.info(`Test Suite Completed at: ${now.toLocaleString()}`);
|
|
67
|
+
logger.info(`Date: ${now.toLocaleDateString()}`);
|
|
68
|
+
logger.info(`Time: ${now.toLocaleTimeString()}`);
|
|
69
|
+
logger.info('='.repeat(80) + '\n');
|
|
70
|
+
logger.info('✨ Test suite completed!');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
beforeEach(() => {
|
|
74
|
+
const now = new Date();
|
|
75
|
+
logger.info(`\n[${now.toLocaleTimeString()}] 📝 Running test...`);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
afterEach(() => {
|
|
79
|
+
const now = new Date();
|
|
80
|
+
logger.info(`[${now.toLocaleTimeString()}] ✅ Test completed!`);
|
|
81
|
+
});
|
package/@template/package.json
CHANGED
|
@@ -1,48 +1,30 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "hazeljs-
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "
|
|
2
|
+
"name": "hazeljs-app",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A HazelJS application",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc",
|
|
8
8
|
"start": "node dist/index.js",
|
|
9
9
|
"dev": "ts-node-dev --respawn --transpile-only src/index.ts",
|
|
10
10
|
"test": "jest",
|
|
11
|
-
"
|
|
12
|
-
"lint": "eslint \"src/**/*.ts\" --
|
|
13
|
-
"lint:fix": "eslint \"src/**/*.ts\" --fix --max-warnings 0",
|
|
11
|
+
"lint": "eslint \"src/**/*.ts\"",
|
|
12
|
+
"lint:fix": "eslint \"src/**/*.ts\" --fix",
|
|
14
13
|
"format": "prettier --write \"src/**/*.ts\""
|
|
15
14
|
},
|
|
16
15
|
"dependencies": {
|
|
17
|
-
"@hazeljs/core": "
|
|
18
|
-
"
|
|
19
|
-
"class-transformer": "^0.5.1",
|
|
20
|
-
"class-validator": "^0.14.1",
|
|
21
|
-
"dotenv": "^16.4.5",
|
|
22
|
-
"jsonwebtoken": "^9.0.2",
|
|
23
|
-
"reflect-metadata": "^0.2.1",
|
|
24
|
-
"winston": "^3.12.0"
|
|
16
|
+
"@hazeljs/core": "^0.2.0",
|
|
17
|
+
"reflect-metadata": "^0.2.2"
|
|
25
18
|
},
|
|
26
19
|
"devDependencies": {
|
|
27
|
-
"@types/
|
|
28
|
-
"
|
|
29
|
-
"
|
|
20
|
+
"@types/node": "^20.0.0",
|
|
21
|
+
"typescript": "^5.3.3",
|
|
22
|
+
"ts-node-dev": "^2.0.0",
|
|
30
23
|
"@types/jest": "^29.5.12",
|
|
31
|
-
"@types/jsonwebtoken": "^9.0.6",
|
|
32
|
-
"@types/node": "^20.11.24",
|
|
33
|
-
"@types/swagger-ui-express": "^4.1.6",
|
|
34
|
-
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
35
|
-
"@typescript-eslint/parser": "^7.0.0",
|
|
36
|
-
"axios": "^1.9.0",
|
|
37
|
-
"eslint": "^8.0.0",
|
|
38
|
-
"eslint-config-prettier": "^9.0.0",
|
|
39
|
-
"eslint-plugin-jest": "^27.0.0",
|
|
40
|
-
"eslint-plugin-prettier": "^5.0.0",
|
|
41
24
|
"jest": "^29.7.0",
|
|
42
|
-
"prettier": "^3.0.0",
|
|
43
25
|
"ts-jest": "^29.1.2",
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
26
|
+
"prettier": "^3.2.5"
|
|
27
|
+
},
|
|
28
|
+
"author": "",
|
|
29
|
+
"license": "MIT"
|
|
48
30
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Controller, Get } from '@hazeljs/core';
|
|
2
2
|
|
|
3
3
|
@Controller('/hello')
|
|
4
4
|
export class HelloController {
|
|
5
5
|
@Get()
|
|
6
|
-
hello()
|
|
7
|
-
return
|
|
6
|
+
hello() {
|
|
7
|
+
return { message: 'Hello from HazelJS!' };
|
|
8
8
|
}
|
|
9
9
|
}
|
package/@template/src/index.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import 'reflect-metadata';
|
|
2
2
|
import { HazelApp } from '@hazeljs/core';
|
|
3
3
|
import { AppModule } from './app.module';
|
|
4
4
|
|
|
5
5
|
async function bootstrap(): Promise<void> {
|
|
6
6
|
const app = new HazelApp(AppModule);
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
// Enable CORS
|
|
9
|
+
app.enableCors({
|
|
10
|
+
origin: '*',
|
|
11
|
+
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const port = parseInt(process.env.PORT || '3000', 10);
|
|
15
|
+
await app.listen(port);
|
|
8
16
|
}
|
|
9
17
|
|
|
10
18
|
bootstrap();
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2017",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"lib": ["ES2020", "DOM"],
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"rootDir": "..",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": false,
|
|
13
|
+
"experimentalDecorators": true,
|
|
14
|
+
"emitDecoratorMetadata": true,
|
|
15
|
+
"resolveJsonModule": true,
|
|
16
|
+
"removeComments": true,
|
|
17
|
+
"sourceMap": true,
|
|
18
|
+
"baseUrl": "./",
|
|
19
|
+
"incremental": true,
|
|
20
|
+
"strictNullChecks": false,
|
|
21
|
+
"noImplicitAny": false,
|
|
22
|
+
"strictBindCallApply": false,
|
|
23
|
+
"noFallthroughCasesInSwitch": false,
|
|
24
|
+
"paths": {
|
|
25
|
+
"@/*": ["src/*"]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"include": ["src/**/*"],
|
|
29
|
+
"exclude": ["node_modules", "dist"]
|
|
30
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 HazelJS Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/commands/add.js
CHANGED
|
@@ -8,17 +8,54 @@ const child_process_1 = require("child_process");
|
|
|
8
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
9
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
10
10
|
const HAZEL_PACKAGES = {
|
|
11
|
-
ai:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
ai: {
|
|
12
|
+
npm: '@hazeljs/ai',
|
|
13
|
+
hint: 'import { AIModule } from "@hazeljs/ai";',
|
|
14
|
+
},
|
|
15
|
+
agent: {
|
|
16
|
+
npm: '@hazeljs/agent',
|
|
17
|
+
hint: 'import { AgentModule } from "@hazeljs/agent";',
|
|
18
|
+
},
|
|
19
|
+
auth: {
|
|
20
|
+
npm: '@hazeljs/auth',
|
|
21
|
+
hint: 'import { JwtModule } from "@hazeljs/auth";\n // JwtModule.forRoot({ secret: "your-secret", expiresIn: "1d" })',
|
|
22
|
+
},
|
|
23
|
+
cache: {
|
|
24
|
+
npm: '@hazeljs/cache',
|
|
25
|
+
hint: 'import { CacheModule } from "@hazeljs/cache";',
|
|
26
|
+
},
|
|
27
|
+
config: {
|
|
28
|
+
npm: '@hazeljs/config',
|
|
29
|
+
hint: 'import { ConfigModule } from "@hazeljs/config";\n // ConfigModule.forRoot({ envFilePath: ".env" })',
|
|
30
|
+
},
|
|
31
|
+
cron: {
|
|
32
|
+
npm: '@hazeljs/cron',
|
|
33
|
+
hint: 'import { CronModule } from "@hazeljs/cron";',
|
|
34
|
+
},
|
|
35
|
+
discovery: {
|
|
36
|
+
npm: '@hazeljs/discovery',
|
|
37
|
+
hint: 'import { ServiceRegistry, DiscoveryClient } from "@hazeljs/discovery";',
|
|
38
|
+
},
|
|
39
|
+
prisma: {
|
|
40
|
+
npm: '@hazeljs/prisma',
|
|
41
|
+
hint: 'import { PrismaModule } from "@hazeljs/prisma";',
|
|
42
|
+
},
|
|
43
|
+
rag: {
|
|
44
|
+
npm: '@hazeljs/rag',
|
|
45
|
+
hint: 'import { RAGPipeline } from "@hazeljs/rag";',
|
|
46
|
+
},
|
|
47
|
+
serverless: {
|
|
48
|
+
npm: '@hazeljs/serverless',
|
|
49
|
+
hint: 'import { createLambdaHandler } from "@hazeljs/serverless";',
|
|
50
|
+
},
|
|
51
|
+
swagger: {
|
|
52
|
+
npm: '@hazeljs/swagger',
|
|
53
|
+
hint: 'import { SwaggerModule } from "@hazeljs/swagger";',
|
|
54
|
+
},
|
|
55
|
+
websocket: {
|
|
56
|
+
npm: '@hazeljs/websocket',
|
|
57
|
+
hint: 'import { WebSocketModule } from "@hazeljs/websocket";',
|
|
58
|
+
},
|
|
22
59
|
};
|
|
23
60
|
function addCommand(program) {
|
|
24
61
|
program
|
|
@@ -36,50 +73,31 @@ function addCommand(program) {
|
|
|
36
73
|
name: 'package',
|
|
37
74
|
message: 'Which HazelJS package would you like to add?',
|
|
38
75
|
choices: Object.keys(HAZEL_PACKAGES).map((key) => ({
|
|
39
|
-
name: `${key} - ${HAZEL_PACKAGES[key]}`,
|
|
76
|
+
name: `${key} - ${HAZEL_PACKAGES[key].npm}`,
|
|
40
77
|
value: key,
|
|
41
78
|
})),
|
|
42
79
|
},
|
|
43
80
|
]);
|
|
44
81
|
selectedPackage = pkg;
|
|
45
82
|
}
|
|
46
|
-
// Get the
|
|
47
|
-
const
|
|
48
|
-
if (!
|
|
83
|
+
// Get the package info
|
|
84
|
+
const pkgInfo = HAZEL_PACKAGES[selectedPackage];
|
|
85
|
+
if (!pkgInfo) {
|
|
49
86
|
console.log(chalk_1.default.yellow(`Unknown package: ${selectedPackage}`));
|
|
50
87
|
console.log(chalk_1.default.gray('\nAvailable packages:'));
|
|
51
88
|
Object.keys(HAZEL_PACKAGES).forEach((key) => {
|
|
52
|
-
console.log(chalk_1.default.gray(` - ${key}: ${HAZEL_PACKAGES[key]}`));
|
|
89
|
+
console.log(chalk_1.default.gray(` - ${key}: ${HAZEL_PACKAGES[key].npm}`));
|
|
53
90
|
});
|
|
54
91
|
return;
|
|
55
92
|
}
|
|
56
|
-
console.log(chalk_1.default.blue(`\n
|
|
93
|
+
console.log(chalk_1.default.blue(`\n\uD83D\uDCE6 Installing ${pkgInfo.npm}...`));
|
|
57
94
|
const devFlag = options?.dev ? '--save-dev' : '';
|
|
58
|
-
const command = `npm install ${
|
|
95
|
+
const command = `npm install ${pkgInfo.npm} ${devFlag}`.trim();
|
|
59
96
|
(0, child_process_1.execSync)(command, { stdio: 'inherit' });
|
|
60
|
-
console.log(chalk_1.default.green(`\n
|
|
97
|
+
console.log(chalk_1.default.green(`\n\u2713 Successfully installed ${pkgInfo.npm}`));
|
|
61
98
|
// Show usage hints
|
|
62
|
-
console.log(chalk_1.default.gray('\
|
|
63
|
-
|
|
64
|
-
case 'ai':
|
|
65
|
-
console.log(chalk_1.default.gray(' import { AIModule } from "@hazeljs/ai";'));
|
|
66
|
-
break;
|
|
67
|
-
case 'auth':
|
|
68
|
-
console.log(chalk_1.default.gray(' import { AuthModule } from "@hazeljs/auth";'));
|
|
69
|
-
break;
|
|
70
|
-
case 'cache':
|
|
71
|
-
console.log(chalk_1.default.gray(' import { CacheModule } from "@hazeljs/cache";'));
|
|
72
|
-
break;
|
|
73
|
-
case 'prisma':
|
|
74
|
-
console.log(chalk_1.default.gray(' import { PrismaModule } from "@hazeljs/prisma";'));
|
|
75
|
-
break;
|
|
76
|
-
case 'swagger':
|
|
77
|
-
console.log(chalk_1.default.gray(' import { SwaggerModule } from "@hazeljs/swagger";'));
|
|
78
|
-
break;
|
|
79
|
-
case 'websocket':
|
|
80
|
-
console.log(chalk_1.default.gray(' import { WebSocketModule } from "@hazeljs/websocket";'));
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
99
|
+
console.log(chalk_1.default.gray('\nUsage:'));
|
|
100
|
+
console.log(chalk_1.default.gray(` ${pkgInfo.hint}`));
|
|
83
101
|
console.log(chalk_1.default.gray(`\nDocumentation: https://hazeljs.com/docs/packages/${selectedPackage}`));
|
|
84
102
|
}
|
|
85
103
|
catch (error) {
|
|
@@ -32,6 +32,10 @@ export class {{className}}Agent {
|
|
|
32
32
|
}
|
|
33
33
|
`;
|
|
34
34
|
class AgentGenerator extends generator_1.Generator {
|
|
35
|
+
constructor() {
|
|
36
|
+
super(...arguments);
|
|
37
|
+
this.suffix = 'agent';
|
|
38
|
+
}
|
|
35
39
|
getDefaultTemplate() {
|
|
36
40
|
return AGENT_TEMPLATE;
|
|
37
41
|
}
|
|
@@ -41,16 +45,14 @@ function generateAgent(program) {
|
|
|
41
45
|
.command('agent <name>')
|
|
42
46
|
.description('Generate a new AI agent with @Agent and @Tool decorators')
|
|
43
47
|
.option('-p, --path <path>', 'Path where the agent should be generated')
|
|
48
|
+
.option('--dry-run', 'Preview files without writing them')
|
|
44
49
|
.action(async (name, options) => {
|
|
45
50
|
const generator = new AgentGenerator();
|
|
46
|
-
|
|
51
|
+
await generator.generate({
|
|
47
52
|
name,
|
|
48
53
|
path: options.path,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
53
|
-
const finalOptions = await generator.promptForOptions(generatorOptions);
|
|
54
|
-
await generator.generate(finalOptions);
|
|
54
|
+
dryRun: options.dryRun,
|
|
55
|
+
data: { description: `A ${name} agent` },
|
|
56
|
+
});
|
|
55
57
|
});
|
|
56
58
|
}
|
|
@@ -3,8 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateAIService = generateAIService;
|
|
4
4
|
const generator_1 = require("../utils/generator");
|
|
5
5
|
const AI_SERVICE_TEMPLATE = `import { Injectable } from '@hazeljs/core';
|
|
6
|
-
import { AIService } from '@hazeljs/ai';
|
|
7
|
-
import { AIFunction, AIPrompt } from '@hazeljs/ai';
|
|
6
|
+
import { AIService, AIFunction, AIPrompt } from '@hazeljs/ai';
|
|
8
7
|
|
|
9
8
|
@Injectable()
|
|
10
9
|
export class {{className}}AIService {
|
|
@@ -15,7 +14,7 @@ export class {{className}}AIService {
|
|
|
15
14
|
model: 'gpt-4',
|
|
16
15
|
streaming: false,
|
|
17
16
|
})
|
|
18
|
-
async {{
|
|
17
|
+
async {{camelName}}Task(@AIPrompt() prompt: string): Promise<unknown> {
|
|
19
18
|
const result = await this.aiService.complete({
|
|
20
19
|
provider: 'openai',
|
|
21
20
|
model: 'gpt-4',
|
|
@@ -27,6 +26,10 @@ export class {{className}}AIService {
|
|
|
27
26
|
}
|
|
28
27
|
`;
|
|
29
28
|
class AIServiceGenerator extends generator_1.Generator {
|
|
29
|
+
constructor() {
|
|
30
|
+
super(...arguments);
|
|
31
|
+
this.suffix = 'ai-service';
|
|
32
|
+
}
|
|
30
33
|
getDefaultTemplate() {
|
|
31
34
|
return AI_SERVICE_TEMPLATE;
|
|
32
35
|
}
|
|
@@ -37,13 +40,9 @@ function generateAIService(program) {
|
|
|
37
40
|
.description('Generate a new AI service with decorators')
|
|
38
41
|
.alias('ai')
|
|
39
42
|
.option('-p, --path <path>', 'Path where the AI service should be generated')
|
|
43
|
+
.option('--dry-run', 'Preview files without writing them')
|
|
40
44
|
.action(async (name, options) => {
|
|
41
45
|
const generator = new AIServiceGenerator();
|
|
42
|
-
|
|
43
|
-
name,
|
|
44
|
-
path: options.path,
|
|
45
|
-
};
|
|
46
|
-
const finalOptions = await generator.promptForOptions(generatorOptions);
|
|
47
|
-
await generator.generate(finalOptions);
|
|
46
|
+
await generator.generate({ name, path: options.path, dryRun: options.dryRun });
|
|
48
47
|
});
|
|
49
48
|
}
|