@openwebf/webf 0.22.3 → 0.22.5
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/dist/IDLBlob.js +17 -0
- package/dist/analyzer.js +578 -0
- package/dist/analyzer_original.js +467 -0
- package/dist/commands.js +704 -0
- package/dist/dart.js +300 -0
- package/dist/declaration.js +63 -0
- package/dist/generator.js +466 -0
- package/dist/logger.js +103 -0
- package/dist/react.js +283 -0
- package/dist/utils.js +127 -0
- package/dist/vue.js +159 -0
- package/package.json +11 -1
- package/src/dart.ts +138 -7
- package/templates/class.dart.tpl +7 -2
- package/templates/react.package.json.tpl +1 -1
- package/CLAUDE.md +0 -206
- package/README-zhCN.md +0 -256
- package/coverage/clover.xml +0 -1295
- package/coverage/coverage-final.json +0 -12
- package/coverage/lcov-report/IDLBlob.ts.html +0 -142
- package/coverage/lcov-report/analyzer.ts.html +0 -2158
- package/coverage/lcov-report/analyzer_original.ts.html +0 -1450
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/commands.ts.html +0 -700
- package/coverage/lcov-report/dart.ts.html +0 -490
- package/coverage/lcov-report/declaration.ts.html +0 -337
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/generator.ts.html +0 -1171
- package/coverage/lcov-report/index.html +0 -266
- package/coverage/lcov-report/logger.ts.html +0 -424
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/react.ts.html +0 -619
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/utils.ts.html +0 -466
- package/coverage/lcov-report/vue.ts.html +0 -613
- package/coverage/lcov.info +0 -2149
- package/jest.config.js +0 -24
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.dartGen = dartGen;
|
|
16
|
+
exports.reactGen = reactGen;
|
|
17
|
+
exports.vueGen = vueGen;
|
|
18
|
+
exports.clearAllCaches = clearAllCaches;
|
|
19
|
+
const path_1 = __importDefault(require("path"));
|
|
20
|
+
const fs_1 = __importDefault(require("fs"));
|
|
21
|
+
const process_1 = __importDefault(require("process"));
|
|
22
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
23
|
+
const glob_1 = require("glob");
|
|
24
|
+
const yaml_1 = __importDefault(require("yaml"));
|
|
25
|
+
const IDLBlob_1 = require("./IDLBlob");
|
|
26
|
+
const declaration_1 = require("./declaration");
|
|
27
|
+
const analyzer_1 = require("./analyzer");
|
|
28
|
+
const dart_1 = require("./dart");
|
|
29
|
+
const react_1 = require("./react");
|
|
30
|
+
const vue_1 = require("./vue");
|
|
31
|
+
const logger_1 = require("./logger");
|
|
32
|
+
// Cache for file content to avoid redundant reads
|
|
33
|
+
const fileContentCache = new Map();
|
|
34
|
+
// Cache for generated content to detect changes
|
|
35
|
+
const generatedContentCache = new Map();
|
|
36
|
+
function writeFileIfChanged(filePath, content) {
|
|
37
|
+
// Check if content has changed by comparing with cache
|
|
38
|
+
const cachedContent = generatedContentCache.get(filePath);
|
|
39
|
+
if (cachedContent === content) {
|
|
40
|
+
return false; // No change
|
|
41
|
+
}
|
|
42
|
+
// Check if file exists and has same content
|
|
43
|
+
if (fs_1.default.existsSync(filePath)) {
|
|
44
|
+
const existingContent = fileContentCache.get(filePath) || fs_1.default.readFileSync(filePath, 'utf-8');
|
|
45
|
+
fileContentCache.set(filePath, existingContent);
|
|
46
|
+
if (existingContent === content) {
|
|
47
|
+
generatedContentCache.set(filePath, content);
|
|
48
|
+
return false; // No change
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Create directory if it doesn't exist
|
|
52
|
+
const dir = path_1.default.dirname(filePath);
|
|
53
|
+
if (!fs_1.default.existsSync(dir)) {
|
|
54
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
55
|
+
}
|
|
56
|
+
// Write file and update caches
|
|
57
|
+
fs_1.default.writeFileSync(filePath, content, 'utf-8');
|
|
58
|
+
fileContentCache.set(filePath, content);
|
|
59
|
+
generatedContentCache.set(filePath, content);
|
|
60
|
+
return true; // File was changed
|
|
61
|
+
}
|
|
62
|
+
class DefinedPropertyCollector {
|
|
63
|
+
constructor() {
|
|
64
|
+
this.properties = new Set();
|
|
65
|
+
this.files = new Set();
|
|
66
|
+
this.interfaces = new Set();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
class UnionTypeCollector {
|
|
70
|
+
constructor() {
|
|
71
|
+
this.types = new Set();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Batch processing for file operations
|
|
75
|
+
function processFilesInBatch(items, batchSize, processor) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
for (let i = 0; i < items.length; i += batchSize) {
|
|
78
|
+
const batch = items.slice(i, i + batchSize);
|
|
79
|
+
yield Promise.all(batch.map(item => processor(item)));
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function validatePaths(source, target) {
|
|
84
|
+
if (!source) {
|
|
85
|
+
throw new Error('Source path is required');
|
|
86
|
+
}
|
|
87
|
+
if (!target) {
|
|
88
|
+
throw new Error('Target path is required');
|
|
89
|
+
}
|
|
90
|
+
// Normalize paths
|
|
91
|
+
const normalizedSource = path_1.default.isAbsolute(source) ? source : path_1.default.join(process_1.default.cwd(), source);
|
|
92
|
+
const normalizedTarget = path_1.default.isAbsolute(target) ? target : path_1.default.join(process_1.default.cwd(), target);
|
|
93
|
+
// Validate source exists
|
|
94
|
+
if (!fs_1.default.existsSync(normalizedSource)) {
|
|
95
|
+
throw new Error(`Source path does not exist: ${normalizedSource}`);
|
|
96
|
+
}
|
|
97
|
+
return { source: normalizedSource, target: normalizedTarget };
|
|
98
|
+
}
|
|
99
|
+
function getTypeFiles(source, excludePatterns) {
|
|
100
|
+
try {
|
|
101
|
+
const defaultIgnore = ['**/node_modules/**', '**/dist/**', '**/build/**', '**/example/**'];
|
|
102
|
+
const ignore = excludePatterns ? [...defaultIgnore, ...excludePatterns] : defaultIgnore;
|
|
103
|
+
const files = glob_1.glob.globSync("**/*.d.ts", {
|
|
104
|
+
cwd: source,
|
|
105
|
+
ignore: ignore
|
|
106
|
+
});
|
|
107
|
+
return files.filter(file => !file.includes('global.d.ts'));
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
(0, logger_1.error)(`Error scanning for type files in ${source}`, err);
|
|
111
|
+
throw new Error(`Failed to scan type files: ${err instanceof Error ? err.message : String(err)}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function createBlobs(typeFiles, source, target) {
|
|
115
|
+
return typeFiles.map(file => {
|
|
116
|
+
const filename = path_1.default.basename(file, '.d.ts');
|
|
117
|
+
const implement = file.replace(path_1.default.join(__dirname, '../../'), '').replace('.d.ts', '');
|
|
118
|
+
// Store the relative directory path for maintaining structure
|
|
119
|
+
const relativeDir = path_1.default.dirname(file);
|
|
120
|
+
const blob = new IDLBlob_1.IDLBlob(path_1.default.join(source, file), target, filename, implement, relativeDir);
|
|
121
|
+
// Pre-cache file content
|
|
122
|
+
if (!fileContentCache.has(blob.source)) {
|
|
123
|
+
try {
|
|
124
|
+
const content = fs_1.default.readFileSync(blob.source, 'utf-8');
|
|
125
|
+
fileContentCache.set(blob.source, content);
|
|
126
|
+
blob.raw = content;
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
(0, logger_1.error)(`Error reading file ${blob.source}`, err);
|
|
130
|
+
throw err;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
blob.raw = fileContentCache.get(blob.source);
|
|
135
|
+
}
|
|
136
|
+
return blob;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function dartGen(_a) {
|
|
140
|
+
return __awaiter(this, arguments, void 0, function* ({ source, target, command, exclude }) {
|
|
141
|
+
(0, logger_1.group)('Dart Code Generation');
|
|
142
|
+
(0, logger_1.time)('dartGen');
|
|
143
|
+
const { source: normalizedSource, target: normalizedTarget } = validatePaths(source, target);
|
|
144
|
+
const definedPropertyCollector = new DefinedPropertyCollector();
|
|
145
|
+
const unionTypeCollector = new UnionTypeCollector();
|
|
146
|
+
// Clear analyzer caches for fresh run
|
|
147
|
+
if (typeof analyzer_1.clearCaches === 'function') {
|
|
148
|
+
(0, analyzer_1.clearCaches)();
|
|
149
|
+
}
|
|
150
|
+
// Get type files
|
|
151
|
+
const typeFiles = getTypeFiles(normalizedSource, exclude);
|
|
152
|
+
(0, logger_1.info)(`Found ${typeFiles.length} type definition files`);
|
|
153
|
+
if (typeFiles.length === 0) {
|
|
154
|
+
(0, logger_1.warn)('No type definition files found');
|
|
155
|
+
(0, logger_1.timeEnd)('dartGen');
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
// Create blobs
|
|
159
|
+
const blobs = createBlobs(typeFiles, normalizedSource, normalizedTarget);
|
|
160
|
+
// Reset global class map
|
|
161
|
+
declaration_1.ClassObject.globalClassMap = Object.create(null);
|
|
162
|
+
// Analyze all files first
|
|
163
|
+
(0, logger_1.info)('Analyzing type definitions...');
|
|
164
|
+
let analyzed = 0;
|
|
165
|
+
for (const blob of blobs) {
|
|
166
|
+
try {
|
|
167
|
+
(0, analyzer_1.analyzer)(blob, definedPropertyCollector, unionTypeCollector);
|
|
168
|
+
analyzed++;
|
|
169
|
+
(0, logger_1.progress)(analyzed, blobs.length, `Analyzing ${blob.filename}`);
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
(0, logger_1.error)(`Error analyzing ${blob.filename}`, err);
|
|
173
|
+
// Continue with other files
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
// Generate Dart code and copy .d.ts files
|
|
177
|
+
(0, logger_1.info)('\nGenerating Dart classes...');
|
|
178
|
+
let filesChanged = 0;
|
|
179
|
+
yield processFilesInBatch(blobs, 5, (blob) => __awaiter(this, void 0, void 0, function* () {
|
|
180
|
+
try {
|
|
181
|
+
const result = (0, dart_1.generateDartClass)(blob, command);
|
|
182
|
+
blob.dist = normalizedTarget;
|
|
183
|
+
// Maintain the same directory structure as the .d.ts file
|
|
184
|
+
const outputDir = path_1.default.join(blob.dist, blob.relativeDir);
|
|
185
|
+
// Ensure the directory exists
|
|
186
|
+
if (!fs_1.default.existsSync(outputDir)) {
|
|
187
|
+
fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
188
|
+
}
|
|
189
|
+
// Generate Dart file
|
|
190
|
+
const genFilePath = path_1.default.join(outputDir, lodash_1.default.snakeCase(blob.filename));
|
|
191
|
+
const fullPath = genFilePath + '_bindings_generated.dart';
|
|
192
|
+
if (writeFileIfChanged(fullPath, result)) {
|
|
193
|
+
filesChanged++;
|
|
194
|
+
(0, logger_1.debug)(`Generated: ${path_1.default.basename(fullPath)}`);
|
|
195
|
+
}
|
|
196
|
+
// Copy the original .d.ts file to the output directory
|
|
197
|
+
const dtsOutputPath = path_1.default.join(outputDir, blob.filename + '.d.ts');
|
|
198
|
+
if (writeFileIfChanged(dtsOutputPath, blob.raw)) {
|
|
199
|
+
filesChanged++;
|
|
200
|
+
(0, logger_1.debug)(`Copied: ${path_1.default.basename(dtsOutputPath)}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
catch (err) {
|
|
204
|
+
(0, logger_1.error)(`Error generating Dart code for ${blob.filename}`, err);
|
|
205
|
+
}
|
|
206
|
+
}));
|
|
207
|
+
// Generate index.d.ts file with references to all .d.ts files
|
|
208
|
+
const indexDtsContent = generateTypeScriptIndex(blobs, normalizedTarget);
|
|
209
|
+
const indexDtsPath = path_1.default.join(normalizedTarget, 'index.d.ts');
|
|
210
|
+
if (writeFileIfChanged(indexDtsPath, indexDtsContent)) {
|
|
211
|
+
filesChanged++;
|
|
212
|
+
(0, logger_1.debug)('Generated: index.d.ts');
|
|
213
|
+
}
|
|
214
|
+
(0, logger_1.timeEnd)('dartGen');
|
|
215
|
+
(0, logger_1.success)(`Dart code generation completed. ${filesChanged} files changed.`);
|
|
216
|
+
(0, logger_1.info)(`Output directory: ${normalizedTarget}`);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
function reactGen(_a) {
|
|
220
|
+
return __awaiter(this, arguments, void 0, function* ({ source, target, exclude, packageName }) {
|
|
221
|
+
(0, logger_1.group)('React Code Generation');
|
|
222
|
+
(0, logger_1.time)('reactGen');
|
|
223
|
+
const { source: normalizedSource, target: normalizedTarget } = validatePaths(source, target);
|
|
224
|
+
const definedPropertyCollector = new DefinedPropertyCollector();
|
|
225
|
+
const unionTypeCollector = new UnionTypeCollector();
|
|
226
|
+
// Clear analyzer caches for fresh run
|
|
227
|
+
if (typeof analyzer_1.clearCaches === 'function') {
|
|
228
|
+
(0, analyzer_1.clearCaches)();
|
|
229
|
+
}
|
|
230
|
+
// Get type files
|
|
231
|
+
const typeFiles = getTypeFiles(normalizedSource, exclude);
|
|
232
|
+
(0, logger_1.info)(`Found ${typeFiles.length} type definition files`);
|
|
233
|
+
if (typeFiles.length === 0) {
|
|
234
|
+
(0, logger_1.warn)('No type definition files found');
|
|
235
|
+
(0, logger_1.timeEnd)('reactGen');
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
// Create blobs
|
|
239
|
+
const blobs = createBlobs(typeFiles, normalizedSource, normalizedTarget);
|
|
240
|
+
// Reset global class map
|
|
241
|
+
declaration_1.ClassObject.globalClassMap = Object.create(null);
|
|
242
|
+
// Analyze all files first
|
|
243
|
+
(0, logger_1.info)('Analyzing type definitions...');
|
|
244
|
+
let analyzed = 0;
|
|
245
|
+
for (const blob of blobs) {
|
|
246
|
+
try {
|
|
247
|
+
(0, analyzer_1.analyzer)(blob, definedPropertyCollector, unionTypeCollector);
|
|
248
|
+
analyzed++;
|
|
249
|
+
(0, logger_1.progress)(analyzed, blobs.length, `Analyzing ${blob.filename}`);
|
|
250
|
+
}
|
|
251
|
+
catch (err) {
|
|
252
|
+
(0, logger_1.error)(`Error analyzing ${blob.filename}`, err);
|
|
253
|
+
// Continue with other files
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// Ensure src directory exists
|
|
257
|
+
const srcDir = path_1.default.join(normalizedTarget, 'src');
|
|
258
|
+
if (!fs_1.default.existsSync(srcDir)) {
|
|
259
|
+
fs_1.default.mkdirSync(srcDir, { recursive: true });
|
|
260
|
+
}
|
|
261
|
+
// Generate React components
|
|
262
|
+
(0, logger_1.info)('\nGenerating React components...');
|
|
263
|
+
let filesChanged = 0;
|
|
264
|
+
yield processFilesInBatch(blobs, 5, (blob) => __awaiter(this, void 0, void 0, function* () {
|
|
265
|
+
try {
|
|
266
|
+
const result = (0, react_1.generateReactComponent)(blob, packageName, blob.relativeDir);
|
|
267
|
+
// Skip if no content was generated
|
|
268
|
+
if (!result || result.trim().length === 0) {
|
|
269
|
+
(0, logger_1.debug)(`Skipped ${blob.filename} - no components found`);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
// Maintain the same directory structure as the .d.ts file
|
|
273
|
+
// Always put files under src/ directory
|
|
274
|
+
const outputDir = path_1.default.join(normalizedTarget, 'src', blob.relativeDir);
|
|
275
|
+
// Ensure the directory exists
|
|
276
|
+
if (!fs_1.default.existsSync(outputDir)) {
|
|
277
|
+
fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
278
|
+
}
|
|
279
|
+
const genFilePath = path_1.default.join(outputDir, blob.filename);
|
|
280
|
+
const fullPath = genFilePath + '.tsx';
|
|
281
|
+
if (writeFileIfChanged(fullPath, result)) {
|
|
282
|
+
filesChanged++;
|
|
283
|
+
(0, logger_1.debug)(`Generated: ${path_1.default.basename(fullPath)}`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
catch (err) {
|
|
287
|
+
(0, logger_1.error)(`Error generating React component for ${blob.filename}`, err);
|
|
288
|
+
}
|
|
289
|
+
}));
|
|
290
|
+
// Generate or update index file
|
|
291
|
+
const indexFilePath = path_1.default.join(normalizedTarget, 'src', 'index.ts');
|
|
292
|
+
const newExports = (0, react_1.generateReactIndex)(blobs);
|
|
293
|
+
if (fs_1.default.existsSync(indexFilePath)) {
|
|
294
|
+
// Read existing index file
|
|
295
|
+
const existingContent = fs_1.default.readFileSync(indexFilePath, 'utf-8');
|
|
296
|
+
const existingLines = existingContent.split('\n');
|
|
297
|
+
// Parse new exports
|
|
298
|
+
const newExportLines = newExports.split('\n').filter(line => line.startsWith('export '));
|
|
299
|
+
// Find which exports are missing
|
|
300
|
+
const missingExports = [];
|
|
301
|
+
for (const newExport of newExportLines) {
|
|
302
|
+
// Extract the export statement to check if it exists
|
|
303
|
+
const exportMatch = newExport.match(/export\s*{\s*([^}]+)\s*}\s*from\s*["']([^"']+)["']/);
|
|
304
|
+
if (exportMatch) {
|
|
305
|
+
const [, exportNames, modulePath] = exportMatch;
|
|
306
|
+
const exportedItems = exportNames.split(',').map(s => s.trim());
|
|
307
|
+
// Check if this exact export exists
|
|
308
|
+
const exists = existingLines.some(line => {
|
|
309
|
+
if (!line.startsWith('export '))
|
|
310
|
+
return false;
|
|
311
|
+
const lineMatch = line.match(/export\s*{\s*([^}]+)\s*}\s*from\s*["']([^"']+)["']/);
|
|
312
|
+
if (!lineMatch)
|
|
313
|
+
return false;
|
|
314
|
+
const [, lineExportNames, lineModulePath] = lineMatch;
|
|
315
|
+
const lineExportedItems = lineExportNames.split(',').map(s => s.trim());
|
|
316
|
+
// Check if same module and same exports
|
|
317
|
+
return lineModulePath === modulePath &&
|
|
318
|
+
exportedItems.every(item => lineExportedItems.includes(item)) &&
|
|
319
|
+
lineExportedItems.every(item => exportedItems.includes(item));
|
|
320
|
+
});
|
|
321
|
+
if (!exists) {
|
|
322
|
+
missingExports.push(newExport);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
// If there are missing exports, append them
|
|
327
|
+
if (missingExports.length > 0) {
|
|
328
|
+
let updatedContent = existingContent.trimRight();
|
|
329
|
+
if (!updatedContent.endsWith('\n')) {
|
|
330
|
+
updatedContent += '\n';
|
|
331
|
+
}
|
|
332
|
+
updatedContent += missingExports.join('\n') + '\n';
|
|
333
|
+
if (writeFileIfChanged(indexFilePath, updatedContent)) {
|
|
334
|
+
filesChanged++;
|
|
335
|
+
(0, logger_1.debug)(`Updated: index.ts (added ${missingExports.length} exports)`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
(0, logger_1.debug)(`Skipped: index.ts (all exports already exist)`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
// File doesn't exist, create it
|
|
344
|
+
if (writeFileIfChanged(indexFilePath, newExports)) {
|
|
345
|
+
filesChanged++;
|
|
346
|
+
(0, logger_1.debug)(`Generated: index.ts`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
(0, logger_1.timeEnd)('reactGen');
|
|
350
|
+
(0, logger_1.success)(`React code generation completed. ${filesChanged} files changed.`);
|
|
351
|
+
(0, logger_1.info)(`Output directory: ${normalizedTarget}`);
|
|
352
|
+
(0, logger_1.info)('You can now import these components in your React project.');
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
function vueGen(_a) {
|
|
356
|
+
return __awaiter(this, arguments, void 0, function* ({ source, target, exclude }) {
|
|
357
|
+
(0, logger_1.group)('Vue Typings Generation');
|
|
358
|
+
(0, logger_1.time)('vueGen');
|
|
359
|
+
const { source: normalizedSource, target: normalizedTarget } = validatePaths(source, target);
|
|
360
|
+
const definedPropertyCollector = new DefinedPropertyCollector();
|
|
361
|
+
const unionTypeCollector = new UnionTypeCollector();
|
|
362
|
+
// Clear analyzer caches for fresh run
|
|
363
|
+
if (typeof analyzer_1.clearCaches === 'function') {
|
|
364
|
+
(0, analyzer_1.clearCaches)();
|
|
365
|
+
}
|
|
366
|
+
// Get type files
|
|
367
|
+
const typeFiles = getTypeFiles(normalizedSource, exclude);
|
|
368
|
+
(0, logger_1.info)(`Found ${typeFiles.length} type definition files`);
|
|
369
|
+
if (typeFiles.length === 0) {
|
|
370
|
+
(0, logger_1.warn)('No type definition files found');
|
|
371
|
+
(0, logger_1.timeEnd)('vueGen');
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
// Create blobs
|
|
375
|
+
const blobs = createBlobs(typeFiles, normalizedSource, normalizedTarget);
|
|
376
|
+
// Reset global class map
|
|
377
|
+
declaration_1.ClassObject.globalClassMap = Object.create(null);
|
|
378
|
+
// Analyze all files first
|
|
379
|
+
(0, logger_1.info)('Analyzing type definitions...');
|
|
380
|
+
let analyzed = 0;
|
|
381
|
+
for (const blob of blobs) {
|
|
382
|
+
try {
|
|
383
|
+
(0, analyzer_1.analyzer)(blob, definedPropertyCollector, unionTypeCollector);
|
|
384
|
+
analyzed++;
|
|
385
|
+
(0, logger_1.progress)(analyzed, blobs.length, `Analyzing ${blob.filename}`);
|
|
386
|
+
}
|
|
387
|
+
catch (err) {
|
|
388
|
+
(0, logger_1.error)(`Error analyzing ${blob.filename}`, err);
|
|
389
|
+
// Continue with other files
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
// Generate Vue typings
|
|
393
|
+
(0, logger_1.info)('\nGenerating Vue typings...');
|
|
394
|
+
const typingsContent = (0, vue_1.generateVueTypings)(blobs);
|
|
395
|
+
const typingsFilePath = path_1.default.join(normalizedTarget, 'index.d.ts');
|
|
396
|
+
let filesChanged = 0;
|
|
397
|
+
if (writeFileIfChanged(typingsFilePath, typingsContent)) {
|
|
398
|
+
filesChanged++;
|
|
399
|
+
(0, logger_1.debug)(`Generated: index.d.ts`);
|
|
400
|
+
}
|
|
401
|
+
(0, logger_1.timeEnd)('vueGen');
|
|
402
|
+
(0, logger_1.success)(`Vue typings generation completed. ${filesChanged} files changed.`);
|
|
403
|
+
(0, logger_1.info)(`Output directory: ${normalizedTarget}`);
|
|
404
|
+
(0, logger_1.info)('You can now import these types in your Vue project.');
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
function generateTypeScriptIndex(blobs, targetPath) {
|
|
408
|
+
const references = ['/// <reference path="./global.d.ts" />'];
|
|
409
|
+
const exports = [];
|
|
410
|
+
// Group blobs by directory to maintain structure
|
|
411
|
+
const filesByDir = new Map();
|
|
412
|
+
blobs.forEach(blob => {
|
|
413
|
+
const dir = blob.relativeDir || '.';
|
|
414
|
+
if (!filesByDir.has(dir)) {
|
|
415
|
+
filesByDir.set(dir, []);
|
|
416
|
+
}
|
|
417
|
+
filesByDir.get(dir).push(blob);
|
|
418
|
+
});
|
|
419
|
+
// Sort directories and files for consistent output
|
|
420
|
+
const sortedDirs = Array.from(filesByDir.keys()).sort();
|
|
421
|
+
sortedDirs.forEach(dir => {
|
|
422
|
+
const dirBlobs = filesByDir.get(dir).sort((a, b) => a.filename.localeCompare(b.filename));
|
|
423
|
+
dirBlobs.forEach(blob => {
|
|
424
|
+
const relativePath = dir === '.' ? blob.filename : path_1.default.join(dir, blob.filename);
|
|
425
|
+
references.push(`/// <reference path="./${relativePath}.d.ts" />`);
|
|
426
|
+
exports.push(`export * from './${relativePath}';`);
|
|
427
|
+
});
|
|
428
|
+
});
|
|
429
|
+
// Get package name from pubspec.yaml if available
|
|
430
|
+
let packageName = 'WebF Package';
|
|
431
|
+
let packageDescription = 'TypeScript Definitions';
|
|
432
|
+
try {
|
|
433
|
+
const pubspecPath = path_1.default.join(targetPath, 'pubspec.yaml');
|
|
434
|
+
if (fs_1.default.existsSync(pubspecPath)) {
|
|
435
|
+
const pubspecContent = fs_1.default.readFileSync(pubspecPath, 'utf-8');
|
|
436
|
+
const pubspec = yaml_1.default.parse(pubspecContent);
|
|
437
|
+
if (pubspec.name) {
|
|
438
|
+
packageName = pubspec.name.replace(/_/g, ' ').replace(/\b\w/g, (l) => l.toUpperCase());
|
|
439
|
+
}
|
|
440
|
+
if (pubspec.description) {
|
|
441
|
+
packageDescription = pubspec.description;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
catch (err) {
|
|
446
|
+
// Ignore errors, use defaults
|
|
447
|
+
}
|
|
448
|
+
return `${references.join('\n')}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* ${packageName} - TypeScript Definitions
|
|
452
|
+
*
|
|
453
|
+
* ${packageDescription}
|
|
454
|
+
*/
|
|
455
|
+
|
|
456
|
+
${exports.join('\n')}
|
|
457
|
+
`;
|
|
458
|
+
}
|
|
459
|
+
// Clear all caches (useful for watch mode or between runs)
|
|
460
|
+
function clearAllCaches() {
|
|
461
|
+
fileContentCache.clear();
|
|
462
|
+
generatedContentCache.clear();
|
|
463
|
+
if (typeof analyzer_1.clearCaches === 'function') {
|
|
464
|
+
(0, analyzer_1.clearCaches)(); // Clear analyzer caches
|
|
465
|
+
}
|
|
466
|
+
}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Simplified logger without chalk dependency for now
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.timeEnd = exports.time = exports.progress = exports.group = exports.error = exports.warn = exports.success = exports.info = exports.debug = exports.logger = exports.LogLevel = void 0;
|
|
5
|
+
var LogLevel;
|
|
6
|
+
(function (LogLevel) {
|
|
7
|
+
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
|
|
8
|
+
LogLevel[LogLevel["INFO"] = 1] = "INFO";
|
|
9
|
+
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
10
|
+
LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
|
|
11
|
+
LogLevel[LogLevel["SILENT"] = 4] = "SILENT";
|
|
12
|
+
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
13
|
+
class Logger {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.logLevel = LogLevel.INFO;
|
|
16
|
+
this.debugMode = false;
|
|
17
|
+
// Check for debug environment variable
|
|
18
|
+
this.debugMode = process.env.WEBF_DEBUG === 'true' || process.env.DEBUG === 'true';
|
|
19
|
+
if (this.debugMode) {
|
|
20
|
+
this.logLevel = LogLevel.DEBUG;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
setLogLevel(level) {
|
|
24
|
+
this.logLevel = level;
|
|
25
|
+
}
|
|
26
|
+
debug(message, ...args) {
|
|
27
|
+
if (this.logLevel <= LogLevel.DEBUG) {
|
|
28
|
+
console.log(`[DEBUG] ${message}`, ...args);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
info(message, ...args) {
|
|
32
|
+
if (this.logLevel <= LogLevel.INFO) {
|
|
33
|
+
console.log(`ℹ ${message}`, ...args);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
success(message, ...args) {
|
|
37
|
+
if (this.logLevel <= LogLevel.INFO) {
|
|
38
|
+
console.log(`✓ ${message}`, ...args);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
warn(message, ...args) {
|
|
42
|
+
if (this.logLevel <= LogLevel.WARN) {
|
|
43
|
+
console.warn(`⚠ ${message}`, ...args);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
error(message, error) {
|
|
47
|
+
if (this.logLevel <= LogLevel.ERROR) {
|
|
48
|
+
console.error(`✗ ${message}`);
|
|
49
|
+
if (error) {
|
|
50
|
+
if (error instanceof Error) {
|
|
51
|
+
console.error(error.stack || error.message);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
console.error(String(error));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
group(title) {
|
|
60
|
+
if (this.logLevel <= LogLevel.INFO) {
|
|
61
|
+
console.log(`\n${title}`);
|
|
62
|
+
console.log('─'.repeat(title.length));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
progress(current, total, message) {
|
|
66
|
+
if (this.logLevel <= LogLevel.INFO) {
|
|
67
|
+
const percentage = Math.round((current / total) * 100);
|
|
68
|
+
const progressBar = this.createProgressBar(percentage);
|
|
69
|
+
process.stdout.write(`\r${progressBar} ${percentage}% - ${message}`);
|
|
70
|
+
if (current === total) {
|
|
71
|
+
process.stdout.write('\n');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
createProgressBar(percentage) {
|
|
76
|
+
const width = 20;
|
|
77
|
+
const filled = Math.round((percentage / 100) * width);
|
|
78
|
+
const empty = width - filled;
|
|
79
|
+
return `[${'█'.repeat(filled)}${'░'.repeat(empty)}]`;
|
|
80
|
+
}
|
|
81
|
+
time(label) {
|
|
82
|
+
if (this.logLevel <= LogLevel.DEBUG) {
|
|
83
|
+
console.time(`[TIMER] ${label}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
timeEnd(label) {
|
|
87
|
+
if (this.logLevel <= LogLevel.DEBUG) {
|
|
88
|
+
console.timeEnd(`[TIMER] ${label}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Export singleton instance
|
|
93
|
+
exports.logger = new Logger();
|
|
94
|
+
// Export convenience functions
|
|
95
|
+
exports.debug = exports.logger.debug.bind(exports.logger);
|
|
96
|
+
exports.info = exports.logger.info.bind(exports.logger);
|
|
97
|
+
exports.success = exports.logger.success.bind(exports.logger);
|
|
98
|
+
exports.warn = exports.logger.warn.bind(exports.logger);
|
|
99
|
+
exports.error = exports.logger.error.bind(exports.logger);
|
|
100
|
+
exports.group = exports.logger.group.bind(exports.logger);
|
|
101
|
+
exports.progress = exports.logger.progress.bind(exports.logger);
|
|
102
|
+
exports.time = exports.logger.time.bind(exports.logger);
|
|
103
|
+
exports.timeEnd = exports.logger.timeEnd.bind(exports.logger);
|