@ts-for-gir/cli 3.3.0 → 4.0.0-beta.10
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 +43 -197
- package/lib/commands/copy.d.ts +12 -0
- package/lib/commands/copy.js +80 -0
- package/lib/commands/copy.js.map +1 -0
- package/lib/commands/doc.js +8 -11
- package/lib/commands/doc.js.map +1 -1
- package/lib/commands/generate.js +29 -15
- package/lib/commands/generate.js.map +1 -1
- package/lib/commands/index.d.ts +1 -0
- package/lib/commands/index.js +1 -0
- package/lib/commands/index.js.map +1 -1
- package/lib/commands/list.js +8 -1
- package/lib/commands/list.js.map +1 -1
- package/lib/config.d.ts +21 -17
- package/lib/config.js +77 -157
- package/lib/config.js.map +1 -1
- package/lib/generation-handler.d.ts +3 -4
- package/lib/generation-handler.js +15 -26
- package/lib/generation-handler.js.map +1 -1
- package/lib/module-loader.d.ts +13 -10
- package/lib/module-loader.js +56 -57
- package/lib/module-loader.js.map +1 -1
- package/lib/start.js +2 -1
- package/lib/start.js.map +1 -1
- package/package.json +15 -15
- package/src/commands/copy.ts +94 -0
- package/src/commands/doc.ts +16 -19
- package/src/commands/generate.ts +37 -20
- package/src/commands/index.ts +1 -0
- package/src/commands/list.ts +9 -1
- package/src/config.ts +88 -176
- package/src/generation-handler.ts +19 -29
- package/src/module-loader.ts +69 -66
- package/src/start.ts +2 -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
|
|
21
|
+
CLI tool to generate Typescript Type Definition files for GJS.
|
|
22
22
|
|
|
23
23
|
## Getting started
|
|
24
24
|
|
|
25
25
|
``` bash
|
|
26
|
-
|
|
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,28 +31,28 @@ ts-for-gir --help
|
|
|
32
31
|
> npm install --save-dev @ts-for-gir/cli
|
|
33
32
|
> ```
|
|
34
33
|
>
|
|
35
|
-
> Or
|
|
34
|
+
> Or globally install it:
|
|
36
35
|
> ```bash
|
|
37
|
-
>
|
|
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
40
|
```bash
|
|
43
|
-
$ ts-for-gir --help
|
|
41
|
+
$ npx @ts-for-gir/cli --help
|
|
44
42
|
|
|
45
|
-
|
|
43
|
+
TypeScript type definition generator for GObject introspection GIR files
|
|
46
44
|
|
|
47
45
|
Commands:
|
|
48
|
-
ts-for-gir generate [modules..] Generates .d.ts files from GIR for GJS
|
|
49
|
-
e-gtk
|
|
46
|
+
ts-for-gir generate [modules..] Generates .d.ts files from GIR for GJS
|
|
50
47
|
ts-for-gir list [modules..] Lists all available GIR modules
|
|
48
|
+
ts-for-gir copy [modules..] Scan for *.gir files and copy them to a new d
|
|
49
|
+
irectory
|
|
51
50
|
ts-for-gir doc [modules..] The HTML documentation generator is not yet i
|
|
52
51
|
mplemented, but feel free to implement it 🤗
|
|
53
52
|
|
|
54
53
|
Options:
|
|
55
54
|
--version Show version number [boolean]
|
|
56
|
-
--help Show help [boolean]
|
|
55
|
+
--help Show help [boolean]
|
|
57
56
|
```
|
|
58
57
|
|
|
59
58
|
## Example
|
|
@@ -64,24 +63,16 @@ To generate the Typescript type definitions of Gtk-4.0 for GJS run:
|
|
|
64
63
|
ts-for-gir generate Gtk-4.0
|
|
65
64
|
```
|
|
66
65
|
|
|
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
66
|
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.
|
|
74
67
|
|
|
75
68
|
## Generate .d.ts files
|
|
76
69
|
|
|
77
70
|
```bash
|
|
78
|
-
$ ts-for-gir generate --help
|
|
71
|
+
$ npx @ts-for-gir/cli generate --help
|
|
79
72
|
|
|
80
73
|
ts-for-gir generate [modules..]
|
|
81
74
|
|
|
82
|
-
ts
|
|
83
|
-
|
|
84
|
-
Generates .d.ts files from GIR for GJS or node-gtk
|
|
75
|
+
Generates .d.ts files from GIR for GJS
|
|
85
76
|
|
|
86
77
|
Options:
|
|
87
78
|
--version Show version number [boolean]
|
|
@@ -90,58 +81,50 @@ Options:
|
|
|
90
81
|
tiple modules [array] [default: ["*"]]
|
|
91
82
|
-g, --girDirectories GIR directories
|
|
92
83
|
[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/
|
|
94
|
-
|
|
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"]]
|
|
84
|
+
/*/gir-1.0","/usr/share/gnome-shell","/usr/share/gnome-shell/gir-1.0","/usr/li
|
|
85
|
+
b64/mutter-*","/usr/lib/mutter-*","/usr/lib/x86_64-linux-gnu/mutter-*"]]
|
|
98
86
|
--root Root directory of your project
|
|
99
|
-
|
|
87
|
+
[string] [default: "/home/jumplink/Projekte/gjsify/ts-for-gir"]
|
|
100
88
|
-o, --outdir Directory to output to
|
|
101
89
|
[string] [default: "./@types"]
|
|
102
|
-
-e, --environments Javascript environment
|
|
103
|
-
[array] [choices: "gjs", "node"] [default: ["gjs"]]
|
|
104
90
|
-i, --ignore Modules that should be ignored
|
|
105
91
|
[array] [default: []]
|
|
106
|
-
-b, --buildType Definitions generation type
|
|
107
|
-
[string] [choices: "lib", "types"] [default: "lib"]
|
|
108
|
-
-t, --moduleType Specify what module code is generated.
|
|
109
|
-
[string] [choices: "esm", "commonjs", "cjs"] [default: "esm"]
|
|
110
92
|
-v, --verbose Switch on/off the verbose mode
|
|
111
93
|
[string] [default: false]
|
|
112
|
-
--ignoreVersionConflicts
|
|
113
|
-
|
|
94
|
+
--ignoreVersionConflicts Skip prompts for library version selection when
|
|
95
|
+
multiple versions are detected
|
|
96
|
+
[string] [default: false]
|
|
114
97
|
-p, --print Print the output to console and create no files
|
|
115
98
|
[string] [default: false]
|
|
116
|
-
--configName
|
|
117
|
-
|
|
99
|
+
--configName Specify a custom name for the configuration file
|
|
100
|
+
[string] [default: ".ts-for-girrc.js"]
|
|
118
101
|
-d, --noNamespace Do not export all symbols for each module as a n
|
|
119
102
|
amespace [string] [default: false]
|
|
120
103
|
-n, --noComments Do not generate documentation comments
|
|
121
104
|
[string] [default: false]
|
|
122
|
-
--noDebugComments Do not generate debugging inline comments
|
|
123
|
-
[string] [default: false]
|
|
124
|
-
--fixConflicts Fix Inheritance and implementation type conflict
|
|
125
|
-
s [string] [default: true]
|
|
126
|
-
-a, --generateAlias Generate an alias tsconfig file to support GJS E
|
|
127
|
-
SM module imports [string] [default: false]
|
|
128
105
|
--promisify Generate promisified functions for async/finish
|
|
129
106
|
calls [string] [default: true]
|
|
130
107
|
--npmScope Scope of the generated NPM packages
|
|
131
108
|
[string] [default: "@girs"]
|
|
132
|
-
--
|
|
133
|
-
|
|
109
|
+
--workspace Uses the workspace protocol for the generated pa
|
|
110
|
+
ckages which can be used with package managers l
|
|
111
|
+
ike Yarn and PNPM [string] [default: false]
|
|
112
|
+
--onlyVersionPrefix Only use the version prefix for the ambient modu
|
|
113
|
+
le exports. This is useful if, for whatever reas
|
|
114
|
+
on, you want to use different library versions o
|
|
115
|
+
f the same library in your project.
|
|
116
|
+
[string] [default: false]
|
|
117
|
+
--package Generate the typescript types with package.json
|
|
118
|
+
support [string] [default: false]
|
|
134
119
|
|
|
135
120
|
Examples:
|
|
136
121
|
ts-for-gir generate Run 'ts-for-gir generate' in your gj
|
|
137
|
-
s
|
|
138
|
-
|
|
139
|
-
|
|
122
|
+
s project to generate typings for yo
|
|
123
|
+
ur project, pass the gir modules you
|
|
124
|
+
need for your project
|
|
140
125
|
ts-for-gir generate Gtk* You can also use wild cards
|
|
141
126
|
ts-for-gir generate '*' If you want to parse all of your loc
|
|
142
127
|
ally installed gir modules run
|
|
143
|
-
ts-for-gir generate '*' -e gjs Generate .d.ts. files only for gjs
|
|
144
|
-
ts-for-gir generate '*' -e node Generate .d.ts. files only for node
|
|
145
128
|
ts-for-gir generate --configName='.ts-fo Use a special config file
|
|
146
129
|
r-gir.gtk4.rc.js
|
|
147
130
|
ts-for-gir generate --ignore=Gtk-4.0 xra Generate .d.ts. files but not for Gt
|
|
@@ -151,7 +134,7 @@ Examples:
|
|
|
151
134
|
## List available GIR modules
|
|
152
135
|
|
|
153
136
|
```bash
|
|
154
|
-
$ ts-for-gir list --help
|
|
137
|
+
$ npx @ts-for-gir/cli list --help
|
|
155
138
|
|
|
156
139
|
ts-for-gir list [modules..]
|
|
157
140
|
|
|
@@ -164,13 +147,12 @@ Options:
|
|
|
164
147
|
dules [array] [default: ["*"]]
|
|
165
148
|
-g, --girDirectories GIR directories
|
|
166
149
|
[array] [default: ["/usr/local/share/gir-1.0","/usr/share/gir-1.0","/usr/share
|
|
167
|
-
/gnome-shell","/usr/share/gnome-shell/gir-1.0","/usr/
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
rts/share/gir-1.0"]]
|
|
150
|
+
/*/gir-1.0","/usr/share/gnome-shell","/usr/share/gnome-shell/gir-1.0","/usr/li
|
|
151
|
+
b64/mutter-*","/usr/lib/mutter-*","/usr/lib/x86_64-linux-gnu/mutter-*"]]
|
|
152
|
+
--root Root directory of your project
|
|
153
|
+
[string] [default: "/home/jumplink/Projekte/gjsify/ts-for-gir"]
|
|
172
154
|
-i, --ignore Modules that should be ignored [array] [default: []]
|
|
173
|
-
--configName
|
|
155
|
+
--configName Specify a custom name for the configuration file
|
|
174
156
|
[string] [default: ".ts-for-girrc.js"]
|
|
175
157
|
-v, --verbose Switch on/off the verbose mode [string] [default: false]
|
|
176
158
|
|
|
@@ -185,7 +167,7 @@ Examples:
|
|
|
185
167
|
## Generate HTML documentation
|
|
186
168
|
|
|
187
169
|
```bash
|
|
188
|
-
$ ts-for-gir doc --help
|
|
170
|
+
$ npx @ts-for-gir/cli doc --help
|
|
189
171
|
|
|
190
172
|
ts-for-gir doc [modules..]
|
|
191
173
|
|
|
@@ -200,16 +182,11 @@ To do that, create a new config file called `.ts-for-girrc.js` in your project r
|
|
|
200
182
|
```js
|
|
201
183
|
// or on CommonJs: exports.default = {
|
|
202
184
|
export default {
|
|
203
|
-
print: false,
|
|
204
185
|
verbose: true,
|
|
205
|
-
environments: ['gjs', 'node'],
|
|
206
186
|
outdir: '@types',
|
|
207
187
|
girDirectories: ['/usr/share/gir-1.0'],
|
|
208
188
|
modules: ['*'],
|
|
209
189
|
ignore: [],
|
|
210
|
-
noNamespace: false,
|
|
211
|
-
buildType: 'lib',
|
|
212
|
-
moduleType: 'esm'
|
|
213
190
|
}
|
|
214
191
|
```
|
|
215
192
|
|
|
@@ -251,97 +228,23 @@ In this example, the generated TypeScript types will be saved in the `./types` d
|
|
|
251
228
|
|
|
252
229
|
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.
|
|
253
230
|
|
|
254
|
-
### environments
|
|
255
|
-
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.
|
|
256
|
-
|
|
257
|
-
The default value for this option is `"gjs"`.
|
|
258
|
-
|
|
259
|
-
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:
|
|
260
|
-
|
|
261
|
-
```bash
|
|
262
|
-
ts-for-gir generate * --environments gjs node
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
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.
|
|
266
|
-
|
|
267
231
|
### ignore
|
|
268
232
|
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.
|
|
269
233
|
|
|
270
234
|
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:
|
|
271
235
|
|
|
272
236
|
```bash
|
|
273
|
-
ts-for-gir generate Gtk-* --ignore Gtk-3.0
|
|
237
|
+
ts-for-gir generate Gtk-* --ignore */Gtk-3.0
|
|
274
238
|
```
|
|
275
239
|
|
|
276
240
|
You can also ignore multiple modules:
|
|
277
241
|
|
|
278
242
|
```bash
|
|
279
|
-
ts-for-gir generate * --ignore Gtk-2.0 Gtk-3.0 Gtk-4.0
|
|
243
|
+
ts-for-gir generate * --ignore */Gtk-2.0 */Gtk-3.0 */Gtk-4.0
|
|
280
244
|
```
|
|
281
245
|
|
|
282
246
|
Note that ignoring a module will prevent ts-for-gir from generating types for that module and any submodules that it might contain.
|
|
283
247
|
|
|
284
|
-
### buildType
|
|
285
|
-
`ts-for-gir` supports two build types for generating the types: `"lib"` and `"types"`.
|
|
286
|
-
|
|
287
|
-
* 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.
|
|
288
|
-
* 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. If you have problems to use imports in `ESM` format, you can also enable the `generateAlias` option and extend your `tsconfig` from the generated `"tsconfig.alias.json"`.
|
|
289
|
-
|
|
290
|
-
### moduleType
|
|
291
|
-
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.
|
|
292
|
-
|
|
293
|
-
> 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.
|
|
294
|
-
|
|
295
|
-
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`.
|
|
296
|
-
|
|
297
|
-
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:
|
|
298
|
-
|
|
299
|
-
```ts
|
|
300
|
-
// Gtk-4.0.d.ts
|
|
301
|
-
import type GLib from './GLib-2.0.js';
|
|
302
|
-
|
|
303
|
-
namespace Gtk {
|
|
304
|
-
class Window extends Widget {
|
|
305
|
-
...
|
|
306
|
-
}
|
|
307
|
-
function builder_error_quark(): GLib.Quark
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
export default Gtk;
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
```js
|
|
314
|
-
// Gtk-4.0.js
|
|
315
|
-
import Gtk from 'gi://Gtk?version=4.0';
|
|
316
|
-
export default Gtk;
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
> 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.
|
|
320
|
-
|
|
321
|
-
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:
|
|
322
|
-
|
|
323
|
-
```ts
|
|
324
|
-
// Gtk-4.0.d.ts
|
|
325
|
-
import type * as GLib from './GLib-2.0.js';
|
|
326
|
-
|
|
327
|
-
export class Window extends Widget {
|
|
328
|
-
...
|
|
329
|
-
}
|
|
330
|
-
export function builder_error_quark(): GLib.Quark
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
```js
|
|
334
|
-
// Gtk-4.0.js
|
|
335
|
-
imports.gi.versions.Gtk = '4.0'
|
|
336
|
-
const Gtk = imports.gi.Gtk;
|
|
337
|
-
|
|
338
|
-
module.exports = { Gtk };
|
|
339
|
-
exports.default = Gtk;
|
|
340
|
-
```
|
|
341
|
-
|
|
342
|
-
> 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.
|
|
343
|
-
|
|
344
|
-
|
|
345
248
|
### verbose
|
|
346
249
|
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.
|
|
347
250
|
|
|
@@ -387,60 +290,6 @@ To use the noComments option, pass it as a command line argument to `ts-for-gir`
|
|
|
387
290
|
ts-for-gir generate * --noComments`
|
|
388
291
|
```
|
|
389
292
|
|
|
390
|
-
### noDebugComments
|
|
391
|
-
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.
|
|
392
|
-
|
|
393
|
-
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.
|
|
394
|
-
|
|
395
|
-
### fixConflicts
|
|
396
|
-
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.
|
|
397
|
-
|
|
398
|
-
> 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.
|
|
399
|
-
|
|
400
|
-
### generateAlias
|
|
401
|
-
The `generateAlias` CLI option, when active, generates an alias `tsconfig.alias.json` file to support ESM module imports in GJS. This is particularly useful if you want to import GIR modules in your GJS code using the `'gi://...'` syntax. The generated `tsconfig.alias.json` file will contain the necessary path aliases to enable TypeScript to properly resolve the imported modules, allowing for improved code editor functionality, such as type checking and code completion.
|
|
402
|
-
|
|
403
|
-
The generateAlias option is particularly useful for GJS applications, as it allows you to import GIR modules using the standard ESM syntax, rather than having to use the global imports object.
|
|
404
|
-
|
|
405
|
-
You can extend the generated `tsconfig.alias.json` file in your main tsconfig.json file by setting the extends field to `./tsconfig.alias.json`.
|
|
406
|
-
|
|
407
|
-
```json
|
|
408
|
-
// tsconfig.alias.json
|
|
409
|
-
{
|
|
410
|
-
"compilerOptions": {
|
|
411
|
-
"baseUrl": ".",
|
|
412
|
-
"paths": {
|
|
413
|
-
"gi://Gio?version=2.0": ["./@types/gio-2.0.d.ts"],
|
|
414
|
-
"gi://Gio": ["./@types/gio-2.0.d.ts"],
|
|
415
|
-
"gi://GObject?version=2.0": ["./@types/gobject-2.0.d.ts"],
|
|
416
|
-
"gi://GObject": ["./@types/gobject-2.0.d.ts"],
|
|
417
|
-
"gi://GLib?version=2.0": ["./@types/glib-2.0.d.ts"],
|
|
418
|
-
"gi://GLib": ["./@types/glib-2.0.d.ts"]
|
|
419
|
-
}
|
|
420
|
-
},
|
|
421
|
-
"include": ["./@types/*.ts"]
|
|
422
|
-
}
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
```json
|
|
426
|
-
// tsconfig.json
|
|
427
|
-
{
|
|
428
|
-
"extends": "./tsconfig.alias.json",
|
|
429
|
-
"compilerOptions": {
|
|
430
|
-
"lib": ["ESNext"],
|
|
431
|
-
"types": [],
|
|
432
|
-
"target": "ESNext",
|
|
433
|
-
"module": "ESNext"
|
|
434
|
-
},
|
|
435
|
-
"include": ["@types/gjs.d.ts"],
|
|
436
|
-
"files": [
|
|
437
|
-
"main.ts",
|
|
438
|
-
]
|
|
439
|
-
}
|
|
440
|
-
```
|
|
441
|
-
|
|
442
|
-
> The example in [examples/gjs/gio-2-cat-alias](https://github.com/gjsify/ts-for-gir/tree/main/examples/gjs/gio-2-cat-alias) demonstrates the usage of the generateAlias option. This example shows how to use the generated tsconfig.alias.json file in a GJS project and provides a clear understanding of how this option can be used in practice.
|
|
443
|
-
|
|
444
293
|
# package
|
|
445
294
|
|
|
446
295
|
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`.
|
|
@@ -494,9 +343,6 @@ Alternatively, you can also use the pre-generated NPM packages for this, so you
|
|
|
494
343
|
|
|
495
344
|
> The advantage of self-generated types is that you generate the types exactly for your locally installed library version. However, we try to keep the pre-generated NPM packages as up to date as possible.
|
|
496
345
|
|
|
497
|
-
### Alias
|
|
498
|
-
If for some reason you don't want to or can't generate NPM packages, you can instead use the [`--generateAlias`](#generatealias) CLI option. This way you can also use imports in the `gi://` syntax with the generated types.
|
|
499
|
-
|
|
500
346
|
To use ambient modules, the `ambient.d.ts` file must be imported either in the code like `import '@girs/gjs/ambient'` or by adding an entry to the `includes` property in the `tsconfig` file. The `ambient.d.ts` file is automatically generated.
|
|
501
347
|
|
|
502
348
|
```json
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everything you need for the `ts-for-gir copy` command is located here
|
|
3
|
+
*/
|
|
4
|
+
import { Argv } from 'yargs';
|
|
5
|
+
import type { ConfigFlags } from '@ts-for-gir/lib';
|
|
6
|
+
export declare const copy: {
|
|
7
|
+
command: string;
|
|
8
|
+
description: string;
|
|
9
|
+
builder: ((args: Argv<any>) => Argv<ConfigFlags>) | ((args: Argv<any>) => void);
|
|
10
|
+
handler: (args: ConfigFlags) => Promise<void>;
|
|
11
|
+
examples: readonly [string, (string | undefined)?][];
|
|
12
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everything you need for the `ts-for-gir copy` command is located here
|
|
3
|
+
*/
|
|
4
|
+
import { copyFile, mkdir } from 'fs/promises';
|
|
5
|
+
import { basename, join } from 'path';
|
|
6
|
+
import { ModuleLoader } from '../module-loader.js';
|
|
7
|
+
import { Config } from '../config.js';
|
|
8
|
+
import { Logger, ERROR_NO_MODULES_FOUND } from '@ts-for-gir/lib';
|
|
9
|
+
const command = 'copy [modules..]';
|
|
10
|
+
const description = 'Scan for *.gir files and copy them to a new directory';
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
const builder = (yargs) => {
|
|
13
|
+
const optionNames = Object.keys(Config.copyOptions);
|
|
14
|
+
for (const optionName of optionNames) {
|
|
15
|
+
yargs = yargs.option(optionName, Config.copyOptions[optionName]);
|
|
16
|
+
}
|
|
17
|
+
return yargs.example(examples);
|
|
18
|
+
};
|
|
19
|
+
const copyGirFile = async (config, depModule) => {
|
|
20
|
+
if (!depModule.path) {
|
|
21
|
+
Logger.danger(`- ${depModule.packageName} not found`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (!config.outdir) {
|
|
25
|
+
Logger.error(`outdir not found`);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const filename = basename(depModule.path);
|
|
29
|
+
const dest = join(config.outdir, filename);
|
|
30
|
+
if (depModule.path === dest) {
|
|
31
|
+
Logger.yellow(`Skip ${depModule.path}`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
Logger.success(`Copy ${depModule.path}`);
|
|
35
|
+
await copyFile(depModule.path, dest);
|
|
36
|
+
};
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
const handler = async (args) => {
|
|
39
|
+
const config = await Config.load(args);
|
|
40
|
+
const generateConfig = Config.getOptionsGeneration(config);
|
|
41
|
+
const moduleLoader = new ModuleLoader(generateConfig);
|
|
42
|
+
const { grouped, failed } = await moduleLoader.getModules(config.modules, config.ignore);
|
|
43
|
+
const moduleGroups = Object.values(grouped);
|
|
44
|
+
if (Object.keys(grouped).length === 0) {
|
|
45
|
+
return Logger.error(ERROR_NO_MODULES_FOUND(config.girDirectories));
|
|
46
|
+
}
|
|
47
|
+
if (!config.outdir) {
|
|
48
|
+
Logger.error(`outdir not found`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
await mkdir(config.outdir, { recursive: true }).catch((err) => {
|
|
52
|
+
Logger.error(`Failed to copy gir files to ${config.outdir}: ${err}`);
|
|
53
|
+
});
|
|
54
|
+
for (const module of moduleGroups) {
|
|
55
|
+
for (const mod of module.modules) {
|
|
56
|
+
await copyGirFile(config, mod);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (failed.length > 0) {
|
|
60
|
+
Logger.danger('\nDependencies not found:');
|
|
61
|
+
for (const fail of failed) {
|
|
62
|
+
Logger.white(`- ${fail}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const examples = [
|
|
67
|
+
[`${Config.appName} copy -o ./gir`, `Copy found *.gir files to ./gir`],
|
|
68
|
+
[
|
|
69
|
+
`${Config.appName} copy -g /usr/share/gir-1.0 --ignore=Gtk-3.0 xrandr-1.3 -o ./gir`,
|
|
70
|
+
'Copy all found *.gir files in /usr/share/gir-1.0 excluding Gtk-3.0 and xrandr-1.3 to ./gir',
|
|
71
|
+
],
|
|
72
|
+
];
|
|
73
|
+
export const copy = {
|
|
74
|
+
command,
|
|
75
|
+
description,
|
|
76
|
+
builder,
|
|
77
|
+
handler,
|
|
78
|
+
examples,
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=copy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copy.js","sourceRoot":"","sources":["../../src/commands/copy.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAA;AAIhE,MAAM,OAAO,GAAG,kBAAkB,CAAA;AAElC,MAAM,WAAW,GAAG,uDAAuD,CAAA;AAE3E,8DAA8D;AAC9D,MAAM,OAAO,GAAsC,CAAC,KAAgB,EAAE,EAAE;IACpE,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;IACnD,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACnC,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAA;IACpE,CAAC;IACD,OAAO,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAsB,CAAA;AACvD,CAAC,CAAA;AAED,MAAM,WAAW,GAAG,KAAK,EAAE,MAAkB,EAAE,SAA8B,EAAE,EAAE;IAC7E,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;QAClB,MAAM,CAAC,MAAM,CAAC,KAAK,SAAS,CAAC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
20
20
|
const handler = async (args) => {
|
|
21
21
|
const config = await Config.load(args);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (keep.length === 0) {
|
|
28
|
-
return Logger.error(ERROR_NO_MODULES_FOUND(config.girDirectories));
|
|
29
|
-
}
|
|
30
|
-
const tsForGir = new GenerationHandler(generateConfig, GeneratorType.HTML_DOC);
|
|
31
|
-
await tsForGir.start(Array.from(keep).map((girModuleResolvedBy) => girModuleResolvedBy.module), Object.values(grouped));
|
|
32
|
-
}
|
|
22
|
+
const generateConfig = Config.getOptionsGeneration(config);
|
|
23
|
+
const moduleLoader = new ModuleLoader(generateConfig);
|
|
24
|
+
const { keep } = await moduleLoader.getModulesResolved(config.modules, config.ignore || [], config.ignoreVersionConflicts);
|
|
25
|
+
if (keep.length === 0) {
|
|
26
|
+
return Logger.error(ERROR_NO_MODULES_FOUND(config.girDirectories));
|
|
33
27
|
}
|
|
28
|
+
const tsForGir = new GenerationHandler(generateConfig, GeneratorType.HTML_DOC);
|
|
29
|
+
const registry = moduleLoader.dependencyManager;
|
|
30
|
+
await tsForGir.start(Array.from(keep).map((girModuleResolvedBy) => girModuleResolvedBy.module), registry);
|
|
34
31
|
};
|
|
35
32
|
const examples = [];
|
|
36
33
|
export const doc = {
|
package/lib/commands/doc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doc.js","sourceRoot":"","sources":["../../src/commands/doc.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAIlD,MAA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cAAc,GAAG,MAAM,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAA;IAC1D,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,cAAc,CAAC,CAAA;IACrD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,YAAY,CAAC,kBAAkB,CAClD,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,MAAM,IAAI,EAAE,EACnB,MAAM,CAAC,sBAAsB,CAChC,CAAA;IACD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpB,OAAO,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAA;IACtE,CAAC;IACD,MAAM,QAAQ,GAAG,IAAI,iBAAiB,CAAC,cAAc,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAA;IAC9E,MAAM,QAAQ,GAAG,YAAY,CAAC,iBAAiB,CAAA;IAE/C,MAAM,QAAQ,CAAC,KAAK,CAChB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,mBAAmB,EAAE,EAAE,CAAC,mBAAmB,CAAC,MAAM,CAAC,EACzE,QAAQ,CACX,CAAA;AACL,CAAC,CAAA;AAED,MAAM,QAAQ,GAAqC,EAAE,CAAA;AAErD,MAAM,CAAC,MAAM,GAAG,GAAG;IACf,OAAO;IACP,WAAW;IACX,OAAO;IACP,OAAO;IACP,QAAQ;CACX,CAAA"}
|
package/lib/commands/generate.js
CHANGED
|
@@ -6,8 +6,10 @@ import { GeneratorType } from '@ts-for-gir/generator-base';
|
|
|
6
6
|
import { GenerationHandler } from '../generation-handler.js';
|
|
7
7
|
import { Config } from '../config.js';
|
|
8
8
|
import { ModuleLoader } from '../module-loader.js';
|
|
9
|
+
import prettier from 'prettier';
|
|
10
|
+
import { Formatter } from '@ts-for-gir/lib';
|
|
9
11
|
const command = 'generate [modules..]';
|
|
10
|
-
const description = 'Generates .d.ts files from GIR for GJS
|
|
12
|
+
const description = 'Generates Typescript type definition .d.ts files from GIR for GJS';
|
|
11
13
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
14
|
const builder = (yargs) => {
|
|
13
15
|
const optionNames = Object.keys(Config.generateOptions);
|
|
@@ -19,34 +21,46 @@ const builder = (yargs) => {
|
|
|
19
21
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
22
|
const handler = async (args) => {
|
|
21
23
|
const config = await Config.load(args);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return Logger.error(ERROR_NO_MODULES_FOUND(config.girDirectories));
|
|
28
|
-
}
|
|
29
|
-
const tsForGir = new GenerationHandler(generateConfig, GeneratorType.TYPES);
|
|
30
|
-
const girModules = Array.from(keep).map((girModuleResolvedBy) => girModuleResolvedBy.module);
|
|
31
|
-
const girModulesGrouped = Object.values(grouped);
|
|
32
|
-
await tsForGir.start(girModules, girModulesGrouped);
|
|
24
|
+
const generateConfig = Config.getOptionsGeneration(config);
|
|
25
|
+
const moduleLoader = new ModuleLoader(generateConfig);
|
|
26
|
+
const { keep } = await moduleLoader.getModulesResolved(config.modules, config.ignore || [], config.ignoreVersionConflicts);
|
|
27
|
+
if (keep.length === 0) {
|
|
28
|
+
return Logger.error(ERROR_NO_MODULES_FOUND(config.girDirectories));
|
|
33
29
|
}
|
|
30
|
+
moduleLoader.parse(keep);
|
|
31
|
+
const tsForGir = new GenerationHandler(generateConfig, GeneratorType.TYPES);
|
|
32
|
+
const girModules = Array.from(keep).map((girModuleResolvedBy) => girModuleResolvedBy.module);
|
|
33
|
+
moduleLoader.dependencyManager.registerFormatter('dts', new TypeScriptFormatter());
|
|
34
|
+
await tsForGir.start(girModules, moduleLoader.dependencyManager);
|
|
34
35
|
};
|
|
35
36
|
const examples = [
|
|
36
37
|
[
|
|
37
38
|
`${Config.appName} generate`,
|
|
38
|
-
`Run '${Config.appName} generate' in your gjs
|
|
39
|
+
`Run '${Config.appName} generate' in your gjs project to generate typings for your project, pass the gir modules you need for your project`,
|
|
39
40
|
],
|
|
40
41
|
[`${Config.appName} generate Gtk*`, 'You can also use wild cards'],
|
|
41
42
|
[`${Config.appName} generate '*'`, 'If you want to parse all of your locally installed gir modules run'],
|
|
42
|
-
[`${Config.appName} generate '*' -e gjs`, 'Generate .d.ts. files only for gjs'],
|
|
43
|
-
[`${Config.appName} generate '*' -e node`, 'Generate .d.ts. files only for node'],
|
|
44
43
|
[`${Config.appName} generate --configName='.ts-for-gir.gtk4.rc.js`, 'Use a special config file'],
|
|
45
44
|
[
|
|
46
45
|
`${Config.appName} generate --ignore=Gtk-4.0 xrandr-1.3`,
|
|
47
46
|
'Generate .d.ts. files but not for Gtk-4.0 and xrandr-1.3',
|
|
48
47
|
],
|
|
49
48
|
];
|
|
49
|
+
class TypeScriptFormatter extends Formatter {
|
|
50
|
+
format(input) {
|
|
51
|
+
try {
|
|
52
|
+
return prettier.format(input, {
|
|
53
|
+
singleQuote: true,
|
|
54
|
+
parser: 'typescript',
|
|
55
|
+
printWidth: 120,
|
|
56
|
+
tabWidth: 4,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
return Promise.resolve(input);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
50
64
|
export const generate = {
|
|
51
65
|
command,
|
|
52
66
|
description,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/commands/generate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,qB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M,CAAC,KAAK,EAAE;gBAC1B,WAAW,EAAE,IAAI;gBACjB,MAAM,EAAE,YAAY;gBACpB,UAAU,EAAE,GAAG;gBACf,QAAQ,EAAE,CAAC;aACd,CAAC,CAAA;QACN,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QACjC,CAAC;IACL,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG;IACpB,OAAO;IACP,WAAW;IACX,OAAO;IACP,OAAO;IACP,QAAQ;CACX,CAAA"}
|
package/lib/commands/index.d.ts
CHANGED
package/lib/commands/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA"}
|