@siyavuyachagi/typesharp 0.1.0 β†’ 0.1.2

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.
Files changed (42) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +196 -49
  3. package/dist/cli/index.js +7 -5
  4. package/dist/cli/index.js.map +1 -1
  5. package/dist/core/create-sample-config.d.ts +5 -0
  6. package/dist/core/create-sample-config.d.ts.map +1 -0
  7. package/dist/core/create-sample-config.js +110 -0
  8. package/dist/core/create-sample-config.js.map +1 -0
  9. package/dist/core/index.d.ts +5 -5
  10. package/dist/core/index.d.ts.map +1 -1
  11. package/dist/core/index.js +36 -66
  12. package/dist/core/index.js.map +1 -1
  13. package/dist/generator/index.js +77 -53
  14. package/dist/generator/index.js.map +1 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +1 -2
  18. package/dist/index.js.map +1 -1
  19. package/dist/parser/index.d.ts.map +1 -1
  20. package/dist/parser/index.js +12 -176
  21. package/dist/parser/index.js.map +1 -1
  22. package/dist/parser/parse-properties.d.ts +6 -0
  23. package/dist/parser/parse-properties.d.ts.map +1 -0
  24. package/dist/parser/parse-properties.js +250 -0
  25. package/dist/parser/parse-properties.js.map +1 -0
  26. package/dist/parser/resolve-project-files-from-source.d.ts +29 -0
  27. package/dist/parser/resolve-project-files-from-source.d.ts.map +1 -0
  28. package/dist/parser/resolve-project-files-from-source.js +98 -0
  29. package/dist/parser/resolve-project-files-from-source.js.map +1 -0
  30. package/dist/types/index.d.ts +7 -1
  31. package/dist/types/index.d.ts.map +1 -1
  32. package/dist/types/naming-convention-config.d.ts +9 -0
  33. package/dist/types/naming-convention-config.d.ts.map +1 -0
  34. package/dist/types/naming-convention-config.js +3 -0
  35. package/dist/types/naming-convention-config.js.map +1 -0
  36. package/dist/types/naming-convention.d.ts +5 -0
  37. package/dist/types/naming-convention.d.ts.map +1 -0
  38. package/dist/types/naming-convention.js +3 -0
  39. package/dist/types/naming-convention.js.map +1 -0
  40. package/dist/types/typesharp-config.d.ts +29 -25
  41. package/dist/types/typesharp-config.d.ts.map +1 -1
  42. package/package.json +14 -6
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Siyavuya Chagi
3
+ Copyright (c) 2025 Siyavuya Chagi
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,35 +1,49 @@
1
1
  # TypeSharp
2
2
 
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
+ [![npm version](https://img.shields.io/npm/v/@siyavuyachagi/typesharp.svg?label=Version)](https://www.npmjs.com/package/@siyavuyachagi/typesharp)
5
+ [![npm downloads](https://img.shields.io/npm/dm/@siyavuyachagi/typesharp.svg?label=Downloads)](https://www.npmjs.com/package/@siyavuyachagi/typesharp)
6
+ [![GitHub commits](https://img.shields.io/github/commit-activity/m/siyavuyachagi/typesharp?label=Commits)](https://github.com/siyavuyachagi/typesharp/commits/main)
7
+ [![GitHub last commit](https://img.shields.io/github/last-commit/siyavuyachagi/typesharp?label=Last+commit)](https://github.com/siyavuyachagi/typesharp/commits/main)
8
+ [![GitHub stars](https://img.shields.io/github/stars/siyavuyachagi/typesharp?label=Stars)](https://github.com/siyavuyachagi/typesharp/stargazers)
9
+ [![Sponsor](https://img.shields.io/badge/Sponsor-πŸ’–-ff69b4)](https://github.com/sponsors/siyavuyachagi)
10
+
3
11
  Generate TypeScript types from C# models with ease! TypeSharp scans your ASP.NET Core projects and automatically generates TypeScript interfaces from your C# classes decorated with the `[TypeSharp]` attribute.
4
12
 
13
+ Project structure: [docs/project-structure](docs/project-structure.md)
14
+
5
15
  ## Features
6
16
 
7
17
  ✨ **Automatic Type Generation** – Convert C# models to TypeScript interfaces
8
18
  🎯 **Custom Attribute Targeting** – Use `[TypeSharp]` or any custom attribute
9
19
  πŸ”„ **Nullable Support** – `string?` β†’ `string | null`
10
20
  πŸ“¦ **Collection Handling** – Supports `List<T>`, `IEnumerable<T>`, arrays **and generic collections**
21
+ πŸ—ΊοΈ **Dictionary Mapping** – `Dictionary<K, V>` β†’ `Record<K, V>`
11
22
  🧬 **Generic Types** – Preserves generic type definitions like `Response<T>` β†’ `Response<T>`
12
23
  🧬 **Inheritance** – Preserves class inheritance using `extends`
24
+ πŸ—οΈ **Computed Properties** – Expression-bodied and block getter properties are included
13
25
  🎨 **Naming Conventions** – Convert property names (camel, pascal, snake, kebab)
14
26
  πŸ“ **Flexible Output** – Single file or multiple files
15
27
  πŸ”’ **Enum Support** – Converts C# enums to TypeScript string enums
16
- πŸ—‚οΈ **File Grouping** – Preserves C# file organization (multiple classes per file stay together)
28
+ πŸ—‚οΈ **File Grouping** – Preserves C# file organization (multiple classes per file stay together)
29
+ πŸ”— **Auto Imports** – Automatically generates `import type` statements between output files
30
+ 🏒 **Multi-Project** – Scan multiple `.csproj` files in a single run
31
+ 🚫 **Obsolete Support** – `[Obsolete]` / `[Obsolete("...")]` β†’ `/** @deprecated ... */` JSDoc
17
32
 
33
+ ## How TypeSharp Compares
18
34
 
19
- ## How TypeSharp Compares
20
35
  This is not an OpenApi-based tool !
21
- | Feature | TypeSharp | NSwag | openapi-typescript | TypeGen |
36
+ | Feature | TypeSharp | NSwag | openapi-typescript | TypeGen |
22
37
  | --------------------- | --------- | ----- | ------------------ | ------- |
23
- | Direct C# parsing | βœ… | ❌ | ❌ | βœ… |
24
- | Attribute targeting | βœ… | ⚠️ | ❌ | ⚠️ |
25
- | Non-API models | βœ… | ❌ | ❌ | βœ… |
26
- | Generics preserved | βœ… | ⚠️ | ⚠️ | ⚠️ |
27
- | File grouping | βœ… | ❌ | ❌ | ❌ |
28
- | Naming control | βœ… | ⚠️ | ⚠️ | ❌ |
29
- | API client generation | ❌ | βœ… | ❌ | ❌ |
30
-
31
- For more [docs/why-typesharp](docs/why-typesharp.md)
38
+ | Direct C# parsing | βœ… | ❌ | ❌ | βœ… |
39
+ | Attribute targeting | βœ… | ⚠️ | ❌ | ⚠️ |
40
+ | Non-API models | βœ… | ❌ | ❌ | βœ… |
41
+ | Generics preserved | βœ… | ⚠️ | ⚠️ | ⚠️ |
42
+ | File grouping | βœ… | ❌ | ❌ | ❌ |
43
+ | Naming control | βœ… | ⚠️ | ⚠️ | ❌ |
44
+ | API client generation | ❌ | βœ… | ❌ | ❌ |
32
45
 
46
+ Also see [docs/why-typesharp](docs/why-typesharp.md)
33
47
 
34
48
  ## Installation
35
49
 
@@ -85,7 +99,7 @@ public class ApiResponse<T>
85
99
 
86
100
  ### 3. Create a configuration file
87
101
 
88
- In your frontend end project run the following script
102
+ In your frontend project run the following script
89
103
 
90
104
  ```bash
91
105
  # Create TypeScript config
@@ -93,29 +107,27 @@ npx typesharp init
93
107
 
94
108
  # ----- OR -------
95
109
 
96
- # Create JSON config (default)
110
+ # Create JSON config
97
111
  npx typesharp init --format json
98
112
 
99
- # Create TypeScript config
113
+ # Create TypeScript config (default)
100
114
  npx typesharp init --format ts
101
115
 
102
116
  # Create JavaScript config
103
117
  npx typesharp init --format js
104
-
105
118
  ```
106
119
 
107
120
  This creates `typesharp.config.json`:
108
121
 
109
122
  ```json
110
123
  {
111
- "projectFile": [
124
+ "source": [
112
125
  "C:/Users/User/Desktop/MyApp/Api/Api.csproj",
113
126
  "C:/Users/User/Desktop/MyApp/Domain/Domain.csproj"
114
127
  ],
115
128
  "outputPath": "./app/types",
116
129
  "targetAnnotation": "TypeSharp",
117
130
  "singleOutputFile": false,
118
- "fileNamingConvention": "kebab",
119
131
  "namingConvention": "camel"
120
132
  }
121
133
  ```
@@ -183,23 +195,40 @@ export interface ApiResponse<T> {
183
195
  errors: string[];
184
196
  }
185
197
  ```
198
+
186
199
  For more advanced usage [docs/usage](docs/usage.md)
187
200
 
188
201
  ## Configuration
189
202
 
190
203
  ### 1. Configuration Options
191
204
 
192
- | Option | Type | Default | Description |
193
- | ---------------------- | ---------- | ------------- | ------------------------------------------------ |
194
- | `projectFiles` | `string[]` | _required_ | Full path(s) to your C# .csproj file |
195
- | `outputPath` | `string` | _required_ | Where to generate TypeScript files |
196
- | `targetAnnotation` | `string` | `'TypeSharp'` | C# attribute name to look for |
197
- | `singleOutputFile` | `boolean` | `false` | Generate one file or multiple files (see below) |
198
- | `fileNamingConvention` | `string` | `'kebab'` | File naming: `kebab`, `camel`, `pascal`, `snake` |
199
- | `namingConvention` | `string` | `'camel'` | Property naming: `camel`, `pascal`, `snake` |
200
- | `fileSuffix` | `string` | `optional` | Suffix for file names: `user-dto.ts` |
205
+ | Option | Type | Default | Description |
206
+ | ------------------ | ----------------------------------------- | ------------- | ------------------------------------------------------------- |
207
+ | `source` | `string \| string[]` | _required_ | Full path(s) to your C# .csproj file(s) |
208
+ | `outputPath` | `string` | _required_ | Where to generate TypeScript files |
209
+ | `targetAnnotation` | `string` | `'TypeSharp'` | C# attribute name to look for |
210
+ | `singleOutputFile` | `boolean` | `false` | Generate one file or multiple files (see below) |
211
+ | `namingConvention` | `string \| { dir: string, file: string }` | `'camel'` | Property/file/dir naming: `kebab`, `camel`, `pascal`, `snake` |
212
+ | `fileSuffix` | `string` | _optional_ | Suffix appended to generated file names: `user-dto.ts` |
201
213
 
202
- ### 2. Output File Behavior
214
+ ### 2. Naming Convention
215
+
216
+ `namingConvention` accepts either a simple string that applies to everything, or a config object for separate control over directories and files:
217
+
218
+ ```json
219
+ // Simple β€” applies to both dirs and files
220
+ { "namingConvention": "kebab" }
221
+
222
+ // Advanced β€” separate control
223
+ {
224
+ "namingConvention": {
225
+ "dir": "kebab",
226
+ "file": "camel"
227
+ }
228
+ }
229
+ ```
230
+
231
+ ### 3. Output File Behavior
203
232
 
204
233
  TypeSharp preserves your C# file organization. Here's how it works:
205
234
 
@@ -226,7 +255,7 @@ Backend/ src/types/
226
255
 
227
256
  **This means if you organize related DTOs in one C# file, they'll stay together in the generated TypeScript file!** 🎯
228
257
 
229
- ### 3. Configuration File Formats
258
+ ### 4. Configuration File Formats
230
259
 
231
260
  TypeSharp supports multiple configuration formats:
232
261
 
@@ -311,44 +340,166 @@ export interface Product extends BaseEntity {
311
340
  }
312
341
  ```
313
342
 
314
- ### 2. Single Output File
343
+ ### 2. Computed Properties
344
+
345
+ TypeSharp includes expression-bodied and block getter properties in the generated output:
346
+
347
+ **C#:**
348
+
349
+ ```csharp
350
+ [TypeSharp]
351
+ public class PollOptionUserLinkDto
352
+ {
353
+ public int Id { get; set; }
354
+ public int UserId { get; set; }
355
+ public UserDto User { get; set; }
356
+
357
+ // Expression-bodied
358
+ public string? Avatar => User?.Avatar;
359
+
360
+ // Block getter
361
+ public string UserFirstName { get { return User.FirstName; } }
362
+
363
+ // Init-only (Planned)
364
+ // public string Slug { get; init; }
365
+ }
366
+ ```
367
+
368
+ **Generated TypeScript:**
369
+
370
+ ```typescript
371
+ export interface PollOptionUserLinkDto {
372
+ id: number;
373
+ userId: number;
374
+ user: UserDto;
375
+ avatar: string | null;
376
+ userFirstName: string;
377
+ slug: string;
378
+ }
379
+ ```
380
+
381
+ ### 3. Dictionary Types
382
+
383
+ **C#:**
384
+
385
+ ```csharp
386
+ [TypeSharp]
387
+ public class PermissionMap
388
+ {
389
+ public Dictionary<string, bool> Flags { get; set; }
390
+ public IReadOnlyDictionary<string, List<string>> RolePermissions { get; set; }
391
+ }
392
+ ```
393
+
394
+ **Generated TypeScript:**
395
+
396
+ ```typescript
397
+ export interface PermissionMap {
398
+ flags: Record<string, boolean>;
399
+ rolePermissions: Record<string, string[]>;
400
+ }
401
+ ```
402
+
403
+ ### 4. Obsolete / Deprecated Properties
404
+
405
+ **C#:**
406
+ ```csharp
407
+ [TypeSharp]
408
+ public class Employee
409
+ {
410
+ public int Id { get; set; }
411
+ public string Department { get; set; }
412
+
413
+ [Obsolete("Use Department instead.")]
414
+ public string? DepartmentName { get; set; }
415
+
416
+ [Obsolete]
417
+ public string? LegacyCode { get; set; }
418
+ }
419
+ ```
420
+
421
+ **Generated TypeScript:**
422
+ ```typescript
423
+ export interface Employee {
424
+ id: number;
425
+ department: string;
426
+ /** @deprecated Use Department instead. */
427
+ departmentName: string | null;
428
+ /** @deprecated */
429
+ legacyCode: string | null;
430
+ }
431
+ ```
432
+
433
+ ### 5. Multi-Project
434
+
435
+ Scan multiple C# projects at once:
436
+
437
+ ```json
438
+ {
439
+ "source": [
440
+ "C:/MyApp/Api/Api.csproj",
441
+ "C:/MyApp/Domain/Domain.csproj",
442
+ "C:/MyApp/Contracts/Contracts.csproj"
443
+ ],
444
+ "outputPath": "./src/types"
445
+ }
446
+ ```
447
+
448
+ ### 6. Single Output File
315
449
 
316
450
  **Config:**
317
451
 
318
452
  ```typescript
319
453
  const config: TypeSharpConfig = {
320
- projectFile: "./Backend/Backend.csproj",
454
+ source: "./Backend/Backend.csproj",
321
455
  outputPath: "./src/types",
322
456
  singleOutputFile: true,
323
457
  };
324
458
  ```
325
459
 
326
- All types will be generated in `src/types/index.ts`
460
+ All types will be generated in `src/types/types.ts`
327
461
 
328
- ### 3. Custom Naming Conventions
462
+ ### 7. Custom Naming Conventions
329
463
 
330
464
  **Config:**
331
465
 
332
466
  ```typescript
333
467
  const config: TypeSharpConfig = {
334
- projectFile: "./Backend/Backend.csproj",
468
+ source: "./Backend/Backend.csproj",
335
469
  outputPath: "./src/types",
336
- fileNamingConvention: "snake", // user_model.ts
337
- namingConvention: "pascal", // UserName, not userName
470
+ namingConvention: {
471
+ dir: "kebab", // ./src/types/my-feature/
472
+ file: "camel", // myFeatureDto.ts
473
+ },
338
474
  };
339
475
  ```
340
476
 
341
477
  ## Type Mappings
342
478
 
343
- | C# Type | TypeScript Type |
344
- | ------------------------------------------- | ---------------- |
345
- | `string` | `string` |
346
- | `int`, `long`, `double`, `float`, `decimal` | `number` |
347
- | `bool` | `boolean` |
348
- | `DateTime`, `DateOnly`, `TimeOnly` | `string` |
349
- | `Guid` | `string` |
350
- | `List<T>`, `IEnumerable<T>`, `T[]` | `T[]` |
351
- | `string?` | `string \| null` |
479
+ ### Primitives & Common Types
480
+
481
+ | C# Type | TypeScript Type |
482
+ | --------------------------------------------------- | --------------- |
483
+ | `bool` | `boolean` |
484
+ | `byte`, `decimal`, `double`, `float`, `int`, `long` | `number` |
485
+ | `DateTime`, `DateOnly`, `TimeOnly` | `string` |
486
+ | `Guid`, `string` | `string` |
487
+ | `object` | `any` |
488
+
489
+ ### Collections
490
+
491
+ | C# Type | TypeScript Type |
492
+ | -------------------------------------------------------------------- | --------------- |
493
+ | `List<T>`, `ICollection<T>`, `IEnumerable<T>`, `T[]` | `T[]` |
494
+ | `Dictionary<K, V>`, `IDictionary<K, V>`, `IReadOnlyDictionary<K, V>` | `Record<K, V>` |
495
+
496
+ ### ASP.NET / File Types
497
+
498
+ | C# Type | TypeScript Type |
499
+ | -------------------------------------- | --------------- |
500
+ | `IFormFile`, `FormFile` | `File` |
501
+ | `IFormFileCollection` | `File[]` |
502
+ | `FileStream`, `MemoryStream`, `Stream` | `Blob` |
352
503
 
353
504
  ## Programmatic Usage
354
505
 
@@ -369,10 +520,6 @@ generateTypes();
369
520
  - Node.js >= 14
370
521
  - TypeScript >= 4.5 (if using TypeScript config)
371
522
 
372
- <!-- ## Contributing
373
-
374
- Contributions are welcome! Please feel free to submit a Pull Request. -->
375
-
376
523
  ## License
377
524
 
378
525
  MIT Β© Siyavuya Chagi
package/dist/cli/index.js CHANGED
@@ -7,11 +7,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const commander_1 = require("commander");
8
8
  const core_1 = require("../core");
9
9
  const chalk_1 = __importDefault(require("chalk"));
10
+ const package_json_1 = require("../../package.json");
11
+ const create_sample_config_1 = require("../core/create-sample-config");
10
12
  const program = new commander_1.Command();
11
13
  program
12
- .name('typesharp')
13
- .description('Generate TypeScript types from C# models with TypeSharp attribute')
14
- .version('1.0.0')
14
+ .name(package_json_1.name)
15
+ .description(package_json_1.description)
16
+ .version(package_json_1.version)
15
17
  .usage('[command] [options]');
16
18
  // Generate command (default)
17
19
  program
@@ -31,7 +33,7 @@ program
31
33
  program
32
34
  .command('init')
33
35
  .description('Create a sample configuration file')
34
- .option('-f, --format <format>', 'Configuration file format (ts, js, json)', 'json') // default to 'json'
36
+ .option('-f, --format <format>', 'Configuration file format (ts, js, json)', 'ts') // default to 'ts'
35
37
  .action((options) => {
36
38
  try {
37
39
  const format = options.format;
@@ -39,7 +41,7 @@ program
39
41
  console.error(chalk_1.default.red.bold('❌ Invalid format.') + ' Use: ' + chalk_1.default.yellow('json, ts, ') + 'or' + chalk_1.default.yellow(' js'));
40
42
  process.exit(1);
41
43
  }
42
- (0, core_1.createSampleConfig)(format);
44
+ (0, create_sample_config_1.createSampleConfig)(format);
43
45
  process.exit(0);
44
46
  }
45
47
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;;;;AAEA,yCAAoC;AACpC,kCAAuD;AACvD,kDAA0B;AAE1B,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,WAAW,CAAC;KACjB,WAAW,CAAC,mEAAmE,CAAC;KAChF,OAAO,CAAC,OAAO,CAAC;KAChB,KAAK,CAAC,qBAAqB,CAAC,CAAC;AAEhC,6BAA6B;AAC7B,OAAO;KACJ,OAAO,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;KACxC,WAAW,CAAC,yCAAyC,CAAC;KACtD,MAAM,CAAC,qBAAqB,EAAE,4BAA4B,CAAC;KAC3D,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACxB,IAAI,CAAC;QACH,MAAM,IAAA,eAAQ,EAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC/B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf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MAAM,CAAC,YAAY,CAAC,GAAG,IAAI,GAAG,eAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YACxH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,IAAA,yCAAkB,EAAC,MAAM,CAAC,CAAC;QAC3B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,eAAK,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QACxE,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Create a sample configuration file
3
+ */
4
+ export declare const createSampleConfig: (format: "ts" | "js" | "json") => void;
5
+ //# sourceMappingURL=create-sample-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-sample-config.d.ts","sourceRoot":"","sources":["../../src/core/create-sample-config.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,QAAQ,IAAI,GAAG,IAAI,GAAG,MAAM,KAAG,IA2CjE,CAAA"}
@@ -0,0 +1,110 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.createSampleConfig = void 0;
40
+ const fs = __importStar(require("fs"));
41
+ const chalk_1 = __importDefault(require("chalk"));
42
+ /**
43
+ * Create a sample configuration file
44
+ */
45
+ const createSampleConfig = (format) => {
46
+ const sampleConfig = {
47
+ source: [
48
+ 'C:/Users/User/Desktop/MyApp/MyApp.sln',
49
+ ],
50
+ outputPath: './app/types',
51
+ targetAnnotation: 'TypeSharp',
52
+ singleOutputFile: false,
53
+ namingConvention: 'camel',
54
+ fileSuffix: ''
55
+ };
56
+ let fileName;
57
+ let content;
58
+ if (format === 'json') {
59
+ fileName = 'typesharp.config.json';
60
+ content = JSON.stringify(sampleConfig, null, 2);
61
+ }
62
+ else if (format === 'js') {
63
+ fileName = 'typesharp.config.js';
64
+ content = `module.exports = ${formatAsJsObject(sampleConfig)};\n`;
65
+ }
66
+ else {
67
+ fileName = 'typesharp.config.ts';
68
+ let namespace = '@siyavuyachagi/typesharp';
69
+ content = [
70
+ `import type { TypeSharpConfig } from '${namespace}';`,
71
+ ``,
72
+ `const config: TypeSharpConfig = ${formatAsJsObject(sampleConfig)};`,
73
+ ``,
74
+ `export default config;`,
75
+ ``
76
+ ].join('\n');
77
+ }
78
+ const allConfigFiles = ['typesharp.config.ts', 'typesharp.config.js', 'typesharp.config.json'];
79
+ const existingConfig = allConfigFiles.find(f => fs.existsSync(f));
80
+ if (existingConfig) {
81
+ console.log(chalk_1.default.yellow.bold('❗ Warning:'), chalk_1.default.white(`${existingConfig} already exists. Skipping creation.`));
82
+ return;
83
+ }
84
+ fs.writeFileSync(fileName, content, 'utf-8');
85
+ console.log(chalk_1.default.green.bold('βœ… Created'), chalk_1.default.white(`./${fileName}`));
86
+ };
87
+ exports.createSampleConfig = createSampleConfig;
88
+ /**
89
+ * Format a plain object as a JS/TS object literal (no quoted keys)
90
+ */
91
+ const formatAsJsObject = (obj, indent = 0) => {
92
+ const pad = ' '.repeat(indent + 2);
93
+ const closePad = ' '.repeat(indent);
94
+ const lines = Object.entries(obj).map(([key, value]) => {
95
+ let formatted;
96
+ if (Array.isArray(value)) {
97
+ const items = value.map(v => `${pad} ${JSON.stringify(v)}`).join(',\n');
98
+ formatted = `[\n${items}\n${pad}]`;
99
+ }
100
+ else if (typeof value === 'object' && value !== null) {
101
+ formatted = formatAsJsObject(value, indent + 2);
102
+ }
103
+ else {
104
+ formatted = JSON.stringify(value);
105
+ }
106
+ return `${pad}${key}: ${formatted}`;
107
+ });
108
+ return `{\n${lines.join(',\n')}\n${closePad}}`;
109
+ };
110
+ //# sourceMappingURL=create-sample-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-sample-config.js","sourceRoot":"","sources":["../../src/core/create-sample-config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,kDAA0B;AAI1B;;GAEG;AACI,MAAM,kBAAkB,GAAG,CAA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AAC;QACtC,CAAC;QAED,OAAO,GAAG,GAAG,GAAG,GAAG,KAAK,SAAS,EAAE,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,QAAQ,GAAG,CAAC;AACnD,CAAC,CAAA"}
@@ -1,4 +1,8 @@
1
1
  import { TypeSharpConfig } from '../types/typesharp-config';
2
+ /**
3
+ * Merge user config with defaults
4
+ */
5
+ export declare const mergeWithDefaults: (config: Partial<TypeSharpConfig>) => TypeSharpConfig;
2
6
  export declare function generate(configPath?: string): Promise<void>;
3
7
  /**
4
8
  * Deletes all contents of a directory but keeps the directory itself.
@@ -8,9 +12,5 @@ export declare function cleanOutputDirectory(dir: string): void;
8
12
  /**
9
13
  * Load configuration from file or use provided config
10
14
  */
11
- export declare function loadConfig(configPath?: string): TypeSharpConfig;
12
- /**
13
- * Create a sample configuration file
14
- */
15
- export declare function createSampleConfig(format?: 'ts' | 'js' | 'json'): void;
15
+ export declare function loadConfig(configPath?: string): Promise<TypeSharpConfig>;
16
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAuD5D,wBAAsB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAiEjE;AASD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,QAiB/C;AAUD;;GAEG;AACH,wBAAgB,UAAU,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,eAAe,CAqB/D;AA2CD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,GAAE,IAAI,GAAG,IAAI,GAAG,MAAe,GAAG,IAAI,CAwC9E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AA6C5D;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,OAAO,CAAC,eAAe,CAAC,KAAG,eAsBpE,CAAC;AAMF,wBAAsB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAiEjE;AASD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,QAiB/C;AAUD;;GAEG;AACH,wBAAsB,UAAU,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAqB9E"}