Skip to content

Commit 6345d6d

Browse files
committed
Major refactor (part 1) towards FUTURE.md
1 parent 4e0b538 commit 6345d6d

File tree

123 files changed

+5250
-6130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+5250
-6130
lines changed

src/cli.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface CliOptions {
1717
input?: string;
1818
output?: string;
1919
clientName?: string;
20+
framework?: 'angular' | 'react' | 'vue';
2021
dateType?: 'string' | 'Date';
2122
enumStyle?: 'enum' | 'union';
2223
admin?: boolean;
@@ -64,6 +65,7 @@ async function runGeneration(options: CliOptions) {
6465
}
6566

6667
const cliOptions: Partial<GeneratorConfigOptions> = {};
68+
if (options.framework) cliOptions.framework = options.framework;
6769
if (options.dateType) cliOptions.dateType = options.dateType;
6870
if (options.enumStyle) cliOptions.enumStyle = options.enumStyle;
6971
if (options.generateServices !== undefined) cliOptions.generateServices = options.generateServices;
@@ -72,6 +74,7 @@ async function runGeneration(options: CliOptions) {
7274
if (options.testsForAdmin !== undefined) cliOptions.generateAdminTests = options.testsForAdmin;
7375

7476
const defaults: GeneratorConfigOptions = {
77+
framework: 'angular',
7578
dateType: 'Date',
7679
enumStyle: 'enum',
7780
generateServices: true,
@@ -138,22 +141,23 @@ async function runGeneration(options: CliOptions) {
138141
const program = new Command();
139142
program
140143
.name('cdd_web_ng')
141-
.description('OpenAPI ↔ Angular (TypeScript, HTML) code generator')
144+
.description('OpenAPI ↔ Client SDK (Angular, React, Vue) code generator')
142145
.version(packageJson.version);
143146

144147
program
145148
.command('from_openapi')
146-
.description('Generate Angular services and admin UI from an OpenAPI specification')
149+
.description('Generate Client SDK services and admin UI from an OpenAPI specification')
147150
.option('-c, --config <path>', 'Path to a configuration file (e.g., cdd-web-ng.config.js)')
148151
.option('-i, --input <path>', 'Path or URL to the OpenAPI spec (overrides config)')
149152
.option('-o, --output <path>', 'Output directory for generated files (overrides config)')
150153
.option('--clientName <name>', 'Name for the generated client (used for DI tokens)')
154+
.addOption(new Option('--framework <framework>', 'Target framework').choices(['angular', 'react', 'vue']).default('angular'))
151155
.addOption(new Option('--dateType <type>', 'Date type to use').choices(['string', 'Date']))
152156
.addOption(new Option('--enumStyle <style>', 'Style for enums').choices(['enum', 'union']))
153-
.option('--admin', 'Generate an Angular Material admin UI')
154-
.addOption(new Option('--no-generate-services', 'Disable generation of Angular services'))
155-
.option('--no-tests-for-service', 'Disable generation of tests for Angular services')
156-
.option('--no-tests-for-admin', 'Disable generation of tests for the Angular admin UI')
157+
.option('--admin', 'Generate an admin UI (Angular only)')
158+
.addOption(new Option('--no-generate-services', 'Disable generation of services'))
159+
.option('--no-tests-for-service', 'Disable generation of tests for services')
160+
.option('--no-tests-for-admin', 'Disable generation of tests for the admin UI')
157161
.action(runGeneration);
158162

159163
program

src/core/generator.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Project } from 'ts-morph';
2+
import { SwaggerParser } from './parser.js';
3+
import { GeneratorConfig } from './types/config.js';
4+
5+
/**
6+
* Abstract contracts for framework-specific generators.
7+
*/
8+
export interface IClientGenerator {
9+
/**
10+
* Execute the generation process.
11+
* @param project The active ts-morph project.
12+
* @param parser The parsed OpenAPI specification.
13+
* @param config The generation configuration.
14+
* @param outputDir The root directory for the output.
15+
*/
16+
generate(project: Project, parser: SwaggerParser, config: GeneratorConfig, outputDir: string): Promise<void>;
17+
}
18+
19+
/**
20+
* Base class for Client Generators.
21+
* Can be extended to share common logic (e.g. Model generation) across frameworks in the future.
22+
*/
23+
export abstract class AbstractClientGenerator implements IClientGenerator {
24+
abstract generate(project: Project, parser: SwaggerParser, config: GeneratorConfig, outputDir: string): Promise<void>;
25+
}

0 commit comments

Comments
 (0)