@ts-for-gir/cli 4.0.0-beta.4 → 4.0.0-beta.41

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 (64) hide show
  1. package/README.md +307 -193
  2. package/bin/ts-for-gir +23851 -0
  3. package/bin/ts-for-gir-dev +43 -0
  4. package/package.json +39 -38
  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 +44 -47
  9. package/src/commands/generate.ts +35 -81
  10. package/src/commands/index.ts +6 -4
  11. package/src/commands/json.ts +43 -0
  12. package/src/commands/list.ts +71 -90
  13. package/src/commands/run-generation-command.ts +70 -0
  14. package/src/config/config-loader.ts +190 -0
  15. package/src/config/config-writer.ts +52 -0
  16. package/src/config/defaults.ts +66 -0
  17. package/src/config/index.ts +8 -0
  18. package/src/config/options.ts +315 -0
  19. package/src/config.ts +3 -450
  20. package/src/formatters/typescript-formatter.ts +24 -0
  21. package/src/generation-handler.ts +122 -67
  22. package/src/index.ts +4 -4
  23. package/src/module-loader/dependency-resolver.ts +100 -0
  24. package/src/module-loader/file-finder.ts +65 -0
  25. package/src/module-loader/index.ts +8 -0
  26. package/src/module-loader/module-grouper.ts +77 -0
  27. package/src/module-loader/prompt-handler.ts +111 -0
  28. package/src/module-loader.ts +289 -578
  29. package/src/start.ts +17 -14
  30. package/src/types/command-args.ts +118 -0
  31. package/src/types/command-definition.ts +17 -0
  32. package/src/types/commands.ts +30 -0
  33. package/src/types/index.ts +15 -0
  34. package/src/types/report-types.ts +34 -0
  35. package/lib/commands/copy.d.ts +0 -12
  36. package/lib/commands/copy.js +0 -80
  37. package/lib/commands/copy.js.map +0 -1
  38. package/lib/commands/doc.d.ts +0 -12
  39. package/lib/commands/doc.js +0 -40
  40. package/lib/commands/doc.js.map +0 -1
  41. package/lib/commands/generate.d.ts +0 -12
  42. package/lib/commands/generate.js +0 -73
  43. package/lib/commands/generate.js.map +0 -1
  44. package/lib/commands/index.d.ts +0 -4
  45. package/lib/commands/index.js +0 -5
  46. package/lib/commands/index.js.map +0 -1
  47. package/lib/commands/list.d.ts +0 -12
  48. package/lib/commands/list.js +0 -81
  49. package/lib/commands/list.js.map +0 -1
  50. package/lib/config.d.ts +0 -104
  51. package/lib/config.js +0 -408
  52. package/lib/config.js.map +0 -1
  53. package/lib/generation-handler.d.ts +0 -10
  54. package/lib/generation-handler.js +0 -47
  55. package/lib/generation-handler.js.map +0 -1
  56. package/lib/index.d.ts +0 -4
  57. package/lib/index.js +0 -5
  58. package/lib/index.js.map +0 -1
  59. package/lib/module-loader.d.ts +0 -148
  60. package/lib/module-loader.js +0 -468
  61. package/lib/module-loader.js.map +0 -1
  62. package/lib/start.d.ts +0 -2
  63. package/lib/start.js +0 -16
  64. package/lib/start.js.map +0 -1
package/README.md CHANGED
@@ -18,13 +18,12 @@
18
18
 
19
19
  # CLI
20
20
 
21
- CLI tool to generate Typescript Type Definition files for GJS and node-gtk.
21
+ CLI tool to generate TypeScript type definitions and HTML documentation for GObject Introspection Repository (GIR) files, primarily for GJS applications.
22
22
 
23
23
  ## Getting started
24
24
 
25
25
  ``` bash
26
- npm install -g @ts-for-gir/cli
27
- ts-for-gir --help
26
+ npx @ts-for-gir/cli --help
28
27
  ```
29
28
 
30
29
  > Alternatively you can also add @ts-for-gir/cli to your dependencies:
@@ -32,117 +31,211 @@ ts-for-gir --help
32
31
  > npm install --save-dev @ts-for-gir/cli
33
32
  > ```
34
33
  >
35
- > Or without installing using `npx`:
34
+ > Or globally install it:
36
35
  > ```bash
37
- > npx @ts-for-gir/cli --help
36
+ > npm install -g @ts-for-gir/cli
37
+ > ts-for-gir --help
38
38
  > ```
39
39
 
40
- After you have installed `@ts-for-gir/cli` you can run the `ts-for-gir` command:
41
-
42
- ```bash
43
- $ ts-for-gir --help
44
-
45
- Typescript .d.ts generator from GIR for GJS or node-gtk
40
+ ```
41
+ TypeScript type definition generator for GObject introspection GIR files
46
42
 
47
43
  Commands:
48
- ts-for-gir generate [modules..] Generates .d.ts files from GIR for GJS or nod
49
- e-gtk
44
+ ts-for-gir generate [modules..] Generates .d.ts files from GIR for GJS
45
+ ts-for-gir json [modules..] Generates JSON representation from GIR files for analysis and tooling
46
+ ts-for-gir doc [modules..] Generates HTML documentation from GIR files using TypeDoc
50
47
  ts-for-gir list [modules..] Lists all available GIR modules
51
- ts-for-gir doc [modules..] The HTML documentation generator is not yet i
52
- mplemented, but feel free to implement it 🤗
48
+ ts-for-gir copy [modules..] Scan for *.gir files and copy them to a new directory
49
+ ts-for-gir analyze Analyze report files generated by ts-for-gir reporter
53
50
 
54
51
  Options:
55
52
  --version Show version number [boolean]
56
- --help Show help [boolean] [boolean]
53
+ --help Show help [boolean]
57
54
  ```
58
55
 
59
56
  ## Example
60
57
 
61
- To generate the Typescript type definitions of Gtk-4.0 for GJS run:
58
+ To generate the TypeScript type definitions of Gtk-4.0 for GJS run:
62
59
 
63
60
  ```
64
61
  ts-for-gir generate Gtk-4.0
65
62
  ```
66
63
 
67
- To generate this types for [node-gtk](https://github.com/romgrk/node-gtk) run:
68
-
69
- ```
70
- ts-for-gir generate Gtk-4.0 -e node
71
- ```
72
-
73
- You can also look at the [examples](https://github.com/gjsify/ts-for-gir/tree/main/examples) to see how the types are generated there.
64
+ You can also look at the [examples](https://github.com/gjsify/ts-for-gir/tree/main/examples) to see how the types are generated and/or used there.
74
65
 
75
66
  ## Generate .d.ts files
76
67
 
77
- ```bash
78
- $ ts-for-gir generate --help
79
-
80
- ts-for-gir generate [modules..]
81
-
68
+ ```
82
69
  ts-for-gir generate [modules..]
83
70
 
84
- Generates .d.ts files from GIR for GJS or node-gtk
71
+ Generates .d.ts files from GIR for GJS
85
72
 
86
73
  Options:
87
74
  --version Show version number [boolean]
88
75
  --help Show help [boolean]
89
- --modules GIR modules to load, e.g. 'Gio-2.0'. Accepts mul
90
- tiple modules [array] [default: ["*"]]
91
- -g, --girDirectories GIR directories
92
- [array] [default: ["/usr/local/share/gir-1.0","/usr/share/gir-1.0","/usr/share
93
- /gnome-shell","/usr/share/gnome-shell/gir-1.0","/usr/lib64/mutter-10","/usr/li
94
- b64/mutter-11","/usr/lib64/mutter-12","/usr/lib/x86_64-linux-gnu/mutter-10","/
95
- usr/lib/x86_64-linux-gnu/mutter-11","/usr/lib/x86_64-linux-gnu/mutter-12","/ho
96
- me/jumplink/.local/share/flatpak/exports/share/gir-1.0","/var/lib/flatpak/expo
97
- rts/share/gir-1.0"]]
98
- --root Root directory of your project
99
- [string] [default: "/home/jumplink/Projekte/ts-for-gir"]
76
+ --modules GIR modules to load, e.g. 'Gio-2.0'. Accepts
77
+ multiple modules [array] [default: ["*"]]
78
+ -g, --girDirectories GIR directories [array]
79
+ --root Root directory of your project [string]
100
80
  -o, --outdir Directory to output to
101
81
  [string] [default: "./@types"]
102
82
  -i, --ignore Modules that should be ignored
103
83
  [array] [default: []]
104
84
  -v, --verbose Switch on/off the verbose mode
105
- [string] [default: false]
106
- --ignoreVersionConflicts Do not ask for package versions if multiple vers
107
- ions are found [string] [default: false]
85
+ [boolean] [default: false]
86
+ --ignoreVersionConflicts Skip prompts for library version selection when
87
+ multiple versions are detected
88
+ [boolean] [default: false]
108
89
  -p, --print Print the output to console and create no files
109
- [string] [default: false]
110
- --configName Name of the config if you want to use a differen
111
- t name [string] [default: ".ts-for-girrc.js"]
112
- -d, --noNamespace Do not export all symbols for each module as a n
113
- amespace [string] [default: false]
90
+ [boolean] [default: false]
91
+ --configName Specify a custom name for the configuration file
92
+ [string] [default: ".ts-for-girrc.js"]
93
+ -d, --noNamespace Do not export all symbols for each module as a
94
+ namespace [boolean] [default: false]
114
95
  -n, --noComments Do not generate documentation comments
115
- [string] [default: false]
116
- --noDebugComments Do not generate debugging inline comments
117
- [string] [default: false]
118
- --fixConflicts Fix Inheritance and implementation type conflict
119
- s [string] [default: true]
96
+ [boolean] [default: false]
120
97
  --promisify Generate promisified functions for async/finish
121
- calls [string] [default: true]
98
+ calls [boolean] [default: true]
122
99
  --npmScope Scope of the generated NPM packages
123
100
  [string] [default: "@girs"]
101
+ --workspace Uses the workspace protocol for the generated
102
+ packages [boolean] [default: false]
103
+ --onlyVersionPrefix Only use the version prefix for the ambient
104
+ module exports [boolean] [default: false]
105
+ --noPrettyPrint Do not prettify the generated types
106
+ [boolean] [default: false]
107
+ --noAdvancedVariants Disable GLib.Variant class with string parsing
108
+ [boolean] [default: false]
109
+ --package Generate the typescript types with package.json
110
+ support [boolean] [default: false]
111
+ --reporter Enable generation problem reporter and create a
112
+ detailed report file [boolean] [default: false]
113
+ --reporterOutput Output file path for the reporter
114
+ [string] [default: "ts-for-gir-report.json"]
124
115
 
125
116
  Examples:
126
- ts-for-gir generate Run 'ts-for-gir generate' in your gj
127
- s or node-gtk project to generate ty
128
- pings for your project, pass the gir
129
- modules you need for your project
130
- ts-for-gir generate Gtk* You can also use wild cards
131
- ts-for-gir generate '*' If you want to parse all of your loc
132
- ally installed gir modules run
133
- ts-for-gir generate '*' -e gjs Generate .d.ts. files only for gjs
134
- ts-for-gir generate '*' -e node Generate .d.ts. files only for node
135
- ts-for-gir generate --configName='.ts-fo Use a special config file
136
- r-gir.gtk4.rc.js
137
- ts-for-gir generate --ignore=Gtk-4.0 xra Generate .d.ts. files but not for Gt
138
- ndr-1.3 k-4.0 and xrandr-1.3
117
+ ts-for-gir generate Run 'ts-for-gir generate'
118
+ in your gjs project to
119
+ generate typings
120
+ ts-for-gir generate 'Gtk*' You can also use wild cards
121
+ ts-for-gir generate '*' Parse all locally installed
122
+ gir modules
123
+ ts-for-gir generate --configName='.rc.js' Use a special config file
124
+ ts-for-gir generate --ignore=Gtk-4.0 xrandr-1.3 Generate .d.ts files but
125
+ not for Gtk-4.0 and
126
+ xrandr-1.3
139
127
  ```
140
128
 
141
- ## List available GIR modules
129
+ ## Generate TypeDoc JSON
130
+
131
+ Generates TypeDoc JSON output enriched with GIR-specific metadata. This is useful as an intermediate step before generating HTML documentation (see `doc --merge`), or for custom tooling.
132
+
133
+ ```
134
+ ts-for-gir json [modules..]
135
+
136
+ Generates JSON representation from GIR files for analysis and tooling
137
+
138
+ Options:
139
+ --version Show version number [boolean]
140
+ --help Show help [boolean]
141
+ --modules GIR modules to load, e.g. 'Gio-2.0'. Accepts
142
+ multiple modules [array] [default: ["*"]]
143
+ -g, --girDirectories GIR directories [array]
144
+ --root Root directory of your project [string]
145
+ -o, --outdir Directory to output to
146
+ [string] [default: "./@types"]
147
+ -i, --ignore Modules that should be ignored
148
+ [array] [default: []]
149
+ -v, --verbose Switch on/off the verbose mode
150
+ [boolean] [default: false]
151
+ --ignoreVersionConflicts Skip prompts for library version selection when
152
+ multiple versions are detected
153
+ [boolean] [default: false]
154
+ --configName Specify a custom name for the configuration file
155
+ [string] [default: ".ts-for-girrc.js"]
156
+
157
+ Examples:
158
+ ts-for-gir json Generate JSON for all modules
159
+ ts-for-gir json Gtk-4.0 --outdir ./json Generate JSON for Gtk-4.0 into ./json
160
+ ts-for-gir json '*' --outdir ./json Generate JSON for all modules
161
+ ```
162
+
163
+ ## Generate HTML documentation
164
+
165
+ Generates a browsable HTML API reference using TypeDoc. Supports two modes:
166
+
167
+ - **Direct mode**: Generates `.d.ts` files from GIR, then converts to HTML in one step.
168
+ - **Merge mode** (`--merge`): Reads pre-generated JSON files (from `ts-for-gir json`) and produces HTML. This uses less memory and is suitable for large module sets.
169
+
170
+ The generated documentation uses a custom theme inspired by [gi-docgen](https://gnome.pages.gitlab.gnome.org/gi-docgen/) with a 3-column layout, GIR metadata badges, and categorized module listings.
171
+
172
+ See the live documentation at [gjsify.github.io/docs](https://gjsify.github.io/docs).
173
+
174
+ ```
175
+ ts-for-gir doc [modules..]
176
+
177
+ Generates HTML documentation from GIR files using TypeDoc
178
+
179
+ Options:
180
+ --version Show version number [boolean]
181
+ --help Show help [boolean]
182
+ --modules GIR modules to load, e.g. 'Gio-2.0'. Accepts
183
+ multiple modules [array] [default: ["*"]]
184
+ -g, --girDirectories GIR directories [array]
185
+ --root Root directory of your project [string]
186
+ -o, --outdir Directory to output to
187
+ [string] [default: "./docs"]
188
+ -i, --ignore Modules that should be ignored
189
+ [array] [default: []]
190
+ -v, --verbose Switch on/off the verbose mode
191
+ [boolean] [default: false]
192
+ --ignoreVersionConflicts Skip prompts for library version selection when
193
+ multiple versions are detected
194
+ [boolean] [default: false]
195
+ --configName Specify a custom name for the configuration file
196
+ [string] [default: ".ts-for-girrc.js"]
197
+ --combined Generate a single unified documentation for all
198
+ modules (use --no-combined for separate
199
+ per-module docs) [boolean] [default: true]
200
+ --sourceLinkTemplate URL template for source links in generated
201
+ documentation. Supports {path}, {line},
202
+ {gitRevision} placeholders [string]
203
+ --theme Theme for HTML documentation generation.
204
+ Use "default" for TypeDoc's built-in theme.
205
+ [string] [default: "gi-docgen"]
206
+ --readme Path to a README file for the documentation
207
+ index page. Use "none" to disable. [string]
208
+ --merge Use TypeDoc merge mode to generate HTML from
209
+ pre-generated JSON files (requires --jsonDir)
210
+ [boolean] [default: false]
211
+ --jsonDir Directory containing pre-generated TypeDoc JSON
212
+ files for merge mode (from 'ts-for-gir json')
213
+ [string]
214
+
215
+ Examples:
216
+ ts-for-gir doc Gtk-4.0 --outdir ./docs Generate HTML documentation
217
+ for Gtk-4.0
218
+ ts-for-gir doc '*' --outdir ./docs Generate documentation for all
219
+ locally installed GIR modules
220
+ ts-for-gir doc --merge --jsonDir ./json Generate HTML from pre-generated
221
+ --outdir ./docs JSON files (low memory)
222
+ ```
223
+
224
+ ### Two-phase workflow
225
+
226
+ For large module sets, you can split documentation generation into two phases to reduce peak memory usage:
142
227
 
143
228
  ```bash
144
- $ ts-for-gir list --help
145
-
229
+ # Phase 1: Generate JSON files (one per module)
230
+ ts-for-gir json '*' --outdir ./json
231
+
232
+ # Phase 2: Merge JSON files into HTML documentation
233
+ ts-for-gir doc --merge --jsonDir ./json --outdir ./docs
234
+ ```
235
+
236
+ ## List available GIR modules
237
+
238
+ ```
146
239
  ts-for-gir list [modules..]
147
240
 
148
241
  Lists all available GIR modules
@@ -150,38 +243,102 @@ Lists all available GIR modules
150
243
  Options:
151
244
  --version Show version number [boolean]
152
245
  --help Show help [boolean]
153
- --modules GIR modules to load, e.g. 'Gio-2.0'. Accepts multiple mo
154
- dules [array] [default: ["*"]]
155
- -g, --girDirectories GIR directories
156
- [array] [default: ["/usr/local/share/gir-1.0","/usr/share/gir-1.0","/usr/share
157
- /gnome-shell","/usr/share/gnome-shell/gir-1.0","/usr/lib64/mutter-10","/usr/li
158
- b64/mutter-11","/usr/lib64/mutter-12","/usr/lib/x86_64-linux-gnu/mutter-10","/
159
- usr/lib/x86_64-linux-gnu/mutter-11","/usr/lib/x86_64-linux-gnu/mutter-12","/ho
160
- me/jumplink/.local/share/flatpak/exports/share/gir-1.0","/var/lib/flatpak/expo
161
- rts/share/gir-1.0"]]
246
+ --modules GIR modules to load, e.g. 'Gio-2.0'. Accepts
247
+ multiple modules [array] [default: ["*"]]
248
+ -g, --girDirectories GIR directories [array]
249
+ --root Root directory of your project [string]
162
250
  -i, --ignore Modules that should be ignored [array] [default: []]
163
- --configName Name of the config if you want to use a different name
251
+ --configName Specify a custom name for the configuration file
164
252
  [string] [default: ".ts-for-girrc.js"]
165
- -v, --verbose Switch on/off the verbose mode [string] [default: false]
253
+ -v, --verbose Switch on/off the verbose mode [boolean] [default: false]
166
254
 
167
255
  Examples:
168
- ts-for-gir list -g ./vala-girs/gir-1.0 Lists all available GIR modules in .
169
- /vala-girs/gir-1.0
170
- ts-for-gir list --ignore=Gtk-3.0 xrandr- Lists all available GIR modules in /
171
- 1.3 usr/share/gir-1.0 but not Gtk-3.0 an
172
- d xrandr-1.3
256
+ ts-for-gir list -g ./vala-girs/gir-1.0 Lists all available GIR
257
+ modules in
258
+ ./vala-girs/gir-1.0
259
+ ts-for-gir list --ignore=Gtk-3.0 xrandr-1.3 Lists all available GIR
260
+ modules but not Gtk-3.0
261
+ and xrandr-1.3
173
262
  ```
174
263
 
175
- ## Generate HTML documentation
264
+ ## Copy GIR files
176
265
 
177
- ```bash
178
- $ ts-for-gir doc --help
266
+ ```
267
+ ts-for-gir copy [modules..]
179
268
 
180
- ts-for-gir doc [modules..]
269
+ Scan for *.gir files and copy them to a new directory
181
270
 
182
- The HTML documentation generator is not yet implemented, but feel free to implem
183
- ent it 🤗
271
+ Options:
272
+ --version Show version number [boolean]
273
+ --help Show help [boolean]
274
+ --modules GIR modules to load, e.g. 'Gio-2.0'. Accepts
275
+ multiple modules [array] [default: ["*"]]
276
+ -g, --girDirectories GIR directories [array]
277
+ --root Root directory of your project [string]
278
+ -o, --outdir Directory to output to [string] [default: "./@types"]
279
+ -i, --ignore Modules that should be ignored [array] [default: []]
280
+ --configName Specify a custom name for the configuration file
281
+ [string] [default: ".ts-for-girrc.js"]
282
+ -v, --verbose Switch on/off the verbose mode [boolean] [default: false]
283
+
284
+ Examples:
285
+ ts-for-gir copy -o ./gir Copy found *.gir files to
286
+ ./gir
287
+ ts-for-gir copy -g /usr/share/gir-1.0 Copy all found *.gir files
288
+ --ignore=Gtk-3.0 xrandr-1.3 -o ./gir excluding Gtk-3.0 and
289
+ xrandr-1.3 to ./gir
290
+ ```
291
+
292
+ ## Analyze report files
293
+
294
+ ```
295
+ ts-for-gir analyze [options]
296
+
297
+ Analyze report files generated by ts-for-gir reporter
298
+
299
+ Options:
300
+ --version Show version number [boolean]
301
+ --help Show help [boolean]
302
+ -f, --reportFile Path to the report file to analyze [string] [required]
303
+ -s, --severity Filter by problem severity
304
+ (debug, info, warning, error, critical) [array]
305
+ -c, --category Filter by problem category [array]
306
+ -n, --namespace Filter by namespace/module [array]
307
+ -t, --type Filter by specific type name [array]
308
+ --search Search for text in messages, details, or type names
309
+ [string]
310
+ --since Filter problems since date/time (ISO format) [string]
311
+ --until Filter problems until date/time (ISO format) [string]
312
+ --top Show top N most problematic items [number] [default: 10]
313
+ --format Output format (table, json, csv)
314
+ [string] [default: "table"]
315
+ -e, --export Export filtered results to file [string]
316
+ -d, --detailed Show detailed problem information [boolean] [default: false]
317
+ --summary Show summary statistics only [boolean] [default: false]
318
+ -v, --verbose Enable verbose output [boolean] [default: false]
319
+
320
+ Examples:
321
+ ts-for-gir analyze -f ./ts-for-gir-report.json
322
+ Show summary statistics of the report
323
+ ts-for-gir analyze -f ./report.json --severity error critical
324
+ Show only critical and error problems
325
+ ts-for-gir analyze -f ./report.json --category type_resolution --format table
326
+ Show type resolution problems
327
+ ts-for-gir analyze -f ./report.json --namespace Gtk --top 10
328
+ Show top 10 problems in Gtk namespace
329
+ ts-for-gir analyze -f ./report.json --search "Unable to resolve" --export errors.json
330
+ Export unresolved type errors to file
184
331
  ```
332
+
333
+ The `analyze` command helps debug type generation issues by providing powerful filtering and analysis capabilities for ts-for-gir report files.
334
+
335
+ **Key Features:**
336
+ - **Comprehensive Filtering**: Filter by severity, category, namespace, type name, or search text
337
+ - **Multiple Output Formats**: Table, JSON, or CSV format for different use cases
338
+ - **Statistical Analysis**: Show most problematic types, namespaces, and categories
339
+ - **Export Capabilities**: Save filtered results for further analysis
340
+ - **Time-based Filtering**: Analyze problems within specific time ranges
341
+
185
342
  ## Config
186
343
 
187
344
  In addition to the option of passing options as a CLI flag, you can also write them in a config file.
@@ -190,27 +347,38 @@ To do that, create a new config file called `.ts-for-girrc.js` in your project r
190
347
  ```js
191
348
  // or on CommonJs: exports.default = {
192
349
  export default {
193
- print: false,
194
350
  verbose: true,
195
- environments: ['gjs', 'node'],
196
351
  outdir: '@types',
197
352
  girDirectories: ['/usr/share/gir-1.0'],
198
353
  modules: ['*'],
199
354
  ignore: [],
200
- noNamespace: false,
201
- buildType: 'lib',
202
- moduleType: 'esm'
203
355
  }
204
356
  ```
205
357
 
206
358
  The javascript config files must also be in ESM format if you are inside a ESM Package, this is the case if `"type": "module"` is defined in your package.json. Alternatively, the file can be saved in json format, then it works in both cases.
207
359
 
208
- You can pass the config file name to the CLI using [configName](#configName).
360
+ You can pass the config file name to the CLI using [configName](#configname).
361
+
362
+ ### Doc-specific config
363
+
364
+ For documentation generation, you can configure doc-specific options in the config file:
365
+
366
+ ```js
367
+ export default {
368
+ modules: ['Gtk-4.0', 'Gdk-4.0', 'Gio-2.0', 'GLib-2.0', 'GObject-2.0'],
369
+ outdir: './docs',
370
+ merge: true,
371
+ jsonDir: './json',
372
+ readme: './DOC.md',
373
+ verbose: true,
374
+ sourceLinkTemplate: 'https://github.com/user/repo/blob/main/{path}#L{line}',
375
+ }
376
+ ```
209
377
 
210
378
  ## Options
211
379
 
212
380
  ### girDirectories
213
- Directories in which `*.gir` files are to be searched for. Default is `["/usr/share/gir-1.0"]`. More than one can be specified. If you want to generate the types for the GNOME Shell you have to search in several folders for the corresponding types:
381
+ Directories in which `*.gir` files are to be searched for. Default is `["/usr/share/gir-1.0"]`. More than one can be specified. If you want to generate the types for the GNOME Shell you have to search in several folders for the corresponding types:
214
382
  ```js
215
383
  girDirectories: [
216
384
  // General gir files
@@ -229,7 +397,7 @@ girDirectories: [
229
397
  ```
230
398
 
231
399
  ### outdir
232
- The `outdir` option is used to specify the name of the directory where the generated TypeScript types should be saved. The default value of the `outdir` option is `"./@types"`.
400
+ The `outdir` option is used to specify the name of the directory where the generated TypeScript types should be saved. The default value of the `outdir` option is `"./@types"` for `generate` and `"./docs"` for `doc`.
233
401
 
234
402
  Here is an example of how you can use the outdir option in the CLI of `ts-for-gir`:
235
403
 
@@ -241,97 +409,23 @@ In this example, the generated TypeScript types will be saved in the `./types` d
241
409
 
242
410
  It is important to note that the outdir option should be a valid directory path, and `ts-for-gir` will create the directory if it does not exist. If the specified directory already contains files, `ts-for-gir` will overwrite the existing files with the newly generated types.
243
411
 
244
- ### environments
245
- The `environments` option allows you to specify the JavaScript environment for which you want to generate the TypeScript type definitions. The available values are `"gjs"` and `"node"`. You can also specify both environments.
246
-
247
- The default value for this option is `"gjs"`.
248
-
249
- To specify the environments option when running ts-for-gir, you would add the `--environments` or `-e` flag, followed by a comma-separated list of values. For example:
250
-
251
- ```bash
252
- ts-for-gir generate * --environments gjs node
253
- ```
254
-
255
- This option is useful if you want to generate type definitions for use in different JavaScript environments, such as in a `GJS` application or in a `Node.js` application using [node-gtk](https://github.com/romgrk/node-gtk). By specifying the appropriate environment, ts-for-gir can generate type definitions that are optimized for that environment, ensuring that your code will be type-checked correctly and you will receive meaningful error messages in your development environment.
256
-
257
412
  ### ignore
258
413
  The `ignore` CLI option allows you to specify modules that should be ignored when generating TypeScript types. This can be useful if you have multiple versions of a library installed but only want to generate types for one of them.
259
414
 
260
415
  To use the ignore option, pass one or more module names as arguments. For example, to ignore the `Gtk-3.0` module, you would use the following command:
261
416
 
262
417
  ```bash
263
- ts-for-gir generate Gtk-* --ignore Gtk-3.0
418
+ ts-for-gir generate Gtk-* --ignore */Gtk-3.0
264
419
  ```
265
420
 
266
421
  You can also ignore multiple modules:
267
422
 
268
423
  ```bash
269
- ts-for-gir generate * --ignore Gtk-2.0 Gtk-3.0 Gtk-4.0
424
+ ts-for-gir generate * --ignore */Gtk-2.0 */Gtk-3.0 */Gtk-4.0
270
425
  ```
271
426
 
272
427
  Note that ignoring a module will prevent ts-for-gir from generating types for that module and any submodules that it might contain.
273
428
 
274
- ### buildType
275
- `ts-for-gir` supports two build types for generating the types: `"lib"` and `"types"`.
276
-
277
- * If `"lib"` is specified, `.js` files are generated as well as `.d.ts`, this is useful for some bundlers that expect a `.js` file. Some bundlers are also able to generate the import of this file only once, even if it occurs multiple times in your code.
278
- * If `"types"` is specified, only `.d.ts` files are generated. In this mode it is recommended to add the generated `"@types/gjs.d.ts"` and `"@types/ambient.d.ts"` under `"include"` in the `tsconfig` to make the generated types known in your project.
279
-
280
- ### moduleType
281
- The `moduleType` CLI option determines the format in which the generated JavaScript files should be exported. The option takes either `"esm"` or `"cjs"` as its value, with `"esm"` being the default.
282
-
283
- > This option is only relevant if the `buildType` is set to `"lib"`. The choice of `moduleType` may affect how the generated code is used in other parts of your project, so it's important to choose the right format that works best for your use case.
284
-
285
- The choice of `moduleType` is also important in the context of the bundler that you plan to use in your project. For example, if you are using a bundler that only supports ESM (such as Rollup), you would need to set `moduleType` to "esm". On the other hand, if you are using a bundler that supports both ESM and CommonJS (such as Webpack), you can choose whichever format you prefer. Ultimately, the choice of `moduleType` will depend on your project requirements and the tools that you are using. For Example, if you want to build a GNOME Shell Extension, you should use `"cjs"` because `ESM` is currently not supported for GNOME Shell Extensions. For [node-gtk](https://github.com/romgrk/node-gtk) you also need to use `"cjs"`. If you want to build a regular GJS Application we recommend to use `ESM`.
286
-
287
- When `"esm"` is set, the generated JavaScript files will use the ECMAScript module (ESM) format for imports and exports. For example, the generated code might look like this:
288
-
289
- ```ts
290
- // Gtk-4.0.d.ts
291
- import type GLib from './GLib-2.0.js';
292
-
293
- namespace Gtk {
294
- class Window extends Widget {
295
- ...
296
- }
297
- function builder_error_quark(): GLib.Quark
298
- }
299
-
300
- export default Gtk;
301
- ```
302
-
303
- ```js
304
- // Gtk-4.0.js
305
- import Gtk from 'gi://Gtk?version=4.0';
306
- export default Gtk;
307
- ```
308
-
309
- > The `"esm"` module type is recommended for GJS applications as it makes use of the ESM import syntax, which is more modern and flexible compared to imports.gi / CommonJS imports. This allows for a more streamlined and convenient way of using the generated types in your GJS application. Support for ES modules can be activated in `gjs` with its `gjs -m` flag.
310
-
311
- When `"cjs"` and [`noNamespace`](#nonamespace) is set, the generated JavaScript files will use the CommonJS format exports and the `imports.gi` object for imports. For example:
312
-
313
- ```ts
314
- // Gtk-4.0.d.ts
315
- import type * as GLib from './GLib-2.0.js';
316
-
317
- export class Window extends Widget {
318
- ...
319
- }
320
- export function builder_error_quark(): GLib.Quark
321
- ```
322
-
323
- ```js
324
- // Gtk-4.0.js
325
- imports.gi.versions.Gtk = '4.0'
326
- const Gtk = imports.gi.Gtk;
327
-
328
- module.exports = { Gtk };
329
- exports.default = Gtk;
330
- ```
331
-
332
- > It is recommended to also set the [noNamespace](#nonamespace) option to true when using the `"cjs"` moduleType option. This will ensure that the generated code is fully compatible with the CommonJS format.
333
-
334
-
335
429
  ### verbose
336
430
  The `--verbose` or `-v` option is a flag that can be used to enable verbose output in the console when running the CLI. When this option is enabled, additional warnings and information about the processing of GIR files and the generation of TypeScript definitions will be printed to the console. This information can be useful for debugging purposes or for understanding what is happening behind the scenes when generating the TypeScript definitions.
337
431
 
@@ -340,7 +434,7 @@ The `ignoreVersionConflicts` CLI option allows you to disable the prompt to choo
340
434
 
341
435
  This option can be useful in certain scenarios where you want to generate types for all versions of a library, even if there are conflicts between the versions. Note that this may result in type conflicts and other issues, so it should be used with caution.
342
436
 
343
- Another way to disable the prompt and ignore conflicting versions of `.gir` files is to use the [ignore CLI option](#ignore).
437
+ Another way to disable the prompt and ignore conflicting versions of `.gir` files is to use the [ignore CLI option](#ignore).
344
438
 
345
439
  ### print
346
440
  The `print` CLI option allows you to output the generated TypeScript definitions to the console, instead of saving them to files on disk. This is useful if you want to quickly inspect the generated types without having to save them to disk and open them in an editor.
@@ -350,7 +444,7 @@ By default, the print option is disabled and the generated types will be saved t
350
444
  ### configName
351
445
  The `configName` CLI option allows you to specify the name of the configuration file to be used when generating the TypeScript definitions. This option is useful if you want to use a custom configuration file instead of the default one.
352
446
 
353
- By default,` ts-for-gir` looks for a configuration file named `.ts-for-girrc.js` in the current directory. If a different configuration file name is required, the `configName` option can be used to specify the name of the configuration file.
447
+ By default, `ts-for-gir` looks for a configuration file named `.ts-for-girrc.js` in the current directory. If a different configuration file name is required, the `configName` option can be used to specify the name of the configuration file.
354
448
 
355
449
  For example, if you have a configuration file named `custom-config.js`, you can use the following command to generate TypeScript definitions using this configuration file:
356
450
 
@@ -374,20 +468,24 @@ When `noComments` is set to `true`, `ts-for-gir` will not include TSDoc comments
374
468
  To use the noComments option, pass it as a command line argument to `ts-for-gir`:
375
469
 
376
470
  ```bash
377
- ts-for-gir generate * --noComments`
471
+ ts-for-gir generate * --noComments
378
472
  ```
379
473
 
380
- ### noDebugComments
381
- The `noDebugComments` CLI option is used to control the generation of inline comments in the generated TypeScript files. These comments are used for debugging purposes and can be useful in tracking down issues with the generated types.
474
+ ### noPrettyPrint
475
+ The `noPrettyPrint` option controls whether the generated TypeScript definitions are formatted using Prettier. When set to `true`, the output will not be formatted, which can be useful for debugging or in cases where you want to handle formatting separately.
382
476
 
383
- By default, the `noDebugComments` option is disabled and these inline comments will be included in the generated TypeScript files. If you do not require these comments for debugging purposes, you can use the -`-noDebugComments` option to disable their generation and keep your TypeScript code more compact.
477
+ ```bash
478
+ ts-for-gir generate * --noPrettyPrint
479
+ ```
384
480
 
385
- ### fixConflicts
386
- The `fixConflicts` CLI option is used to resolve type conflicts between the GObject Introspection descriptions in GIR XML format and TypeScript. For example, properties in the GIR XML format can be overwritten by methods, which is not allowed in TypeScript. When this option is active, `ts-for-gir` attempts to resolve these conflicts. However, it's important to note that this may result in generating types that do not exist.
481
+ ### noAdvancedVariants
482
+ 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.
387
483
 
388
- > If you have found an issue with the `fixConflicts` CLI option, we encourage you to report it. Reporting issues helps improve the quality of `ts-for-gir` and makes it a better tool for everyone.
484
+ ```bash
485
+ ts-for-gir generate * --noAdvancedVariants=false
486
+ ```
389
487
 
390
- # package
488
+ ### package
391
489
 
392
490
  The `--package` option of ts-for-gir is used to package the generated TypeScript type definitions into an NPM package. The generated package can be easily installed and used in other TypeScript projects via `npm install`.
393
491
 
@@ -395,14 +493,14 @@ The `--package` option of ts-for-gir is used to package the generated TypeScript
395
493
 
396
494
  When this option is used, each GObject introspection module will be packaged into its own NPM package. The package name will be in the format of `@girs/<lower case module name>-<version>`.
397
495
 
398
- For example, if the `--package` option is used to generate the TypeScript type definitions for the `Gtk-4.0` module, then the generated NPM package will have the name `@girs/gtk-3.0`.
496
+ For example, if the `--package` option is used to generate the TypeScript type definitions for the `Gtk-4.0` module, then the generated NPM package will have the name `@girs/gtk-4.0`.
399
497
 
400
498
  > You can change the NPM package scope name with the [`--npmScope`](#npmscope) option.
401
499
 
402
500
  To use the generated NPM package in your TypeScript project, you can also install our pregenerated packages:
403
501
 
404
502
  ```bash
405
- npm install @girs/gtk-3.0
503
+ npm install @girs/gtk-4.0
406
504
  ```
407
505
 
408
506
  Then, import the desired module in your TypeScript code:
@@ -426,10 +524,10 @@ The `--npmScope` CLI option can be used to specify a custom NPM package scope na
426
524
  Here's an example command to generate NPM packages with a custom scope name:
427
525
 
428
526
  ```bash
429
- ts-for-gir --buildType lib --package --npmScope my-scope
527
+ ts-for-gir generate * --package --npmScope my-scope
430
528
  ```
431
529
 
432
- This command will generate NPM packages with the scope `my-scope` instead of the default `@girs` scope. For `Gtk-4.0` this would generate a package with the name of `@my-scope/gtk-4.0`.
530
+ This command will generate NPM packages with the scope `@my-scope` instead of the default `@girs` scope. For `Gtk-4.0` this would generate a package with the name of `@my-scope/gtk-4.0`.
433
531
 
434
532
  ## Ambient modules
435
533
 
@@ -445,7 +543,7 @@ To use ambient modules, the `ambient.d.ts` file must be imported either in the c
445
543
  ```json
446
544
  // tsconfig.json
447
545
  {
448
- "compilerOptions": {
546
+ "compilerOptions": {
449
547
  "lib": ["ESNext"],
450
548
  "types": [],
451
549
  "target": "ESNext",
@@ -473,4 +571,20 @@ declare module "gi://Gtk" {
473
571
  import Gtk from "gi://Gtk?version=4.0";
474
572
  export default Gtk;
475
573
  }
476
- ```
574
+ ```
575
+
576
+ ## reporter
577
+
578
+ The `--reporter` option enables the generation of a problem reporter and creates a detailed report file.
579
+
580
+ ```bash
581
+ ts-for-gir generate * --reporter
582
+ ```
583
+
584
+ ## reporterOutput
585
+
586
+ The `--reporterOutput` option specifies the output file path for the reporter. The default value is `ts-for-gir-report.json`.
587
+
588
+ ```bash
589
+ ts-for-gir generate * --reporterOutput custom-report.json
590
+ ```