@ts-for-gir/cli 3.0.0-beta.8 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +429 -49
- package/lib/commands/doc.d.ts +1 -17
- package/lib/commands/doc.js +7 -13
- package/lib/commands/doc.js.map +1 -1
- package/lib/commands/generate.d.ts +1 -39
- package/lib/commands/generate.js +8 -25
- package/lib/commands/generate.js.map +1 -1
- package/lib/commands/list.d.ts +1 -11
- package/lib/commands/list.js +6 -10
- package/lib/commands/list.js.map +1 -1
- package/lib/config.d.ts +25 -11
- package/lib/config.js +194 -112
- package/lib/config.js.map +1 -1
- package/lib/generation-handler.d.ts +3 -4
- package/lib/generation-handler.js +8 -12
- package/lib/generation-handler.js.map +1 -1
- package/lib/index.d.ts +0 -12
- package/lib/index.js +0 -12
- package/lib/index.js.map +1 -1
- package/lib/module-loader.d.ts +41 -27
- package/lib/module-loader.js +54 -56
- package/lib/module-loader.js.map +1 -1
- package/lib/utils.d.ts +13 -86
- package/lib/utils.js +13 -194
- package/lib/utils.js.map +1 -1
- package/package.json +32 -37
- package/src/commands/doc.ts +9 -14
- package/src/commands/generate.ts +10 -25
- package/src/commands/list.ts +8 -10
- package/src/config.ts +211 -115
- package/src/generation-handler.ts +12 -13
- package/src/index.ts +0 -12
- package/src/module-loader.ts +88 -75
- package/src/utils.ts +12 -222
- package/lib/conflict-resolver.d.ts +0 -155
- package/lib/conflict-resolver.js +0 -1103
- package/lib/conflict-resolver.js.map +0 -1
- package/lib/constants.d.ts +0 -18
- package/lib/constants.js +0 -23
- package/lib/constants.js.map +0 -1
- package/lib/generator.d.ts +0 -5
- package/lib/generator.js +0 -2
- package/lib/generator.js.map +0 -1
- package/lib/gir-factory.d.ts +0 -51
- package/lib/gir-factory.js +0 -361
- package/lib/gir-factory.js.map +0 -1
- package/lib/gir-module.d.ts +0 -256
- package/lib/gir-module.js +0 -2075
- package/lib/gir-module.js.map +0 -1
- package/lib/html-doc-generator.d.ts +0 -13
- package/lib/html-doc-generator.js +0 -18
- package/lib/html-doc-generator.js.map +0 -1
- package/lib/injection/callbacks/gjs/Gio-2.0.d.ts +0 -2
- package/lib/injection/callbacks/gjs/Gio-2.0.js +0 -36
- package/lib/injection/callbacks/gjs/Gio-2.0.js.map +0 -1
- package/lib/injection/callbacks/gjs/index.d.ts +0 -2
- package/lib/injection/callbacks/gjs/index.js +0 -3
- package/lib/injection/callbacks/gjs/index.js.map +0 -1
- package/lib/injection/callbacks/index.d.ts +0 -4
- package/lib/injection/callbacks/index.js +0 -4
- package/lib/injection/callbacks/index.js.map +0 -1
- package/lib/injection/callbacks/node-gtk/index.d.ts +0 -2
- package/lib/injection/callbacks/node-gtk/index.js +0 -2
- package/lib/injection/callbacks/node-gtk/index.js.map +0 -1
- package/lib/injection/classes/GLib-2-0.d.ts +0 -2
- package/lib/injection/classes/GLib-2-0.js +0 -35
- package/lib/injection/classes/GLib-2-0.js.map +0 -1
- package/lib/injection/classes/gjs/GLib-2.0.d.ts +0 -2
- package/lib/injection/classes/gjs/GLib-2.0.js +0 -200
- package/lib/injection/classes/gjs/GLib-2.0.js.map +0 -1
- package/lib/injection/classes/gjs/GObject-2.0.d.ts +0 -2
- package/lib/injection/classes/gjs/GObject-2.0.js +0 -634
- package/lib/injection/classes/gjs/GObject-2.0.js.map +0 -1
- package/lib/injection/classes/gjs/Gio-2.0.d.ts +0 -5
- package/lib/injection/classes/gjs/Gio-2.0.js +0 -218
- package/lib/injection/classes/gjs/Gio-2.0.js.map +0 -1
- package/lib/injection/classes/gjs/index.d.ts +0 -2
- package/lib/injection/classes/gjs/index.js +0 -5
- package/lib/injection/classes/gjs/index.js.map +0 -1
- package/lib/injection/classes/index.d.ts +0 -4
- package/lib/injection/classes/index.js +0 -5
- package/lib/injection/classes/index.js.map +0 -1
- package/lib/injection/classes/node-gtk/GLib-2.0.d.ts +0 -2
- package/lib/injection/classes/node-gtk/GLib-2.0.js +0 -19
- package/lib/injection/classes/node-gtk/GLib-2.0.js.map +0 -1
- package/lib/injection/classes/node-gtk/GObject-2.0.d.ts +0 -2
- package/lib/injection/classes/node-gtk/GObject-2.0.js +0 -66
- package/lib/injection/classes/node-gtk/GObject-2.0.js.map +0 -1
- package/lib/injection/classes/node-gtk/Gdk-4.0.d.ts +0 -2
- package/lib/injection/classes/node-gtk/Gdk-4.0.js +0 -32
- package/lib/injection/classes/node-gtk/Gdk-4.0.js.map +0 -1
- package/lib/injection/classes/node-gtk/Gio-2.0.d.ts +0 -2
- package/lib/injection/classes/node-gtk/Gio-2.0.js +0 -14
- package/lib/injection/classes/node-gtk/Gio-2.0.js.map +0 -1
- package/lib/injection/classes/node-gtk/Graphene-1.0.d.ts +0 -2
- package/lib/injection/classes/node-gtk/Graphene-1.0.js +0 -133
- package/lib/injection/classes/node-gtk/Graphene-1.0.js.map +0 -1
- package/lib/injection/classes/node-gtk/Gtk-3.0.d.ts +0 -2
- package/lib/injection/classes/node-gtk/Gtk-3.0.js +0 -31
- package/lib/injection/classes/node-gtk/Gtk-3.0.js.map +0 -1
- package/lib/injection/classes/node-gtk/Gtk-4.0.d.ts +0 -2
- package/lib/injection/classes/node-gtk/Gtk-4.0.js +0 -52
- package/lib/injection/classes/node-gtk/Gtk-4.0.js.map +0 -1
- package/lib/injection/classes/node-gtk/Pango-1.0.d.ts +0 -2
- package/lib/injection/classes/node-gtk/Pango-1.0.js +0 -31
- package/lib/injection/classes/node-gtk/Pango-1.0.js.map +0 -1
- package/lib/injection/classes/node-gtk/index.d.ts +0 -2
- package/lib/injection/classes/node-gtk/index.js +0 -19
- package/lib/injection/classes/node-gtk/index.js.map +0 -1
- package/lib/injection/index.d.ts +0 -3
- package/lib/injection/index.js +0 -4
- package/lib/injection/index.js.map +0 -1
- package/lib/injection/injector.d.ts +0 -17
- package/lib/injection/injector.js +0 -139
- package/lib/injection/injector.js.map +0 -1
- package/lib/logger.d.ts +0 -36
- package/lib/logger.js +0 -137
- package/lib/logger.js.map +0 -1
- package/lib/messages.d.ts +0 -30
- package/lib/messages.js +0 -45
- package/lib/messages.js.map +0 -1
- package/lib/symtable.d.ts +0 -24
- package/lib/symtable.js +0 -63
- package/lib/symtable.js.map +0 -1
- package/lib/template-processor.d.ts +0 -75
- package/lib/template-processor.js +0 -207
- package/lib/template-processor.js.map +0 -1
- package/lib/transformation.d.ts +0 -156
- package/lib/transformation.js +0 -523
- package/lib/transformation.js.map +0 -1
- package/lib/type-definition-generator.d.ts +0 -116
- package/lib/type-definition-generator.js +0 -989
- package/lib/type-definition-generator.js.map +0 -1
- package/lib/types/answer-version.d.ts +0 -4
- package/lib/types/answer-version.js +0 -2
- package/lib/types/answer-version.js.map +0 -1
- package/lib/types/build-type.d.ts +0 -1
- package/lib/types/build-type.js +0 -2
- package/lib/types/build-type.js.map +0 -1
- package/lib/types/class-parent.d.ts +0 -11
- package/lib/types/class-parent.js +0 -2
- package/lib/types/class-parent.js.map +0 -1
- package/lib/types/config-flags.d.ts +0 -4
- package/lib/types/config-flags.js +0 -2
- package/lib/types/config-flags.js.map +0 -1
- package/lib/types/conflict-child-element.d.ts +0 -10
- package/lib/types/conflict-child-element.js +0 -2
- package/lib/types/conflict-child-element.js.map +0 -1
- package/lib/types/conflict-grouped-element.d.ts +0 -6
- package/lib/types/conflict-grouped-element.js +0 -2
- package/lib/types/conflict-grouped-element.js.map +0 -1
- package/lib/types/conflict-grouped-elements.d.ts +0 -4
- package/lib/types/conflict-grouped-elements.js +0 -2
- package/lib/types/conflict-grouped-elements.js.map +0 -1
- package/lib/types/construct-name.d.ts +0 -1
- package/lib/types/construct-name.js +0 -2
- package/lib/types/construct-name.js.map +0 -1
- package/lib/types/dependency-map.d.ts +0 -4
- package/lib/types/dependency-map.js +0 -2
- package/lib/types/dependency-map.js.map +0 -1
- package/lib/types/dependency.d.ts +0 -14
- package/lib/types/dependency.js +0 -2
- package/lib/types/dependency.js.map +0 -1
- package/lib/types/environment.d.ts +0 -1
- package/lib/types/environment.js +0 -2
- package/lib/types/environment.js.map +0 -1
- package/lib/types/generate-config.d.ts +0 -34
- package/lib/types/generate-config.js +0 -2
- package/lib/types/generate-config.js.map +0 -1
- package/lib/types/generator-type.d.ts +0 -4
- package/lib/types/generator-type.js +0 -6
- package/lib/types/generator-type.js.map +0 -1
- package/lib/types/gir-alias-element.d.ts +0 -13
- package/lib/types/gir-alias-element.js +0 -2
- package/lib/types/gir-alias-element.js.map +0 -1
- package/lib/types/gir-annotation.d.ts +0 -9
- package/lib/types/gir-annotation.js +0 -2
- package/lib/types/gir-annotation.js.map +0 -1
- package/lib/types/gir-any-element.d.ts +0 -2
- package/lib/types/gir-any-element.js +0 -2
- package/lib/types/gir-any-element.js.map +0 -1
- package/lib/types/gir-any-type.d.ts +0 -5
- package/lib/types/gir-any-type.js +0 -2
- package/lib/types/gir-any-type.js.map +0 -1
- package/lib/types/gir-array-type.d.ts +0 -20
- package/lib/types/gir-array-type.js +0 -3
- package/lib/types/gir-array-type.js.map +0 -1
- package/lib/types/gir-bitfield-element.d.ts +0 -17
- package/lib/types/gir-bitfield-element.js +0 -2
- package/lib/types/gir-bitfield-element.js.map +0 -1
- package/lib/types/gir-boolean.d.ts +0 -1
- package/lib/types/gir-boolean.js +0 -2
- package/lib/types/gir-boolean.js.map +0 -1
- package/lib/types/gir-boxed-element.d.ts +0 -15
- package/lib/types/gir-boxed-element.js +0 -2
- package/lib/types/gir-boxed-element.js.map +0 -1
- package/lib/types/gir-c-include.d.ts +0 -7
- package/lib/types/gir-c-include.js +0 -2
- package/lib/types/gir-c-include.js.map +0 -1
- package/lib/types/gir-callable-attrs.d.ts +0 -15
- package/lib/types/gir-callable-attrs.js +0 -3
- package/lib/types/gir-callable-attrs.js.map +0 -1
- package/lib/types/gir-callable-param-element.d.ts +0 -30
- package/lib/types/gir-callable-param-element.js +0 -2
- package/lib/types/gir-callable-param-element.js.map +0 -1
- package/lib/types/gir-callable-param.d.ts +0 -7
- package/lib/types/gir-callable-param.js +0 -2
- package/lib/types/gir-callable-param.js.map +0 -1
- package/lib/types/gir-callable-return.d.ts +0 -22
- package/lib/types/gir-callable-return.js +0 -2
- package/lib/types/gir-callable-return.js.map +0 -1
- package/lib/types/gir-callback-element.d.ts +0 -15
- package/lib/types/gir-callback-element.js +0 -2
- package/lib/types/gir-callback-element.js.map +0 -1
- package/lib/types/gir-class-element.d.ts +0 -48
- package/lib/types/gir-class-element.js +0 -2
- package/lib/types/gir-class-element.js.map +0 -1
- package/lib/types/gir-constant-element.d.ts +0 -15
- package/lib/types/gir-constant-element.js +0 -2
- package/lib/types/gir-constant-element.js.map +0 -1
- package/lib/types/gir-constructor-element.d.ts +0 -8
- package/lib/types/gir-constructor-element.js +0 -2
- package/lib/types/gir-constructor-element.js.map +0 -1
- package/lib/types/gir-direction.d.ts +0 -5
- package/lib/types/gir-direction.js +0 -7
- package/lib/types/gir-direction.js.map +0 -1
- package/lib/types/gir-doc-element.d.ts +0 -68
- package/lib/types/gir-doc-element.js +0 -2
- package/lib/types/gir-doc-element.js.map +0 -1
- package/lib/types/gir-enum-element.d.ts +0 -19
- package/lib/types/gir-enum-element.js +0 -2
- package/lib/types/gir-enum-element.js.map +0 -1
- package/lib/types/gir-field-element.d.ts +0 -18
- package/lib/types/gir-field-element.js +0 -2
- package/lib/types/gir-field-element.js.map +0 -1
- package/lib/types/gir-function-element.d.ts +0 -8
- package/lib/types/gir-function-element.js +0 -2
- package/lib/types/gir-function-element.js.map +0 -1
- package/lib/types/gir-implements.d.ts +0 -8
- package/lib/types/gir-implements.js +0 -2
- package/lib/types/gir-implements.js.map +0 -1
- package/lib/types/gir-include.d.ts +0 -9
- package/lib/types/gir-include.js +0 -2
- package/lib/types/gir-include.js.map +0 -1
- package/lib/types/gir-info-attrs.d.ts +0 -13
- package/lib/types/gir-info-attrs.js +0 -2
- package/lib/types/gir-info-attrs.js.map +0 -1
- package/lib/types/gir-info-elements.d.ts +0 -5
- package/lib/types/gir-info-elements.js +0 -2
- package/lib/types/gir-info-elements.js.map +0 -1
- package/lib/types/gir-instance-parameter.d.ts +0 -21
- package/lib/types/gir-instance-parameter.js +0 -2
- package/lib/types/gir-instance-parameter.js.map +0 -1
- package/lib/types/gir-interface-element.d.ts +0 -31
- package/lib/types/gir-interface-element.js +0 -2
- package/lib/types/gir-interface-element.js.map +0 -1
- package/lib/types/gir-member-element.d.ts +0 -17
- package/lib/types/gir-member-element.js +0 -2
- package/lib/types/gir-member-element.js.map +0 -1
- package/lib/types/gir-method-element.d.ts +0 -13
- package/lib/types/gir-method-element.js +0 -2
- package/lib/types/gir-method-element.js.map +0 -1
- package/lib/types/gir-module-resolved-by.d.ts +0 -10
- package/lib/types/gir-module-resolved-by.js +0 -2
- package/lib/types/gir-module-resolved-by.js.map +0 -1
- package/lib/types/gir-modules-grouped-map.d.ts +0 -4
- package/lib/types/gir-modules-grouped-map.js +0 -2
- package/lib/types/gir-modules-grouped-map.js.map +0 -1
- package/lib/types/gir-modules-grouped.d.ts +0 -12
- package/lib/types/gir-modules-grouped.js +0 -2
- package/lib/types/gir-modules-grouped.js.map +0 -1
- package/lib/types/gir-namespace.d.ts +0 -30
- package/lib/types/gir-namespace.js +0 -2
- package/lib/types/gir-namespace.js.map +0 -1
- package/lib/types/gir-package.d.ts +0 -7
- package/lib/types/gir-package.js +0 -2
- package/lib/types/gir-package.js.map +0 -1
- package/lib/types/gir-prerequisite.d.ts +0 -5
- package/lib/types/gir-prerequisite.js +0 -2
- package/lib/types/gir-prerequisite.js.map +0 -1
- package/lib/types/gir-property-element.d.ts +0 -21
- package/lib/types/gir-property-element.js +0 -2
- package/lib/types/gir-property-element.js.map +0 -1
- package/lib/types/gir-record-element.d.ts +0 -30
- package/lib/types/gir-record-element.js +0 -2
- package/lib/types/gir-record-element.js.map +0 -1
- package/lib/types/gir-repository.d.ts +0 -16
- package/lib/types/gir-repository.js +0 -2
- package/lib/types/gir-repository.js.map +0 -1
- package/lib/types/gir-signal.d.ts +0 -25
- package/lib/types/gir-signal.js +0 -2
- package/lib/types/gir-signal.js.map +0 -1
- package/lib/types/gir-transfer-ownership-type.d.ts +0 -5
- package/lib/types/gir-transfer-ownership-type.js +0 -7
- package/lib/types/gir-transfer-ownership-type.js.map +0 -1
- package/lib/types/gir-transfer-ownership.d.ts +0 -5
- package/lib/types/gir-transfer-ownership.js +0 -2
- package/lib/types/gir-transfer-ownership.js.map +0 -1
- package/lib/types/gir-type.d.ts +0 -14
- package/lib/types/gir-type.js +0 -2
- package/lib/types/gir-type.js.map +0 -1
- package/lib/types/gir-union-element.d.ts +0 -22
- package/lib/types/gir-union-element.js +0 -2
- package/lib/types/gir-union-element.js.map +0 -1
- package/lib/types/gir-unparsed-number.d.ts +0 -2
- package/lib/types/gir-unparsed-number.js +0 -2
- package/lib/types/gir-unparsed-number.js.map +0 -1
- package/lib/types/gir-var-args.d.ts +0 -5
- package/lib/types/gir-var-args.js +0 -2
- package/lib/types/gir-var-args.js.map +0 -1
- package/lib/types/gir-virtual-method.d.ts +0 -10
- package/lib/types/gir-virtual-method.js +0 -2
- package/lib/types/gir-virtual-method.js.map +0 -1
- package/lib/types/index.d.ts +0 -118
- package/lib/types/index.js +0 -119
- package/lib/types/index.js.map +0 -1
- package/lib/types/inheritance-table.d.ts +0 -3
- package/lib/types/inheritance-table.js +0 -2
- package/lib/types/inheritance-table.js.map +0 -1
- package/lib/types/injection-callback.d.ts +0 -16
- package/lib/types/injection-callback.js +0 -2
- package/lib/types/injection-callback.js.map +0 -1
- package/lib/types/injection-class.d.ts +0 -25
- package/lib/types/injection-class.js +0 -2
- package/lib/types/injection-class.js.map +0 -1
- package/lib/types/injection-function.d.ts +0 -7
- package/lib/types/injection-function.js +0 -2
- package/lib/types/injection-function.js.map +0 -1
- package/lib/types/injection-generic-parameter.d.ts +0 -2
- package/lib/types/injection-generic-parameter.js +0 -2
- package/lib/types/injection-generic-parameter.js.map +0 -1
- package/lib/types/injection-instance-parameter.d.ts +0 -2
- package/lib/types/injection-instance-parameter.js +0 -2
- package/lib/types/injection-instance-parameter.js.map +0 -1
- package/lib/types/injection-parameter.d.ts +0 -8
- package/lib/types/injection-parameter.js +0 -2
- package/lib/types/injection-parameter.js.map +0 -1
- package/lib/types/injection-property.d.ts +0 -4
- package/lib/types/injection-property.js +0 -2
- package/lib/types/injection-property.js.map +0 -1
- package/lib/types/injection-type.d.ts +0 -2
- package/lib/types/injection-type.js +0 -2
- package/lib/types/injection-type.js.map +0 -1
- package/lib/types/injection.d.ts +0 -5
- package/lib/types/injection.js +0 -2
- package/lib/types/injection.js.map +0 -1
- package/lib/types/local-name-check.d.ts +0 -4
- package/lib/types/local-name-check.js +0 -2
- package/lib/types/local-name-check.js.map +0 -1
- package/lib/types/local-name-type.d.ts +0 -1
- package/lib/types/local-name-type.js +0 -2
- package/lib/types/local-name-type.js.map +0 -1
- package/lib/types/local-name.d.ts +0 -7
- package/lib/types/local-name.js +0 -2
- package/lib/types/local-name.js.map +0 -1
- package/lib/types/local-names.d.ts +0 -4
- package/lib/types/local-names.js +0 -2
- package/lib/types/local-names.js.map +0 -1
- package/lib/types/module-type.d.ts +0 -1
- package/lib/types/module-type.js +0 -2
- package/lib/types/module-type.js.map +0 -1
- package/lib/types/parsed-gir.d.ts +0 -4
- package/lib/types/parsed-gir.js +0 -2
- package/lib/types/parsed-gir.js.map +0 -1
- package/lib/types/part-of-class.d.ts +0 -7
- package/lib/types/part-of-class.js +0 -2
- package/lib/types/part-of-class.js.map +0 -1
- package/lib/types/part-of-module.d.ts +0 -6
- package/lib/types/part-of-module.js +0 -2
- package/lib/types/part-of-module.js.map +0 -1
- package/lib/types/resolve-type.d.ts +0 -4
- package/lib/types/resolve-type.js +0 -6
- package/lib/types/resolve-type.js.map +0 -1
- package/lib/types/sym-table-items.d.ts +0 -4
- package/lib/types/sym-table-items.js +0 -2
- package/lib/types/sym-table-items.js.map +0 -1
- package/lib/types/transformation-case.d.ts +0 -1
- package/lib/types/transformation-case.js +0 -2
- package/lib/types/transformation-case.js.map +0 -1
- package/lib/types/transformations.d.ts +0 -11
- package/lib/types/transformations.js +0 -2
- package/lib/types/transformations.js.map +0 -1
- package/lib/types/ts-alias.d.ts +0 -10
- package/lib/types/ts-alias.js +0 -2
- package/lib/types/ts-alias.js.map +0 -1
- package/lib/types/ts-callback-interface.d.ts +0 -10
- package/lib/types/ts-callback-interface.js +0 -2
- package/lib/types/ts-callback-interface.js.map +0 -1
- package/lib/types/ts-callback.d.ts +0 -17
- package/lib/types/ts-callback.js +0 -2
- package/lib/types/ts-callback.js.map +0 -1
- package/lib/types/ts-class.d.ts +0 -85
- package/lib/types/ts-class.js +0 -2
- package/lib/types/ts-class.js.map +0 -1
- package/lib/types/ts-doc-tag.d.ts +0 -21
- package/lib/types/ts-doc-tag.js +0 -2
- package/lib/types/ts-doc-tag.js.map +0 -1
- package/lib/types/ts-doc.d.ts +0 -20
- package/lib/types/ts-doc.js +0 -2
- package/lib/types/ts-doc.js.map +0 -1
- package/lib/types/ts-enum.d.ts +0 -12
- package/lib/types/ts-enum.js +0 -2
- package/lib/types/ts-enum.js.map +0 -1
- package/lib/types/ts-function.d.ts +0 -44
- package/lib/types/ts-function.js +0 -2
- package/lib/types/ts-function.js.map +0 -1
- package/lib/types/ts-generic-parameter.d.ts +0 -8
- package/lib/types/ts-generic-parameter.js +0 -2
- package/lib/types/ts-generic-parameter.js.map +0 -1
- package/lib/types/ts-instance-parameter.d.ts +0 -4
- package/lib/types/ts-instance-parameter.js +0 -2
- package/lib/types/ts-instance-parameter.js.map +0 -1
- package/lib/types/ts-member.d.ts +0 -10
- package/lib/types/ts-member.js +0 -2
- package/lib/types/ts-member.js.map +0 -1
- package/lib/types/ts-method.d.ts +0 -5
- package/lib/types/ts-method.js +0 -2
- package/lib/types/ts-method.js.map +0 -1
- package/lib/types/ts-parameter.d.ts +0 -15
- package/lib/types/ts-parameter.js +0 -2
- package/lib/types/ts-parameter.js.map +0 -1
- package/lib/types/ts-property.d.ts +0 -17
- package/lib/types/ts-property.js +0 -2
- package/lib/types/ts-property.js.map +0 -1
- package/lib/types/ts-signal.d.ts +0 -17
- package/lib/types/ts-signal.js +0 -2
- package/lib/types/ts-signal.js.map +0 -1
- package/lib/types/ts-type-name.d.ts +0 -1
- package/lib/types/ts-type-name.js +0 -2
- package/lib/types/ts-type-name.js.map +0 -1
- package/lib/types/ts-type-separator.d.ts +0 -1
- package/lib/types/ts-type-separator.js +0 -2
- package/lib/types/ts-type-separator.js.map +0 -1
- package/lib/types/ts-type.d.ts +0 -22
- package/lib/types/ts-type.js +0 -2
- package/lib/types/ts-type.js.map +0 -1
- package/lib/types/ts-var.d.ts +0 -17
- package/lib/types/ts-var.js +0 -2
- package/lib/types/ts-var.js.map +0 -1
- package/lib/types/type-gir-alias.d.ts +0 -2
- package/lib/types/type-gir-alias.js +0 -2
- package/lib/types/type-gir-alias.js.map +0 -1
- package/lib/types/type-gir-class.d.ts +0 -2
- package/lib/types/type-gir-class.js +0 -2
- package/lib/types/type-gir-class.js.map +0 -1
- package/lib/types/type-gir-element.d.ts +0 -3
- package/lib/types/type-gir-element.js +0 -2
- package/lib/types/type-gir-element.js.map +0 -1
- package/lib/types/type-gir-enumeration-member.d.ts +0 -2
- package/lib/types/type-gir-enumeration-member.js +0 -2
- package/lib/types/type-gir-enumeration-member.js.map +0 -1
- package/lib/types/type-gir-enumeration.d.ts +0 -2
- package/lib/types/type-gir-enumeration.js +0 -2
- package/lib/types/type-gir-enumeration.js.map +0 -1
- package/lib/types/type-gir-function.d.ts +0 -1
- package/lib/types/type-gir-function.js +0 -2
- package/lib/types/type-gir-function.js.map +0 -1
- package/lib/types/type-gir-interface.d.ts +0 -2
- package/lib/types/type-gir-interface.js +0 -2
- package/lib/types/type-gir-interface.js.map +0 -1
- package/lib/types/type-gir-method.d.ts +0 -2
- package/lib/types/type-gir-method.js +0 -2
- package/lib/types/type-gir-method.js.map +0 -1
- package/lib/types/type-gir-parameter.d.ts +0 -1
- package/lib/types/type-gir-parameter.js +0 -2
- package/lib/types/type-gir-parameter.js.map +0 -1
- package/lib/types/type-gir-property.d.ts +0 -2
- package/lib/types/type-gir-property.js +0 -2
- package/lib/types/type-gir-property.js.map +0 -1
- package/lib/types/type-gir-variable.d.ts +0 -1
- package/lib/types/type-gir-variable.js +0 -2
- package/lib/types/type-gir-variable.js.map +0 -1
- package/lib/types/type-ts-element.d.ts +0 -3
- package/lib/types/type-ts-element.js +0 -2
- package/lib/types/type-ts-element.js.map +0 -1
- package/lib/types/type-ts-enumeration-member.d.ts +0 -2
- package/lib/types/type-ts-enumeration-member.js +0 -2
- package/lib/types/type-ts-enumeration-member.js.map +0 -1
- package/lib/types/type-ts-function.d.ts +0 -1
- package/lib/types/type-ts-function.js +0 -2
- package/lib/types/type-ts-function.js.map +0 -1
- package/lib/types/type-ts-property.d.ts +0 -1
- package/lib/types/type-ts-property.js +0 -2
- package/lib/types/type-ts-property.js.map +0 -1
- package/lib/types/user-config-load-result.d.ts +0 -6
- package/lib/types/user-config-load-result.js +0 -2
- package/lib/types/user-config-load-result.js.map +0 -1
- package/lib/types/user-config.d.ts +0 -42
- package/lib/types/user-config.js +0 -2
- package/lib/types/user-config.js.map +0 -1
- package/src/conflict-resolver.ts +0 -1358
- package/src/constants.ts +0 -29
- package/src/generator.ts +0 -10
- package/src/gir-factory.ts +0 -499
- package/src/gir-module.ts +0 -2816
- package/src/html-doc-generator.ts +0 -23
- package/src/injection/callbacks/gjs/Gio-2.0.ts +0 -37
- package/src/injection/callbacks/gjs/index.ts +0 -5
- package/src/injection/callbacks/index.ts +0 -6
- package/src/injection/callbacks/node-gtk/index.ts +0 -3
- package/src/injection/classes/GLib-2-0.ts +0 -36
- package/src/injection/classes/gjs/GLib-2.0.ts +0 -201
- package/src/injection/classes/gjs/GObject-2.0.ts +0 -635
- package/src/injection/classes/gjs/Gio-2.0.ts +0 -219
- package/src/injection/classes/gjs/index.ts +0 -7
- package/src/injection/classes/index.ts +0 -7
- package/src/injection/classes/node-gtk/GLib-2.0.ts +0 -20
- package/src/injection/classes/node-gtk/GObject-2.0.ts +0 -67
- package/src/injection/classes/node-gtk/Gdk-4.0.ts +0 -33
- package/src/injection/classes/node-gtk/Gio-2.0.ts +0 -15
- package/src/injection/classes/node-gtk/Graphene-1.0.ts +0 -134
- package/src/injection/classes/node-gtk/Gtk-3.0.ts +0 -32
- package/src/injection/classes/node-gtk/Gtk-4.0.ts +0 -53
- package/src/injection/classes/node-gtk/Pango-1.0.ts +0 -32
- package/src/injection/classes/node-gtk/index.ts +0 -21
- package/src/injection/index.ts +0 -3
- package/src/injection/injector.ts +0 -184
- package/src/logger.ts +0 -134
- package/src/messages.ts +0 -68
- package/src/symtable.ts +0 -70
- package/src/template-processor.ts +0 -233
- package/src/transformation.ts +0 -583
- package/src/type-definition-generator.ts +0 -1458
- package/src/types/answer-version.ts +0 -4
- package/src/types/build-type.ts +0 -1
- package/src/types/class-parent.ts +0 -12
- package/src/types/config-flags.ts +0 -5
- package/src/types/conflict-child-element.ts +0 -11
- package/src/types/conflict-grouped-element.ts +0 -7
- package/src/types/conflict-grouped-elements.ts +0 -5
- package/src/types/construct-name.ts +0 -11
- package/src/types/dependency-map.ts +0 -4
- package/src/types/dependency.ts +0 -14
- package/src/types/environment.ts +0 -1
- package/src/types/generate-config.ts +0 -35
- package/src/types/generator-type.ts +0 -4
- package/src/types/gir-alias-element.ts +0 -15
- package/src/types/gir-annotation.ts +0 -10
- package/src/types/gir-any-element.ts +0 -35
- package/src/types/gir-any-type.ts +0 -7
- package/src/types/gir-array-type.ts +0 -23
- package/src/types/gir-bitfield-element.ts +0 -20
- package/src/types/gir-boolean.ts +0 -1
- package/src/types/gir-boxed-element.ts +0 -19
- package/src/types/gir-c-include.ts +0 -7
- package/src/types/gir-callable-attrs.ts +0 -19
- package/src/types/gir-callable-param-element.ts +0 -45
- package/src/types/gir-callable-param.ts +0 -9
- package/src/types/gir-callable-return.ts +0 -25
- package/src/types/gir-callback-element.ts +0 -28
- package/src/types/gir-class-element.ts +0 -71
- package/src/types/gir-constant-element.ts +0 -17
- package/src/types/gir-constructor-element.ts +0 -18
- package/src/types/gir-direction.ts +0 -5
- package/src/types/gir-doc-element.ts +0 -73
- package/src/types/gir-enum-element.ts +0 -28
- package/src/types/gir-field-element.ts +0 -31
- package/src/types/gir-function-element.ts +0 -19
- package/src/types/gir-implements.ts +0 -9
- package/src/types/gir-include.ts +0 -9
- package/src/types/gir-info-attrs.ts +0 -16
- package/src/types/gir-info-elements.ts +0 -8
- package/src/types/gir-instance-parameter.ts +0 -25
- package/src/types/gir-interface-element.ts +0 -53
- package/src/types/gir-member-element.ts +0 -19
- package/src/types/gir-method-element.ts +0 -25
- package/src/types/gir-module-resolved-by.ts +0 -11
- package/src/types/gir-modules-grouped-map.ts +0 -5
- package/src/types/gir-modules-grouped.ts +0 -13
- package/src/types/gir-namespace.ts +0 -47
- package/src/types/gir-package.ts +0 -7
- package/src/types/gir-prerequisite.ts +0 -5
- package/src/types/gir-property-element.ts +0 -31
- package/src/types/gir-record-element.ts +0 -47
- package/src/types/gir-repository.ts +0 -20
- package/src/types/gir-signal.ts +0 -43
- package/src/types/gir-transfer-ownership-type.ts +0 -5
- package/src/types/gir-transfer-ownership.ts +0 -6
- package/src/types/gir-type.ts +0 -16
- package/src/types/gir-union-element.ts +0 -35
- package/src/types/gir-unparsed-number.ts +0 -2
- package/src/types/gir-var-args.ts +0 -6
- package/src/types/gir-virtual-method.ts +0 -22
- package/src/types/index.ts +0 -118
- package/src/types/inheritance-table.ts +0 -3
- package/src/types/injection-callback.ts +0 -20
- package/src/types/injection-class.ts +0 -30
- package/src/types/injection-function.ts +0 -23
- package/src/types/injection-generic-parameter.ts +0 -3
- package/src/types/injection-instance-parameter.ts +0 -3
- package/src/types/injection-parameter.ts +0 -9
- package/src/types/injection-property.ts +0 -7
- package/src/types/injection-type.ts +0 -3
- package/src/types/injection.ts +0 -6
- package/src/types/local-name-check.ts +0 -5
- package/src/types/local-name-type.ts +0 -1
- package/src/types/local-name.ts +0 -8
- package/src/types/local-names.ts +0 -5
- package/src/types/module-type.ts +0 -1
- package/src/types/parsed-gir.ts +0 -5
- package/src/types/part-of-class.ts +0 -9
- package/src/types/part-of-module.ts +0 -8
- package/src/types/resolve-type.ts +0 -4
- package/src/types/sym-table-items.ts +0 -5
- package/src/types/transformation-case.ts +0 -7
- package/src/types/transformations.ts +0 -12
- package/src/types/ts-alias.ts +0 -11
- package/src/types/ts-callback-interface.ts +0 -11
- package/src/types/ts-callback.ts +0 -21
- package/src/types/ts-class.ts +0 -109
- package/src/types/ts-doc-tag.ts +0 -23
- package/src/types/ts-doc.ts +0 -23
- package/src/types/ts-enum.ts +0 -15
- package/src/types/ts-function.ts +0 -59
- package/src/types/ts-generic-parameter.ts +0 -8
- package/src/types/ts-instance-parameter.ts +0 -4
- package/src/types/ts-member.ts +0 -11
- package/src/types/ts-method.ts +0 -6
- package/src/types/ts-parameter.ts +0 -20
- package/src/types/ts-property.ts +0 -22
- package/src/types/ts-signal.ts +0 -21
- package/src/types/ts-type-name.ts +0 -1
- package/src/types/ts-type-separator.ts +0 -1
- package/src/types/ts-type.ts +0 -25
- package/src/types/ts-var.ts +0 -21
- package/src/types/type-gir-alias.ts +0 -2
- package/src/types/type-gir-class.ts +0 -2
- package/src/types/type-gir-element.ts +0 -25
- package/src/types/type-gir-enumeration-member.ts +0 -2
- package/src/types/type-gir-enumeration.ts +0 -2
- package/src/types/type-gir-function.ts +0 -8
- package/src/types/type-gir-interface.ts +0 -2
- package/src/types/type-gir-method.ts +0 -2
- package/src/types/type-gir-parameter.ts +0 -1
- package/src/types/type-gir-property.ts +0 -2
- package/src/types/type-gir-variable.ts +0 -1
- package/src/types/type-ts-element.ts +0 -13
- package/src/types/type-ts-enumeration-member.ts +0 -2
- package/src/types/type-ts-function.ts +0 -1
- package/src/types/type-ts-property.ts +0 -1
- package/src/types/user-config-load-result.ts +0 -6
- package/src/types/user-config.ts +0 -43
- package/templates/Cogl-2.0.d.ts +0 -0
- package/templates/Gjs/GObject-2.0.d.ts +0 -238
- package/templates/Gjs/Gio-2.0.d.ts +0 -64
- package/templates/Gjs/Gjs.d.ts +0 -137
- package/templates/Gjs/Gjs.js +0 -21
- package/templates/Gjs/GnomeShell.d.ts +0 -122
- package/templates/Gjs/GnomeShell.js +0 -10
- package/templates/Gjs/index.d.ts +0 -594
- package/templates/Gjs/index.js +0 -4
- package/templates/Gjs/misc/dbusUtils.d.ts +0 -15
- package/templates/Gjs/misc/dbusUtils.js +0 -6
- package/templates/Gjs/misc/extensionUtils.d.ts +0 -99
- package/templates/Gjs/misc/extensionUtils.js +0 -6
- package/templates/Gjs/misc/fileUtils.d.ts +0 -49
- package/templates/Gjs/misc/fileUtils.js +0 -6
- package/templates/Gjs/misc/gnomeSession.d.ts +0 -72
- package/templates/Gjs/misc/gnomeSession.js +0 -6
- package/templates/Gjs/module.d.ts +0 -10
- package/templates/Gjs/module.js +0 -16
- package/templates/Gjs/ui/userWidget.d.ts +0 -10
- package/templates/Gjs/ui/userWidget.js +0 -6
- package/templates/Granite-1.0.d.ts +0 -7
- package/templates/Granite-7.0.d.ts +0 -7
- package/templates/GstBase-0.10.d.ts +0 -5
- package/templates/RygelServer-2.6.d.ts +0 -3
- package/templates/node-gtk/GObject-2.0.d.ts +0 -57
- package/templates/node-gtk/index.d.ts +0 -40
- package/templates/node-gtk/index.js +0 -9
- package/templates/node-gtk/module.d.ts +0 -10
- package/templates/node-gtk/module.js +0 -17
|
@@ -1,1458 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
GenerateConfig,
|
|
3
|
-
InheritanceTable,
|
|
4
|
-
GirClassElement,
|
|
5
|
-
GirCallableParamElement,
|
|
6
|
-
GirSignalElement,
|
|
7
|
-
GirEnumElement,
|
|
8
|
-
GirAliasElement,
|
|
9
|
-
GirInterfaceElement,
|
|
10
|
-
GirUnionElement,
|
|
11
|
-
GirModulesGrouped,
|
|
12
|
-
GirRecordElement,
|
|
13
|
-
GirBitfieldElement,
|
|
14
|
-
GirInstanceParameter,
|
|
15
|
-
TsGenericParameter,
|
|
16
|
-
TsType,
|
|
17
|
-
TsDoc,
|
|
18
|
-
TsFunction,
|
|
19
|
-
TsCallback,
|
|
20
|
-
TsSignal,
|
|
21
|
-
TsMember,
|
|
22
|
-
TsVar,
|
|
23
|
-
TsProperty,
|
|
24
|
-
TsParameter,
|
|
25
|
-
} from './types/index.js'
|
|
26
|
-
import { Generator } from './generator.js'
|
|
27
|
-
import type { GirModule } from './gir-module.js'
|
|
28
|
-
import TemplateProcessor from './template-processor.js'
|
|
29
|
-
import { Logger } from './logger.js'
|
|
30
|
-
import {
|
|
31
|
-
generateIndent,
|
|
32
|
-
findFileInDirs,
|
|
33
|
-
splitModuleName,
|
|
34
|
-
removeNamespace,
|
|
35
|
-
removeClassModule,
|
|
36
|
-
girElementIsIntrospectable,
|
|
37
|
-
typeIsOptional,
|
|
38
|
-
} from './utils.js'
|
|
39
|
-
import {
|
|
40
|
-
NO_TSDATA,
|
|
41
|
-
WARN_NOT_FOUND_DEPENDENCY_GIR_FILE,
|
|
42
|
-
WARN_IGNORE_MULTIPLE_CALLBACKS,
|
|
43
|
-
WARN_IGNORE_MULTIPLE_FUNC_DESC,
|
|
44
|
-
} from './messages.js'
|
|
45
|
-
|
|
46
|
-
export default class TypeDefinitionGenerator implements Generator {
|
|
47
|
-
protected log: Logger
|
|
48
|
-
constructor(protected readonly config: GenerateConfig) {
|
|
49
|
-
this.log = new Logger(config.environment, config.verbose, TypeDefinitionGenerator.name)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
*
|
|
54
|
-
* @param namespace E.g. 'Gtk'
|
|
55
|
-
* @param packageName E.g. 'Gtk-3.0'
|
|
56
|
-
* @param asExternType Currently only used for node type imports
|
|
57
|
-
*/
|
|
58
|
-
private generateModuleDependenciesImport(namespace: string, packageName: string, asExternType = false): string[] {
|
|
59
|
-
const def: string[] = []
|
|
60
|
-
const sas = this.config.useNamespace && packageName !== 'Gjs' ? '' : '* as '
|
|
61
|
-
if (this.config.buildType === 'lib') {
|
|
62
|
-
def.push(`import type ${sas}${namespace} from './${packageName}.js';`)
|
|
63
|
-
} else if (this.config.buildType === 'types') {
|
|
64
|
-
if (asExternType) {
|
|
65
|
-
// def.push(`/// <reference types="${packageName}" />`)
|
|
66
|
-
def.push(`import ${namespace} from "${packageName}.js"`)
|
|
67
|
-
} else {
|
|
68
|
-
def.push(`/// <reference path="${packageName}.d.ts" />`)
|
|
69
|
-
def.push(`import type ${sas}${namespace} from './${packageName}.js';`)
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return def
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
private generateExport(type: string, name: string, definition: string, indentCount = 0) {
|
|
76
|
-
const exp = this.config.useNamespace || this.config.buildType === 'types' ? '' : 'export '
|
|
77
|
-
const indent = generateIndent(indentCount)
|
|
78
|
-
if (!definition.startsWith(':')) {
|
|
79
|
-
definition = ' ' + definition
|
|
80
|
-
}
|
|
81
|
-
return `${indent}${exp}${type} ${name}${definition}`
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
private generateProperty(tsProp: TsProperty, onlyStatic: boolean, namespace: string, indentCount = 0) {
|
|
85
|
-
if (!tsProp) {
|
|
86
|
-
throw new Error('[generateProperty] Not all required properties set!')
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const desc: string[] = []
|
|
90
|
-
const isStatic = tsProp.isStatic
|
|
91
|
-
|
|
92
|
-
if ((isStatic && !onlyStatic) || (!isStatic && onlyStatic)) {
|
|
93
|
-
return desc
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (!tsProp.hasUnresolvedConflict) {
|
|
97
|
-
desc.push(...this.addGirDocComment(tsProp.doc, indentCount))
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const indent = generateIndent(indentCount)
|
|
101
|
-
const varDesc = this.generateVariable(tsProp, namespace, 0, false)
|
|
102
|
-
const staticStr = isStatic ? 'static ' : ''
|
|
103
|
-
const readonly = tsProp.readonly ? 'readonly ' : ''
|
|
104
|
-
|
|
105
|
-
// temporary solution, will be solved differently later
|
|
106
|
-
const commentOut = tsProp.hasUnresolvedConflict ? '// Has conflict: ' : ''
|
|
107
|
-
|
|
108
|
-
desc.push(`${indent}${commentOut}${staticStr}${readonly}${varDesc}`)
|
|
109
|
-
return desc
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
private generateProperties(
|
|
113
|
-
tsProps: TsProperty[],
|
|
114
|
-
onlyStatic: boolean,
|
|
115
|
-
namespace: string,
|
|
116
|
-
comment: string,
|
|
117
|
-
indentCount = 0,
|
|
118
|
-
) {
|
|
119
|
-
const def: string[] = []
|
|
120
|
-
for (const tsProp of tsProps) {
|
|
121
|
-
def.push(...this.generateProperty(tsProp, onlyStatic, namespace, indentCount))
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (def.length > 0) {
|
|
125
|
-
def.unshift(...this.addInfoComment(comment, indentCount))
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return def
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
private generateVariableCallbackType(tsType: TsType, namespace: string) {
|
|
132
|
-
// The type of a callback is a functions definition
|
|
133
|
-
|
|
134
|
-
let typeStr = 'any'
|
|
135
|
-
|
|
136
|
-
const { callbacks } = tsType
|
|
137
|
-
|
|
138
|
-
if (!callbacks.length) return typeStr
|
|
139
|
-
|
|
140
|
-
if (callbacks.length > 1) {
|
|
141
|
-
this.log.warn(WARN_IGNORE_MULTIPLE_CALLBACKS)
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const girCallback = callbacks[0]
|
|
145
|
-
|
|
146
|
-
if (!girCallback._tsData) {
|
|
147
|
-
throw new Error(NO_TSDATA('generateVariableCallbackType'))
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const funcDesc = this.generateFunction(girCallback._tsData, false, namespace, 0)
|
|
151
|
-
|
|
152
|
-
if (girCallback._tsData && funcDesc?.length) {
|
|
153
|
-
if (funcDesc.length > 1) {
|
|
154
|
-
this.log.warn(WARN_IGNORE_MULTIPLE_FUNC_DESC)
|
|
155
|
-
}
|
|
156
|
-
typeStr = funcDesc[0]
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return typeStr
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
private generateVariable(tsVar: TsProperty | TsVar, namespace: string, indentCount = 0, allowCommentOut = true) {
|
|
163
|
-
const indent = generateIndent(indentCount)
|
|
164
|
-
const name = tsVar.name
|
|
165
|
-
const optional = typeIsOptional(tsVar.type)
|
|
166
|
-
|
|
167
|
-
if (!name) {
|
|
168
|
-
throw new Error('[generateVariable] "name" not set!')
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const affix = optional ? '?' : ''
|
|
172
|
-
const typeStr = this.generateTypes(tsVar.type, namespace)
|
|
173
|
-
|
|
174
|
-
// temporary solution, will be solved differently later
|
|
175
|
-
const commentOut = allowCommentOut && tsVar.hasUnresolvedConflict ? '// Has conflict: ' : ''
|
|
176
|
-
|
|
177
|
-
return `${indent}${commentOut}${name}${affix}: ${typeStr}`
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
private generateTypes(tsTypes: TsType[], namespace: string) {
|
|
181
|
-
let def = ''
|
|
182
|
-
for (const tsType of tsTypes) {
|
|
183
|
-
const separator = tsType.leftSeparator || '|'
|
|
184
|
-
const typeStr = this.generateType(tsType, namespace)
|
|
185
|
-
if (!def) {
|
|
186
|
-
def = typeStr
|
|
187
|
-
} else {
|
|
188
|
-
def += ` ${separator} ${typeStr}`
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return def
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
private generateGenericValues(tsType: TsType, namespace: string) {
|
|
195
|
-
// We just use the generic values here
|
|
196
|
-
const genericValues = tsType.generics.map((g) => removeNamespace(g.value || '', namespace)).filter((g) => !!g)
|
|
197
|
-
const genericStr = tsType.generics.length ? `<${genericValues.join(', ')}>` : ''
|
|
198
|
-
return genericStr
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
private generateType(tsType: TsType, namespace: string) {
|
|
202
|
-
let typeName = removeNamespace(tsType.type, namespace)
|
|
203
|
-
|
|
204
|
-
if (tsType.callbacks.length) {
|
|
205
|
-
typeName = this.generateVariableCallbackType(tsType, namespace)
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (!typeName) {
|
|
209
|
-
throw new Error('[generateVariable] "typeName" not set!')
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
let prefix = tsType.isArray ? '[]' : ''
|
|
213
|
-
prefix += tsType.nullable ? ' | null' : ''
|
|
214
|
-
|
|
215
|
-
// We just use the generic values here
|
|
216
|
-
const genericStr = this.generateGenericValues(tsType, namespace)
|
|
217
|
-
|
|
218
|
-
return `${typeName}${genericStr}${prefix}`
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Generates signals from all properties of a base class
|
|
223
|
-
* TODO: Build new `GirSignalElement`s in `gir-module.ts` instead of generate the strings directly
|
|
224
|
-
* @param girClass
|
|
225
|
-
* @param namespace
|
|
226
|
-
* @param indentCount
|
|
227
|
-
* @returns
|
|
228
|
-
*/
|
|
229
|
-
private generateClassPropertySignals(
|
|
230
|
-
girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
|
|
231
|
-
namespace: string,
|
|
232
|
-
indentCount = 1,
|
|
233
|
-
) {
|
|
234
|
-
const def: string[] = []
|
|
235
|
-
|
|
236
|
-
if (!girClass._tsData || !girClass._fullSymName || !girClass._module) {
|
|
237
|
-
throw new Error(NO_TSDATA('generateClassPropertySignals'))
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (girClass._tsData?.isDerivedFromGObject) {
|
|
241
|
-
if (girClass._tsData.propertySignalMethods.length > 0) {
|
|
242
|
-
def.push(
|
|
243
|
-
...this.addInfoComment(
|
|
244
|
-
`Class property signals of ${girClass._module?.packageName}.${girClass._fullSymName}`,
|
|
245
|
-
indentCount,
|
|
246
|
-
),
|
|
247
|
-
)
|
|
248
|
-
for (const tsSignalMethod of girClass._tsData.propertySignalMethods) {
|
|
249
|
-
if (!tsSignalMethod) {
|
|
250
|
-
continue
|
|
251
|
-
}
|
|
252
|
-
def.push(...this.generateFunction(tsSignalMethod, false, namespace, indentCount))
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return def
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
private generateInParameters(
|
|
260
|
-
inParams: GirCallableParamElement[],
|
|
261
|
-
instanceParameters: GirInstanceParameter[],
|
|
262
|
-
namespace: string,
|
|
263
|
-
) {
|
|
264
|
-
const inParamsDef: string[] = []
|
|
265
|
-
|
|
266
|
-
// TODO: Should use of a constructor, and even of an instance, be discouraged?
|
|
267
|
-
for (const instanceParameter of instanceParameters) {
|
|
268
|
-
if (instanceParameter._tsData) {
|
|
269
|
-
let { structFor } = instanceParameter._tsData
|
|
270
|
-
const { name } = instanceParameter._tsData
|
|
271
|
-
const gobject = namespace === 'GObject' || namespace === 'GLib' ? '' : 'GObject.'
|
|
272
|
-
|
|
273
|
-
structFor = removeNamespace(structFor, namespace)
|
|
274
|
-
|
|
275
|
-
const returnTypes = [structFor, 'Function', `${gobject}GType`]
|
|
276
|
-
inParamsDef.push(`${name}: ${returnTypes.join(' | ')}`)
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
for (const inParam of inParams) {
|
|
281
|
-
if (inParam._tsData) inParamsDef.push(...this.generateParameter(inParam._tsData, namespace))
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
return inParamsDef
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
private generateSignals(
|
|
288
|
-
girSignals: GirSignalElement[],
|
|
289
|
-
girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
|
|
290
|
-
namespace: string,
|
|
291
|
-
indentCount = 0,
|
|
292
|
-
) {
|
|
293
|
-
const def: string[] = []
|
|
294
|
-
|
|
295
|
-
for (const girSignal of girSignals) {
|
|
296
|
-
if (girSignal._tsData?.tsMethods?.length) {
|
|
297
|
-
for (const tsSignalMethod of girSignal._tsData?.tsMethods) {
|
|
298
|
-
if (!tsSignalMethod) {
|
|
299
|
-
continue
|
|
300
|
-
}
|
|
301
|
-
def.push(...this.generateFunction(tsSignalMethod, false, namespace, indentCount))
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
return def
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* Adds documentation comments
|
|
310
|
-
* @see https://github.com/microsoft/tsdoc
|
|
311
|
-
* @param lines
|
|
312
|
-
* @param indentCount
|
|
313
|
-
*/
|
|
314
|
-
private addTSDocCommentLines(lines: string[], indentCount = 0): string[] {
|
|
315
|
-
const def: string[] = []
|
|
316
|
-
const indent = generateIndent(indentCount)
|
|
317
|
-
def.push(`${indent}/**`)
|
|
318
|
-
for (const line of lines) {
|
|
319
|
-
def.push(`${indent} * ${line}`)
|
|
320
|
-
}
|
|
321
|
-
def.push(`${indent} */`)
|
|
322
|
-
return def
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* Adds the documentation as comments
|
|
327
|
-
* @see https://github.com/microsoft/tsdoc
|
|
328
|
-
* @param girDoc
|
|
329
|
-
* @param indentCount
|
|
330
|
-
* @param overwriteDoc
|
|
331
|
-
* @returns
|
|
332
|
-
*/
|
|
333
|
-
private addGirDocComment(tsDoc: TsDoc | undefined, indentCount = 0, overwriteDoc?: Partial<TsDoc>) {
|
|
334
|
-
const desc: string[] = []
|
|
335
|
-
const indent = generateIndent(indentCount)
|
|
336
|
-
if (this.config.noComments) {
|
|
337
|
-
return desc
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
const text = overwriteDoc?.text || tsDoc?.text
|
|
341
|
-
const tags = overwriteDoc?.tags || tsDoc?.tags || []
|
|
342
|
-
|
|
343
|
-
if (text) {
|
|
344
|
-
desc.push(`${indent}/**`)
|
|
345
|
-
|
|
346
|
-
if (text) {
|
|
347
|
-
const lines = text.split('\n')
|
|
348
|
-
if (lines.length) {
|
|
349
|
-
for (const line of lines) {
|
|
350
|
-
desc.push(`${indent} * ${line}`)
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
for (const tag of tags) {
|
|
356
|
-
if (tag.paramName) {
|
|
357
|
-
desc.push(`${indent} * @${tag.tagName} ${tag.paramName} ${tag.text}`)
|
|
358
|
-
} else {
|
|
359
|
-
desc.push(`${indent} * @${tag.tagName} ${tag.text}`)
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
desc.push(`${indent} */`)
|
|
363
|
-
}
|
|
364
|
-
return desc
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* Adds an info comment, is used for debugging the generated types
|
|
369
|
-
* @param comment
|
|
370
|
-
* @param indentCount
|
|
371
|
-
* @returns
|
|
372
|
-
*/
|
|
373
|
-
private addInfoComment(comment?: string, indentCount = 0) {
|
|
374
|
-
const def: string[] = []
|
|
375
|
-
if (this.config.noDebugComments) {
|
|
376
|
-
return def
|
|
377
|
-
}
|
|
378
|
-
const indent = generateIndent(indentCount)
|
|
379
|
-
if (comment) {
|
|
380
|
-
def.push('')
|
|
381
|
-
def.push(`${indent}// ${comment}`)
|
|
382
|
-
def.push('')
|
|
383
|
-
}
|
|
384
|
-
return def
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* Adds an inline info comment, is used for debugging the generated types
|
|
389
|
-
* @param comment
|
|
390
|
-
* @param indentCount
|
|
391
|
-
* @returns
|
|
392
|
-
*/
|
|
393
|
-
private addInlineInfoComment(comment?: string, indentCount = 0) {
|
|
394
|
-
const def: string[] = []
|
|
395
|
-
if (this.config.noDebugComments) {
|
|
396
|
-
return def
|
|
397
|
-
}
|
|
398
|
-
const indent = generateIndent(indentCount)
|
|
399
|
-
if (comment) {
|
|
400
|
-
def.push(`${indent}/* ${comment} */`)
|
|
401
|
-
}
|
|
402
|
-
return def
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
private mergeDescs(descs: string[], comment?: string, indentCount = 1) {
|
|
406
|
-
const def: string[] = []
|
|
407
|
-
const indent = generateIndent(indentCount)
|
|
408
|
-
|
|
409
|
-
for (const desc of descs) {
|
|
410
|
-
def.push(`${indent}${desc}`)
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
if (def.length > 0) {
|
|
414
|
-
def.unshift(...this.addInfoComment(comment, indentCount))
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
return def
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
private generateParameter(tsParam: TsParameter, namespace: string) {
|
|
421
|
-
if (typeof tsParam?.name !== 'string') {
|
|
422
|
-
throw new Error(NO_TSDATA('generateParameter'))
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
const types = tsParam.type
|
|
426
|
-
const name = tsParam.name
|
|
427
|
-
const typeStr = this.generateTypes(types, namespace)
|
|
428
|
-
const optional = typeIsOptional(types) && !tsParam.isRest
|
|
429
|
-
const affix = optional ? '?' : ''
|
|
430
|
-
const prefix = tsParam.isRest ? '...' : ''
|
|
431
|
-
|
|
432
|
-
return [`${prefix}${name}${affix}: ${typeStr}`]
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
/**
|
|
436
|
-
*
|
|
437
|
-
* @param tsGenerics
|
|
438
|
-
* @param isOut If this generic parameters are out do only generate the type parameter names
|
|
439
|
-
* @returns
|
|
440
|
-
*/
|
|
441
|
-
private generateGenericParameters(tsGenerics?: TsGenericParameter[], isOut = false) {
|
|
442
|
-
const desc: string[] = []
|
|
443
|
-
if (!tsGenerics?.length) {
|
|
444
|
-
return ''
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
for (const tsGeneric of tsGenerics) {
|
|
448
|
-
if (!tsGeneric.name) {
|
|
449
|
-
continue
|
|
450
|
-
}
|
|
451
|
-
let genericStr = `${tsGeneric.name}`
|
|
452
|
-
if (!isOut && tsGeneric.extends) {
|
|
453
|
-
genericStr += ` extends ${tsGeneric.extends}`
|
|
454
|
-
}
|
|
455
|
-
if (!isOut && tsGeneric.value) {
|
|
456
|
-
genericStr += ` = ${tsGeneric.value}`
|
|
457
|
-
}
|
|
458
|
-
desc.push(genericStr)
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
return `<${desc.join(', ')}>`
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
private generateOutParameterReturn(girParam: GirCallableParamElement, namespace: string) {
|
|
465
|
-
const desc: string[] = []
|
|
466
|
-
|
|
467
|
-
if (!girParam._tsData) {
|
|
468
|
-
this.log.warn(NO_TSDATA('generateOutParameterReturn'))
|
|
469
|
-
return desc
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
const { name } = girParam._tsData
|
|
473
|
-
const typeStr = this.generateTypes(girParam._tsData.type, namespace)
|
|
474
|
-
|
|
475
|
-
desc.push(`/* ${name} */ ${typeStr}`)
|
|
476
|
-
return desc
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
private generateFunctionReturn(tsFunction: TsFunction | TsCallback | TsSignal, namespace: string) {
|
|
480
|
-
if (tsFunction.name === 'constructor') {
|
|
481
|
-
return ''
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
const overrideReturnType = tsFunction.overrideReturnType
|
|
485
|
-
const outParams = tsFunction.outParams
|
|
486
|
-
const retTypeIsVoid = tsFunction.retTypeIsVoid
|
|
487
|
-
const typeStr = this.generateTypes(tsFunction.returnTypes, namespace)
|
|
488
|
-
|
|
489
|
-
let desc = typeStr
|
|
490
|
-
|
|
491
|
-
if (overrideReturnType) {
|
|
492
|
-
desc = removeNamespace(overrideReturnType, namespace)
|
|
493
|
-
} else if (outParams.length + (retTypeIsVoid ? 0 : 1) > 1) {
|
|
494
|
-
const outParamsDesc: string[] = []
|
|
495
|
-
|
|
496
|
-
if (!retTypeIsVoid) {
|
|
497
|
-
outParamsDesc.push(`/* returnType */ ${typeStr}`)
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
for (const outParam of outParams) {
|
|
501
|
-
outParamsDesc.push(...this.generateOutParameterReturn(outParam, namespace))
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
desc = outParamsDesc.join(', ')
|
|
505
|
-
desc = `[ ${desc} ]`
|
|
506
|
-
} else if (outParams.length === 1 && retTypeIsVoid) {
|
|
507
|
-
desc = this.generateOutParameterReturn(outParams[0], namespace).join(' ')
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
return desc
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
private generateFunction(
|
|
514
|
-
tsFunction: TsFunction | TsCallback | TsSignal | undefined,
|
|
515
|
-
/** If true only generate static functions otherwise generate only non static functions */
|
|
516
|
-
onlyStatic: boolean,
|
|
517
|
-
namespace: string,
|
|
518
|
-
indentCount = 1,
|
|
519
|
-
overloads = true,
|
|
520
|
-
) {
|
|
521
|
-
const def: string[] = []
|
|
522
|
-
const indent = generateIndent(indentCount)
|
|
523
|
-
|
|
524
|
-
if (!tsFunction) {
|
|
525
|
-
this.log.warn(NO_TSDATA('generateFunction'))
|
|
526
|
-
return def
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
let { name } = tsFunction
|
|
530
|
-
const { isStatic } = tsFunction
|
|
531
|
-
|
|
532
|
-
const { isArrowType, isGlobal, inParams, instanceParameters } = tsFunction
|
|
533
|
-
|
|
534
|
-
if ((isStatic && !onlyStatic) || (!isStatic && onlyStatic)) {
|
|
535
|
-
return def
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
if (tsFunction.doc && !tsFunction.hasUnresolvedConflict)
|
|
539
|
-
def.push(...this.addGirDocComment(tsFunction.doc, indentCount))
|
|
540
|
-
|
|
541
|
-
const staticStr = isStatic && tsFunction.name !== 'constructor' ? 'static ' : ''
|
|
542
|
-
|
|
543
|
-
const globalStr = isGlobal ? 'function ' : ''
|
|
544
|
-
const genericStr = this.generateGenericParameters(tsFunction.generics)
|
|
545
|
-
|
|
546
|
-
// temporary solution, will be solved differently later
|
|
547
|
-
const commentOut = tsFunction.hasUnresolvedConflict ? '// Has conflict: ' : ''
|
|
548
|
-
|
|
549
|
-
let exportStr = ''
|
|
550
|
-
// `tsType === 'function'` are a global methods which can be exported
|
|
551
|
-
if (isGlobal) {
|
|
552
|
-
exportStr = this.config.useNamespace || this.config.buildType === 'types' ? '' : 'export '
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
const returnType = this.generateFunctionReturn(tsFunction, namespace)
|
|
556
|
-
|
|
557
|
-
let retSep = ''
|
|
558
|
-
if (returnType) {
|
|
559
|
-
if (isArrowType) {
|
|
560
|
-
name = ''
|
|
561
|
-
retSep = ' =>'
|
|
562
|
-
} else {
|
|
563
|
-
retSep = ':'
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
const inParamsDef: string[] = this.generateInParameters(inParams, instanceParameters, namespace)
|
|
568
|
-
|
|
569
|
-
def.push(
|
|
570
|
-
`${indent}${commentOut}${exportStr}${staticStr}${globalStr}${name}${genericStr}(${inParamsDef.join(
|
|
571
|
-
', ',
|
|
572
|
-
)})${retSep} ${returnType}`,
|
|
573
|
-
)
|
|
574
|
-
|
|
575
|
-
// Add overloaded methods
|
|
576
|
-
if (overloads && tsFunction.overloads.length > 0) {
|
|
577
|
-
def.push(...this.addInfoComment(`Overloads of ${name}`, indentCount))
|
|
578
|
-
for (const func of tsFunction.overloads) {
|
|
579
|
-
def.push(...this.generateFunction(func, onlyStatic, namespace, indentCount, false))
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
return def
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
private generateFunctions(
|
|
587
|
-
tsFunctions: TsFunction[],
|
|
588
|
-
onlyStatic: boolean,
|
|
589
|
-
namespace: string,
|
|
590
|
-
indentCount = 1,
|
|
591
|
-
comment?: string,
|
|
592
|
-
) {
|
|
593
|
-
const def: string[] = []
|
|
594
|
-
|
|
595
|
-
for (const girFunction of tsFunctions) {
|
|
596
|
-
def.push(...this.generateFunction(girFunction, onlyStatic, namespace, indentCount))
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
if (def.length > 0) {
|
|
600
|
-
def.unshift(...this.addInfoComment(comment, indentCount))
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
return def
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
private generateCallbackInterface(
|
|
607
|
-
tsCallback: TsCallback | TsSignal,
|
|
608
|
-
namespace: string,
|
|
609
|
-
indentCount = 0,
|
|
610
|
-
classModuleName?: string,
|
|
611
|
-
) {
|
|
612
|
-
const def: string[] = []
|
|
613
|
-
|
|
614
|
-
if (!tsCallback?.tsCallbackInterface) {
|
|
615
|
-
this.log.warn(NO_TSDATA('generateCallbackInterface'))
|
|
616
|
-
return def
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
def.push(...this.addGirDocComment(tsCallback.doc, indentCount, tsCallback.tsCallbackInterface.overwriteDoc))
|
|
620
|
-
|
|
621
|
-
const indent = generateIndent(indentCount)
|
|
622
|
-
const indentBody = generateIndent(indentCount + 1)
|
|
623
|
-
const { inParams, instanceParameters } = tsCallback
|
|
624
|
-
const returnTypeStr = this.generateTypes(tsCallback.returnTypes, namespace)
|
|
625
|
-
|
|
626
|
-
// Get name, remove namespace and remove module class name prefix
|
|
627
|
-
let { name } = tsCallback.tsCallbackInterface
|
|
628
|
-
const { generics } = tsCallback.tsCallbackInterface
|
|
629
|
-
name = removeNamespace(name, namespace)
|
|
630
|
-
if (classModuleName) name = removeClassModule(name, classModuleName)
|
|
631
|
-
const genericParameters = this.generateGenericParameters(generics)
|
|
632
|
-
|
|
633
|
-
const inParamsDef: string[] = this.generateInParameters(inParams, instanceParameters, namespace)
|
|
634
|
-
|
|
635
|
-
const interfaceHead = `${name}${genericParameters}`
|
|
636
|
-
|
|
637
|
-
def.push(this.generateExport('interface', `${interfaceHead}`, '{', indentCount))
|
|
638
|
-
def.push(`${indentBody}(${inParamsDef.join(', ')}): ${returnTypeStr}`)
|
|
639
|
-
def.push(indent + '}')
|
|
640
|
-
|
|
641
|
-
return def
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
private generateCallbackInterfaces(
|
|
645
|
-
tsCallbacks: Array<TsCallback | TsSignal>,
|
|
646
|
-
namespace: string,
|
|
647
|
-
indentCount = 0,
|
|
648
|
-
classModuleName: string,
|
|
649
|
-
comment?: string,
|
|
650
|
-
) {
|
|
651
|
-
const def: string[] = []
|
|
652
|
-
|
|
653
|
-
for (const tsCallback of tsCallbacks) {
|
|
654
|
-
def.push(...this.generateCallbackInterface(tsCallback, namespace, indentCount, classModuleName), '')
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
if (def.length > 0) {
|
|
658
|
-
def.unshift(...this.addInfoComment(comment, indentCount))
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
return def
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
private generateEnumeration(girEnum: GirEnumElement | GirBitfieldElement, indentCount = 0) {
|
|
665
|
-
const desc: string[] = []
|
|
666
|
-
|
|
667
|
-
if (!girElementIsIntrospectable(girEnum)) {
|
|
668
|
-
return desc
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
if (!girEnum._tsData) {
|
|
672
|
-
this.log.warn(NO_TSDATA('generateEnumeration'))
|
|
673
|
-
return desc
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
desc.push(...this.addGirDocComment(girEnum._tsData.doc, indentCount))
|
|
677
|
-
|
|
678
|
-
const { name } = girEnum._tsData
|
|
679
|
-
desc.push(this.generateExport('enum', name, '{', indentCount))
|
|
680
|
-
if (girEnum.member) {
|
|
681
|
-
for (const girEnumMember of girEnum.member) {
|
|
682
|
-
if (!girEnumMember._tsData) continue
|
|
683
|
-
desc.push(...this.generateEnumerationMember(girEnumMember._tsData, indentCount + 1))
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
desc.push('}')
|
|
687
|
-
return desc
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
private generateEnumerationMember(tsMember: TsMember, indentCount = 1) {
|
|
691
|
-
const desc: string[] = []
|
|
692
|
-
|
|
693
|
-
if (!tsMember) {
|
|
694
|
-
this.log.warn(NO_TSDATA('generateEnumerationMember'))
|
|
695
|
-
return desc
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
desc.push(...this.addGirDocComment(tsMember.doc, indentCount))
|
|
699
|
-
|
|
700
|
-
const indent = generateIndent(indentCount)
|
|
701
|
-
desc.push(`${indent}${tsMember.name},`)
|
|
702
|
-
return desc
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
private generateConstant(tsConst: TsVar, namespace: string, indentCount = 0) {
|
|
706
|
-
const desc: string[] = []
|
|
707
|
-
|
|
708
|
-
if (!tsConst.hasUnresolvedConflict) {
|
|
709
|
-
desc.push(...this.addGirDocComment(tsConst.doc, indentCount))
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
const indent = generateIndent(indentCount)
|
|
713
|
-
const exp = this.config.useNamespace || this.config.buildType === 'types' ? '' : 'export '
|
|
714
|
-
const varDesc = this.generateVariable(tsConst, namespace, 0)
|
|
715
|
-
desc.push(`${indent}${exp}const ${varDesc}`)
|
|
716
|
-
return desc
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
private generateAlias(girAlias: GirAliasElement, namespace: string, indentCount = 0) {
|
|
720
|
-
const desc: string[] = []
|
|
721
|
-
|
|
722
|
-
if (!girElementIsIntrospectable(girAlias)) {
|
|
723
|
-
return ''
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
if (!girAlias._tsData) {
|
|
727
|
-
this.log.warn(NO_TSDATA('generateAlias'))
|
|
728
|
-
return desc
|
|
729
|
-
}
|
|
730
|
-
const indent = generateIndent(indentCount)
|
|
731
|
-
|
|
732
|
-
const exp = this.config.useNamespace || this.config.buildType === 'types' ? '' : 'export '
|
|
733
|
-
const type = removeNamespace(girAlias._tsData.type, namespace)
|
|
734
|
-
|
|
735
|
-
desc.push(`${indent}${exp}type ${girAlias._tsData.name} = ${type}`)
|
|
736
|
-
return desc
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
private generateConstructPropsInterface(
|
|
740
|
-
girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
|
|
741
|
-
namespace: string,
|
|
742
|
-
indentCount = 0,
|
|
743
|
-
) {
|
|
744
|
-
const def: string[] = []
|
|
745
|
-
|
|
746
|
-
if (!girClass._tsData || !girClass._fullSymName || !girClass._module) {
|
|
747
|
-
throw new Error(NO_TSDATA('generateConstructPropsInterface'))
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
if (!girClass._tsData.isDerivedFromGObject) {
|
|
751
|
-
return def
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
const indent = generateIndent(indentCount)
|
|
755
|
-
const exp = this.config.useNamespace || this.config.buildType === 'types' ? '' : 'export '
|
|
756
|
-
let ext = ''
|
|
757
|
-
|
|
758
|
-
if (girClass._tsData.inheritConstructPropInterfaceNames.length) {
|
|
759
|
-
const constructPropInterfaceNames = girClass._tsData.inheritConstructPropInterfaceNames.map((n) =>
|
|
760
|
-
removeNamespace(n, namespace),
|
|
761
|
-
)
|
|
762
|
-
ext = `extends ${constructPropInterfaceNames.join(', ')} `
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
// Remove namespace and class module name
|
|
766
|
-
const constructPropInterfaceName = removeClassModule(
|
|
767
|
-
removeNamespace(girClass._tsData.constructPropInterfaceName, namespace),
|
|
768
|
-
girClass._tsData.name,
|
|
769
|
-
)
|
|
770
|
-
|
|
771
|
-
def.push(...this.addInfoComment('Constructor properties interface', indentCount))
|
|
772
|
-
|
|
773
|
-
// START BODY
|
|
774
|
-
{
|
|
775
|
-
def.push(`${indent}${exp}interface ${constructPropInterfaceName} ${ext}{`)
|
|
776
|
-
def.push(
|
|
777
|
-
...this.generateProperties(
|
|
778
|
-
girClass._tsData.constructProps.map((cp) => cp._tsData).filter((cp) => !!cp) as TsProperty[],
|
|
779
|
-
false,
|
|
780
|
-
namespace,
|
|
781
|
-
`Own constructor properties of ${girClass._module.packageName}.${girClass._fullSymName}`,
|
|
782
|
-
indentCount + 1,
|
|
783
|
-
),
|
|
784
|
-
)
|
|
785
|
-
def.push(`${indent}}`, '')
|
|
786
|
-
}
|
|
787
|
-
// END BODY
|
|
788
|
-
|
|
789
|
-
return def
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
private generateClassFields(
|
|
793
|
-
girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
|
|
794
|
-
onlyStatic: boolean,
|
|
795
|
-
namespace: string,
|
|
796
|
-
indentCount = 1,
|
|
797
|
-
) {
|
|
798
|
-
const def: string[] = []
|
|
799
|
-
if (!girClass._tsData || !girClass._fullSymName || !girClass._module) {
|
|
800
|
-
throw new Error(NO_TSDATA('generateClassFields'))
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
def.push(
|
|
804
|
-
...this.generateProperties(
|
|
805
|
-
girClass._tsData.fields.map((f) => f._tsData).filter((f) => !!f) as TsProperty[],
|
|
806
|
-
onlyStatic,
|
|
807
|
-
namespace,
|
|
808
|
-
`Own fields of ${girClass._module.packageName}.${girClass._fullSymName}`,
|
|
809
|
-
indentCount,
|
|
810
|
-
),
|
|
811
|
-
)
|
|
812
|
-
|
|
813
|
-
return def
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
private generateClassProperties(
|
|
817
|
-
girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
|
|
818
|
-
onlyStatic: boolean,
|
|
819
|
-
namespace: string,
|
|
820
|
-
indentCount = 1,
|
|
821
|
-
) {
|
|
822
|
-
const def: string[] = []
|
|
823
|
-
|
|
824
|
-
if (!girClass._tsData || !girClass._fullSymName || !girClass._module) {
|
|
825
|
-
throw new Error(NO_TSDATA('generateClassProperties'))
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
def.push(
|
|
829
|
-
...this.generateProperties(
|
|
830
|
-
girClass._tsData.properties.map((p) => p._tsData).filter((p) => !!p) as TsProperty[],
|
|
831
|
-
onlyStatic,
|
|
832
|
-
namespace,
|
|
833
|
-
`Own properties of ${girClass._module.packageName}.${girClass._fullSymName}`,
|
|
834
|
-
indentCount,
|
|
835
|
-
),
|
|
836
|
-
)
|
|
837
|
-
|
|
838
|
-
def.push(
|
|
839
|
-
...this.generateProperties(
|
|
840
|
-
girClass._tsData.conflictProperties,
|
|
841
|
-
onlyStatic,
|
|
842
|
-
namespace,
|
|
843
|
-
`Conflicting properties`,
|
|
844
|
-
indentCount,
|
|
845
|
-
),
|
|
846
|
-
)
|
|
847
|
-
|
|
848
|
-
return def
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
private generateClassMethods(
|
|
852
|
-
girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
|
|
853
|
-
onlyStatic: boolean,
|
|
854
|
-
namespace: string,
|
|
855
|
-
indentCount = 1,
|
|
856
|
-
) {
|
|
857
|
-
const def: string[] = []
|
|
858
|
-
if (!girClass._tsData || !girClass._fullSymName || !girClass._module) {
|
|
859
|
-
throw new Error(NO_TSDATA('generateClassMethods'))
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
def.push(
|
|
863
|
-
...this.generateFunctions(
|
|
864
|
-
girClass._tsData.methods.map((girFunc) => girFunc._tsData).filter((tsFunc) => !!tsFunc) as TsFunction[],
|
|
865
|
-
onlyStatic,
|
|
866
|
-
namespace,
|
|
867
|
-
indentCount,
|
|
868
|
-
`Owm ${onlyStatic ? 'static ' : ''}methods of ${girClass._module.packageName}.${girClass._fullSymName}`,
|
|
869
|
-
),
|
|
870
|
-
)
|
|
871
|
-
|
|
872
|
-
def.push(
|
|
873
|
-
...this.generateFunctions(
|
|
874
|
-
girClass._tsData.conflictMethods,
|
|
875
|
-
onlyStatic,
|
|
876
|
-
namespace,
|
|
877
|
-
indentCount,
|
|
878
|
-
`Conflicting ${onlyStatic ? 'static ' : ''}methods`,
|
|
879
|
-
),
|
|
880
|
-
)
|
|
881
|
-
|
|
882
|
-
return def
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
private generateClassConstructors(
|
|
886
|
-
girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
|
|
887
|
-
namespace: string,
|
|
888
|
-
indentCount = 1,
|
|
889
|
-
) {
|
|
890
|
-
const def: string[] = []
|
|
891
|
-
if (!girClass._tsData || !girClass._fullSymName || !girClass._module) {
|
|
892
|
-
throw new Error(NO_TSDATA('generateClassConstructors'))
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
// Constructors
|
|
896
|
-
def.push(
|
|
897
|
-
...this.generateFunctions(
|
|
898
|
-
girClass._tsData.constructors
|
|
899
|
-
.map((girFunc) => girFunc._tsData)
|
|
900
|
-
.filter((tsFunc) => !!tsFunc) as TsFunction[],
|
|
901
|
-
true,
|
|
902
|
-
namespace,
|
|
903
|
-
indentCount,
|
|
904
|
-
),
|
|
905
|
-
)
|
|
906
|
-
// _init method
|
|
907
|
-
def.push(
|
|
908
|
-
...this.generateFunctions(
|
|
909
|
-
girClass._tsData.constructors
|
|
910
|
-
.map((girFunc) => girFunc._tsData)
|
|
911
|
-
.filter((tsFunc) => !!tsFunc) as TsFunction[],
|
|
912
|
-
false,
|
|
913
|
-
namespace,
|
|
914
|
-
indentCount,
|
|
915
|
-
),
|
|
916
|
-
)
|
|
917
|
-
// Pseudo constructors
|
|
918
|
-
def.push(
|
|
919
|
-
...this.generateFunctions(
|
|
920
|
-
girClass._tsData.staticFunctions
|
|
921
|
-
.map((girFunc) => girFunc._tsData)
|
|
922
|
-
.filter((tsFunc) => !!tsFunc) as TsFunction[],
|
|
923
|
-
true,
|
|
924
|
-
namespace,
|
|
925
|
-
indentCount,
|
|
926
|
-
),
|
|
927
|
-
)
|
|
928
|
-
|
|
929
|
-
if (def.length) {
|
|
930
|
-
def.unshift(
|
|
931
|
-
...this.addInfoComment(
|
|
932
|
-
`Constructors of ${girClass._module.packageName}.${girClass._fullSymName}`,
|
|
933
|
-
indentCount,
|
|
934
|
-
),
|
|
935
|
-
)
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
return def
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
/**
|
|
942
|
-
* Instance methods, vfunc_ prefix
|
|
943
|
-
* @param girClass
|
|
944
|
-
*/
|
|
945
|
-
private generateClassVirtualMethods(
|
|
946
|
-
girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
|
|
947
|
-
namespace: string,
|
|
948
|
-
indentCount = 1,
|
|
949
|
-
) {
|
|
950
|
-
const def: string[] = []
|
|
951
|
-
if (!girClass._tsData || !girClass._fullSymName || !girClass._module) {
|
|
952
|
-
throw new Error(NO_TSDATA('generateClassVirtualMethods'))
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
def.push(
|
|
956
|
-
...this.generateFunctions(
|
|
957
|
-
girClass._tsData.virtualMethods
|
|
958
|
-
.map((girFunc) => girFunc._tsData)
|
|
959
|
-
.filter((tsFunc) => !!tsFunc) as TsFunction[],
|
|
960
|
-
false,
|
|
961
|
-
namespace,
|
|
962
|
-
indentCount,
|
|
963
|
-
`Own virtual methods of ${girClass._module.packageName}.${girClass._fullSymName}`,
|
|
964
|
-
),
|
|
965
|
-
)
|
|
966
|
-
|
|
967
|
-
return def
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
private generateClassSignalInterfaces(
|
|
971
|
-
girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
|
|
972
|
-
namespace: string,
|
|
973
|
-
indentCount = 0,
|
|
974
|
-
) {
|
|
975
|
-
const def: string[] = []
|
|
976
|
-
if (!girClass._tsData) {
|
|
977
|
-
throw new Error(NO_TSDATA('generateClassSignalInterface'))
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
const tsSignals = girClass._tsData.signals
|
|
981
|
-
.map((signal) => signal._tsData)
|
|
982
|
-
.filter((signal) => !!signal) as TsSignal[]
|
|
983
|
-
|
|
984
|
-
def.push(
|
|
985
|
-
...this.generateCallbackInterfaces(
|
|
986
|
-
tsSignals,
|
|
987
|
-
namespace,
|
|
988
|
-
indentCount,
|
|
989
|
-
girClass._tsData.name,
|
|
990
|
-
'Signal callback interfaces',
|
|
991
|
-
),
|
|
992
|
-
)
|
|
993
|
-
|
|
994
|
-
return def
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
private generateClassSignals(
|
|
998
|
-
girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
|
|
999
|
-
namespace: string,
|
|
1000
|
-
) {
|
|
1001
|
-
const def: string[] = []
|
|
1002
|
-
if (!girClass._tsData || !girClass._fullSymName || !girClass._module) {
|
|
1003
|
-
throw new Error(NO_TSDATA('generateClassSignals'))
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
const signalDescs = this.generateSignals(girClass._tsData.signals, girClass, namespace, 0)
|
|
1007
|
-
|
|
1008
|
-
def.push(
|
|
1009
|
-
...this.mergeDescs(
|
|
1010
|
-
signalDescs,
|
|
1011
|
-
`Own signals of ${girClass._module.packageName}.${girClass._fullSymName}`,
|
|
1012
|
-
1,
|
|
1013
|
-
),
|
|
1014
|
-
)
|
|
1015
|
-
|
|
1016
|
-
return def
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
private generateClassModules(
|
|
1020
|
-
girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
|
|
1021
|
-
namespace: string,
|
|
1022
|
-
indentCount = 0,
|
|
1023
|
-
) {
|
|
1024
|
-
const def: string[] = []
|
|
1025
|
-
const bodyDef: string[] = []
|
|
1026
|
-
if (!girClass._tsData) return def
|
|
1027
|
-
const indent = generateIndent(indentCount)
|
|
1028
|
-
|
|
1029
|
-
const exp = this.config.useNamespace || this.config.buildType === 'types' ? '' : 'export '
|
|
1030
|
-
|
|
1031
|
-
// Signal interfaces
|
|
1032
|
-
bodyDef.push(...this.generateClassSignalInterfaces(girClass, namespace, indentCount + 1))
|
|
1033
|
-
|
|
1034
|
-
// Properties interface for construction
|
|
1035
|
-
bodyDef.push(...this.generateConstructPropsInterface(girClass, namespace, indentCount + 1))
|
|
1036
|
-
|
|
1037
|
-
if (!bodyDef.length) {
|
|
1038
|
-
return []
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
// START BODY
|
|
1042
|
-
{
|
|
1043
|
-
def.push(`${indent}${exp}module ${girClass._tsData.name} {`)
|
|
1044
|
-
|
|
1045
|
-
// Properties interface for construction
|
|
1046
|
-
def.push(...bodyDef)
|
|
1047
|
-
|
|
1048
|
-
def.push(`${indent}}`, '')
|
|
1049
|
-
}
|
|
1050
|
-
// END BODY
|
|
1051
|
-
|
|
1052
|
-
return def
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
/**
|
|
1056
|
-
* In Typescript, interfaces and classes can have the same name,
|
|
1057
|
-
* so we use this to generate interfaces with the same name to implement multiple inheritance
|
|
1058
|
-
* @param girClass
|
|
1059
|
-
* @param namespace
|
|
1060
|
-
*/
|
|
1061
|
-
private generateImplementationInterface(
|
|
1062
|
-
girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
|
|
1063
|
-
namespace: string,
|
|
1064
|
-
) {
|
|
1065
|
-
const def: string[] = []
|
|
1066
|
-
|
|
1067
|
-
if (!girClass._tsData) return def
|
|
1068
|
-
|
|
1069
|
-
const genericParameters = this.generateGenericParameters(girClass._tsData.generics)
|
|
1070
|
-
const implementationNames = girClass._tsData.parents
|
|
1071
|
-
.filter((implementation) => implementation.type !== 'parent')
|
|
1072
|
-
.map((implementation) => implementation.localParentName)
|
|
1073
|
-
const ext = implementationNames.length ? ` extends ${implementationNames.join(', ')}` : ''
|
|
1074
|
-
const interfaceHead = `${girClass._tsData.name}${genericParameters}${ext}`
|
|
1075
|
-
|
|
1076
|
-
// START INTERFACE
|
|
1077
|
-
{
|
|
1078
|
-
def.push(this.generateExport('interface', interfaceHead, '{'))
|
|
1079
|
-
|
|
1080
|
-
// START BODY
|
|
1081
|
-
{
|
|
1082
|
-
// Properties
|
|
1083
|
-
def.push(...this.generateClassProperties(girClass, false, namespace))
|
|
1084
|
-
|
|
1085
|
-
// Fields
|
|
1086
|
-
def.push(...this.generateClassFields(girClass, false, namespace))
|
|
1087
|
-
|
|
1088
|
-
// Methods
|
|
1089
|
-
def.push(...this.generateClassMethods(girClass, false, namespace))
|
|
1090
|
-
|
|
1091
|
-
// Virtual methods
|
|
1092
|
-
def.push(...this.generateClassVirtualMethods(girClass, namespace))
|
|
1093
|
-
|
|
1094
|
-
// Signals
|
|
1095
|
-
def.push(...this.generateClassSignals(girClass, namespace))
|
|
1096
|
-
|
|
1097
|
-
// TODO: Generate `GirSignalElement`s instead of generate the signal definition strings directly
|
|
1098
|
-
def.push(...this.generateClassPropertySignals(girClass, namespace))
|
|
1099
|
-
}
|
|
1100
|
-
// END BODY
|
|
1101
|
-
|
|
1102
|
-
// END INTERFACE
|
|
1103
|
-
def.push('}')
|
|
1104
|
-
def.push('')
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1107
|
-
return def
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
/**
|
|
1111
|
-
* Represents a record, GObject class or interface as a Typescript class
|
|
1112
|
-
* @param girClass
|
|
1113
|
-
* @param namespace
|
|
1114
|
-
*/
|
|
1115
|
-
private generateClass(
|
|
1116
|
-
girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
|
|
1117
|
-
namespace: string,
|
|
1118
|
-
) {
|
|
1119
|
-
const def: string[] = []
|
|
1120
|
-
|
|
1121
|
-
if (!girClass._tsData) return def
|
|
1122
|
-
|
|
1123
|
-
def.push(...this.generateClassModules(girClass, namespace))
|
|
1124
|
-
|
|
1125
|
-
def.push(...this.generateImplementationInterface(girClass, namespace))
|
|
1126
|
-
|
|
1127
|
-
def.push(...this.addGirDocComment(girClass._tsData.doc, 0))
|
|
1128
|
-
|
|
1129
|
-
const genericParameters = this.generateGenericParameters(girClass._tsData.generics)
|
|
1130
|
-
const parentName = girClass._tsData.parents.find((parent) => parent.type === 'parent')?.localParentName
|
|
1131
|
-
const ext = parentName ? ` extends ${parentName}` : ''
|
|
1132
|
-
const classHead = `${girClass._tsData.name}${genericParameters}${ext}`
|
|
1133
|
-
|
|
1134
|
-
// START CLASS
|
|
1135
|
-
{
|
|
1136
|
-
if (girClass._tsData.isAbstract) {
|
|
1137
|
-
def.push(this.generateExport('abstract class', classHead, '{'))
|
|
1138
|
-
} else {
|
|
1139
|
-
def.push(this.generateExport('class', classHead, '{'))
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
|
-
// START BODY
|
|
1143
|
-
{
|
|
1144
|
-
// Static Properties
|
|
1145
|
-
def.push(...this.generateClassProperties(girClass, true, namespace))
|
|
1146
|
-
|
|
1147
|
-
// Static Fields
|
|
1148
|
-
def.push(...this.generateClassFields(girClass, true, namespace))
|
|
1149
|
-
|
|
1150
|
-
// Constructors
|
|
1151
|
-
def.push(...this.generateClassConstructors(girClass, namespace))
|
|
1152
|
-
|
|
1153
|
-
// Static Methods
|
|
1154
|
-
def.push(...this.generateClassMethods(girClass, true, namespace))
|
|
1155
|
-
}
|
|
1156
|
-
// END BODY
|
|
1157
|
-
|
|
1158
|
-
// END CLASS
|
|
1159
|
-
def.push('}')
|
|
1160
|
-
def.push('')
|
|
1161
|
-
}
|
|
1162
|
-
|
|
1163
|
-
return def
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
|
-
private async exportModuleJS(moduleTemplateProcessor: TemplateProcessor, girModule: GirModule): Promise<void> {
|
|
1167
|
-
const template = 'module.js'
|
|
1168
|
-
if (this.config.outdir) {
|
|
1169
|
-
await moduleTemplateProcessor.create(template, this.config.outdir, `${girModule.packageName}.js`)
|
|
1170
|
-
} else {
|
|
1171
|
-
const moduleContent = moduleTemplateProcessor.load(template)
|
|
1172
|
-
this.log.log(moduleContent)
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
|
|
1176
|
-
private async exportModuleTS(moduleTemplateProcessor: TemplateProcessor, girModule: GirModule): Promise<void> {
|
|
1177
|
-
const template = 'module.d.ts'
|
|
1178
|
-
const out: string[] = []
|
|
1179
|
-
|
|
1180
|
-
out.push(...this.addTSDocCommentLines([girModule.packageName]))
|
|
1181
|
-
|
|
1182
|
-
out.push('')
|
|
1183
|
-
|
|
1184
|
-
const deps: string[] = girModule.transitiveDependencies
|
|
1185
|
-
|
|
1186
|
-
// Module dependencies as type references or imports
|
|
1187
|
-
if (this.config.environment === 'gjs') {
|
|
1188
|
-
out.push(...this.generateModuleDependenciesImport('Gjs', 'Gjs', false))
|
|
1189
|
-
}
|
|
1190
|
-
|
|
1191
|
-
for (const depPackageName of deps) {
|
|
1192
|
-
// Don't reference yourself as a dependency
|
|
1193
|
-
if (girModule.packageName !== depPackageName) {
|
|
1194
|
-
const girFilename = `${depPackageName}.gir`
|
|
1195
|
-
const { namespace } = splitModuleName(depPackageName)
|
|
1196
|
-
const depFile = findFileInDirs(this.config.girDirectories, girFilename)
|
|
1197
|
-
if (depFile.exists) {
|
|
1198
|
-
out.push(...this.generateModuleDependenciesImport(namespace, depPackageName, false))
|
|
1199
|
-
} else {
|
|
1200
|
-
out.push(`// WARN: Dependency not found: '${depPackageName}'`)
|
|
1201
|
-
this.log.warn(WARN_NOT_FOUND_DEPENDENCY_GIR_FILE(girFilename))
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
|
|
1206
|
-
// START Namespace
|
|
1207
|
-
{
|
|
1208
|
-
if (this.config.buildType === 'types') {
|
|
1209
|
-
out.push('')
|
|
1210
|
-
out.push(`declare namespace ${girModule.namespace} {`)
|
|
1211
|
-
} else if (this.config.useNamespace) {
|
|
1212
|
-
out.push('')
|
|
1213
|
-
out.push(`export namespace ${girModule.namespace} {`)
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
// Newline
|
|
1217
|
-
out.push('')
|
|
1218
|
-
|
|
1219
|
-
if (girModule.ns.enumeration)
|
|
1220
|
-
for (const girEnum of girModule.ns.enumeration) out.push(...this.generateEnumeration(girEnum))
|
|
1221
|
-
|
|
1222
|
-
if (girModule.ns.bitfield)
|
|
1223
|
-
for (const girBitfield of girModule.ns.bitfield) out.push(...this.generateEnumeration(girBitfield))
|
|
1224
|
-
|
|
1225
|
-
if (girModule.ns.constant)
|
|
1226
|
-
for (const girConst of girModule.ns.constant) {
|
|
1227
|
-
if (!girConst._tsData) continue
|
|
1228
|
-
out.push(...this.generateConstant(girConst._tsData, girModule.namespace, 0))
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
if (girModule.ns.function)
|
|
1232
|
-
for (const girFunc of girModule.ns.function) {
|
|
1233
|
-
if (!girFunc._tsData) {
|
|
1234
|
-
// this.log.warn(NO_TSDATA('exportModuleTS functions'))
|
|
1235
|
-
continue
|
|
1236
|
-
}
|
|
1237
|
-
out.push(...this.generateFunction(girFunc._tsData, false, girModule.namespace, 0))
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1240
|
-
if (girModule.ns.callback)
|
|
1241
|
-
for (const girCallback of girModule.ns.callback) {
|
|
1242
|
-
if (!girCallback._tsData) continue
|
|
1243
|
-
out.push(...this.generateCallbackInterface(girCallback._tsData, girModule.namespace))
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
if (girModule.ns.interface)
|
|
1247
|
-
for (const girIface of girModule.ns.interface)
|
|
1248
|
-
if (girIface._module) {
|
|
1249
|
-
out.push(...this.generateClass(girIface, girIface._module.namespace))
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
// Extra interfaces if a template with the module name (e.g. '../templates/GObject-2.0.d.ts') is found
|
|
1253
|
-
// E.g. used for GObject-2.0 to help define GObject classes in js;
|
|
1254
|
-
// these aren't part of gi.
|
|
1255
|
-
if (moduleTemplateProcessor.exists(`${girModule.packageName}.d.ts`)) {
|
|
1256
|
-
const templatePatches = await moduleTemplateProcessor.load(`${girModule.packageName}.d.ts`)
|
|
1257
|
-
out.push(templatePatches)
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
if (girModule.ns.class)
|
|
1261
|
-
for (const gitClass of girModule.ns.class)
|
|
1262
|
-
if (gitClass._module) {
|
|
1263
|
-
out.push(...this.generateClass(gitClass, gitClass._module.namespace))
|
|
1264
|
-
}
|
|
1265
|
-
|
|
1266
|
-
if (girModule.ns.record)
|
|
1267
|
-
for (const girRecord of girModule.ns.record)
|
|
1268
|
-
if (girRecord._module) {
|
|
1269
|
-
out.push(...this.generateClass(girRecord, girRecord._module.namespace))
|
|
1270
|
-
}
|
|
1271
|
-
|
|
1272
|
-
if (girModule.ns.union)
|
|
1273
|
-
for (const girUnion of girModule.ns.union)
|
|
1274
|
-
if (girUnion._module) {
|
|
1275
|
-
out.push(...this.generateClass(girUnion, girUnion._module.namespace))
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
if (girModule.ns.alias)
|
|
1279
|
-
// GType is not a number in GJS
|
|
1280
|
-
for (const girAlias of girModule.ns.alias)
|
|
1281
|
-
if (girModule.packageName !== 'GObject-2.0' || girAlias.$.name !== 'Type')
|
|
1282
|
-
out.push(...this.generateAlias(girAlias, girModule.namespace, 1))
|
|
1283
|
-
|
|
1284
|
-
if (this.config.environment === 'gjs') {
|
|
1285
|
-
// Properties added to every GIRepositoryNamespace
|
|
1286
|
-
// https://gitlab.gnome.org/GNOME/gjs/-/blob/master/gi/ns.cpp#L186-190
|
|
1287
|
-
out.push(
|
|
1288
|
-
...this.generateConstant(
|
|
1289
|
-
{
|
|
1290
|
-
doc: {
|
|
1291
|
-
text: 'Name of the imported GIR library',
|
|
1292
|
-
tags: [
|
|
1293
|
-
{
|
|
1294
|
-
text: 'https://gitlab.gnome.org/GNOME/gjs/-/blob/master/gi/ns.cpp#L188',
|
|
1295
|
-
tagName: 'see',
|
|
1296
|
-
paramName: '',
|
|
1297
|
-
},
|
|
1298
|
-
],
|
|
1299
|
-
},
|
|
1300
|
-
name: '__name__',
|
|
1301
|
-
type: [
|
|
1302
|
-
{
|
|
1303
|
-
type: 'string',
|
|
1304
|
-
optional: false,
|
|
1305
|
-
nullable: false,
|
|
1306
|
-
callbacks: [],
|
|
1307
|
-
generics: [],
|
|
1308
|
-
isArray: false,
|
|
1309
|
-
isFunction: false,
|
|
1310
|
-
isCallback: false,
|
|
1311
|
-
},
|
|
1312
|
-
],
|
|
1313
|
-
isInjected: false,
|
|
1314
|
-
tsTypeName: 'constant',
|
|
1315
|
-
girTypeName: 'constant',
|
|
1316
|
-
},
|
|
1317
|
-
girModule.namespace,
|
|
1318
|
-
0,
|
|
1319
|
-
),
|
|
1320
|
-
...this.generateConstant(
|
|
1321
|
-
{
|
|
1322
|
-
doc: {
|
|
1323
|
-
text: 'Version of the imported GIR library',
|
|
1324
|
-
tags: [
|
|
1325
|
-
{
|
|
1326
|
-
text: 'https://gitlab.gnome.org/GNOME/gjs/-/blob/master/gi/ns.cpp#L189',
|
|
1327
|
-
tagName: 'see',
|
|
1328
|
-
paramName: '',
|
|
1329
|
-
},
|
|
1330
|
-
],
|
|
1331
|
-
},
|
|
1332
|
-
name: '__version__',
|
|
1333
|
-
type: [
|
|
1334
|
-
{
|
|
1335
|
-
type: 'string',
|
|
1336
|
-
optional: false,
|
|
1337
|
-
nullable: false,
|
|
1338
|
-
callbacks: [],
|
|
1339
|
-
generics: [],
|
|
1340
|
-
isArray: false,
|
|
1341
|
-
isFunction: false,
|
|
1342
|
-
isCallback: false,
|
|
1343
|
-
},
|
|
1344
|
-
],
|
|
1345
|
-
isInjected: false,
|
|
1346
|
-
tsTypeName: 'constant',
|
|
1347
|
-
girTypeName: 'constant',
|
|
1348
|
-
},
|
|
1349
|
-
girModule.namespace,
|
|
1350
|
-
0,
|
|
1351
|
-
),
|
|
1352
|
-
)
|
|
1353
|
-
}
|
|
1354
|
-
}
|
|
1355
|
-
// END Namespace
|
|
1356
|
-
if (this.config.useNamespace) {
|
|
1357
|
-
out.push(`}`)
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1360
|
-
if (this.config.useNamespace) {
|
|
1361
|
-
out.push(`export default ${girModule.namespace};`)
|
|
1362
|
-
}
|
|
1363
|
-
|
|
1364
|
-
const outResult = out.join('\n') // End of file
|
|
1365
|
-
|
|
1366
|
-
if (this.config.outdir) {
|
|
1367
|
-
await moduleTemplateProcessor.create(
|
|
1368
|
-
template,
|
|
1369
|
-
this.config.outdir,
|
|
1370
|
-
`${girModule.packageName}.d.ts`,
|
|
1371
|
-
outResult,
|
|
1372
|
-
)
|
|
1373
|
-
} else {
|
|
1374
|
-
const moduleContent = await moduleTemplateProcessor.load(template)
|
|
1375
|
-
this.log.log(moduleContent + '\n' + outResult)
|
|
1376
|
-
}
|
|
1377
|
-
}
|
|
1378
|
-
|
|
1379
|
-
private async exportModule(girModule: GirModule) {
|
|
1380
|
-
const moduleTemplateProcessor = new TemplateProcessor(
|
|
1381
|
-
{
|
|
1382
|
-
name: girModule.namespace,
|
|
1383
|
-
namespace: girModule.namespace,
|
|
1384
|
-
version: girModule.version,
|
|
1385
|
-
importName: girModule.importName,
|
|
1386
|
-
},
|
|
1387
|
-
girModule.packageName,
|
|
1388
|
-
this.config,
|
|
1389
|
-
)
|
|
1390
|
-
|
|
1391
|
-
await this.exportModuleTS(moduleTemplateProcessor, girModule)
|
|
1392
|
-
|
|
1393
|
-
if (this.config.buildType === 'lib') {
|
|
1394
|
-
await this.exportModuleJS(moduleTemplateProcessor, girModule)
|
|
1395
|
-
}
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
|
-
private async exportGjs(girModules: GirModule[], girModulesGrouped: GirModulesGrouped[]) {
|
|
1399
|
-
if (!this.config.outdir) return
|
|
1400
|
-
|
|
1401
|
-
const templateProcessor = new TemplateProcessor(
|
|
1402
|
-
{ girModules: girModules, girModulesGrouped },
|
|
1403
|
-
'gjs',
|
|
1404
|
-
this.config,
|
|
1405
|
-
)
|
|
1406
|
-
|
|
1407
|
-
// Types
|
|
1408
|
-
await templateProcessor.create('Gjs.d.ts', this.config.outdir, 'Gjs.d.ts')
|
|
1409
|
-
await templateProcessor.create('index.d.ts', this.config.outdir, 'index.d.ts')
|
|
1410
|
-
if (this.config.gnomeShellTypes) {
|
|
1411
|
-
await templateProcessor.create('GnomeShell.d.ts', this.config.outdir, 'GnomeShell.d.ts')
|
|
1412
|
-
await templateProcessor.createAll('.d.ts', 'misc', this.config.outdir, 'misc')
|
|
1413
|
-
await templateProcessor.createAll('.d.ts', 'ui', this.config.outdir, 'ui')
|
|
1414
|
-
}
|
|
1415
|
-
|
|
1416
|
-
// Lib
|
|
1417
|
-
if (this.config.buildType === 'lib') {
|
|
1418
|
-
await templateProcessor.create('Gjs.js', this.config.outdir, 'Gjs.js')
|
|
1419
|
-
await templateProcessor.create('index.js', this.config.outdir, 'index.js')
|
|
1420
|
-
if (this.config.gnomeShellTypes) {
|
|
1421
|
-
await templateProcessor.create('GnomeShell.js', this.config.outdir, 'GnomeShell.js')
|
|
1422
|
-
await templateProcessor.createAll('.js', 'misc', this.config.outdir, 'misc')
|
|
1423
|
-
await templateProcessor.createAll('.js', 'ui', this.config.outdir, 'ui')
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
}
|
|
1427
|
-
|
|
1428
|
-
private async exportNodeGtk(girModules: GirModule[], girModulesGrouped: GirModulesGrouped[]) {
|
|
1429
|
-
if (!this.config.outdir) return
|
|
1430
|
-
|
|
1431
|
-
const templateProcessor = new TemplateProcessor({ girModules, girModulesGrouped }, 'node', this.config)
|
|
1432
|
-
|
|
1433
|
-
await templateProcessor.create('index.d.ts', this.config.outdir, 'index.d.ts')
|
|
1434
|
-
if (this.config.buildType === 'lib') {
|
|
1435
|
-
await templateProcessor.create('index.js', this.config.outdir, 'index.js')
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
public async start(
|
|
1440
|
-
girModules: GirModule[],
|
|
1441
|
-
girModulesGrouped?: GirModulesGrouped[],
|
|
1442
|
-
inheritanceTable?: InheritanceTable,
|
|
1443
|
-
) {
|
|
1444
|
-
for (const girModule of girModules) {
|
|
1445
|
-
await this.exportModule(girModule)
|
|
1446
|
-
}
|
|
1447
|
-
|
|
1448
|
-
if (this.config.environment === 'node' && girModulesGrouped) {
|
|
1449
|
-
// node-gtk internal stuff
|
|
1450
|
-
await this.exportNodeGtk(girModules, girModulesGrouped)
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
|
-
if (this.config.environment === 'gjs' && girModulesGrouped && inheritanceTable) {
|
|
1454
|
-
// GJS internal stuff
|
|
1455
|
-
await this.exportGjs(girModules, girModulesGrouped)
|
|
1456
|
-
}
|
|
1457
|
-
}
|
|
1458
|
-
}
|