@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
package/src/commands/test.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { execSync } from 'child_process';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
|
|
7
|
-
export function testCommand(program: Command) {
|
|
8
|
-
program
|
|
9
|
-
.command('test [pattern]')
|
|
10
|
-
.description('Run tests')
|
|
11
|
-
.option('-w, --watch', 'Watch mode')
|
|
12
|
-
.option('-c, --coverage', 'Generate coverage report')
|
|
13
|
-
.option('--ci', 'Run in CI mode')
|
|
14
|
-
.action((pattern?: string, options?: { watch?: boolean; coverage?: boolean; ci?: boolean }) => {
|
|
15
|
-
try {
|
|
16
|
-
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
17
|
-
|
|
18
|
-
if (!fs.existsSync(packageJsonPath)) {
|
|
19
|
-
console.log(chalk.red('✗ No package.json found'));
|
|
20
|
-
console.log(chalk.gray('Run this command from your project root'));
|
|
21
|
-
process.exit(1);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
25
|
-
|
|
26
|
-
if (!packageJson.scripts?.test) {
|
|
27
|
-
console.log(chalk.yellow('⚠ No test script found in package.json'));
|
|
28
|
-
console.log(chalk.gray('\nAdd a test script to your package.json:'));
|
|
29
|
-
console.log(chalk.gray(' "scripts": {'));
|
|
30
|
-
console.log(chalk.gray(' "test": "jest"'));
|
|
31
|
-
console.log(chalk.gray(' }'));
|
|
32
|
-
process.exit(1);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
console.log(chalk.blue('🧪 Running tests...\n'));
|
|
36
|
-
|
|
37
|
-
let command = 'npm test';
|
|
38
|
-
const args: string[] = [];
|
|
39
|
-
|
|
40
|
-
if (pattern) {
|
|
41
|
-
args.push(pattern);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (options?.watch) {
|
|
45
|
-
args.push('--watch');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (options?.coverage) {
|
|
49
|
-
args.push('--coverage');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (options?.ci) {
|
|
53
|
-
command = packageJson.scripts['test:ci'] ? 'npm run test:ci' : 'npm test -- --ci';
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (args.length > 0 && !options?.ci) {
|
|
57
|
-
command += ' -- ' + args.join(' ');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
execSync(command, { stdio: 'inherit' });
|
|
61
|
-
|
|
62
|
-
if (!options?.watch) {
|
|
63
|
-
console.log(chalk.green('\n✓ Tests completed'));
|
|
64
|
-
}
|
|
65
|
-
} catch {
|
|
66
|
-
console.error(chalk.red('\n✗ Tests failed'));
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { Command } from 'commander';
|
|
4
|
-
import { generateModule } from './commands/generate-module';
|
|
5
|
-
import { generateApp } from './commands/generate-app';
|
|
6
|
-
import { generateController } from './commands/generate-controller';
|
|
7
|
-
import { generateService } from './commands/generate-service';
|
|
8
|
-
import { generateDto } from './commands/generate-dto';
|
|
9
|
-
import { generateGuard } from './commands/generate-guard';
|
|
10
|
-
import { generateInterceptor } from './commands/generate-interceptor';
|
|
11
|
-
import { generateWebSocketGateway } from './commands/generate-websocket-gateway';
|
|
12
|
-
import { generateExceptionFilter } from './commands/generate-exception-filter';
|
|
13
|
-
import { generatePipe } from './commands/generate-pipe';
|
|
14
|
-
import { generateRepository } from './commands/generate-repository';
|
|
15
|
-
import { generateAIService } from './commands/generate-ai-service';
|
|
16
|
-
import { generateAgent } from './commands/generate-agent';
|
|
17
|
-
import { generateServerlessHandler } from './commands/generate-serverless-handler';
|
|
18
|
-
import { generateCrud } from './commands/generate-crud';
|
|
19
|
-
import { generateMiddleware } from './commands/generate-middleware';
|
|
20
|
-
import { infoCommand } from './commands/info';
|
|
21
|
-
import { addCommand } from './commands/add';
|
|
22
|
-
import { buildCommand } from './commands/build';
|
|
23
|
-
import { startCommand } from './commands/start';
|
|
24
|
-
import { testCommand } from './commands/test';
|
|
25
|
-
|
|
26
|
-
const program = new Command();
|
|
27
|
-
|
|
28
|
-
program
|
|
29
|
-
.name('hazel')
|
|
30
|
-
.description('CLI for generating HazelJS components and applications')
|
|
31
|
-
.version('0.2.0');
|
|
32
|
-
|
|
33
|
-
// New app command
|
|
34
|
-
generateApp(program);
|
|
35
|
-
|
|
36
|
-
// Utility commands
|
|
37
|
-
infoCommand(program);
|
|
38
|
-
addCommand(program);
|
|
39
|
-
buildCommand(program);
|
|
40
|
-
startCommand(program);
|
|
41
|
-
testCommand(program);
|
|
42
|
-
|
|
43
|
-
// Generate command group
|
|
44
|
-
const generateCommand = program
|
|
45
|
-
.command('generate')
|
|
46
|
-
.description('Generate HazelJS components')
|
|
47
|
-
.alias('g');
|
|
48
|
-
|
|
49
|
-
// Core components
|
|
50
|
-
generateController(generateCommand);
|
|
51
|
-
generateService(generateCommand);
|
|
52
|
-
generateModule(generateCommand);
|
|
53
|
-
generateDto(generateCommand);
|
|
54
|
-
generateGuard(generateCommand);
|
|
55
|
-
generateInterceptor(generateCommand);
|
|
56
|
-
generateMiddleware(generateCommand);
|
|
57
|
-
|
|
58
|
-
// Advanced generators
|
|
59
|
-
generateCrud(generateCommand);
|
|
60
|
-
generateWebSocketGateway(generateCommand);
|
|
61
|
-
generateExceptionFilter(generateCommand);
|
|
62
|
-
generatePipe(generateCommand);
|
|
63
|
-
generateRepository(generateCommand);
|
|
64
|
-
generateAIService(generateCommand);
|
|
65
|
-
generateAgent(generateCommand);
|
|
66
|
-
generateServerlessHandler(generateCommand);
|
|
67
|
-
|
|
68
|
-
program.parse(process.argv);
|
package/src/utils/generator.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import inquirer from 'inquirer';
|
|
5
|
-
import mustache from 'mustache';
|
|
6
|
-
|
|
7
|
-
export interface GeneratorOptions {
|
|
8
|
-
name: string;
|
|
9
|
-
path?: string;
|
|
10
|
-
template?: string;
|
|
11
|
-
data?: Record<string, unknown>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class Generator {
|
|
15
|
-
public async generate(options: GeneratorOptions): Promise<void> {
|
|
16
|
-
const { name, path: customPath, template, data = {} } = options;
|
|
17
|
-
|
|
18
|
-
// Get the template
|
|
19
|
-
const templateContent = template || this.getDefaultTemplate();
|
|
20
|
-
|
|
21
|
-
// Prepare the data
|
|
22
|
-
const templateData = {
|
|
23
|
-
name,
|
|
24
|
-
className: this.toPascalCase(name),
|
|
25
|
-
fileName: this.toKebabCase(name),
|
|
26
|
-
...data,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// Render the template
|
|
30
|
-
const content = mustache.render(templateContent, templateData);
|
|
31
|
-
|
|
32
|
-
// Determine the file path
|
|
33
|
-
const filePath = this.getFilePath(name, customPath);
|
|
34
|
-
|
|
35
|
-
// Create directory if it doesn't exist
|
|
36
|
-
const dir = path.dirname(filePath);
|
|
37
|
-
if (!fs.existsSync(dir)) {
|
|
38
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Write the file
|
|
42
|
-
fs.writeFileSync(filePath, content);
|
|
43
|
-
|
|
44
|
-
console.log(chalk.green(`✓ Generated ${filePath}`));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
protected toPascalCase(str: string): string {
|
|
48
|
-
return str
|
|
49
|
-
.split(/[-_]/)
|
|
50
|
-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
51
|
-
.join('');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
protected toKebabCase(str: string): string {
|
|
55
|
-
return str
|
|
56
|
-
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
57
|
-
.replace(/[\s_]+/g, '-')
|
|
58
|
-
.toLowerCase();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
protected getFilePath(name: string, customPath?: string): string {
|
|
62
|
-
const fileName = this.toKebabCase(name);
|
|
63
|
-
const basePath = customPath || 'src';
|
|
64
|
-
return path.join(process.cwd(), basePath, `${fileName}.ts`);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
protected getDefaultTemplate(): string {
|
|
68
|
-
return '';
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public async promptForOptions(options: Partial<GeneratorOptions>): Promise<GeneratorOptions> {
|
|
72
|
-
const answers = await inquirer.prompt([
|
|
73
|
-
{
|
|
74
|
-
type: 'input',
|
|
75
|
-
name: 'name',
|
|
76
|
-
message: 'What is the name of the component?',
|
|
77
|
-
when: !options.name,
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
type: 'input',
|
|
81
|
-
name: 'path',
|
|
82
|
-
message: 'Where should the component be generated?',
|
|
83
|
-
default: 'src',
|
|
84
|
-
when: !options.path,
|
|
85
|
-
},
|
|
86
|
-
]);
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
...options,
|
|
90
|
-
...answers,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
}
|