@siyavuyachagi/typesharp 0.1.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 +21 -0
- package/README.md +389 -0
- package/bin/typesharp.js +3 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +53 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/index.d.ts +16 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +263 -0
- package/dist/core/index.js.map +1 -0
- package/dist/generator/index.d.ts +6 -0
- package/dist/generator/index.d.ts.map +1 -0
- package/dist/generator/index.js +346 -0
- package/dist/generator/index.js.map +1 -0
- package/dist/helpers/helper.d.ts +12 -0
- package/dist/helpers/helper.d.ts.map +1 -0
- package/dist/helpers/helper.js +51 -0
- package/dist/helpers/helper.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/index.d.ts +7 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +340 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/types/index.d.ts +43 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/typesharp-config.d.ts +60 -0
- package/dist/types/typesharp-config.d.ts.map +1 -0
- package/dist/types/typesharp-config.js +3 -0
- package/dist/types/typesharp-config.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// --- add helper(s) near the top of the file (or anywhere above parsePropertyType) ---
|
|
3
|
+
/**
|
|
4
|
+
* Split a comma-separated generic-argument string into top-level args,
|
|
5
|
+
* i.e. respects nested <...> and does NOT split commas inside nested generics.
|
|
6
|
+
* Example: "string, List<Dictionary<string, Foo>>, int" -> ["string", "List<Dictionary<string, Foo>>", "int"]
|
|
7
|
+
*/
|
|
8
|
+
function splitTopLevelGenericArgs(s) {
|
|
9
|
+
const parts = [];
|
|
10
|
+
let depth = 0;
|
|
11
|
+
let buf = '';
|
|
12
|
+
for (let i = 0; i < s.length; i++) {
|
|
13
|
+
const ch = s[i];
|
|
14
|
+
if (ch === '<') {
|
|
15
|
+
depth++;
|
|
16
|
+
buf += ch;
|
|
17
|
+
}
|
|
18
|
+
else if (ch === '>') {
|
|
19
|
+
depth--;
|
|
20
|
+
buf += ch;
|
|
21
|
+
}
|
|
22
|
+
else if (ch === ',' && depth === 0) {
|
|
23
|
+
parts.push(buf.trim());
|
|
24
|
+
buf = '';
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
buf += ch;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (buf.trim().length > 0)
|
|
31
|
+
parts.push(buf.trim());
|
|
32
|
+
return parts;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Find the index of the matching '>' for the first '<' at startIdx.
|
|
36
|
+
* Returns -1 if not found.
|
|
37
|
+
*/
|
|
38
|
+
function findMatchingAngleBracket(s, startIdx) {
|
|
39
|
+
let depth = 0;
|
|
40
|
+
for (let i = startIdx; i < s.length; i++) {
|
|
41
|
+
if (s[i] === '<')
|
|
42
|
+
depth++;
|
|
43
|
+
else if (s[i] === '>') {
|
|
44
|
+
depth--;
|
|
45
|
+
if (depth === 0)
|
|
46
|
+
return i;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return -1;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../src/helpers/helper.ts"],"names":[],"mappings":";AAAA,uFAAuF;AAEvF;;;;GAIG;AACH,SAAS,wBAAwB,CAAC,CAAS;IACzC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,KAAK,GAAG,CAAC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,CAAC;IACD,OAAO,CAAC,CAAC,CAAC;AACZ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { generate, loadConfig, createSampleConfig } from './core';
|
|
2
|
+
export { parseCSharpFiles } from './parser';
|
|
3
|
+
export { generateTypeScriptFiles } from './generator';
|
|
4
|
+
export type { TypeSharpConfig, NamingConvention, CSharpClass, CSharpProperty, ParseResult, GenerationOptions } from './types';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,WAAW,EACX,iBAAiB,EAClB,MAAM,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateTypeScriptFiles = exports.parseCSharpFiles = exports.createSampleConfig = exports.loadConfig = exports.generate = void 0;
|
|
4
|
+
// Main exports for programmatic usage
|
|
5
|
+
var core_1 = require("./core");
|
|
6
|
+
Object.defineProperty(exports, "generate", { enumerable: true, get: function () { return core_1.generate; } });
|
|
7
|
+
Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return core_1.loadConfig; } });
|
|
8
|
+
Object.defineProperty(exports, "createSampleConfig", { enumerable: true, get: function () { return core_1.createSampleConfig; } });
|
|
9
|
+
var parser_1 = require("./parser");
|
|
10
|
+
Object.defineProperty(exports, "parseCSharpFiles", { enumerable: true, get: function () { return parser_1.parseCSharpFiles; } });
|
|
11
|
+
var generator_1 = require("./generator");
|
|
12
|
+
Object.defineProperty(exports, "generateTypeScriptFiles", { enumerable: true, get: function () { return generator_1.generateTypeScriptFiles; } });
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;AACtC,+BAAkE;AAAzD,gGAAA,QAAQ,OAAA;AAAE,kGAAA,UAAU,OAAA;AAAE,0GAAA,kBAAkB,OAAA;AACjD,mCAA4C;AAAnC,0GAAA,gBAAgB,OAAA;AACzB,yCAAsD;AAA7C,oHAAA,uBAAuB,OAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ParseResult } from '../types';
|
|
2
|
+
import { TypeSharpConfig } from '../types/typesharp-config';
|
|
3
|
+
/**
|
|
4
|
+
* Parse C# files in the target project(s)
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseCSharpFiles(config: TypeSharpConfig): Promise<ParseResult[]>;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/parser/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAA+B,WAAW,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAM5D;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAiCtF"}
|
|
@@ -0,0 +1,340 @@
|
|
|
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.parseCSharpFiles = parseCSharpFiles;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const glob_1 = require("glob");
|
|
40
|
+
/**
|
|
41
|
+
* Parse C# files in the target project(s)
|
|
42
|
+
*/
|
|
43
|
+
async function parseCSharpFiles(config) {
|
|
44
|
+
const targetAnnotation = config.targetAnnotation ?? 'TypeSharp';
|
|
45
|
+
// Convert single project to array for unified handling
|
|
46
|
+
const projectFiles = Array.isArray(config.projectFiles)
|
|
47
|
+
? config.projectFiles
|
|
48
|
+
: [config.projectFiles];
|
|
49
|
+
const allResults = [];
|
|
50
|
+
// Process each project
|
|
51
|
+
for (const projectFile of projectFiles) {
|
|
52
|
+
const projectDir = path.dirname(projectFile);
|
|
53
|
+
const csFiles = await (0, glob_1.glob)('**/*.cs', {
|
|
54
|
+
cwd: projectDir,
|
|
55
|
+
absolute: true,
|
|
56
|
+
ignore: ['**/bin/**', '**/obj/**', '**/node_modules/**']
|
|
57
|
+
});
|
|
58
|
+
for (const filePath of csFiles) {
|
|
59
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
60
|
+
const classes = parseClassesFromFile(content, targetAnnotation);
|
|
61
|
+
if (classes.length > 0) {
|
|
62
|
+
// Store relative path for preserving folder structure later
|
|
63
|
+
const relativePath = path.relative(projectDir, filePath);
|
|
64
|
+
allResults.push({ classes, filePath, relativePath });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return allResults;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Parse classes from a C# file content
|
|
72
|
+
*/
|
|
73
|
+
function parseClassesFromFile(content, targetAnnotation) {
|
|
74
|
+
const classes = [];
|
|
75
|
+
// Remove comments
|
|
76
|
+
const cleanContent = removeComments(content);
|
|
77
|
+
// Find all classes/enums with the target annotation
|
|
78
|
+
const annotationRegex = new RegExp(`\\[${targetAnnotation}\\]`, 'g');
|
|
79
|
+
const matches = [...cleanContent.matchAll(annotationRegex)];
|
|
80
|
+
for (const match of matches) {
|
|
81
|
+
const startIndex = match.index;
|
|
82
|
+
const afterAnnotation = cleanContent.substring(startIndex);
|
|
83
|
+
// Check if it's an enum
|
|
84
|
+
const enumMatch = afterAnnotation.match(/\[[\w]+\]\s*public\s+enum\s+(\w+)/);
|
|
85
|
+
if (enumMatch) {
|
|
86
|
+
const enumClass = parseEnum(afterAnnotation, enumMatch[1]);
|
|
87
|
+
if (enumClass)
|
|
88
|
+
classes.push(enumClass);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
// Parse as class with full generic support
|
|
92
|
+
// Matches: public class ClassName<T, U> : BaseClass<T>
|
|
93
|
+
const classMatch = afterAnnotation.match(/\[[\w]+\]\s*public\s+class\s+(\w+)(?:<([^>]+)>)?(?:\s*:\s*(\w+)(?:<([^>]+)>)?)?/);
|
|
94
|
+
if (classMatch) {
|
|
95
|
+
const className = classMatch[1];
|
|
96
|
+
const genericParams = classMatch[2]; // e.g., "T" or "T, U"
|
|
97
|
+
const inheritsFrom = classMatch[3];
|
|
98
|
+
const baseGenerics = classMatch[4]; // e.g., "T" or "T, U"
|
|
99
|
+
const classBody = extractClassBody(afterAnnotation);
|
|
100
|
+
if (classBody) {
|
|
101
|
+
const properties = parseProperties(classBody);
|
|
102
|
+
// Parse generic parameters
|
|
103
|
+
const genericParameters = genericParams
|
|
104
|
+
? genericParams.split(',').map(p => p.trim())
|
|
105
|
+
: undefined;
|
|
106
|
+
const baseClassGenerics = baseGenerics
|
|
107
|
+
? baseGenerics.split(',').map(p => p.trim())
|
|
108
|
+
: undefined;
|
|
109
|
+
classes.push({
|
|
110
|
+
name: className,
|
|
111
|
+
properties,
|
|
112
|
+
inheritsFrom,
|
|
113
|
+
isEnum: false,
|
|
114
|
+
genericParameters,
|
|
115
|
+
baseClassGenerics
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return classes;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Parse enum from C# content
|
|
124
|
+
*/
|
|
125
|
+
function parseEnum(content, enumName) {
|
|
126
|
+
const enumBodyMatch = content.match(/enum\s+\w+\s*\{([^}]+)\}/);
|
|
127
|
+
if (!enumBodyMatch)
|
|
128
|
+
return null;
|
|
129
|
+
const enumBody = enumBodyMatch[1];
|
|
130
|
+
const enumValues = enumBody
|
|
131
|
+
.split(',')
|
|
132
|
+
.map(v => v.trim())
|
|
133
|
+
.filter(v => v.length > 0)
|
|
134
|
+
.map(v => v.split('=')[0].trim()); // Remove value assignments
|
|
135
|
+
return {
|
|
136
|
+
name: enumName,
|
|
137
|
+
properties: [],
|
|
138
|
+
isEnum: true,
|
|
139
|
+
enumValues
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Extract class body between curly braces
|
|
144
|
+
*/
|
|
145
|
+
function extractClassBody(content) {
|
|
146
|
+
let braceCount = 0;
|
|
147
|
+
let startIndex = -1;
|
|
148
|
+
for (let i = 0; i < content.length; i++) {
|
|
149
|
+
if (content[i] === '{') {
|
|
150
|
+
if (braceCount === 0)
|
|
151
|
+
startIndex = i;
|
|
152
|
+
braceCount++;
|
|
153
|
+
}
|
|
154
|
+
else if (content[i] === '}') {
|
|
155
|
+
braceCount--;
|
|
156
|
+
if (braceCount === 0 && startIndex !== -1) {
|
|
157
|
+
return content.substring(startIndex + 1, i);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Parse properties from class body
|
|
165
|
+
*/
|
|
166
|
+
function parseProperties(classBody) {
|
|
167
|
+
const properties = [];
|
|
168
|
+
// Match property declarations with get/set
|
|
169
|
+
const propertyRegex = /public\s+([\w<>[\]?]+)\s+(\w+)\s*\{\s*get;\s*set;\s*\}/g;
|
|
170
|
+
let match;
|
|
171
|
+
while ((match = propertyRegex.exec(classBody)) !== null) {
|
|
172
|
+
const type = match[1];
|
|
173
|
+
const name = match[2];
|
|
174
|
+
properties.push(parsePropertyType(name, type));
|
|
175
|
+
}
|
|
176
|
+
// Also match computed/expression-bodied properties (with =>)
|
|
177
|
+
// These are read-only, so we'll skip them for now since they don't have set;
|
|
178
|
+
// If you want to include them, uncomment below:
|
|
179
|
+
/*
|
|
180
|
+
const computedPropertyRegex = /public\s+([\w<>[\]?]+)\s+(\w+)\s*=>/g;
|
|
181
|
+
while ((match = computedPropertyRegex.exec(classBody)) !== null) {
|
|
182
|
+
const type = match[1]!;
|
|
183
|
+
const name = match[2]!;
|
|
184
|
+
|
|
185
|
+
properties.push(parsePropertyType(name, type));
|
|
186
|
+
}
|
|
187
|
+
*/
|
|
188
|
+
return properties;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Find the index of the matching '>' for the first '<' at startIdx.
|
|
192
|
+
* Returns -1 if not found.
|
|
193
|
+
*/
|
|
194
|
+
function findMatchingAngleBracket(s, startIdx) {
|
|
195
|
+
let depth = 0;
|
|
196
|
+
for (let i = startIdx; i < s.length; i++) {
|
|
197
|
+
if (s[i] === '<')
|
|
198
|
+
depth++;
|
|
199
|
+
else if (s[i] === '>') {
|
|
200
|
+
depth--;
|
|
201
|
+
if (depth === 0)
|
|
202
|
+
return i;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return -1;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Split a comma-separated generic-argument string into top-level args,
|
|
209
|
+
* i.e. respects nested <...> and does NOT split commas inside nested generics.
|
|
210
|
+
* Example: "string, List<Dictionary<string, Foo>>, int" -> ["string", "List<Dictionary<string, Foo>>", "int"]
|
|
211
|
+
*/
|
|
212
|
+
function splitTopLevelGenericArgs(s) {
|
|
213
|
+
const parts = [];
|
|
214
|
+
let depth = 0;
|
|
215
|
+
let buf = '';
|
|
216
|
+
for (let i = 0; i < s.length; i++) {
|
|
217
|
+
const ch = s[i];
|
|
218
|
+
if (ch === '<') {
|
|
219
|
+
depth++;
|
|
220
|
+
buf += ch;
|
|
221
|
+
}
|
|
222
|
+
else if (ch === '>') {
|
|
223
|
+
depth--;
|
|
224
|
+
buf += ch;
|
|
225
|
+
}
|
|
226
|
+
else if (ch === ',' && depth === 0) {
|
|
227
|
+
parts.push(buf.trim());
|
|
228
|
+
buf = '';
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
buf += ch;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (buf.trim().length > 0)
|
|
235
|
+
parts.push(buf.trim());
|
|
236
|
+
return parts;
|
|
237
|
+
}
|
|
238
|
+
function parsePropertyType(name, csType) {
|
|
239
|
+
let raw = csType.trim();
|
|
240
|
+
let isNullable = false;
|
|
241
|
+
// Extract nullable marker (T?)
|
|
242
|
+
if (raw.endsWith('?')) {
|
|
243
|
+
isNullable = true;
|
|
244
|
+
raw = raw.slice(0, -1).trim();
|
|
245
|
+
}
|
|
246
|
+
// Recursive resolver: returns { tsType, isArray }
|
|
247
|
+
function resolveType(typeText) {
|
|
248
|
+
const t = typeText.trim();
|
|
249
|
+
// 1) Array syntax: T[]
|
|
250
|
+
if (t.endsWith('[]')) {
|
|
251
|
+
const inner = t.slice(0, -2).trim();
|
|
252
|
+
const resolved = resolveType(inner);
|
|
253
|
+
// If inner is already an array, keep it as array-of-array semantics;
|
|
254
|
+
// mark as array so generator will append [] (or use resolved.tsType which may include [] already)
|
|
255
|
+
return { tsType: resolved.tsType, isArray: true };
|
|
256
|
+
}
|
|
257
|
+
// 2) Dictionary-like types (handle Dictionary, IDictionary, IReadOnlyDictionary)
|
|
258
|
+
if (/^(?:[\w\.]+\.)?(?:Dictionary|IDictionary|IReadOnlyDictionary)\s*</.test(t)) {
|
|
259
|
+
// locate first '<' and its matching '>'
|
|
260
|
+
const firstAngle = t.indexOf('<');
|
|
261
|
+
const lastAngle = findMatchingAngleBracket(t, firstAngle);
|
|
262
|
+
if (firstAngle !== -1 && lastAngle !== -1) {
|
|
263
|
+
const inner = t.slice(firstAngle + 1, lastAngle).trim();
|
|
264
|
+
const args = splitTopLevelGenericArgs(inner);
|
|
265
|
+
if (args.length === 2) {
|
|
266
|
+
const keyCs = args[0];
|
|
267
|
+
const valueCs = args[1];
|
|
268
|
+
// Guard against undefined/null/empty parts before resolving
|
|
269
|
+
if (typeof keyCs !== 'string' || typeof valueCs !== 'string' || keyCs.trim() === '' || valueCs.trim() === '') {
|
|
270
|
+
// Fallback: avoid throwing — emit a generic record
|
|
271
|
+
return { tsType: 'Record<string, any>', isArray: false };
|
|
272
|
+
}
|
|
273
|
+
const resolvedKey = resolveType(keyCs);
|
|
274
|
+
const resolvedValue = resolveType(valueCs);
|
|
275
|
+
// Normalize key to a safe TS key type: Record<K extends keyof any, V>
|
|
276
|
+
// If key is not primitive 'string' or 'number' or 'symbol', coerce to 'string'
|
|
277
|
+
const keyTsRaw = resolvedKey.tsType;
|
|
278
|
+
const safeKey = keyTsRaw === 'string' || keyTsRaw === 'number' || keyTsRaw === 'symbol'
|
|
279
|
+
? keyTsRaw
|
|
280
|
+
: 'string';
|
|
281
|
+
// Build value type (respect nested arrays)
|
|
282
|
+
const valueType = resolvedValue.isArray ? `${resolvedValue.tsType}[]` : resolvedValue.tsType;
|
|
283
|
+
return { tsType: `Record<${safeKey}, ${valueType}>`, isArray: false };
|
|
284
|
+
}
|
|
285
|
+
// else: fallthrough to other checks (malformed or >2 args) — do not falsely match
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
// 3) Collections: List<T>, IEnumerable<T>, ICollection<T>, IList<T>
|
|
289
|
+
const collectionMatch = t.match(/^(?:List|IEnumerable|ICollection|IList)\s*<\s*(.+)\s*>$/);
|
|
290
|
+
if (collectionMatch) {
|
|
291
|
+
const inner = collectionMatch[1].trim();
|
|
292
|
+
const resolvedInner = resolveType(inner);
|
|
293
|
+
// Collections become inner[] in TS; mark isArray true and tsType = resolvedInner.tsType
|
|
294
|
+
// The generator will append [].
|
|
295
|
+
return { tsType: resolvedInner.tsType, isArray: true };
|
|
296
|
+
}
|
|
297
|
+
// 4) Fallback: map primitive / known types, else return as-is (class name)
|
|
298
|
+
return { tsType: mapCSharpTypeToTypeScript(t), isArray: false };
|
|
299
|
+
}
|
|
300
|
+
const resolved = resolveType(raw);
|
|
301
|
+
return {
|
|
302
|
+
name,
|
|
303
|
+
type: resolved.tsType,
|
|
304
|
+
isNullable,
|
|
305
|
+
isArray: resolved.isArray,
|
|
306
|
+
isGeneric: false,
|
|
307
|
+
genericType: undefined
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Map C# primitive types to TypeScript types
|
|
312
|
+
*/
|
|
313
|
+
function mapCSharpTypeToTypeScript(csType) {
|
|
314
|
+
const typeMap = {
|
|
315
|
+
'string': 'string',
|
|
316
|
+
'int': 'number',
|
|
317
|
+
'long': 'number',
|
|
318
|
+
'double': 'number',
|
|
319
|
+
'float': 'number',
|
|
320
|
+
'decimal': 'number',
|
|
321
|
+
'bool': 'boolean',
|
|
322
|
+
'DateTime': 'string',
|
|
323
|
+
'DateOnly': 'string',
|
|
324
|
+
'TimeOnly': 'string',
|
|
325
|
+
'Guid': 'string',
|
|
326
|
+
'object': 'any'
|
|
327
|
+
};
|
|
328
|
+
return typeMap[csType] || csType;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Remove single-line and multi-line comments
|
|
332
|
+
*/
|
|
333
|
+
function removeComments(content) {
|
|
334
|
+
// Remove multi-line comments
|
|
335
|
+
let result = content.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
336
|
+
// Remove single-line comments
|
|
337
|
+
result = result.replace(/\/\/.*/g, '');
|
|
338
|
+
return result;
|
|
339
|
+
}
|
|
340
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/parser/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,4CAiCC;AA9CD,uCAAyB;AACzB,2CAA6B;AAC7B,+BAA4B;AAQ5B;;GAEG;AACI,KAAK,UAAU,gBAAgB,CAAC,MAAuB;IAC5D,MAAM,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,IAAI,WAAW,CAAC;IAEhE,uDAAuD;IACvD,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAA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OAAe;IACrC,6BAA6B;IAC7B,IAAI,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;IAEtD,8BAA8B;IAC9B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAEvC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { NamingConvention } from "./typesharp-config";
|
|
2
|
+
import { TypeSharpConfig } from "./typesharp-config";
|
|
3
|
+
/**
|
|
4
|
+
* Parsed C# property
|
|
5
|
+
*/
|
|
6
|
+
export interface CSharpProperty {
|
|
7
|
+
name: string;
|
|
8
|
+
type: string;
|
|
9
|
+
isNullable: boolean;
|
|
10
|
+
isArray: boolean;
|
|
11
|
+
isGeneric: boolean;
|
|
12
|
+
genericType?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Parsed C# class/interface
|
|
16
|
+
*/
|
|
17
|
+
export interface CSharpClass {
|
|
18
|
+
name: string;
|
|
19
|
+
properties: CSharpProperty[];
|
|
20
|
+
inheritsFrom?: string;
|
|
21
|
+
isEnum: boolean;
|
|
22
|
+
enumValues?: string[];
|
|
23
|
+
genericParameters?: string[];
|
|
24
|
+
baseClassGenerics?: string[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Result of parsing C# files
|
|
28
|
+
*/
|
|
29
|
+
export interface ParseResult {
|
|
30
|
+
classes: CSharpClass[];
|
|
31
|
+
filePath: string;
|
|
32
|
+
relativePath: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Generation options
|
|
36
|
+
*/
|
|
37
|
+
export interface GenerationOptions {
|
|
38
|
+
config: TypeSharpConfig;
|
|
39
|
+
classes: CSharpClass[];
|
|
40
|
+
}
|
|
41
|
+
export type { TypeSharpConfig };
|
|
42
|
+
export type { NamingConvention };
|
|
43
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,cAAc,EAAE,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,eAAe,CAAC;IACxB,OAAO,EAAE,WAAW,EAAE,CAAC;CACxB;AAGD,YAAY,EAAE,eAAe,EAAE,CAAA;AAC/B,YAAY,EAAE,gBAAgB,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeSharp configuration
|
|
3
|
+
*/
|
|
4
|
+
export interface TypeSharpConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Full path(s) to the C# .csproj file(s).
|
|
7
|
+
* Can be a single path or an array of paths.
|
|
8
|
+
* Example (Windows):
|
|
9
|
+
* ```
|
|
10
|
+
* `C:\\Users\\User\\Desktop\\MyApp\\Api\\Api.csproj`
|
|
11
|
+
* // or
|
|
12
|
+
* [
|
|
13
|
+
* `C:\\Users\\User\\Desktop\\MyApp\\Api\\Api.csproj`,
|
|
14
|
+
* `C:\\Users\\User\\Desktop\\MyApp\\Domain\\Domain.csproj`
|
|
15
|
+
* ]
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
projectFiles: string | string[];
|
|
19
|
+
/**
|
|
20
|
+
* Path where TypeScript files will be generated
|
|
21
|
+
*/
|
|
22
|
+
outputPath: string;
|
|
23
|
+
/**
|
|
24
|
+
* The C# attribute name to look for (default: "TypeSharp")
|
|
25
|
+
*/
|
|
26
|
+
targetAnnotation?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Controls whether generated types are written to one file or multiple files.
|
|
29
|
+
*
|
|
30
|
+
* - true → All generated types go into a single file: "index.ts"
|
|
31
|
+
* - false → Each type is written to its own file, using the naming convention.
|
|
32
|
+
* The original folder structure is preserved in the output.
|
|
33
|
+
*/
|
|
34
|
+
singleOutputFile?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Naming convention for generated file names
|
|
37
|
+
*/
|
|
38
|
+
fileNamingConvention?: NamingConvention;
|
|
39
|
+
/**
|
|
40
|
+
* Naming convention for property names in generated types
|
|
41
|
+
*/
|
|
42
|
+
namingConvention?: NamingConvention;
|
|
43
|
+
/**
|
|
44
|
+
* Suffix appended to generated TypeScript type names.
|
|
45
|
+
* The suffix is formatted based on the selected naming convention.
|
|
46
|
+
* ```
|
|
47
|
+
* Examples (suffix = "Dto"):
|
|
48
|
+
* camel : User -> userDto
|
|
49
|
+
* pascal: User -> UserDto
|
|
50
|
+
* snake : User -> user_dto
|
|
51
|
+
* kebab : User -> user-dto
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
fileSuffix?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Naming convention options for file and property names
|
|
58
|
+
*/
|
|
59
|
+
export type NamingConvention = 'kebab' | 'snake' | 'camel' | 'pascal';
|
|
60
|
+
//# sourceMappingURL=typesharp-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typesharp-config.d.ts","sourceRoot":"","sources":["../../src/types/typesharp-config.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,eAAe;IAE5B;;;;;;;;;;;;OAYG;IACH,YAAY,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAEhC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;OAEG;IACH,oBAAoB,CAAC,EAAE,gBAAgB,CAAC;IAExC;;OAEG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;;;;;;;;;OAUG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAID;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typesharp-config.js","sourceRoot":"","sources":["../../src/types/typesharp-config.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@siyavuyachagi/typesharp",
|
|
3
|
+
"description": "Generate TypeScript types from C# models with TypeSharp attribute",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Siyavuya Chagi <syavuya08@gmail.com>",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/siyavuyachagi/typesharp.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/siyavuyachagi/typesharp#readme",
|
|
12
|
+
"main": "dist/index.js",
|
|
13
|
+
"types": "dist/index.d.ts",
|
|
14
|
+
"bin": {
|
|
15
|
+
"typesharp": "./bin/typesharp.js"
|
|
16
|
+
},
|
|
17
|
+
"type": "commonjs",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"keywords": [
|
|
24
|
+
"typescript",
|
|
25
|
+
"csharp",
|
|
26
|
+
"code-generation",
|
|
27
|
+
"types"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc",
|
|
31
|
+
"dev": "tsc --watch",
|
|
32
|
+
"prepublishOnly": "npm run build",
|
|
33
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/node": "^25.0.0",
|
|
37
|
+
"typescript": "^5.9.3"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"chalk": "^5.6.2",
|
|
41
|
+
"commander": "^14.0.2",
|
|
42
|
+
"glob": "^13.0.0"
|
|
43
|
+
}
|
|
44
|
+
}
|