@ts-for-gir/cli 3.0.0-beta.8 → 3.0.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/README.md +318 -63
  2. package/lib/commands/generate.d.ts +3 -5
  3. package/lib/commands/generate.js +2 -3
  4. package/lib/commands/generate.js.map +1 -1
  5. package/lib/config.d.ts +4 -6
  6. package/lib/config.js +55 -51
  7. package/lib/config.js.map +1 -1
  8. package/lib/constants.d.ts +1 -1
  9. package/lib/constants.js +1 -1
  10. package/lib/constants.js.map +1 -1
  11. package/lib/dependency-manager.d.ts +34 -0
  12. package/lib/dependency-manager.js +78 -0
  13. package/lib/dependency-manager.js.map +1 -0
  14. package/lib/generation-handler.js +2 -2
  15. package/lib/generation-handler.js.map +1 -1
  16. package/lib/gir-module.d.ts +7 -6
  17. package/lib/gir-module.js +34 -23
  18. package/lib/gir-module.js.map +1 -1
  19. package/lib/messages.d.ts +4 -3
  20. package/lib/messages.js +4 -3
  21. package/lib/messages.js.map +1 -1
  22. package/lib/module-loader.d.ts +11 -8
  23. package/lib/module-loader.js +53 -50
  24. package/lib/module-loader.js.map +1 -1
  25. package/lib/symtable.d.ts +4 -4
  26. package/lib/symtable.js +1 -1
  27. package/lib/symtable.js.map +1 -1
  28. package/lib/template-processor.d.ts +4 -5
  29. package/lib/template-processor.js +18 -60
  30. package/lib/template-processor.js.map +1 -1
  31. package/lib/type-definition-generator.js +24 -22
  32. package/lib/type-definition-generator.js.map +1 -1
  33. package/lib/types/class-parent.d.ts +2 -0
  34. package/lib/types/dependency-map.d.ts +1 -1
  35. package/lib/types/dependency.d.ts +2 -1
  36. package/lib/types/file-info.d.ts +14 -0
  37. package/lib/types/file-info.js +2 -0
  38. package/lib/types/file-info.js.map +1 -0
  39. package/lib/types/generate-config.d.ts +4 -6
  40. package/lib/types/index.d.ts +1 -0
  41. package/lib/types/index.js +1 -0
  42. package/lib/types/index.js.map +1 -1
  43. package/lib/types/promisify-func.d.ts +5 -0
  44. package/lib/types/promisify-func.js +2 -0
  45. package/lib/types/promisify-func.js.map +1 -0
  46. package/lib/types/user-config.d.ts +4 -6
  47. package/lib/utils.d.ts +195 -6
  48. package/lib/utils.js +199 -17
  49. package/lib/utils.js.map +1 -1
  50. package/package.json +14 -14
  51. package/src/commands/generate.ts +2 -3
  52. package/src/config.ts +62 -52
  53. package/src/constants.ts +1 -1
  54. package/src/dependency-manager.ts +91 -0
  55. package/src/generation-handler.ts +2 -2
  56. package/src/gir-module.ts +43 -32
  57. package/src/messages.ts +4 -3
  58. package/src/module-loader.ts +59 -54
  59. package/src/symtable.ts +8 -6
  60. package/src/template-processor.ts +30 -64
  61. package/src/type-definition-generator.ts +26 -24
  62. package/src/types/class-parent.ts +2 -0
  63. package/src/types/dependency-map.ts +1 -1
  64. package/src/types/dependency.ts +3 -1
  65. package/src/types/file-info.ts +14 -0
  66. package/src/types/generate-config.ts +4 -6
  67. package/src/types/index.ts +1 -0
  68. package/src/types/user-config.ts +4 -6
  69. package/src/utils.ts +201 -18
  70. package/templates/Gjs/Gjs.d.ts +75 -8
  71. package/templates/Gjs/GnomeShell.d.ts +62 -32
  72. package/templates/Gjs/index.d.ts +3 -3
  73. package/templates/Gjs/misc/fileUtils.d.ts +5 -3
  74. package/templates/Gjs/misc/gnomeSession.d.ts +5 -3
  75. package/templates/Gjs/misc/parentalControlsManager.d.ts +42 -0
  76. package/templates/Gjs/misc/parentalControlsManager.js +6 -0
  77. package/templates/Gjs/misc/signals.d.ts +15 -0
  78. package/templates/Gjs/misc/signals.js +6 -0
  79. package/templates/Gjs/module.d.ts +0 -4
  80. package/templates/Gjs/module.js +1 -1
  81. package/templates/Gjs/tsconfig.alias.json +10 -0
  82. package/templates/Gjs/ui/accessDialog.d.ts +19 -0
  83. package/templates/Gjs/ui/accessDialog.js +6 -0
  84. package/templates/Gjs/ui/altTab.d.ts +124 -0
  85. package/templates/Gjs/ui/altTab.js +6 -0
  86. package/templates/Gjs/ui/animation.d.ts +58 -0
  87. package/templates/Gjs/ui/animation.js +6 -0
  88. package/templates/Gjs/ui/appDisplay.d.ts +204 -0
  89. package/templates/Gjs/ui/appDisplay.js +6 -0
  90. package/templates/Gjs/ui/appFavorites.d.ts +34 -0
  91. package/templates/Gjs/ui/appFavorites.js +6 -0
  92. package/templates/Gjs/ui/appMenu.d.ts +74 -0
  93. package/templates/Gjs/ui/appMenu.js +6 -0
  94. package/templates/Gjs/ui/audioDeviceSelection.d.ts +51 -0
  95. package/templates/Gjs/ui/audioDeviceSelection.js +6 -0
  96. package/templates/Gjs/ui/background.d.ts +255 -0
  97. package/templates/Gjs/ui/background.js +5 -0
  98. package/templates/Gjs/ui/backgroundMenu.d.ts +19 -0
  99. package/templates/Gjs/ui/backgroundMenu.js +5 -0
  100. package/templates/Gjs/ui/barLevel.d.ts +42 -0
  101. package/templates/Gjs/ui/barLevel.js +5 -0
  102. package/templates/Gjs/ui/boxpointer.d.ts +103 -0
  103. package/templates/Gjs/ui/boxpointer.js +5 -0
  104. package/templates/Gjs/ui/calendar.d.ts +261 -0
  105. package/templates/Gjs/ui/calendar.js +5 -0
  106. package/templates/Gjs/ui/components/__init__.d.ts +9 -0
  107. package/templates/Gjs/ui/components/__init__.js +6 -0
  108. package/templates/Gjs/ui/components/automountManager.d.ts +8 -0
  109. package/templates/Gjs/ui/components/automountManager.js +6 -0
  110. package/templates/Gjs/ui/components/autorunManager.d.ts +8 -0
  111. package/templates/Gjs/ui/components/autorunManager.js +6 -0
  112. package/templates/Gjs/ui/components/index.d.ts +6 -0
  113. package/templates/Gjs/ui/components/index.js +6 -0
  114. package/templates/Gjs/ui/components/keyring.d.ts +19 -0
  115. package/templates/Gjs/ui/components/keyring.js +6 -0
  116. package/templates/Gjs/ui/components/networkAgent.d.ts +10 -0
  117. package/templates/Gjs/ui/components/networkAgent.js +6 -0
  118. package/templates/Gjs/ui/components/polkitAgent.d.ts +19 -0
  119. package/templates/Gjs/ui/components/polkitAgent.js +6 -0
  120. package/templates/Gjs/ui/components/telepathyClient.d.ts +10 -0
  121. package/templates/Gjs/ui/components/telepathyClient.js +6 -0
  122. package/templates/Gjs/ui/dialog.d.ts +78 -0
  123. package/templates/Gjs/ui/dialog.js +0 -0
  124. package/templates/Gjs/ui/dnd.d.ts +127 -0
  125. package/templates/Gjs/ui/dnd.js +6 -0
  126. package/templates/Gjs/ui/iconGrid.d.ts +172 -0
  127. package/templates/Gjs/ui/iconGrid.js +6 -0
  128. package/templates/Gjs/ui/layout.d.ts +311 -0
  129. package/templates/Gjs/ui/layout.js +6 -0
  130. package/templates/Gjs/ui/main.d.ts +215 -0
  131. package/templates/Gjs/ui/main.js +6 -0
  132. package/templates/Gjs/ui/messageList.d.ts +113 -0
  133. package/templates/Gjs/ui/messageList.js +6 -0
  134. package/templates/Gjs/ui/messageTray.d.ts +423 -0
  135. package/templates/Gjs/ui/messageTray.js +6 -0
  136. package/templates/Gjs/ui/modalDialog.d.ts +96 -0
  137. package/templates/Gjs/ui/modalDialog.js +6 -0
  138. package/templates/Gjs/ui/mpris.d.ts +78 -0
  139. package/templates/Gjs/ui/mpris.js +6 -0
  140. package/templates/Gjs/ui/notificationDaemon.d.ts +5 -0
  141. package/templates/Gjs/ui/notificationDaemon.js +6 -0
  142. package/templates/Gjs/ui/panel.d.ts +65 -0
  143. package/templates/Gjs/ui/panel.js +6 -0
  144. package/templates/Gjs/ui/panelMenu.d.ts +51 -0
  145. package/templates/Gjs/ui/panelMenu.js +6 -0
  146. package/templates/Gjs/ui/popupMenu.d.ts +228 -0
  147. package/templates/Gjs/ui/popupMenu.js +6 -0
  148. package/templates/Gjs/ui/ripples.d.ts +44 -0
  149. package/templates/Gjs/ui/ripples.js +6 -0
  150. package/templates/Gjs/ui/search.d.ts +158 -0
  151. package/templates/Gjs/ui/search.js +6 -0
  152. package/templates/Gjs/ui/switcherPopup.d.ts +107 -0
  153. package/templates/Gjs/ui/switcherPopup.js +6 -0
  154. package/templates/Gjs/ui/userWidget.d.ts +7 -4
  155. package/templates/node-gtk/index.d.ts +3 -3
  156. package/templates/node-gtk/module.d.ts +0 -4
  157. package/templates/node-gtk/module.js +1 -1
@@ -1,4 +1,4 @@
1
1
  import { Dependency } from './dependency'
2
2
  export interface DependencyMap {
3
- [name: string]: Dependency[]
3
+ [packageName: string]: Dependency[]
4
4
  }
@@ -1,4 +1,6 @@
1
- export interface Dependency {
1
+ import { FileInfo } from './file-info.js'
2
+
3
+ export interface Dependency extends FileInfo {
2
4
  /**
3
5
  * E.g. 'Gtk'
4
6
  */
@@ -0,0 +1,14 @@
1
+ export interface FileInfo {
2
+ /**
3
+ * The path to the gir file or null if the file does not exist
4
+ */
5
+ path: string | null
6
+ /**
7
+ * The filename of the gir file
8
+ */
9
+ filename: string
10
+ /**
11
+ * Whether the file exists or not
12
+ */
13
+ exists: boolean
14
+ }
@@ -16,20 +16,18 @@ export interface GenerateConfig {
16
16
  girDirectories: string[]
17
17
  /** Switch on/off the verbose mode */
18
18
  verbose: boolean
19
- /** prettifies the generated .d.ts files */
20
- pretty: boolean
21
- /** Export all symbols for each module as a namespace */
22
- useNamespace: boolean
19
+ /** Do not export all symbols for each module as a namespace */
20
+ noNamespace: boolean
23
21
  /** Do not generate documentation comments */
24
22
  noComments: boolean
25
23
  /** Do not generate debugging inline comments */
26
24
  noDebugComments: boolean
27
- /** Disable typescript semantic checks using @ts-nocheck */
28
- noCheck: boolean
29
25
  /** Fix Inheritance and implementation type conflicts */
30
26
  fixConflicts: boolean
31
27
  /** Disables the generation of types that are in conflict with the DOM types */
32
28
  noDOMLib: boolean
33
29
  /** Generate types for GNOME Shell */
34
30
  gnomeShellTypes: boolean
31
+ /** Generate a tsconfig alias */
32
+ generateAlias: boolean
35
33
  }
@@ -9,6 +9,7 @@ export * from './construct-name.js'
9
9
  export * from './dependency-map.js'
10
10
  export * from './dependency.js'
11
11
  export * from './environment.js'
12
+ export * from './file-info.js'
12
13
  export * from './generate-config.js'
13
14
  export * from './generator-type.js'
14
15
  export * from './gir-alias-element.js'
@@ -20,24 +20,22 @@ export interface UserConfig {
20
20
  ignoreVersionConflicts: boolean
21
21
  /** print the output to console and create no files */
22
22
  print: boolean
23
- /** prettifies the generated .d.ts files */
24
- pretty: boolean
25
23
  /** GIR modules to load, e.g. 'Gio-2.0'. Accepts multiple modules */
26
24
  modules: string[]
27
25
  /** modules that should be ignored */
28
26
  ignore?: string[]
29
- /** Export all symbols for each module as a namespace */
30
- useNamespace: boolean
27
+ /** Do not export all symbols for each module as a namespace */
28
+ noNamespace: boolean
31
29
  /** Do not generate documentation comments */
32
30
  noComments: boolean
33
31
  /** Do not generate debugging inline comments */
34
32
  noDebugComments: boolean
35
- /** Disable typescript semantic checks using @ts-nocheck */
36
- noCheck: boolean
37
33
  /** Fix Inheritance and implementation type conflicts */
38
34
  fixConflicts: boolean
39
35
  /** Disables the generation of types that are in conflict with the DOM types */
40
36
  noDOMLib: boolean
41
37
  /** Generate types for GNOME Shell */
42
38
  gnomeShellTypes: boolean
39
+ /** Generate a tsconfig alias */
40
+ generateAlias: boolean
43
41
  }
package/src/utils.ts CHANGED
@@ -4,7 +4,7 @@ import Path from 'path'
4
4
  import fs from 'fs'
5
5
  import { getTsconfig, TsConfigJsonResolved } from 'get-tsconfig'
6
6
  import { fileURLToPath } from 'url'
7
- import { Environment, GirInfoAttrs, TsType } from './types/index.js'
7
+ import { Environment, GirInfoAttrs, TsType, FileInfo } from './types/index.js'
8
8
  import { inspect } from 'util'
9
9
  import { Logger } from './logger.js'
10
10
 
@@ -12,18 +12,115 @@ import { COMMENT_REG_EXP, PARAM_REG_EXP, OPT_PARAM_REG_EXP } from './constants.j
12
12
 
13
13
  export { inspect }
14
14
 
15
+ /**
16
+ * Performs a deep comparison between two values to determine if they are
17
+ * equivalent.
18
+ *
19
+ * **Note:** This method supports comparing arrays, array buffers, booleans,
20
+ * date objects, error objects, maps, numbers, `Object` objects, regexes,
21
+ * sets, strings, symbols, and typed arrays. `Object` objects are compared
22
+ * by their own, not inherited, enumerable properties. Functions and DOM
23
+ * nodes are **not** supported.
24
+ *
25
+ * @category Lang
26
+ * @param value The value to compare.
27
+ * @param other The other value to compare.
28
+ * @returns Returns `true` if the values are equivalent, else `false`.
29
+ * @example
30
+ *
31
+ * var object = { 'user': 'fred' };
32
+ * var other = { 'user': 'fred' };
33
+ *
34
+ * _.isEqual(object, other);
35
+ * // => true
36
+ *
37
+ * object === other;
38
+ * // => false
39
+ */
15
40
  export const isEqual = lodash.isEqual
16
41
 
42
+ /**
43
+ * Creates an array of values by running each element in collection through iteratee. The iteratee is
44
+ * invoked with three arguments: (value, index|key, collection).
45
+ *
46
+ * Many lodash methods are guarded to work as iteratees for methods like _.every, _.filter, _.map, _.mapValues,
47
+ * _.reject, and _.some.
48
+ *
49
+ * The guarded methods are:
50
+ * ary, callback, chunk, clone, create, curry, curryRight, drop, dropRight, every, fill, flatten, invert, max,
51
+ * min, parseInt, slice, sortBy, take, takeRight, template, trim, trimLeft, trimRight, trunc, random, range,
52
+ * sample, some, sum, uniq, and words
53
+ *
54
+ * @param collection The collection to iterate over.
55
+ * @param iteratee The function invoked per iteration.
56
+ * @return Returns the new mapped array.
57
+ */
17
58
  export const map = lodash.map
18
59
 
60
+ /**
61
+ * Iterates over elements of collection, returning the first element predicate returns truthy for.
62
+ * The predicate is invoked with three arguments: (value, index|key, collection).
63
+ *
64
+ * @param collection The collection to search.
65
+ * @param predicate The function invoked per iteration.
66
+ * @param fromIndex The index to search from.
67
+ * @return Returns the matched element, else undefined.
68
+ */
19
69
  export const find = lodash.find
20
70
 
71
+ /**
72
+ * Recursively merges own and inherited enumerable properties of source
73
+ * objects into the destination object, skipping source properties that resolve
74
+ * to `undefined`. Array and plain object properties are merged recursively.
75
+ * Other objects and value types are overridden by assignment. Source objects
76
+ * are applied from left to right. Subsequent sources overwrite property
77
+ * assignments of previous sources.
78
+ *
79
+ * **Note:** This method mutates `object`.
80
+ *
81
+ * @category Object
82
+ * @param object The destination object.
83
+ * @param [sources] The source objects.
84
+ * @returns Returns `object`.
85
+ * @example
86
+ *
87
+ * var users = {
88
+ * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
89
+ * };
90
+ *
91
+ * var ages = {
92
+ * 'data': [{ 'age': 36 }, { 'age': 40 }]
93
+ * };
94
+ *
95
+ * _.merge(users, ages);
96
+ * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
97
+ */
21
98
  export const merge = lodash.merge
22
99
 
100
+ /**
101
+ * Creates a shallow clone of value.
102
+ *
103
+ * Note: This method is loosely based on the structured clone algorithm and supports cloning arrays,
104
+ * array buffers, booleans, date objects, maps, numbers, Object objects, regex's, sets, strings, symbols,
105
+ * and typed arrays. The own enumerable properties of arguments objects are cloned as plain objects. An empty
106
+ * object is returned for not cloneable values such as error objects, functions, DOM nodes, and WeakMaps.
107
+ *
108
+ * @param value The value to clone.
109
+ * @return Returns the cloned value.
110
+ */
23
111
  export const clone = lodash.clone
24
112
 
113
+ /**
114
+ * This method is like clone except that it recursively clones value.
115
+ *
116
+ * @param value The value to recursively clone.
117
+ * @return Returns the deep cloned value.
118
+ */
25
119
  export const cloneDeep = lodash.cloneDeep
26
120
 
121
+ /**
122
+ * Split a package name into namespace and version
123
+ */
27
124
  export const splitModuleName = (packageName: string): { packageName: string; namespace: string; version: string } => {
28
125
  // There are modules that use multiple hyphens like 'GUPnP-DLNA-1.0'
29
126
  const splits = packageName.split('-')
@@ -47,6 +144,9 @@ export const removeNamespace = (type: string, namespace: string) => {
47
144
  /** Remove class module name prefix */
48
145
  export const removeClassModule = removeNamespace
49
146
 
147
+ /**
148
+ * Add namespace prefix
149
+ */
50
150
  export const addNamespace = (type: string, namespace: string) => {
51
151
  if (!type.startsWith(namespace + '.')) {
52
152
  type = namespace + '.' + type
@@ -56,30 +156,56 @@ export const addNamespace = (type: string, namespace: string) => {
56
156
 
57
157
  /**
58
158
  * Checking whether some variable is iterable
59
- * see https://stackoverflow.com/a/32538867
159
+ * @see https://stackoverflow.com/a/32538867
60
160
  * @param obj Variable to check for iterable
161
+ * @returns Whether the variable is iterable or not
61
162
  */
62
163
  export const isIterable = (obj: unknown[]): boolean => {
63
164
  return obj != null && typeof obj[Symbol.iterator] === 'function'
64
165
  }
65
166
 
167
+ /**
168
+ * Checking whether a string is numeric
169
+ * @param str The string to check
170
+ * @returns Whether the string is numeric or not
171
+ */
66
172
  export const isNumeric = (str: string): boolean => {
67
173
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
174
  return !isNaN((str as any) - parseFloat(str))
69
175
  }
70
176
 
177
+ /**
178
+ * Get the first character of a string
179
+ * @param str The string to get the first character from
180
+ * @returns The first character
181
+ */
71
182
  export const getFirstChar = (str: string): string => {
72
183
  return str.charAt(0)
73
184
  }
74
185
 
186
+ /**
187
+ * Get the last character of a string
188
+ * @param str The string to get the last character from
189
+ * @returns The last character
190
+ */
75
191
  export const getLastChar = (str: string): string => {
76
192
  return str.charAt(str.length - 1)
77
193
  }
78
194
 
195
+ /**
196
+ * Check if the first character of a string is numeric
197
+ * @param str The string to check
198
+ * @returns Whether the first character is numeric or not
199
+ */
79
200
  export const isFirstCharNumeric = (str: string): boolean => {
80
201
  return isNumeric(getFirstChar(str))
81
202
  }
82
203
 
204
+ /**
205
+ * Convert a string to camelCase
206
+ * @param str The string to convert
207
+ * @returns The converted string
208
+ */
83
209
  export const camelCase = (str: string): string => {
84
210
  return str
85
211
  .replace(/\s(.)|(\s|-|_|\.)(.)/g, (a) => {
@@ -88,34 +214,50 @@ export const camelCase = (str: string): string => {
88
214
  .replace(/(\s|-|_|\.)/g, '')
89
215
  }
90
216
 
217
+ /**
218
+ * Convert a string to lowerCamelCase
219
+ * @param str The string to convert
220
+ * @returns The converted string
221
+ */
91
222
  export const lowerCamelCase = (str: string): string => {
92
223
  str = camelCase(str)
93
224
  str = getFirstChar(str).toLowerCase() + str.slice(1)
94
225
  return str
95
226
  }
96
227
 
228
+ /**
229
+ * Convert a string to UpperCamelCase
230
+ * @param str The string to convert
231
+ * @returns The converted string
232
+ */
97
233
  export const upperCamelCase = (str: string): string => {
98
234
  str = camelCase(str)
99
235
  str = getFirstChar(str).toUpperCase() + str.slice(1)
100
236
  return str
101
237
  }
102
238
 
103
- export const findFileInDirs = (dirs: string[], filename: string): { path: string | null; exists: boolean } => {
104
- let exists = false
239
+ /**
240
+ * Find a file in a list of directories
241
+ * @param dirs The directories to search in
242
+ * @param filename The filename to search for
243
+ * @returns The file info
244
+ */
245
+ export const findFileInDirs = (dirs: string[], filename: string): FileInfo => {
246
+ const FileInfo: FileInfo = {
247
+ path: null,
248
+ filename,
249
+ exists: false,
250
+ }
105
251
  for (const dir of dirs) {
106
252
  const filePath = Path.join(dir, filename)
107
- exists = fs.existsSync(filePath)
108
- if (exists) {
109
- return {
110
- path: filePath,
111
- exists,
112
- }
253
+ FileInfo.exists = fs.existsSync(filePath)
254
+ if (FileInfo.exists) {
255
+ FileInfo.path = filePath
256
+ return FileInfo
113
257
  }
114
258
  }
115
- return {
116
- path: null,
117
- exists,
118
- }
259
+
260
+ return FileInfo
119
261
  }
120
262
 
121
263
  /**
@@ -141,19 +283,37 @@ export const stripParamNames = (func: string, ignoreTail = false): string => {
141
283
  return `${lb[0]}(${params})${tail}`
142
284
  }
143
285
 
286
+ /**
287
+ * Check if a line is a comment line
288
+ * @param line The line to check
289
+ * @returns Whether the line is a comment line or not
290
+ */
144
291
  export const isCommentLine = (line: string) => {
145
292
  const lineTrim = line.trim()
146
293
  return lineTrim.startsWith('//') || (lineTrim.startsWith('/*') && lineTrim.endsWith('*/'))
147
294
  }
148
295
 
296
+ /**
297
+ * Add indents to a string
298
+ * @param indents The number of indents
299
+ * @param spaceForIndent The number of spaces for each indent
300
+ * @returns The indented string
301
+ */
149
302
  export const generateIndent = (indents = 1, spaceForIndent = 4): string => {
150
303
  return ' '.repeat(indents * spaceForIndent)
151
304
  }
152
305
 
153
- // Get __dirname on ESM
306
+ // Get __filename on ESM
154
307
  export const __filename = fileURLToPath(import.meta.url)
308
+ // Get __dirname on ESM
155
309
  export const __dirname = Path.dirname(__filename)
156
310
 
311
+ /**
312
+ * Get the output or input directory of the environment
313
+ * @param environment The environment to get the directory for
314
+ * @param baseDir The base directory
315
+ * @returns The path to the directory
316
+ */
157
317
  export const getEnvironmentDir = (environment: Environment, baseDir: string): string => {
158
318
  if (!baseDir.endsWith(environment))
159
319
  if (environment === 'gjs' && !baseDir.endsWith('/Gjs')) {
@@ -165,12 +325,25 @@ export const getEnvironmentDir = (environment: Environment, baseDir: string): st
165
325
  return baseDir
166
326
  }
167
327
 
328
+ /**
329
+ * Get the destination path for the environment
330
+ * @param environment The environment to get the destination path for
331
+ * @param outputDir The output directory
332
+ * @param parts The path parts
333
+ * @returns The destination path
334
+ */
168
335
  export const getDestPath = (environment: Environment, outputDir: string, ...parts: string[]) => {
169
336
  const outputEnvDir = getEnvironmentDir(environment, outputDir)
170
337
  const destPath = Path.join(outputEnvDir, ...parts)
171
338
  return destPath
172
339
  }
173
340
 
341
+ /**
342
+ * Convert a GirBoolean to a boolean
343
+ * @param boolStr The GirBoolean string
344
+ * @param defaultVal The default value
345
+ * @returns The boolean value
346
+ */
174
347
  export const girBool = (boolStr: string | undefined, defaultVal = false): boolean => {
175
348
  if (boolStr) {
176
349
  if (parseInt(boolStr) === 0) return false
@@ -210,6 +383,11 @@ export const girElementIsIntrospectable = (girElement?: { $: GirInfoAttrs & { na
210
383
  return true
211
384
  }
212
385
 
386
+ /**
387
+ * Check if a type is optional
388
+ * @param types The types to check
389
+ * @returns Whether the type is optional or not
390
+ */
213
391
  export const typeIsOptional = (types: TsType[]) => {
214
392
  for (const type of types) {
215
393
  if (type.optional) return true
@@ -217,7 +395,12 @@ export const typeIsOptional = (types: TsType[]) => {
217
395
  return false
218
396
  }
219
397
 
220
- function convertTsJsConfigToObject(path: string) {
398
+ /**
399
+ * Get a typescript or javascript config by path
400
+ * @param path The path to search for a tsconfig.json or jsconfig.json file
401
+ * @returns The config or null if not found
402
+ */
403
+ export const getTsJsConfigByPath = (path: string) => {
221
404
  try {
222
405
  const config = getTsconfig(path)?.config
223
406
  if (config) return config
@@ -240,8 +423,8 @@ export function readTsJsConfig(path: string) {
240
423
  const tsConfigPath = Path.join(currentPath, 'tsconfig.json')
241
424
  const jsConfigPath = Path.join(currentPath, 'jsconfig.json')
242
425
  config =
243
- (fs.existsSync(tsConfigPath) && convertTsJsConfigToObject(tsConfigPath)) ||
244
- (fs.existsSync(jsConfigPath) && convertTsJsConfigToObject(jsConfigPath))
426
+ (fs.existsSync(tsConfigPath) && getTsJsConfigByPath(tsConfigPath)) ||
427
+ (fs.existsSync(jsConfigPath) && getTsJsConfigByPath(jsConfigPath))
245
428
  lastPath = currentPath
246
429
  currentPath = Path.dirname(currentPath)
247
430
  }
@@ -1,10 +1,13 @@
1
- <% if(useNamespace){ %>
2
- import GObject from './GObject-2.0.js';
3
- import GLib from './GLib-2.0.js';
4
- <% } else { %>
5
- import * as GObject from './GObject-2.0.js';
6
- import * as GLib from './GLib-2.0.js';
7
- <% } %>
1
+ <% const gobject = dep.find('GObject') %>
2
+ <% const glib = dep.find('GLib') %>
3
+
4
+ <%_ if(noNamespace){ _%>
5
+ import type * as GObject from './<%= gobject.packageName %>.js';
6
+ import type * as GLib from './<%= glib.packageName %>.js';
7
+ <%_ } else { _%>
8
+ import type GObject from './<%= gobject.packageName %>.js';
9
+ import type GLib from './<%= glib.packageName %>.js';
10
+ <%_ } _%>
8
11
 
9
12
  // https://gitlab.gnome.org/GNOME/gjs/-/blob/1.72.0/modules/script/package.js
10
13
  export namespace Package {
@@ -133,5 +136,69 @@ export namespace Mainloop {
133
136
  }
134
137
 
135
138
  export namespace Signals {
136
- export function addSignalMethods(proto: object): void
139
+
140
+ /**
141
+ * You can use the `Signals.addSignalMethods` method to apply the `Signals` convenience methods to an `Object`.
142
+ * Generally, this is called on an object prototype, but may also be called on an object instance.
143
+ * You can use this Interface for this object or prototype to make the methods in typescript known
144
+ * @example
145
+ * ```ts
146
+ * const Signals = imports.signals;
147
+ *
148
+ * // Define an interface with the same name of your class to make the methods known
149
+ * interface Events extends Signals.Methods {}
150
+ *
151
+ * class Events {}
152
+ * Signals.addSignalMethods(Events.prototype);
153
+ *
154
+ * const events = new Events();
155
+ *
156
+ * // Typescript will not complain here
157
+ * events.emit("test-signal", "test argument");
158
+ * ```
159
+ */
160
+ export interface Methods {
161
+ /**
162
+ * Connects a callback to a signal for an object. Pass the returned ID to
163
+ * `disconect()` to remove the handler.
164
+ *
165
+ * If `callback` returns `true`, emission will stop and no other handlers will be
166
+ * invoked.
167
+ *
168
+ * > Warning: Unlike GObject signals, `this` within a signal callback will always
169
+ * > refer to the global object (ie. `globalThis`).
170
+ *
171
+ * @param sigName A signal name
172
+ * @param callback A callback function
173
+ * @returns A handler ID
174
+ */
175
+ connect(sigName: string, callback: (self: any, ...args: any[]) => void): number;
176
+ /**
177
+ * Emits a signal for an object. Emission stops if a signal handler returns `true`.
178
+ *
179
+ * Unlike GObject signals, it is not necessary to declare signals or define their
180
+ * signature. Simply call `emit()` with whatever signal name you wish, with
181
+ * whatever arguments you wish.
182
+ * @param sigName A signal name
183
+ * @param args Any number of arguments, of any type
184
+ */
185
+ emit(sigName: string, ...args: any[]): void;
186
+ /**
187
+ * Disconnects a handler for a signal.
188
+ * @param id The ID of the handler to be disconnected
189
+ */
190
+ disconnect(id: number): void;
191
+ /**
192
+ * Disconnects all signal handlers for an object.
193
+ */
194
+ disconnectAll(): void
195
+ /**
196
+ * Checks if a handler ID is connected.
197
+ * @param id The ID of the handler to be disconnected
198
+ * @returns `true` if connected, or `false` if not
199
+ */
200
+ signalHandlerIsConnected(id: number): boolean;
201
+ }
202
+
203
+ export function addSignalMethods<T = any>(proto: T): proto is T & Methods;
137
204
  }