@geekles007/spring-to-ts 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 spring-to-ts contributors
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/README.md ADDED
@@ -0,0 +1,274 @@
1
+ # Spring to TypeScript Generator
2
+
3
+ [![npm version](https://badge.fury.io/js/spring-to-ts.svg)](https://www.npmjs.com/package/spring-to-ts)
4
+ [![CI](https://github.com/geekles007/spring-to-ts/workflows/CI/badge.svg)](https://github.com/geekles007/spring-to-ts/actions)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![Node.js Version](https://img.shields.io/node/v/spring-to-ts.svg)](https://nodejs.org)
7
+
8
+ Generate TypeScript types automatically from your Spring Boot/Kotlin entities to ensure synchronization between backend and frontend.
9
+
10
+ ## Features
11
+
12
+ - ✨ Parse Kotlin/Java classes annotated with JPA
13
+ - 🔄 Generate TypeScript interfaces with proper types
14
+ - 🔗 Support entity relations (@OneToMany, @ManyToOne, etc.)
15
+ - 📦 Handle enums, nullable types, and Optional
16
+ - ✅ Include validation annotations
17
+ - 👀 Watch mode for automatic regeneration
18
+ - ⚙️ Highly configurable via JSON/YAML
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ npm install -g spring-to-ts
24
+ ```
25
+
26
+ Or use with npx:
27
+
28
+ ```bash
29
+ npx spring-to-ts generate --source ./src/main/kotlin --output ./frontend/types
30
+ ```
31
+
32
+ ## Quick Start
33
+
34
+ 1. Initialize a configuration file:
35
+
36
+ ```bash
37
+ spring-to-ts init
38
+ ```
39
+
40
+ 2. Edit the generated `spring-to-ts.config.json`:
41
+
42
+ ```json
43
+ {
44
+ "sourceDir": "./backend/src/main/kotlin/entities",
45
+ "outputDir": "./frontend/src/types",
46
+ "includeValidation": true,
47
+ "dateFormat": "ISO"
48
+ }
49
+ ```
50
+
51
+ 3. Generate TypeScript types:
52
+
53
+ ```bash
54
+ spring-to-ts generate
55
+ ```
56
+
57
+ ## CLI Usage
58
+
59
+ ### Generate Types
60
+
61
+ ```bash
62
+ spring-to-ts generate [options]
63
+ ```
64
+
65
+ Options:
66
+ - `-s, --source <path>`: Source directory containing Kotlin/Java entities
67
+ - `-o, --output <path>`: Output directory for TypeScript types
68
+ - `-c, --config <path>`: Path to configuration file
69
+ - `-w, --watch`: Watch mode - regenerate on file changes
70
+ - `--no-validation`: Exclude validation annotations
71
+ - `--no-relations`: Exclude entity relations
72
+ - `--date-format <format>`: Date format (ISO, Date, or number)
73
+
74
+ ### Initialize Configuration
75
+
76
+ ```bash
77
+ spring-to-ts init [options]
78
+ ```
79
+
80
+ Options:
81
+ - `-f, --format <format>`: Configuration format (json or yaml)
82
+
83
+ ## Configuration
84
+
85
+ ### Configuration File
86
+
87
+ Create a `spring-to-ts.config.json` or `spring-to-ts.config.yaml`:
88
+
89
+ ```json
90
+ {
91
+ "sourceDir": "./backend/src/main/kotlin/entities",
92
+ "outputDir": "./frontend/src/types",
93
+ "includeValidation": true,
94
+ "dateFormat": "ISO",
95
+ "includeEnums": true,
96
+ "includeRelations": true,
97
+ "excludePatterns": ["**/*Test.kt", "**/*Spec.kt"],
98
+ "watch": false,
99
+ "customTypeMapping": {
100
+ "UUID": "string",
101
+ "BigDecimal": "number",
102
+ "LocalDateTime": "string",
103
+ "LocalDate": "string"
104
+ }
105
+ }
106
+ ```
107
+
108
+ ### Configuration Options
109
+
110
+ | Option | Type | Default | Description |
111
+ |--------|------|---------|-------------|
112
+ | `sourceDir` | string | - | **Required.** Source directory with entities |
113
+ | `outputDir` | string | - | **Required.** Output directory for types |
114
+ | `includeValidation` | boolean | true | Include validation annotations as comments |
115
+ | `dateFormat` | string | "ISO" | Date format: "ISO", "Date", or "number" |
116
+ | `includeEnums` | boolean | true | Generate enums |
117
+ | `includeRelations` | boolean | true | Include entity relations |
118
+ | `excludePatterns` | string[] | [] | Glob patterns to exclude files |
119
+ | `watch` | boolean | false | Enable watch mode |
120
+ | `customTypeMapping` | object | {} | Custom type mappings |
121
+
122
+ ## Examples
123
+
124
+ ### Example Kotlin Entity
125
+
126
+ ```kotlin
127
+ package com.example.entities
128
+
129
+ import jakarta.persistence.*
130
+ import java.time.LocalDateTime
131
+ import java.util.UUID
132
+
133
+ @Entity
134
+ @Table(name = "users")
135
+ data class User(
136
+ @Id
137
+ @GeneratedValue(strategy = GenerationType.UUID)
138
+ val id: UUID? = null,
139
+
140
+ @Column(nullable = false)
141
+ val username: String,
142
+
143
+ @Column(nullable = false)
144
+ val email: String,
145
+
146
+ val createdAt: LocalDateTime = LocalDateTime.now(),
147
+
148
+ @OneToMany(mappedBy = "user")
149
+ val posts: List<Post> = emptyList()
150
+ )
151
+
152
+ enum class UserRole {
153
+ ADMIN,
154
+ USER,
155
+ GUEST
156
+ }
157
+ ```
158
+
159
+ ### Generated TypeScript
160
+
161
+ ```typescript
162
+ // User.ts
163
+ import { Post } from './Post';
164
+
165
+ export interface User {
166
+ id?: string;
167
+ username: string;
168
+ email: string;
169
+ createdAt: string;
170
+ posts: Post[];
171
+ }
172
+
173
+ // UserRole.ts
174
+ export enum UserRole {
175
+ ADMIN = 'ADMIN',
176
+ USER = 'USER',
177
+ GUEST = 'GUEST',
178
+ }
179
+ ```
180
+
181
+ ## Type Mappings
182
+
183
+ Default Kotlin/Java to TypeScript mappings:
184
+
185
+ | Kotlin/Java | TypeScript |
186
+ |-------------|------------|
187
+ | String | string |
188
+ | Int, Long, Double, Float | number |
189
+ | Boolean | boolean |
190
+ | UUID | string |
191
+ | LocalDate, LocalDateTime | string (configurable) |
192
+ | List<T>, Set<T> | T[] |
193
+ | Map<K, V> | Record<K, V> |
194
+ | Optional<T>, T? | T \| undefined |
195
+
196
+ ## Watch Mode
197
+
198
+ Enable automatic regeneration when files change:
199
+
200
+ ```bash
201
+ spring-to-ts generate --watch
202
+ ```
203
+
204
+ Or in configuration:
205
+
206
+ ```json
207
+ {
208
+ "watch": true
209
+ }
210
+ ```
211
+
212
+ ## Supported Annotations
213
+
214
+ - `@Entity`, `@Table`, `@Document` - Entity detection
215
+ - `@OneToMany`, `@ManyToOne`, `@OneToOne`, `@ManyToMany` - Relations
216
+ - `@Column(nullable = false)` - Nullable detection
217
+ - Validation annotations (included as comments when `includeValidation: true`)
218
+
219
+ ## Development
220
+
221
+ ```bash
222
+ # Install dependencies
223
+ npm install
224
+
225
+ # Build
226
+ npm run build
227
+
228
+ # Development mode
229
+ npm run dev
230
+
231
+ # Run tests
232
+ npm test
233
+
234
+ # Lint
235
+ npm run lint
236
+
237
+ # Format
238
+ npm run format
239
+ ```
240
+
241
+ ## 📚 Documentation
242
+
243
+ - [Publishing Guide](PUBLISHING.md) - How to publish to npm
244
+ - [Contributing Guide](CONTRIBUTING.md) - How to contribute
245
+ - [Changelog](CHANGELOG.md) - Version history
246
+
247
+ ## 🤝 Contributing
248
+
249
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details on:
250
+
251
+ - How to set up your development environment
252
+ - Coding standards and guidelines
253
+ - How to submit pull requests
254
+ - Reporting bugs and requesting features
255
+
256
+ ## 📝 License
257
+
258
+ MIT License - see the [LICENSE](LICENSE) file for details.
259
+
260
+ ## 🙏 Acknowledgments
261
+
262
+ - Built with [Commander.js](https://github.com/tj/commander.js/)
263
+ - Styled with [Chalk](https://github.com/chalk/chalk)
264
+ - Powered by [TypeScript](https://www.typescriptlang.org/)
265
+
266
+ ## 📞 Support
267
+
268
+ - 🐛 [Report a bug](https://github.com/geekles007/spring-to-ts/issues/new?template=bug_report.md)
269
+ - ✨ [Request a feature](https://github.com/geekles007/spring-to-ts/issues/new?template=feature_request.md)
270
+ - 💬 [Discussions](https://github.com/geekles007/spring-to-ts/discussions)
271
+
272
+ ---
273
+
274
+ Made with ❤️ by Geekles007 (https://github.com/geekles007)
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ require('../dist/cli/cli.js');
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli/cli.ts"],"names":[],"mappings":""}
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const commander_1 = require("commander");
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ const config_loader_1 = require("../config/config-loader");
10
+ const index_1 = require("../index");
11
+ const program = new commander_1.Command();
12
+ program
13
+ .name('spring-to-ts')
14
+ .description('Generate TypeScript types from Spring Boot/Kotlin entities')
15
+ .version('1.0.0');
16
+ program
17
+ .command('generate')
18
+ .description('Generate TypeScript types from source files')
19
+ .option('-s, --source <path>', 'Source directory containing Kotlin/Java entities')
20
+ .option('-o, --output <path>', 'Output directory for TypeScript types')
21
+ .option('-c, --config <path>', 'Path to configuration file')
22
+ .option('-w, --watch', 'Watch mode: regenerate on file changes')
23
+ .option('--no-validation', 'Exclude validation annotations from generated types')
24
+ .option('--no-relations', 'Exclude entity relations from generated types')
25
+ .option('--date-format <format>', 'Date format: ISO, Date, or number', 'ISO')
26
+ .action(async (options) => {
27
+ try {
28
+ let config;
29
+ if (options.config) {
30
+ config = config_loader_1.ConfigLoader.loadConfig(options.config);
31
+ }
32
+ else {
33
+ config = config_loader_1.ConfigLoader.loadConfig();
34
+ }
35
+ // Override config with CLI options
36
+ if (options.source) {
37
+ config.sourceDir = options.source;
38
+ }
39
+ if (options.output) {
40
+ config.outputDir = options.output;
41
+ }
42
+ if (options.watch !== undefined) {
43
+ config.watch = options.watch;
44
+ }
45
+ if (options.validation !== undefined) {
46
+ config.includeValidation = options.validation;
47
+ }
48
+ if (options.relations !== undefined) {
49
+ config.includeRelations = options.relations;
50
+ }
51
+ if (options.dateFormat) {
52
+ config.dateFormat = options.dateFormat;
53
+ }
54
+ const converter = new index_1.SpringToTsConverter(config);
55
+ await converter.run();
56
+ }
57
+ catch (error) {
58
+ if (error instanceof Error) {
59
+ console.error(chalk_1.default.red(`Error: ${error.message}`));
60
+ }
61
+ process.exit(1);
62
+ }
63
+ });
64
+ program
65
+ .command('init')
66
+ .description('Create a default configuration file')
67
+ .option('-f, --format <format>', 'Configuration format: json or yaml', 'json')
68
+ .action((options) => {
69
+ try {
70
+ const extension = options.format === 'yaml' ? 'yaml' : 'json';
71
+ const fileName = `spring-to-ts.config.${extension}`;
72
+ config_loader_1.ConfigLoader.createDefaultConfig(fileName);
73
+ console.log(chalk_1.default.green(`✅ Configuration file created: ${fileName}`));
74
+ console.log(chalk_1.default.gray('Edit the file to match your project structure'));
75
+ }
76
+ catch (error) {
77
+ if (error instanceof Error) {
78
+ console.error(chalk_1.default.red(`Error: ${error.message}`));
79
+ }
80
+ process.exit(1);
81
+ }
82
+ });
83
+ program.parse(process.argv);
84
+ if (!process.argv.slice(2).length) {
85
+ program.outputHelp();
86
+ }
87
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli/cli.ts"],"names":[],"mappings":";;;;;;AAEA,yCAAoC;AACpC,kDAA0B;AAC1B,2DAAuD;AACvD,oCAA+C;AAG/C,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,cAAc,CAAC;KACpB,WAAW,CAAC,4DAA4D,CAAC;KACzE,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO;KACJ,OAAO,CAAC,UAAU,CAAC;KACnB,WAAW,CAAC,6CAA6C,CAAC;KAC1D,MAAM,CAAC,qBAAqB,EAAE,kDAAkD,CAAC;KACjF,MAAM,CAAC,qBAAqB,EAAE,uCAAuC,CAAC;KACtE,MAAM,CAAC,qBAAqB,EAAE,4BAA4B,CAAC;KAC3D,MAAM,CAAC,aAAa,EAAE,wCAAwC,CAAC;KAC/D,MAAM,CAAC,iBAAiB,EAAE,qDAAqD,CAAC;KAChF,MAAM,CAAC,gBAAgB,EAAE,+CAA+C,CAAC;KACzE,MAAM,CAAC,wBAAwB,EAAE,mCAAmC,EAAE,KAAK,CAAC;KAC5E,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACxB,IAAI,CAAC;QACH,IAAI,MAAwB,CAAC;QAE7B,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACnB,MAAM,GAAG,4BAAY,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACnD,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,4BAAY,CAAC,UAAU,EAAE,CAAC;QACrC,CAAC;QAED,mCAAmC;QACnC,IAAI,OAAO,CAAC,MA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,CAAC;QACH,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;QAC9D,MAAM,QAAQ,GAAG,uBAAuB,SAAS,EAAE,CAAC;QAEpD,4BAAY,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,iCAAiC,QAAQ,EAAE,CAAC,CAAC,CAAC;QACtE,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,+CAA+C,CAAC,CAAC,CAAC;IAC3E,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,UAAU,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAClC,OAAO,CAAC,UAAU,EAAE,CAAC;AACvB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { SpringToTsConfig } from '../types';
2
+ export declare class ConfigLoader {
3
+ static loadConfig(configPath?: string): SpringToTsConfig;
4
+ private static loadFromFile;
5
+ private static validateConfig;
6
+ static createDefaultConfig(filePath?: string): void;
7
+ }
8
+ //# sourceMappingURL=config-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-loader.d.ts","sourceRoot":"","sources":["../../src/config/config-loader.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAW5C,qBAAa,YAAY;IACvB,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,gBAAgB;IA4BxD,OAAO,CAAC,MAAM,CAAC,YAAY;IAiB3B,OAAO,CAAC,MAAM,CAAC,cAAc;IAc7B,MAAM,CAAC,mBAAmB,CAAC,QAAQ,GAAE,MAAmC,GAAG,IAAI;CAqBhF"}
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ConfigLoader = void 0;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const yaml = __importStar(require("js-yaml"));
40
+ const DEFAULT_CONFIG = {
41
+ includeValidation: true,
42
+ dateFormat: 'ISO',
43
+ includeEnums: true,
44
+ includeRelations: true,
45
+ excludePatterns: [],
46
+ watch: false,
47
+ };
48
+ class ConfigLoader {
49
+ static loadConfig(configPath) {
50
+ let fileConfig = {};
51
+ if (configPath) {
52
+ fileConfig = this.loadFromFile(configPath);
53
+ }
54
+ else {
55
+ const defaultPaths = [
56
+ 'spring-to-ts.config.json',
57
+ 'spring-to-ts.config.yaml',
58
+ 'spring-to-ts.config.yml',
59
+ '.spring-to-ts.json',
60
+ ];
61
+ for (const defaultPath of defaultPaths) {
62
+ if (fs.existsSync(defaultPath)) {
63
+ fileConfig = this.loadFromFile(defaultPath);
64
+ break;
65
+ }
66
+ }
67
+ }
68
+ const mergedConfig = { ...DEFAULT_CONFIG, ...fileConfig };
69
+ this.validateConfig(mergedConfig);
70
+ return mergedConfig;
71
+ }
72
+ static loadFromFile(filePath) {
73
+ if (!fs.existsSync(filePath)) {
74
+ throw new Error(`Configuration file not found: ${filePath}`);
75
+ }
76
+ const fileContent = fs.readFileSync(filePath, 'utf-8');
77
+ const ext = path.extname(filePath);
78
+ if (ext === '.json') {
79
+ return JSON.parse(fileContent);
80
+ }
81
+ else if (ext === '.yaml' || ext === '.yml') {
82
+ return yaml.load(fileContent);
83
+ }
84
+ throw new Error(`Unsupported configuration file format: ${ext}`);
85
+ }
86
+ static validateConfig(config) {
87
+ if (!config.sourceDir) {
88
+ throw new Error('Configuration error: sourceDir is required');
89
+ }
90
+ if (!config.outputDir) {
91
+ throw new Error('Configuration error: outputDir is required');
92
+ }
93
+ if (!fs.existsSync(config.sourceDir)) {
94
+ throw new Error(`Source directory does not exist: ${config.sourceDir}`);
95
+ }
96
+ }
97
+ static createDefaultConfig(filePath = 'spring-to-ts.config.json') {
98
+ const defaultConfig = {
99
+ sourceDir: './backend/src/main/kotlin/entities',
100
+ outputDir: './frontend/src/types',
101
+ includeValidation: true,
102
+ dateFormat: 'ISO',
103
+ includeEnums: true,
104
+ includeRelations: true,
105
+ excludePatterns: ['**/*Test.kt', '**/*Spec.kt'],
106
+ watch: false,
107
+ customTypeMapping: {
108
+ UUID: 'string',
109
+ BigDecimal: 'number',
110
+ LocalDateTime: 'string',
111
+ LocalDate: 'string',
112
+ },
113
+ };
114
+ fs.writeFileSync(filePath, JSON.stringify(defaultConfig, null, 2));
115
+ console.log(`Default configuration created at: ${filePath}`);
116
+ }
117
+ }
118
+ exports.ConfigLoader = ConfigLoader;
119
+ //# sourceMappingURL=config-loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-loader.js","sourceRoot":"","sources":["../../src/config/config-loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAC7B,8CAAgC;AAGhC,MAAM,cAAc,GAA8B;IAChD,iBAAiB,EAAE,IAAI;IACvB,UAAU,EAAE,KAAK;IACjB,YAAY,EAAE,IAAI;IAClB,gBAAgB,EAAE,IAAI;IACtB,eAAe,EAAE,EAAE;IACnB,KAAK,EAAE,KAAK;CACb,CAAC;AAEF,MAAa,YAAY;IACvB,MAAM,CAAC,UAAU,CAAC,UAAmB;QACnC,IAAI,UAAU,GAA8B,EAAE,CAAC;QAE/C,IAAI,UAAU,EAAE,CAAC;YACf,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;QAC7C,CAAC;aAAM,CAAC;YACN,MAAM,YAAY,GAAG;gBACnB,0BAA0B;gBAC1B,0BAA0B;gBAC1B,yBAAyB;gBACzB,oBAAoB;aACrB,CAAC;YAEF,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;gBACvC,IAAI,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;oBAC/B,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;oBAC5C,MAAM;gBACR,CAAC;YACH,CAAC;QACH,CAAC;QAED,MAA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;IAED,MAAM,CAAC,mBAAmB,CAAC,WAAmB,0BAA0B;QACtE,MAAM,aAAa,GAAqB;YACtC,SAAS,EAAE,oCAAoC;YAC/C,SAAS,EAAE,sBAAsB;YACjC,iBAAiB,EAAE,IAAI;YACvB,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,IAAI;YAClB,gBAAgB,EAAE,IAAI;YACtB,eAAe,EAAE,CAAC,aAAa,EAAE,aAAa,CAAC;YAC/C,KAAK,EAAE,KAAK;YACZ,iBAAiB,EAAE;gBACjB,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE,QAAQ;gBACpB,aAAa,EAAE,QAAQ;gBACvB,SAAS,EAAE,QAAQ;aACpB;SACF,CAAC;QAEF,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACnE,OAAO,CAAC,GAAG,CAAC,qCAAqC,QAAQ,EAAE,CAAC,CAAC;IAC/D,CAAC;CACF;AAjFD,oCAiFC"}
@@ -0,0 +1,13 @@
1
+ import { ParsedEntity, SpringToTsConfig } from '../types';
2
+ export declare class TypeScriptGenerator {
3
+ private config;
4
+ constructor(config: SpringToTsConfig);
5
+ generate(entities: ParsedEntity[]): void;
6
+ private generateInterface;
7
+ private generateEnum;
8
+ private generateImports;
9
+ private generateDocumentation;
10
+ private generateFieldDocumentation;
11
+ private generateIndexFile;
12
+ }
13
+ //# sourceMappingURL=typescript-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescript-generator.d.ts","sourceRoot":"","sources":["../../src/generator/typescript-generator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG1D,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,MAAM,CAAmB;gBAErB,MAAM,EAAE,gBAAgB;IAIpC,QAAQ,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,IAAI;IAmBxC,OAAO,CAAC,iBAAiB;IA0CzB,OAAO,CAAC,YAAY;IAqBpB,OAAO,CAAC,eAAe;IA+BvB,OAAO,CAAC,qBAAqB;IAc7B,OAAO,CAAC,0BAA0B;IAiBlC,OAAO,CAAC,iBAAiB;CAY1B"}