@ts-for-gir/cli 4.0.0-beta.25 → 4.0.0-beta.27

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 (63) hide show
  1. package/README.md +84 -2
  2. package/bin/ts-for-gir-dev.js +43 -0
  3. package/bin/ts-for-gir.js +20046 -0
  4. package/package.json +34 -36
  5. package/src/commands/analyze.ts +344 -0
  6. package/src/commands/command-builder.ts +30 -0
  7. package/src/commands/copy.ts +71 -76
  8. package/src/commands/doc.ts +58 -46
  9. package/src/commands/generate.ts +97 -77
  10. package/src/commands/index.ts +6 -4
  11. package/src/commands/json.ts +104 -0
  12. package/src/commands/list.ts +81 -90
  13. package/src/config/config-loader.ts +203 -0
  14. package/src/config/config-writer.ts +52 -0
  15. package/src/config/defaults.ts +61 -0
  16. package/src/config/index.ts +8 -0
  17. package/src/config/options.ts +292 -0
  18. package/src/config.ts +3 -456
  19. package/src/formatters/typescript-formatter.ts +24 -0
  20. package/src/generation-handler.ts +122 -67
  21. package/src/index.ts +4 -4
  22. package/src/module-loader/dependency-resolver.ts +100 -0
  23. package/src/module-loader/file-finder.ts +58 -0
  24. package/src/module-loader/index.ts +8 -0
  25. package/src/module-loader/module-grouper.ts +77 -0
  26. package/src/module-loader/prompt-handler.ts +111 -0
  27. package/src/module-loader.ts +280 -580
  28. package/src/start.ts +17 -14
  29. package/src/types/command-args.ts +110 -0
  30. package/src/types/command-definition.ts +15 -0
  31. package/src/types/commands.ts +35 -0
  32. package/src/types/index.ts +15 -0
  33. package/src/types/report-types.ts +34 -0
  34. package/lib/commands/copy.d.ts +0 -12
  35. package/lib/commands/copy.js +0 -78
  36. package/lib/commands/copy.js.map +0 -1
  37. package/lib/commands/doc.d.ts +0 -12
  38. package/lib/commands/doc.js +0 -38
  39. package/lib/commands/doc.js.map +0 -1
  40. package/lib/commands/generate.d.ts +0 -12
  41. package/lib/commands/generate.js +0 -70
  42. package/lib/commands/generate.js.map +0 -1
  43. package/lib/commands/index.d.ts +0 -4
  44. package/lib/commands/index.js +0 -5
  45. package/lib/commands/index.js.map +0 -1
  46. package/lib/commands/list.d.ts +0 -12
  47. package/lib/commands/list.js +0 -79
  48. package/lib/commands/list.js.map +0 -1
  49. package/lib/config.d.ts +0 -108
  50. package/lib/config.js +0 -409
  51. package/lib/config.js.map +0 -1
  52. package/lib/generation-handler.d.ts +0 -10
  53. package/lib/generation-handler.js +0 -48
  54. package/lib/generation-handler.js.map +0 -1
  55. package/lib/index.d.ts +0 -4
  56. package/lib/index.js +0 -5
  57. package/lib/index.js.map +0 -1
  58. package/lib/module-loader.d.ts +0 -154
  59. package/lib/module-loader.js +0 -465
  60. package/lib/module-loader.js.map +0 -1
  61. package/lib/start.d.ts +0 -2
  62. package/lib/start.js +0 -16
  63. package/lib/start.js.map +0 -1
package/README.md CHANGED
@@ -45,6 +45,7 @@ TypeScript type definition generator for GObject introspection GIR files
45
45
  Commands:
46
46
  ts-for-gir generate [modules..] Generates .d.ts files from GIR for GJS
47
47
  ts-for-gir list [modules..] Lists all available GIR modules
48
+ ts-for-gir analyze Analyze report files generated by ts-for-gir reporter
48
49
  ts-for-gir copy [modules..] Scan for *.gir files and copy them to a new directory
49
50
  ts-for-gir doc [modules..] The HTML documentation generator is not yet implemented, but feel free to implement it 🤗
50
51
 
@@ -111,9 +112,14 @@ Options:
111
112
  --noPrettyPrint Do not prettify the generated types
112
113
  [boolean] [default: false]
113
114
  --noAdvancedVariants Disable GLib.Variant class with string parsing
114
- [boolean] [default: true]
115
+ [boolean] [default: false]
115
116
  --package Generate the typescript types with package.json
116
117
  support [boolean] [default: false]
118
+ --reporter Enable generation problem reporter and create a
119
+ detailed report file [boolean] [default: false]
120
+ --reporterOutput Output file path for the reporter (default:
121
+ ts-for-gir-report.json)
122
+ [string] [default: "ts-for-gir-report.json"]
117
123
 
118
124
  Examples:
119
125
  ts-for-gir generate Run 'ts-for-gir generate' in your gjs
@@ -155,6 +161,66 @@ Examples:
155
161
  ts-for-gir list --ignore=Gtk-3.0 xrandr-1.3 Lists all available GIR modules but not Gtk-3.0 and xrandr-1.3
156
162
  ```
157
163
 
164
+ ## Analyze report files
165
+
166
+ ```bash
167
+ $ npx @ts-for-gir/cli analyze --help
168
+
169
+ ts-for-gir analyze [options]
170
+
171
+ Analyze report files generated by ts-for-gir reporter
172
+
173
+ Options:
174
+ --version Show version number [boolean]
175
+ --help Show help [boolean]
176
+ -f, --reportFile Path to the report file to analyze [string] [required]
177
+ --severity Filter by problem severity (debug, info, warning, error, critical)
178
+ [array]
179
+ --category Filter by problem category [array]
180
+ --namespace Filter by namespace/module [array]
181
+ --type Filter by specific type name [array]
182
+ --search Search for text in messages, details, or type names
183
+ [string]
184
+ --since Filter problems since date/time (ISO format) [string]
185
+ --until Filter problems until date/time (ISO format) [string]
186
+ --top Show top N most problematic items [number]
187
+ --format Output format (table, json, summary)
188
+ [string] [default: "summary"]
189
+ --export Export filtered results to file [string]
190
+ --verbose Enable verbose output [boolean] [default: false]
191
+
192
+ Examples:
193
+ ts-for-gir analyze -f ./ts-for-gir-report.json
194
+ Show summary statistics of the report
195
+ ts-for-gir analyze -f ./report.json --severity error critical
196
+ Show only critical and error problems
197
+ ts-for-gir analyze -f ./report.json --category type_resolution --format table
198
+ Show type resolution problems in table format
199
+ ts-for-gir analyze -f ./report.json --namespace Gtk --top 10
200
+ Show top 10 problems in Gtk namespace
201
+ ts-for-gir analyze -f ./report.json --search "Unable to resolve" --export errors.json
202
+ Export unresolved type errors to file
203
+ ts-for-gir analyze -f ./report.json --type time_t --format json
204
+ Analyze specific type problems in JSON format
205
+ ```
206
+
207
+ The `analyze` command is designed to help developers and AI agents efficiently debug type generation issues by providing powerful filtering and analysis capabilities for ts-for-gir report files.
208
+
209
+ **Key Features:**
210
+ - **Comprehensive Filtering**: Filter by severity, category, namespace, type name, or search text
211
+ - **Multiple Output Formats**: Table, JSON, or summary format for different use cases
212
+ - **Statistical Analysis**: Show most problematic types, namespaces, and categories
213
+ - **Export Capabilities**: Save filtered results for further analysis
214
+ - **Time-based Filtering**: Analyze problems within specific time ranges
215
+ - **AI-Friendly**: Structured output perfect for automated analysis and debugging
216
+
217
+ **Common Use Cases:**
218
+ - Debug type resolution failures for specific libraries
219
+ - Identify patterns in generation problems across modules
220
+ - Export specific error categories for detailed analysis
221
+ - Monitor type generation quality over time
222
+ - Automated problem detection in CI/CD pipelines
223
+
158
224
  ## Generate HTML documentation
159
225
 
160
226
  ```bash
@@ -310,7 +376,7 @@ ts-for-gir generate * --noPrettyPrint
310
376
  ```
311
377
 
312
378
  ### noAdvancedVariants
313
- The `noAdvancedVariants` option disables the advanced GLib.Variant class with string parsing capabilities. This option is enabled by default (`true`) as these advanced features can impact performance, especially with older TypeScript versions.
379
+ The `noAdvancedVariants` option disables the advanced GLib.Variant class with string parsing capabilities. This option is enabled by default (`false`) as these advanced features can impact performance, especially with older TypeScript versions.
314
380
 
315
381
  ```bash
316
382
  ts-for-gir generate * --noAdvancedVariants=false
@@ -402,4 +468,20 @@ declare module "gi://Gtk" {
402
468
  import Gtk from "gi://Gtk?version=4.0";
403
469
  export default Gtk;
404
470
  }
471
+ ```
472
+
473
+ ## reporter
474
+
475
+ The `--reporter` option enables the generation of a problem reporter and creates a detailed report file.
476
+
477
+ ```bash
478
+ ts-for-gir generate * --reporter
479
+ ```
480
+
481
+ ## reporterOutput
482
+
483
+ The `--reporterOutput` option specifies the output file path for the reporter. The default value is `ts-for-gir-report.json`.
484
+
485
+ ```bash
486
+ ts-for-gir generate * --reporterOutput custom-report.json
405
487
  ```
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * CLI Wrapper for TypeScript Execution
5
+ *
6
+ * This wrapper is required to execute our CLI tool with the necessary Node.js parameters.
7
+ * Due to "type": "module" specified in package.json, Node.js only accepts .js files
8
+ * and rejects .ts or .sh files directly. This wrapper bridges that gap by:
9
+ *
10
+ * 1. Providing a .js entry point that Node.js can execute
11
+ * 2. Spawning the actual TypeScript file with experimental Node.js flags
12
+ * 3. Enabling TypeScript execution without compilation step
13
+ *
14
+ * The experimental flags used:
15
+ * - --experimental-specifier-resolution=node: Enables Node.js-style module resolution
16
+ * - --experimental-strip-types: Strips TypeScript types during execution
17
+ * - --experimental-transform-types: Transforms TypeScript syntax to JavaScript
18
+ * - --no-warnings: Suppresses experimental feature warnings
19
+ */
20
+
21
+ import { spawn } from 'node:child_process';
22
+ import { fileURLToPath } from 'node:url';
23
+ import { dirname, resolve } from 'node:path';
24
+
25
+ // Get the current file's directory in ES module context
26
+ const __filename = fileURLToPath(import.meta.url);
27
+ const __dirname = dirname(__filename);
28
+
29
+ // Resolve the path to the actual TypeScript CLI entry point
30
+ const tsPath = resolve(__dirname, '../src/start.ts');
31
+
32
+ // Configure Node.js arguments for TypeScript execution
33
+ const nodeArgs = [
34
+ '--experimental-specifier-resolution=node',
35
+ '--experimental-strip-types',
36
+ '--experimental-transform-types',
37
+ '--no-warnings',
38
+ tsPath,
39
+ ...process.argv.slice(2), // Forward all CLI arguments to the TypeScript file
40
+ ];
41
+
42
+ // Spawn the Node.js process with TypeScript support and inherit stdio
43
+ spawn('node', nodeArgs, { stdio: 'inherit' });