@siyavuyachagi/typesharp 0.1.5 → 0.2.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/README.md +50 -33
- package/bin/typesharp.js +4 -1
- package/dist/cli/index.js +14 -18
- package/dist/cli/index.js.map +1 -1
- package/dist/core/create-sample-config.d.ts.map +1 -1
- package/dist/core/create-sample-config.js +7 -47
- package/dist/core/create-sample-config.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +67 -184
- package/dist/core/index.js.map +1 -1
- package/dist/generator/index.d.ts +7 -3
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +61 -65
- package/dist/generator/index.js.map +1 -1
- package/dist/helpers/change-tracker.d.ts.map +1 -1
- package/dist/helpers/change-tracker.js +7 -46
- package/dist/helpers/change-tracker.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -10
- package/dist/index.js.map +1 -1
- package/dist/parser/index.d.ts +2 -2
- package/dist/parser/index.d.ts.map +1 -1
- package/dist/parser/index.js +11 -46
- package/dist/parser/index.js.map +1 -1
- package/dist/parser/parse-classes-from-file.d.ts +1 -1
- package/dist/parser/parse-classes-from-file.d.ts.map +1 -1
- package/dist/parser/parse-classes-from-file.js +7 -10
- package/dist/parser/parse-classes-from-file.js.map +1 -1
- package/dist/parser/parse-properties.d.ts +1 -1
- package/dist/parser/parse-properties.d.ts.map +1 -1
- package/dist/parser/parse-properties.js +3 -7
- package/dist/parser/parse-properties.js.map +1 -1
- package/dist/parser/resolve-project-files-from-source.d.ts.map +1 -1
- package/dist/parser/resolve-project-files-from-source.js +7 -40
- package/dist/parser/resolve-project-files-from-source.js.map +1 -1
- package/dist/scripts/pre-unistall.d.ts +2 -0
- package/dist/scripts/pre-unistall.d.ts.map +1 -0
- package/dist/scripts/pre-unistall.js +10 -0
- package/dist/scripts/pre-unistall.js.map +1 -0
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -2
- package/dist/types/naming-convention-config.d.ts +1 -1
- package/dist/types/naming-convention-config.d.ts.map +1 -1
- package/dist/types/naming-convention-config.js +1 -2
- package/dist/types/naming-convention.js +1 -2
- package/dist/types/typesharp-config.d.ts +2 -6
- package/dist/types/typesharp-config.d.ts.map +1 -1
- package/dist/types/typesharp-config.js +1 -2
- package/package.json +16 -5
package/dist/core/index.js
CHANGED
|
@@ -1,57 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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.mergeWithDefaults = void 0;
|
|
40
|
-
exports.generate = generate;
|
|
41
|
-
exports.cleanOutputDirectory = cleanOutputDirectory;
|
|
42
|
-
exports.loadConfig = loadConfig;
|
|
43
|
-
const fs = __importStar(require("fs"));
|
|
44
|
-
const path = __importStar(require("path"));
|
|
45
|
-
const parser_1 = require("../parser");
|
|
46
|
-
const generator_1 = require("../generator");
|
|
47
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
48
|
-
const url_1 = require("url");
|
|
49
|
-
const resolve_project_files_from_source_1 = require("../parser/resolve-project-files-from-source");
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { parseCSharpFiles } from '../parser/index.js';
|
|
4
|
+
import { convertFileName, generateTypeScriptFiles } from '../generator/index.js';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import { pathToFileURL } from 'url';
|
|
50
7
|
/**
|
|
51
8
|
* Default configuration values
|
|
52
9
|
*/
|
|
53
10
|
const DEFAULT_CONFIG = {
|
|
54
|
-
targetAnnotation: 'TypeSharp',
|
|
55
11
|
singleOutputFile: false,
|
|
56
12
|
namingConvention: 'camel'
|
|
57
13
|
};
|
|
@@ -63,31 +19,41 @@ async function loadConfigFromFile(filePath) {
|
|
|
63
19
|
if (ext === '.json') {
|
|
64
20
|
const content = fs.readFileSync(filePath, 'utf-8');
|
|
65
21
|
const config = JSON.parse(content);
|
|
66
|
-
return
|
|
22
|
+
return mergeWithDefaults(config);
|
|
67
23
|
}
|
|
68
24
|
if (ext === '.js') {
|
|
69
|
-
const fileUrl =
|
|
70
|
-
const module = await
|
|
25
|
+
const fileUrl = pathToFileURL(path.resolve(filePath)).href;
|
|
26
|
+
const module = await import(fileUrl);
|
|
71
27
|
const exportedConfig = module.default || module;
|
|
72
|
-
return
|
|
28
|
+
return mergeWithDefaults(exportedConfig);
|
|
73
29
|
}
|
|
74
30
|
if (ext === '.ts') {
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
31
|
+
// In ESM mode, .ts config files need special handling
|
|
32
|
+
// Try to import directly (works if tsx is registered as a loader)
|
|
33
|
+
try {
|
|
34
|
+
const fileUrl = pathToFileURL(path.resolve(filePath)).href;
|
|
35
|
+
const module = await import(fileUrl);
|
|
36
|
+
const exportedConfig = module.default || module;
|
|
37
|
+
return mergeWithDefaults(exportedConfig);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw new Error(`Failed to load TypeScript config file: ${filePath}\n` +
|
|
41
|
+
`In ESM mode, you have two options:\n` +
|
|
42
|
+
`1. Use a .json config file instead\n` +
|
|
43
|
+
`2. Use a .js config file (compile your TypeScript first)\n` +
|
|
44
|
+
`3. Run TypeSharp with: node --loader tsx/cjs ./bin/typesharp.js\n` +
|
|
45
|
+
`Original error: ${error instanceof Error ? error.message : String(error)}`);
|
|
46
|
+
}
|
|
81
47
|
}
|
|
82
48
|
throw new Error(`Unsupported config file format: ${ext}`);
|
|
83
49
|
}
|
|
84
50
|
/**
|
|
85
51
|
* Merge user config with defaults
|
|
86
52
|
*/
|
|
87
|
-
const mergeWithDefaults = (config) => {
|
|
53
|
+
export const mergeWithDefaults = (config) => {
|
|
88
54
|
// Deprecation warning
|
|
89
55
|
if (config.projectFiles && !config.source) {
|
|
90
|
-
console.warn(
|
|
56
|
+
console.warn(chalk.yellow.bold('⚠ Deprecation:'), chalk.white('`projectFiles` is deprecated. Please rename it to `source` in your config.'));
|
|
91
57
|
config.source = config.source || config.projectFiles;
|
|
92
58
|
}
|
|
93
59
|
if (!config.source && !config.projectFiles) {
|
|
@@ -101,130 +67,78 @@ const mergeWithDefaults = (config) => {
|
|
|
101
67
|
...config,
|
|
102
68
|
};
|
|
103
69
|
};
|
|
104
|
-
|
|
105
|
-
async function generate(configPath, incremental = true) {
|
|
70
|
+
export async function generate(configPath, incremental = true) {
|
|
106
71
|
try {
|
|
107
|
-
console.log(
|
|
72
|
+
console.log(chalk.cyan.bold('\n🚀 TypeSharp - Starting generation...'));
|
|
108
73
|
const config = await loadConfig(configPath);
|
|
109
|
-
console.log(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
console.log(
|
|
113
|
-
|
|
74
|
+
console.log(chalk.green.bold('\n✓ Configuration loaded'));
|
|
75
|
+
console.log(chalk.cyan(`-> Output:`), chalk.white(config.outputPath));
|
|
76
|
+
console.log(chalk.cyan(`-> Single file:`), chalk.white(config.singleOutputFile));
|
|
77
|
+
console.log(chalk.cyan(`-> Naming convention:`), chalk.white(config.namingConvention));
|
|
78
|
+
console.log(chalk.cyan('\n⧖ Parsing C# files...'));
|
|
79
|
+
const parseResults = await parseCSharpFiles(config);
|
|
114
80
|
if (parseResults.length === 0) {
|
|
115
|
-
console.warn(
|
|
81
|
+
console.warn(chalk.yellow.bold('\n❗ Warning:'), chalk.white(`No C# files found with [TypeSharp] attribute\n`));
|
|
116
82
|
return;
|
|
117
83
|
}
|
|
118
|
-
|
|
84
|
+
const allClasses = parseResults.flatMap(result => result.classes);
|
|
85
|
+
console.log(chalk.green.bold(`\n✓ Found ${allClasses.length} ${allClasses.length === 1 ? 'class' : 'classes'} with [TypeSharp] attribute`));
|
|
86
|
+
let metrics;
|
|
119
87
|
if (incremental) {
|
|
120
|
-
await cleanOnlyChangedOutputFiles(config, parseResults);
|
|
88
|
+
const changedFiles = await cleanOnlyChangedOutputFiles(config, parseResults);
|
|
89
|
+
metrics = generateTypeScriptFiles(config, parseResults, changedFiles);
|
|
121
90
|
}
|
|
122
91
|
else {
|
|
123
|
-
cleanOutputDirectory(config.outputPath);
|
|
92
|
+
cleanOutputDirectory(config.outputPath);
|
|
93
|
+
metrics = generateTypeScriptFiles(config, parseResults);
|
|
124
94
|
}
|
|
125
|
-
|
|
126
|
-
console.log(
|
|
127
|
-
console.log(chalk_1.default.blue.cyan('\n⧖ Generating TypeScript files...'));
|
|
128
|
-
(0, generator_1.generateTypeScriptFiles)(config, parseResults);
|
|
129
|
-
console.log(chalk_1.default.green.bold('✅ Generation completed successfully!\n'));
|
|
95
|
+
console.log(chalk.blue(`\nCreated: ${metrics.created} | Updated: ${metrics.updated} | Total files: ${metrics.total}`));
|
|
96
|
+
console.log(chalk.green.bold('\n✓ Generation completed successfully!'));
|
|
130
97
|
}
|
|
131
98
|
catch (error) {
|
|
132
|
-
|
|
99
|
+
if (error instanceof Error) {
|
|
100
|
+
console.error(chalk.red.bold(`\n❌ Error:`), chalk.white(error.message));
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
console.error(chalk.red.bold(`\n❌ An unknown error occurred`));
|
|
104
|
+
}
|
|
105
|
+
throw error;
|
|
133
106
|
}
|
|
134
107
|
}
|
|
135
|
-
// export async function generate(configPath?: string): Promise<void> {
|
|
136
|
-
// try {
|
|
137
|
-
// console.log(chalk.cyan.bold('\n🚀 TypeSharp - Starting generation...'));
|
|
138
|
-
// // Load configuration
|
|
139
|
-
// const config = await loadConfig(configPath);
|
|
140
|
-
// console.log(chalk.green.bold('\n✓ Configuration loaded'));
|
|
141
|
-
// // Display project files
|
|
142
|
-
// const projectFiles = Array.isArray(config.projectFiles)
|
|
143
|
-
// ? config.projectFiles
|
|
144
|
-
// : [config.projectFiles];
|
|
145
|
-
// if (projectFiles.length === 1) {
|
|
146
|
-
// console.log(chalk.cyan(`-> Target:`), chalk.white(projectFiles[0]));
|
|
147
|
-
// } else {
|
|
148
|
-
// console.log(chalk.cyan(`-> Targets (${projectFiles.length} projects):`));
|
|
149
|
-
// projectFiles.forEach((file, index) => {
|
|
150
|
-
// console.log(chalk.cyan(` ${index + 1}.`), chalk.white(file));
|
|
151
|
-
// });
|
|
152
|
-
// }
|
|
153
|
-
// console.log(chalk.cyan(`-> Output:`), chalk.white(config.outputPath));
|
|
154
|
-
// console.log(chalk.cyan(`-> Annotation:`), chalk.white(`[${config.targetAnnotation}]`));
|
|
155
|
-
// console.log(chalk.cyan(`-> Single file:`), chalk.white(config.singleOutputFile));
|
|
156
|
-
// if (config.fileSuffix) {
|
|
157
|
-
// console.log(chalk.cyan(`-> File suffix:`), chalk.white(config.fileSuffix));
|
|
158
|
-
// }
|
|
159
|
-
// // Validate configuration
|
|
160
|
-
// console.log(chalk.cyan('\n⧖ Configuration validation...'));
|
|
161
|
-
// validateConfig(config);
|
|
162
|
-
// console.log(chalk.green.bold('✓ Configuration validated'));
|
|
163
|
-
// // Clean output directory
|
|
164
|
-
// cleanOutputDirectory(config.outputPath);
|
|
165
|
-
// // Parse C# files from all projects
|
|
166
|
-
// console.log(chalk.cyan('\n⧖ Parsing C# files...'));
|
|
167
|
-
// const parseResults = await parseCSharpFiles(config);
|
|
168
|
-
// if (parseResults.length === 0) {
|
|
169
|
-
// console.warn(chalk.yellow.bold('❗ Warning:'), chalk.white(`No C# files found with [${config.targetAnnotation}] attribute\n`));
|
|
170
|
-
// return;
|
|
171
|
-
// }
|
|
172
|
-
// // Collect all classes
|
|
173
|
-
// const allClasses = parseResults.flatMap(result => result.classes);
|
|
174
|
-
// console.log(chalk.green.bold(`✓ Found ${allClasses.length} class(es) with [${config.targetAnnotation}] attribute`));
|
|
175
|
-
// // Generate TypeScript files
|
|
176
|
-
// console.log(chalk.blue.cyan('\n⧖ Generating TypeScript files...'));
|
|
177
|
-
// generateTypeScriptFiles(config, parseResults);
|
|
178
|
-
// console.log(chalk.green.bold('✅ Generation completed successfully!\n'));
|
|
179
|
-
// } catch (error) {
|
|
180
|
-
// if (error instanceof Error) {
|
|
181
|
-
// console.error(chalk.red.bold(`\n❌ Error:`), chalk.white(error.message));
|
|
182
|
-
// } else {
|
|
183
|
-
// console.error(chalk.red.bold(`\n❌ An unknown error occurred`));
|
|
184
|
-
// }
|
|
185
|
-
// throw error;
|
|
186
|
-
// }
|
|
187
|
-
// }
|
|
188
108
|
/**
|
|
189
109
|
* Clean only output files corresponding to changed C# files
|
|
190
110
|
*/
|
|
191
111
|
async function cleanOnlyChangedOutputFiles(config, parseResults) {
|
|
192
|
-
const { loadPreviousHashes, savePreviousHashes, getChangedFiles, computeFileHash } = await
|
|
112
|
+
const { loadPreviousHashes, savePreviousHashes, getChangedFiles, computeFileHash } = await import('../helpers/change-tracker.js');
|
|
193
113
|
const csharpFiles = parseResults.map(r => r.filePath);
|
|
194
114
|
const previousHashes = loadPreviousHashes();
|
|
195
115
|
const { changed, deleted } = getChangedFiles(csharpFiles, previousHashes);
|
|
196
|
-
console.log('\n🔍 Change Detection:');
|
|
197
|
-
if (changed.length > 0) {
|
|
198
|
-
console.log(chalk_1.default.yellow(` Changed files: ${changed.length}`));
|
|
199
|
-
changed.forEach(f => console.log(chalk_1.default.yellow(` ↳ ${f}`)));
|
|
200
|
-
}
|
|
201
116
|
if (deleted.length > 0) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
// Remove TS files for deleted C# files
|
|
206
|
-
for (const deletedFile of deleted) {
|
|
207
|
-
removeCorrespondingTsFile(config, deletedFile);
|
|
117
|
+
for (const deletedFile of deleted) {
|
|
118
|
+
removeCorrespondingTsFile(config, deletedFile);
|
|
119
|
+
}
|
|
208
120
|
}
|
|
209
|
-
// Save current hashes for next run
|
|
210
121
|
const currentHashes = new Map();
|
|
211
122
|
for (const file of csharpFiles) {
|
|
212
123
|
currentHashes.set(file, computeFileHash(file));
|
|
213
124
|
}
|
|
214
125
|
savePreviousHashes(currentHashes);
|
|
126
|
+
return new Set(changed);
|
|
215
127
|
}
|
|
216
128
|
/**
|
|
217
129
|
* Deletes all contents of a directory but keeps the directory itself.
|
|
218
130
|
* @param dir Path to the directory to clean
|
|
219
131
|
*/
|
|
220
|
-
function cleanOutputDirectory(dir) {
|
|
132
|
+
export function cleanOutputDirectory(dir) {
|
|
221
133
|
if (!fs.existsSync(dir))
|
|
222
134
|
return;
|
|
223
135
|
const entries = fs.readdirSync(dir);
|
|
224
|
-
console.log('\
|
|
225
|
-
for (const entry of entries) {
|
|
136
|
+
console.log(chalk.cyan('\n⧖ Clearing output directory:'));
|
|
137
|
+
for (const [index, entry] of entries.entries()) {
|
|
226
138
|
const fullPath = path.join(dir, entry);
|
|
227
|
-
|
|
139
|
+
const isLast = index === entries.length - 1;
|
|
140
|
+
const tree = chalk.gray(isLast ? '└──' : '├──');
|
|
141
|
+
console.log(tree, chalk.red('deleted'), chalk.gray(`${chalk.strikethrough(fullPath)}`));
|
|
228
142
|
const stat = fs.lstatSync(fullPath);
|
|
229
143
|
if (stat.isDirectory()) {
|
|
230
144
|
fs.rmSync(fullPath, { recursive: true, force: true });
|
|
@@ -248,17 +162,17 @@ function removeCorrespondingTsFile(config, csharpFilePath) {
|
|
|
248
162
|
if (config.fileSuffix) {
|
|
249
163
|
baseName = `${baseName}${config.fileSuffix}`;
|
|
250
164
|
}
|
|
251
|
-
const tsFileName =
|
|
165
|
+
const tsFileName = convertFileName(baseName, fileConvention) + '.ts';
|
|
252
166
|
const tsFilePath = path.join(outputPath, path.dirname(relativePath), tsFileName);
|
|
253
167
|
if (fs.existsSync(tsFilePath)) {
|
|
254
168
|
fs.unlinkSync(tsFilePath);
|
|
255
|
-
console.log(
|
|
169
|
+
console.log(chalk.red(` Removed: ${tsFilePath}`));
|
|
256
170
|
}
|
|
257
171
|
}
|
|
258
172
|
/**
|
|
259
173
|
* Load configuration from file or use provided config
|
|
260
174
|
*/
|
|
261
|
-
async function loadConfig(configPath) {
|
|
175
|
+
export async function loadConfig(configPath) {
|
|
262
176
|
if (configPath && fs.existsSync(configPath)) {
|
|
263
177
|
return await loadConfigFromFile(configPath);
|
|
264
178
|
}
|
|
@@ -275,35 +189,4 @@ async function loadConfig(configPath) {
|
|
|
275
189
|
}
|
|
276
190
|
throw new Error('No configuration file found. Please create typesharp.config.ts, typesharp.config.js, or typesharp.config.json');
|
|
277
191
|
}
|
|
278
|
-
/**
|
|
279
|
-
* Validate configuration
|
|
280
|
-
*/
|
|
281
|
-
function validateConfig(config) {
|
|
282
|
-
// Convert single project to array for unified handling
|
|
283
|
-
const projectFiles = (0, resolve_project_files_from_source_1.resolveProjectFilesFromSource)(config.source);
|
|
284
|
-
// Validate each project file
|
|
285
|
-
for (const projectFile of projectFiles) {
|
|
286
|
-
if (!fs.existsSync(projectFile)) {
|
|
287
|
-
throw new Error(`Project file does not exist: ${projectFile}`);
|
|
288
|
-
}
|
|
289
|
-
const stats = fs.statSync(projectFile);
|
|
290
|
-
if (!stats.isFile()) {
|
|
291
|
-
throw new Error(`Target path is not a file: ${projectFile}`);
|
|
292
|
-
}
|
|
293
|
-
if (!projectFile.endsWith('.csproj')) {
|
|
294
|
-
throw new Error(`Target file is not a .csproj: ${projectFile}`);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Optional fields sanitization
|
|
299
|
-
*/
|
|
300
|
-
if (config.targetAnnotation) {
|
|
301
|
-
const original = config.targetAnnotation;
|
|
302
|
-
// Remove spaces, [ and ]
|
|
303
|
-
config.targetAnnotation = config.targetAnnotation.replace(/[ \[\]]/g, '');
|
|
304
|
-
if (config.targetAnnotation !== original) {
|
|
305
|
-
console.warn(chalk_1.default.yellow.bold('❗ Warning:'), chalk_1.default.white(`remove invalid characters (space, [ or ]) from your`), chalk_1.default.bold('targetAnnotation'), `\n`);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
192
|
//# sourceMappingURL=index.js.map
|
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OA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CAAC;IACxB,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QACtB,QAAQ,GAAG,GAAG,QAAQ,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;IAC/C,CAAC;IAED,MAAM,UAAU,GAAG,eAAe,CAAC,QAAQ,EAAE,cAAc,CAAC,GAAG,KAAK,CAAC;IACrE,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,UAAU,CAAC,CAAC;IAEjF,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAC1B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,cAAc,UAAU,EAAE,CAAC,CAAC,CAAC;IACrD,CAAC;AACH,CAAC;AAOD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,UAAmB;IAClD,IAAI,UAAU,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC5C,OAAO,MAAM,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAC9C,CAAC;IAED,gCAAgC;IAChC,MAAM,YAAY,GAAG;QACnB,qBAAqB;QACrB,qBAAqB;QACrB,uBAAuB;KACxB,CAAC;IAEF,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;QACvC,IAAI,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;YAC/B,OAAO,MAAM,kBAAkB,CAAC,WAAW,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;IAED,MAAM,IAAI,KAAK,CACb,+GAA+G,CAChH,CAAC;AACJ,CAAC"}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { NamingConvention } from '../types';
|
|
2
|
-
import type { ParseResult, TypeSharpConfig } from '../types';
|
|
1
|
+
import { NamingConvention } from '../types/index.js';
|
|
2
|
+
import type { ParseResult, TypeSharpConfig } from '../types/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Generate TypeScript files from parsed C# classes
|
|
5
5
|
*/
|
|
6
|
-
export declare function generateTypeScriptFiles(config: TypeSharpConfig, parseResults: ParseResult[]):
|
|
6
|
+
export declare function generateTypeScriptFiles(config: TypeSharpConfig, parseResults: ParseResult[], changedFiles?: Set<string>): {
|
|
7
|
+
created: number;
|
|
8
|
+
updated: number;
|
|
9
|
+
total: number;
|
|
10
|
+
};
|
|
7
11
|
/**
|
|
8
12
|
* Convert file name to specified convention
|
|
9
13
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAA+B,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAA+B,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAClF,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGtE;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,eAAe,EACvB,YAAY,EAAE,WAAW,EAAE,EAC3B,YAAY,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GACzB;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAarD;AAuZD;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,gBAAgB,GAAG,MAAM,CAalF"}
|
package/dist/generator/index.js
CHANGED
|
@@ -1,61 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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.generateTypeScriptFiles = generateTypeScriptFiles;
|
|
40
|
-
exports.convertFileName = convertFileName;
|
|
41
|
-
const fs = __importStar(require("fs"));
|
|
42
|
-
const path = __importStar(require("path"));
|
|
43
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import chalk from 'chalk';
|
|
44
4
|
/**
|
|
45
5
|
* Generate TypeScript files from parsed C# classes
|
|
46
6
|
*/
|
|
47
|
-
function generateTypeScriptFiles(config, parseResults) {
|
|
7
|
+
export function generateTypeScriptFiles(config, parseResults, changedFiles) {
|
|
48
8
|
const outputPath = config.outputPath;
|
|
49
9
|
if (!fs.existsSync(outputPath)) {
|
|
50
10
|
fs.mkdirSync(outputPath, { recursive: true });
|
|
51
11
|
}
|
|
52
12
|
if (config.singleOutputFile) {
|
|
53
13
|
const allClasses = parseResults.flatMap(r => r.classes);
|
|
54
|
-
generateSingleFile(allClasses, outputPath);
|
|
14
|
+
return generateSingleFile(allClasses, outputPath);
|
|
55
15
|
}
|
|
56
16
|
else {
|
|
57
|
-
|
|
58
|
-
generateMultipleFiles(outputPath, config, parseResults);
|
|
17
|
+
return generateMultipleFiles(outputPath, config, parseResults, changedFiles);
|
|
59
18
|
}
|
|
60
19
|
}
|
|
61
20
|
/**
|
|
@@ -70,25 +29,44 @@ function generateSingleFile(classes, outputPath) {
|
|
|
70
29
|
const fullContent = `${header}\n\n${content}\n`;
|
|
71
30
|
const fileName = 'types.ts';
|
|
72
31
|
const filePath = path.join(outputPath, fileName);
|
|
32
|
+
const isNewFile = !fs.existsSync(filePath);
|
|
73
33
|
fs.writeFileSync(filePath, fullContent, 'utf-8');
|
|
74
|
-
|
|
34
|
+
const status = isNewFile ? chalk.cyan('Created') : chalk.green('Updated');
|
|
35
|
+
console.log(chalk.blue(` ↳`), status + ':', chalk.blue(filePath));
|
|
36
|
+
return {
|
|
37
|
+
created: isNewFile ? 1 : 0,
|
|
38
|
+
updated: !isNewFile ? 1 : 0,
|
|
39
|
+
total: 1
|
|
40
|
+
};
|
|
75
41
|
}
|
|
76
42
|
/**
|
|
77
43
|
* Generate multiple files - with incremental writing
|
|
78
44
|
* This preserves the original grouping of classes
|
|
79
45
|
*/
|
|
80
|
-
function generateMultipleFiles(outputPath, config, parseResults) {
|
|
46
|
+
function generateMultipleFiles(outputPath, config, parseResults, changedFiles) {
|
|
81
47
|
const dirConvention = typeof config.namingConvention === 'string' ? config.namingConvention : config.namingConvention?.dir ?? 'snake';
|
|
82
48
|
const fileConvention = typeof config.namingConvention === 'string' ? config.namingConvention : config.namingConvention?.file ?? 'camel';
|
|
83
49
|
const classToFileMap = buildClassToFileMap(parseResults, config, outputPath, fileConvention);
|
|
84
50
|
const parseResultsSorted = parseResults.sort((a, b) => a.relativePath.localeCompare(b.relativePath));
|
|
51
|
+
let createdCount = 0;
|
|
52
|
+
let updatedCount = 0;
|
|
53
|
+
const total = parseResultsSorted.length;
|
|
54
|
+
let fileIndex = 0;
|
|
55
|
+
console.log(chalk.cyan('\n⧖ Generating TypeScript files...'));
|
|
85
56
|
for (const result of parseResultsSorted) {
|
|
57
|
+
// Skip if this C# file hasn't changed
|
|
58
|
+
if (changedFiles && !changedFiles.has(result.filePath)) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
86
61
|
const content = result.classes.map(cls => generateTypeScriptClass(cls)).join('\n\n');
|
|
87
62
|
const relativeDir = path.dirname(result.relativePath);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (
|
|
91
|
-
|
|
63
|
+
let appDir = path.join(outputPath, relativeDir);
|
|
64
|
+
// Only convert naming convention for the relative path part, not the base outputPath
|
|
65
|
+
if (relativeDir !== '.') {
|
|
66
|
+
appDir = path.join(outputPath, convertDirName(relativeDir, dirConvention));
|
|
67
|
+
}
|
|
68
|
+
if (!fs.existsSync(appDir)) {
|
|
69
|
+
fs.mkdirSync(appDir, { recursive: true });
|
|
92
70
|
}
|
|
93
71
|
const originalFileName = path.basename(result.relativePath, '.cs');
|
|
94
72
|
let baseName = originalFileName;
|
|
@@ -97,22 +75,38 @@ function generateMultipleFiles(outputPath, config, parseResults) {
|
|
|
97
75
|
baseName = `${baseName}${suffix}`;
|
|
98
76
|
}
|
|
99
77
|
const fileName = convertFileName(baseName, fileConvention);
|
|
100
|
-
const filePath = path.join(
|
|
78
|
+
const filePath = path.join(appDir, `${fileName}.ts`);
|
|
101
79
|
const currentClassNames = result.classes.map(c => c.name);
|
|
102
80
|
const imports = generateImports(result.classes, classToFileMap, filePath, currentClassNames, dirConvention);
|
|
103
81
|
const header = generateFileHeader();
|
|
104
82
|
const fullContent = imports
|
|
105
83
|
? `${imports}\n\n${header}\n\n${content}\n`
|
|
106
84
|
: `${header}\n\n${content}\n`;
|
|
107
|
-
//
|
|
108
|
-
|
|
85
|
+
// Check if file is new or updated
|
|
86
|
+
const isNewFile = !fs.existsSync(filePath);
|
|
87
|
+
// Only write if content changed or file is new
|
|
88
|
+
if (isNewFile || shouldWriteFile(filePath, fullContent)) {
|
|
109
89
|
fs.writeFileSync(filePath, fullContent, 'utf-8');
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
90
|
+
fileIndex++;
|
|
91
|
+
const isLast = fileIndex === total;
|
|
92
|
+
const tree = chalk.gray(isLast ? '└──' : '├──');
|
|
93
|
+
if (isNewFile) {
|
|
94
|
+
createdCount++;
|
|
95
|
+
console.log(tree, chalk.cyan('created'), chalk.blue(filePath));
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
updatedCount++;
|
|
99
|
+
console.log(tree, chalk.yellow('updated'), chalk.blue(filePath));
|
|
100
|
+
}
|
|
114
101
|
}
|
|
115
102
|
}
|
|
103
|
+
// Return metrics to be logged at the end
|
|
104
|
+
const totalFiles = createdCount + updatedCount;
|
|
105
|
+
return {
|
|
106
|
+
created: createdCount,
|
|
107
|
+
updated: updatedCount,
|
|
108
|
+
total: totalFiles
|
|
109
|
+
};
|
|
116
110
|
}
|
|
117
111
|
/**
|
|
118
112
|
* Check if file content changed before writing
|
|
@@ -131,7 +125,11 @@ function buildClassToFileMap(parseResults, config, outputPath, namingConvension)
|
|
|
131
125
|
const map = new Map();
|
|
132
126
|
for (const result of parseResults) {
|
|
133
127
|
const relativeDir = path.dirname(result.relativePath);
|
|
134
|
-
|
|
128
|
+
let targetDir = path.join(outputPath, relativeDir);
|
|
129
|
+
// Only convert naming convention for the relative path part, not the base outputPath
|
|
130
|
+
if (relativeDir !== '.') {
|
|
131
|
+
targetDir = path.join(outputPath, convertDirName(relativeDir, namingConvension));
|
|
132
|
+
}
|
|
135
133
|
const originalFileName = path.basename(result.relativePath, '.cs');
|
|
136
134
|
let baseName = originalFileName;
|
|
137
135
|
if (config.fileSuffix) {
|
|
@@ -169,7 +167,7 @@ function generateImports(classes, classToFileMap, currentFilePath, currentClassN
|
|
|
169
167
|
// Check property types
|
|
170
168
|
for (const prop of cls.properties) {
|
|
171
169
|
// Extract base type (remove array brackets and nullable)
|
|
172
|
-
|
|
170
|
+
const referencedType = prop.type;
|
|
173
171
|
// Skip primitive types
|
|
174
172
|
if (isPrimitiveType(referencedType))
|
|
175
173
|
continue;
|
|
@@ -299,7 +297,7 @@ function convertPropertyName(name) {
|
|
|
299
297
|
/**
|
|
300
298
|
* Convert file name to specified convention
|
|
301
299
|
*/
|
|
302
|
-
function convertFileName(name, convention) {
|
|
300
|
+
export function convertFileName(name, convention) {
|
|
303
301
|
switch (convention) {
|
|
304
302
|
case 'camel':
|
|
305
303
|
return toCamelCase(name);
|
|
@@ -363,10 +361,8 @@ function toKebabCase(str) {
|
|
|
363
361
|
* Generate file header comment
|
|
364
362
|
*/
|
|
365
363
|
function generateFileHeader() {
|
|
366
|
-
const timestamp = new Date().toISOString();
|
|
367
364
|
return `/**
|
|
368
365
|
* Auto-generated by TypeSharp
|
|
369
|
-
* Generated at: ${timestamp}
|
|
370
366
|
* Do not edit this file manually
|
|
371
367
|
*/`;
|
|
372
368
|
}
|