@ts-for-gir/cli 3.0.0-beta.5 → 3.0.0-beta.7

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 (73) hide show
  1. package/README.md +15 -6
  2. package/lib/config.js +40 -48
  3. package/lib/config.js.map +1 -1
  4. package/lib/conflict-resolver.js +9 -3
  5. package/lib/conflict-resolver.js.map +1 -1
  6. package/lib/gir-factory.d.ts +1 -0
  7. package/lib/gir-factory.js +7 -0
  8. package/lib/gir-factory.js.map +1 -1
  9. package/lib/injection/classes/gjs/GLib-2.0.js +110 -0
  10. package/lib/injection/classes/gjs/GLib-2.0.js.map +1 -1
  11. package/lib/injection/injector.js +3 -0
  12. package/lib/injection/injector.js.map +1 -1
  13. package/lib/module-loader.d.ts +1 -1
  14. package/lib/module-loader.js +7 -2
  15. package/lib/module-loader.js.map +1 -1
  16. package/lib/template-processor.js +1 -1
  17. package/lib/template-processor.js.map +1 -1
  18. package/lib/type-definition-generator.d.ts +0 -1
  19. package/lib/type-definition-generator.js +8 -13
  20. package/lib/type-definition-generator.js.map +1 -1
  21. package/lib/types/build-type.d.ts +1 -1
  22. package/lib/types/construct-name.d.ts +1 -1
  23. package/lib/types/environment.d.ts +1 -1
  24. package/lib/types/gir-any-element.d.ts +1 -1
  25. package/lib/types/gir-boolean.d.ts +1 -1
  26. package/lib/types/gir-unparsed-number.d.ts +1 -1
  27. package/lib/types/injection-class.d.ts +2 -1
  28. package/lib/types/injection-generic-parameter.d.ts +1 -1
  29. package/lib/types/injection-instance-parameter.d.ts +1 -1
  30. package/lib/types/injection-type.d.ts +1 -1
  31. package/lib/types/local-name-type.d.ts +1 -1
  32. package/lib/types/module-type.d.ts +1 -1
  33. package/lib/types/transformation-case.d.ts +1 -1
  34. package/lib/types/ts-method.d.ts +1 -1
  35. package/lib/types/ts-type-name.d.ts +1 -1
  36. package/lib/types/ts-type-separator.d.ts +1 -1
  37. package/lib/types/type-gir-alias.d.ts +1 -1
  38. package/lib/types/type-gir-class.d.ts +1 -1
  39. package/lib/types/type-gir-element.d.ts +1 -1
  40. package/lib/types/type-gir-enumeration-member.d.ts +1 -1
  41. package/lib/types/type-gir-enumeration.d.ts +1 -1
  42. package/lib/types/type-gir-function.d.ts +1 -1
  43. package/lib/types/type-gir-interface.d.ts +1 -1
  44. package/lib/types/type-gir-method.d.ts +1 -1
  45. package/lib/types/type-gir-parameter.d.ts +1 -1
  46. package/lib/types/type-gir-property.d.ts +1 -1
  47. package/lib/types/type-gir-variable.d.ts +1 -1
  48. package/lib/types/type-ts-element.d.ts +1 -1
  49. package/lib/types/type-ts-enumeration-member.d.ts +1 -1
  50. package/lib/types/type-ts-function.d.ts +1 -1
  51. package/lib/types/type-ts-property.d.ts +1 -1
  52. package/lib/utils.d.ts +10 -3
  53. package/lib/utils.js +4 -6
  54. package/lib/utils.js.map +1 -1
  55. package/package.json +20 -19
  56. package/src/config.ts +42 -59
  57. package/src/conflict-resolver.ts +11 -3
  58. package/src/gir-factory.ts +11 -0
  59. package/src/injection/classes/gjs/GLib-2.0.ts +110 -0
  60. package/src/injection/injector.ts +5 -0
  61. package/src/module-loader.ts +6 -2
  62. package/src/template-processor.ts +1 -1
  63. package/src/type-definition-generator.ts +8 -14
  64. package/src/types/injection-class.ts +2 -2
  65. package/src/utils.ts +5 -10
  66. package/templates/Gjs/Gjs.d.ts +3 -1
  67. package/templates/Gjs/GnomeShell.d.ts +118 -0
  68. package/templates/Gjs/GnomeShell.js +10 -0
  69. package/templates/Gjs/index.d.ts +17 -13
  70. package/templates/Gjs/index.js +1 -1
  71. package/templates/Gjs/misc/extensionUtils.d.ts +99 -0
  72. package/templates/Gjs/misc/extensionUtils.js +6 -0
  73. package/templates/Gjs/cast.ts +0 -52
@@ -45,6 +45,11 @@ export class Injector {
45
45
  ...this.girFactory.newGirFunctions(toClass.staticFunctions, girClass._tsData, { isInjected: true }),
46
46
  )
47
47
  }
48
+ if (toClass.properties) {
49
+ girClass._tsData.properties.push(
50
+ ...this.girFactory.newGirProperties(toClass.properties, { isInjected: true }),
51
+ )
52
+ }
48
53
  if (toClass.constructors) {
49
54
  girClass._tsData.constructors.push(
50
55
  ...this.girFactory.newGirFunctions(toClass.constructors, girClass._tsData, { isInjected: true }),
@@ -495,8 +495,8 @@ export class ModuleLoader {
495
495
 
496
496
  /**
497
497
  * Find modules with the possibility to use wild cards for module names. E.g. `Gtk*` or `'*'`
498
- * @param girDirectories
499
498
  * @param modules
499
+ * @param ignore
500
500
  */
501
501
  private async findModules(modules: string[], ignore: string[] = []): Promise<Set<string>> {
502
502
  const foundModules = new Set<string>()
@@ -506,7 +506,11 @@ export class ModuleLoader {
506
506
  const filename = `${modules[i]}.gir`
507
507
  let files: string[] = []
508
508
  for (const girDirectory of this.config.girDirectories) {
509
- files = files.concat(await glob(filename, { cwd: girDirectory }))
509
+ try {
510
+ files = files.concat(await glob(filename, { cwd: girDirectory }))
511
+ } catch (error) {
512
+ this.log.warn(`Error on finding "${filename}" in "${girDirectory}"`, error)
513
+ }
510
514
  }
511
515
 
512
516
  let globModules = files.map((file) => Path.basename(file, '.gir'))
@@ -69,7 +69,7 @@ export class TemplateProcessor {
69
69
  const destPath = getDestPath(this.config.environment, outputDir, outputFilename)
70
70
 
71
71
  // write template result file
72
- mkdirSync(outputDir, { recursive: true })
72
+ mkdirSync(Path.dirname(destPath), { recursive: true })
73
73
  writeFileSync(destPath, content, { encoding: 'utf8', flag: 'w' })
74
74
 
75
75
  return Promise.resolve(destPath)
@@ -57,8 +57,8 @@ export default class TypeDefinitionGenerator implements Generator {
57
57
  */
58
58
  private generateModuleDependenciesImport(namespace: string, packageName: string, asExternType = false): string[] {
59
59
  const def: string[] = []
60
+ const sas = this.config.useNamespace && packageName !== 'Gjs' ? '' : '* as '
60
61
  if (this.config.buildType === 'lib') {
61
- const sas = this.config.useNamespace && packageName !== 'Gjs' ? '' : '* as '
62
62
  def.push(`import type ${sas}${namespace} from './${packageName}.js';`)
63
63
  } else if (this.config.buildType === 'types') {
64
64
  if (asExternType) {
@@ -66,7 +66,7 @@ export default class TypeDefinitionGenerator implements Generator {
66
66
  def.push(`import ${namespace} from "${packageName}.js"`)
67
67
  } else {
68
68
  def.push(`/// <reference path="${packageName}.d.ts" />`)
69
- def.push(`import type ${namespace} from './${packageName}.js';`)
69
+ def.push(`import type ${sas}${namespace} from './${packageName}.js';`)
70
70
  }
71
71
  }
72
72
  return def
@@ -1357,7 +1357,7 @@ export default class TypeDefinitionGenerator implements Generator {
1357
1357
  out.push(`}`)
1358
1358
  }
1359
1359
 
1360
- if (this.config.buildType !== 'types' && this.config.useNamespace) {
1360
+ if (this.config.useNamespace) {
1361
1361
  out.push(`export default ${girModule.namespace};`)
1362
1362
  }
1363
1363
 
@@ -1406,24 +1406,19 @@ export default class TypeDefinitionGenerator implements Generator {
1406
1406
 
1407
1407
  // Types
1408
1408
  await templateProcessor.create('Gjs.d.ts', this.config.outdir, 'Gjs.d.ts')
1409
+ await templateProcessor.create('GnomeShell.d.ts', this.config.outdir, 'GnomeShell.d.ts')
1410
+ await templateProcessor.create('misc/extensionUtils.d.ts', this.config.outdir, 'misc/extensionUtils.d.ts')
1409
1411
  await templateProcessor.create('index.d.ts', this.config.outdir, 'index.d.ts')
1410
1412
 
1411
1413
  // Lib
1412
1414
  if (this.config.buildType === 'lib') {
1415
+ await templateProcessor.create('Gjs.js', this.config.outdir, 'Gjs.js')
1416
+ await templateProcessor.create('GnomeShell.js', this.config.outdir, 'GnomeShell.js')
1417
+ await templateProcessor.create('misc/extensionUtils.js', this.config.outdir, 'misc/extensionUtils.js')
1413
1418
  await templateProcessor.create('index.js', this.config.outdir, 'index.js')
1414
- const template = 'Gjs.js'
1415
- await templateProcessor.create(template, this.config.outdir, 'Gjs.js')
1416
1419
  }
1417
1420
  }
1418
1421
 
1419
- private async exportGjsCastLib(inheritanceTable: InheritanceTable) {
1420
- if (!this.config.outdir) return
1421
-
1422
- const inheritanceTableKeys = Object.keys(inheritanceTable)
1423
- const templateProcessor = new TemplateProcessor({ inheritanceTableKeys, inheritanceTable }, 'gjs', this.config)
1424
- await templateProcessor.create('cast.ts', this.config.outdir, 'cast.ts')
1425
- }
1426
-
1427
1422
  private async exportNodeGtk(girModules: GirModule[], girModulesGrouped: GirModulesGrouped[]) {
1428
1423
  if (!this.config.outdir) return
1429
1424
 
@@ -1452,7 +1447,6 @@ export default class TypeDefinitionGenerator implements Generator {
1452
1447
  if (this.config.environment === 'gjs' && girModulesGrouped && inheritanceTable) {
1453
1448
  // GJS internal stuff
1454
1449
  await this.exportGjs(girModules, girModulesGrouped)
1455
- await this.exportGjsCastLib(inheritanceTable)
1456
1450
  }
1457
1451
  }
1458
1452
  }
@@ -1,4 +1,4 @@
1
- import type { InjectionFunction, InjectionGenericParameter, TsMethod } from './index.js'
1
+ import type { InjectionFunction, InjectionGenericParameter, InjectionProperty, TsMethod } from './index.js'
2
2
 
3
3
  /** Interface to inject additional methods, properties, etc to a class */
4
4
  export interface InjectionClass {
@@ -10,7 +10,7 @@ export interface InjectionClass {
10
10
  /** Fields of the base class itself */
11
11
  // TODO: fields: InjectionField[]
12
12
  /** Properties of the base class itself */
13
- // TODO: properties: InjectionProperty[]
13
+ properties?: InjectionProperty[]
14
14
  /** Constructor properties of the base class itself */
15
15
  // TODO:constructProps: InjectionProperty[]
16
16
  /** Array of signal methods for GObject properties */
package/src/utils.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import lodash from 'lodash'
3
3
  import Path from 'path'
4
4
  import fs from 'fs'
5
- import ts from 'typescript'
5
+ import { getTsconfig, TsConfigJsonResolved } from 'get-tsconfig'
6
6
  import { fileURLToPath } from 'url'
7
7
  import { Environment, GirInfoAttrs, TsType } from './types/index.js'
8
8
  import { inspect } from 'util'
@@ -219,11 +219,8 @@ export const typeIsOptional = (types: TsType[]) => {
219
219
 
220
220
  function convertTsJsConfigToObject(path: string) {
221
221
  try {
222
- const config: unknown = ts.parseConfigFileTextToJson(
223
- Path.basename(path),
224
- fs.readFileSync(path, 'utf8').trim(),
225
- ).config
226
- if (typeof config === 'object' && !Array.isArray(config)) return config as Record<PropertyKey, unknown>
222
+ const config = getTsconfig(path)?.config
223
+ if (config) return config
227
224
  } catch {
228
225
  // ignored
229
226
  }
@@ -232,13 +229,11 @@ function convertTsJsConfigToObject(path: string) {
232
229
 
233
230
  /**
234
231
  * Given an directory path search for a tsconfig.json or jsconfig.json file in it or any of its parent directories, then read the file and parse it as json.
235
- * @see {@link https://github.com/microsoft/TypeScript/blob/5f9c9a6ccf61fa131849797248438e292e7b496a/src/harness/compilerImpl.ts#L11-L35}
236
- * @see {@link https://github.com/microsoft/TypeScript/blob/3fd8a6e44341f14681aa9d303dc380020ccb2147/src/harness/vfsUtil.ts#L286-L316}
237
232
  *
238
233
  * @param path - The directory path to search for a tsconfig.json or jsconfig.json file
239
234
  */
240
235
  export function readTsJsConfig(path: string) {
241
- let config: null | false | Record<PropertyKey, unknown> = null
236
+ let config: null | false | TsConfigJsonResolved = null
242
237
  let lastPath = ''
243
238
  let currentPath = Path.resolve(path)
244
239
  while (!config && currentPath !== lastPath) {
@@ -251,5 +246,5 @@ export function readTsJsConfig(path: string) {
251
246
  currentPath = Path.dirname(currentPath)
252
247
  }
253
248
 
254
- return config === false ? null : config
249
+ return config || null
255
250
  }
@@ -93,10 +93,12 @@ export namespace gettext {
93
93
  export function dcgettext(domainname: string | null, msgid: string, category: number): string
94
94
  export function ngettext(msgid: string, msgid_plural: string, n: number): string
95
95
  export function dngettext(domainname: string, msgid: string, msgid_plural: string, n: number): string
96
+ export function pgettext(context: string, msgid: string): string
97
+ export function dpgettext(dom: string | null, context: string, msgid: string): string
96
98
  export function domain(domainName: string): {
97
99
  gettext: (msgid: string) => string
98
100
  ngettext: (msgid: string, msgid_plural: string, n: number) => string
99
- pgettext: (context: any, msgid: string) => any
101
+ pgettext: (context: string, msgid: string) => string
100
102
  }
101
103
  }
102
104
 
@@ -0,0 +1,118 @@
1
+
2
+ import type * as ExtensionUtils from './misc/extensionUtils.js';
3
+
4
+ // TODO: https://gitlab.gnome.org/GNOME/gnome-shell/-/tree/main/js/misc
5
+ export namespace misc {
6
+ export const dbusUtils: any;
7
+ export const extensionUtils: typeof ExtensionUtils;
8
+ export const fileUtils: any;
9
+ export const gnomeSession: any;
10
+ export const history: any;
11
+ export const ibusManager: any;
12
+ export const inputMethod: any;
13
+ export const introspect: any;
14
+ export const jsParse: any;
15
+ export const keyboardManager: any;
16
+ export const loginManager: any;
17
+ export const modemManager: any;
18
+ export const objectManager: any;
19
+ export const params: any;
20
+ export const parentalControlsManager: any;
21
+ export const permissionStore: any;
22
+ export const signalTracker: any;
23
+ export const signals: any;
24
+ export const smartcardManager: any;
25
+ export const systemActions: any;
26
+ export const util: any;
27
+ export const weather: any;
28
+ }
29
+
30
+ // TODO: https://gitlab.gnome.org/GNOME/gnome-shell/-/tree/main/js/ui
31
+ export namespace ui {
32
+ export const components: any;
33
+ export const status: any;
34
+ export const accessDialog: any;
35
+ export const altTab: any;
36
+ export const animation: any;
37
+ export const appDisplay: any;
38
+ export const appFavorites: any;
39
+ export const appMenu: any;
40
+ export const audioDeviceSelection: any;
41
+ export const background: any;
42
+ export const backgroundMenu: any;
43
+ export const barLevel: any;
44
+ export const boxpointer: any;
45
+ export const calendar: any;
46
+ export const checkBox: any;
47
+ export const closeDialog: any;
48
+ export const ctrlAltTab: any;
49
+ export const dash: any;
50
+ export const dateMenu: any;
51
+ export const dialog: any;
52
+ export const dnd: any;
53
+ export const edgeDragAction: any;
54
+ export const endSessionDialog: any;
55
+ export const environment: any;
56
+ export const extensionDownloader: any;
57
+ export const extensionSystem: any;
58
+ export const focusCaretTracker: any;
59
+ export const grabHelper: any;
60
+ export const ibusCandidatePopup: any;
61
+ export const iconGrid: any;
62
+ export const inhibitShortcutsDialog: any;
63
+ export const init: any;
64
+ export const kbdA11yDialog: any;
65
+ export const keyboard: any;
66
+ export const layout: any;
67
+ export const lightbox: any;
68
+ export const locatePointer: any;
69
+ export const lookingGlass: any;
70
+ export const magnifier: any;
71
+ export const main: any;
72
+ export const messageList: any;
73
+ export const messageTray: any;
74
+ export const modalDialog: any;
75
+ export const mpris: any;
76
+ export const notificationDaemon: any;
77
+ export const osdMonitorLabeler: any;
78
+ export const osdWindow: any;
79
+ export const overview: any;
80
+ export const overviewControls: any;
81
+ export const padOsd: any;
82
+ export const pageIndicators: any;
83
+ export const panel: any;
84
+ export const panelMenu: any;
85
+ export const pointerA11yTimeout: any;
86
+ export const pointerWatcher: any;
87
+ export const popupMenu: any;
88
+ export const quickSettings: any;
89
+ export const remoteSearch: any;
90
+ export const ripples: any;
91
+ export const runDialog: any;
92
+ export const screenShield: any;
93
+ export const screenshot: any;
94
+ export const scripting: any;
95
+ export const search: any;
96
+ export const searchController: any;
97
+ export const sessionMode: any;
98
+ export const shellDBus: any;
99
+ export const shellEntry: any;
100
+ export const shellMountOperation: any;
101
+ export const slider: any;
102
+ export const swipeTracker: any;
103
+ export const switchMonitor: any;
104
+ export const switcherPopup: any;
105
+ export const unlockDialog: any;
106
+ export const userWidget: any;
107
+ export const welcomeDialog: any;
108
+ export const windowAttentionHandler: any;
109
+ export const windowManager: any;
110
+ export const windowMenu: any;
111
+ export const windowPreview: any;
112
+ export const workspace: any;
113
+ export const workspaceAnimation: any;
114
+ export const workspaceSwitcherPopup: any;
115
+ export const workspaceThumbnail: any;
116
+ export const workspacesView: any;
117
+ export const xdndHandler: any;
118
+ }
@@ -0,0 +1,10 @@
1
+ <% if(moduleType === 'esm') { %>
2
+ export const misc = imports.misc;
3
+ export const ui = imports.ui;
4
+ <% } else { %>
5
+ module.exports = {
6
+ misc: imports.misc,
7
+ ui: imports.ui
8
+ }
9
+ <% } %>
10
+
@@ -6,6 +6,7 @@
6
6
  */
7
7
 
8
8
  import type * as Gjs from './Gjs.js'
9
+ import type * as GnomeShell from './GnomeShell.js'
9
10
  <%_ for (const girModule of girModules) { _%>
10
11
  <%_ if(useNamespace){ _%>
11
12
  import type <%= girModule.importName %> from "./<%= girModule.packageName %>.js";
@@ -465,8 +466,8 @@ declare global {
465
466
 
466
467
  <% if(!noDOMLib){ %>
467
468
  const TextDecoder: {
468
- prototype: TextDecoder
469
- new (label?: TextDecoderEncoding, options?: TextDecoderOptions): TextDecoder
469
+ prototype: TextDecoder
470
+ new (label?: TextDecoderEncoding, options?: TextDecoderOptions): TextDecoder
470
471
  }
471
472
  <% } %>
472
473
 
@@ -555,29 +556,32 @@ declare global {
555
556
 
556
557
  const imports: typeof Gjs & {
557
558
  gi: {
558
- <%_ for (const girModuleGroup of girModulesGrouped) { _%>
559
- <%= girModuleGroup.namespace %>: <%_ for (const [i, girModule] of girModuleGroup.modules.entries()) { _%>
560
- typeof <%= girModule.module.importName %>
561
- <%_ if (i !== girModuleGroup.modules.length - 1) { _%>
562
- |
563
- <%_ } _%>
564
- <%_ } _%>
565
- <%_ } _%>
566
- versions: {
567
559
  <%_ for (const girModuleGroup of girModulesGrouped) { _%>
568
560
  <%= girModuleGroup.namespace %>: <%_ for (const [i, girModule] of girModuleGroup.modules.entries()) { _%>
569
- '<%= girModule.module.version %>'
561
+ typeof <%= girModule.module.importName %>
570
562
  <%_ if (i !== girModuleGroup.modules.length - 1) { _%>
571
563
  |
572
564
  <%_ } _%>
573
565
  <%_ } _%>
574
566
  <%_ } _%>
575
- }
567
+ versions: {
568
+ <%_ for (const girModuleGroup of girModulesGrouped) { _%>
569
+ <%= girModuleGroup.namespace %>: <%_ for (const [i, girModule] of girModuleGroup.modules.entries()) { _%>
570
+ '<%= girModule.module.version %>'
571
+ <%_ if (i !== girModuleGroup.modules.length - 1) { _%>
572
+ |
573
+ <%_ } _%>
574
+ <%_ } _%>
575
+ <%_ } _%>
576
+ }
576
577
  }
577
578
  lang: typeof Gjs.Lang
578
579
  system: typeof Gjs.System
580
+ signals: typeof Gjs.Signals
579
581
  package: typeof Gjs.Package
580
582
  mainloop: typeof Gjs.Mainloop
583
+ misc: typeof GnomeShell.misc
584
+ ui: typeof GnomeShell.ui
581
585
  searchPath: string[]
582
586
  }
583
587
  }
@@ -1,4 +1,4 @@
1
- const _imports = imports || {}
1
+ const _imports = globalThis.imports || {}
2
2
 
3
3
  export { _imports }
4
4
  export default _imports
@@ -0,0 +1,99 @@
1
+ // https://gitlab.gnome.org/GNOME/gnome-shell/blob/main/js/misc/extensionUtils.js
2
+
3
+ // TODO: untested
4
+ export interface Extension {
5
+ type: ExtensionType;
6
+ state: ExtensionState;
7
+ path: string;
8
+ error: string | null;
9
+ hasPrefs: boolean;
10
+ hasUpdate: boolean;
11
+ canChange: boolean;
12
+ }
13
+
14
+ export enum ExtensionType {
15
+ SYSTEM = 1,
16
+ PER_USER = 2,
17
+ }
18
+
19
+ export enum ExtensionState {
20
+ ENABLED = 1,
21
+ DISABLED = 2,
22
+ ERROR = 3,
23
+ OUT_OF_DATE = 4,
24
+ DOWNLOADING = 5,
25
+ INITIALIZED = 6,
26
+ DISABLING = 7,
27
+ ENABLING = 8,
28
+ UNINSTALLED = 99,
29
+ }
30
+
31
+ declare const SERIALIZED_PROPERTIES: string[];
32
+
33
+ /**
34
+ * Get current extension
35
+ * @param extension the extension object to use in utilities like `initTranslations()`
36
+ */
37
+ export function setCurrentExtension(extension: Extension): void;
38
+
39
+ /**
40
+ * @returns The current extension, or null if not called from an extension.
41
+ */
42
+ export function getCurrentExtension(): Extension | null;
43
+
44
+ /**
45
+ * Init translation
46
+ * @param domain the gettext domain to use
47
+ *
48
+ * Initialize Gettext to load translations from extensionsdir/locale.
49
+ * If @domain is not provided, it will be taken from metadata['gettext-domain']
50
+ */
51
+ export function initTranslations(domain: string): void;
52
+
53
+ /**
54
+ * gettext:
55
+ * @param str the string to translate
56
+ *
57
+ * Translate @str using the extension's gettext domain
58
+ *
59
+ * @returns the translated string
60
+ */
61
+ export function gettext(str: string): string;
62
+
63
+ /**
64
+ * ngettext:
65
+ * @param str the string to translate
66
+ * @param strPlural the plural form of the string
67
+ * @param n the quantity for which translation is needed
68
+ *
69
+ * Translate @str and choose plural form using the extension's gettext domain
70
+ *
71
+ * @returns the translated string
72
+ */
73
+ export function ngettext(str: string, strPlural: string, n: number): string;
74
+
75
+ /**
76
+ * pgettext:
77
+ * @param context context to disambiguate @str
78
+ * @param str the string to translate
79
+ *
80
+ * Translate @str in the context of @context using the extension's gettext domain
81
+ *
82
+ * @returns the translated string
83
+ */
84
+ export function pgettext(context: string, str: string): string;
85
+
86
+ /**
87
+ * openPrefs:
88
+ *
89
+ * Open the preference dialog of the current extension
90
+ */
91
+ export function openPrefs(): void;
92
+
93
+ export function isOutOfDate(extension: Extension): boolean;
94
+
95
+ export function installImporter(extension: Extension): void;
96
+
97
+ export function serializeExtension(extension: Extension): object;
98
+
99
+ export function deserializeExtension(data: object): Extension;
@@ -0,0 +1,6 @@
1
+ <% if(moduleType === 'esm') { %>
2
+ export imports.misc.extensionUtils;
3
+ <% } else { %>
4
+ module.exports = imports.misc.extensionUtils;
5
+ <% } %>
6
+
@@ -1,52 +0,0 @@
1
-
2
- <% if(useNamespace){ %>
3
- import GObject from './GObject-2.0.js';
4
- <% } else { %>
5
- import * as GObject from './GObject-2.0.js';
6
- <% } %>
7
-
8
- const inheritanceTable: { [key: string]: string[] } = {
9
- <%_ for (const key of inheritanceTableKeys) { _%>
10
- '<%= key %>': [
11
- <%_ for (const value of inheritanceTable[key]) { _%>
12
- '<%= value %>',
13
- <%_ } _%>
14
- ],
15
- <%_ } _%>
16
- }
17
-
18
-
19
- interface StaticNamedClass<T> {
20
- new (...args: any[]): T
21
- name: string
22
- }
23
-
24
- /**
25
- * Casts between derived classes, performing a run-time type-check
26
- * and raising an exception if the cast fails. Allows casting to implemented
27
- * interfaces, too.
28
- */
29
- export function giCast<T>(from_: GObject.Object, to_: StaticNamedClass<T>): T {
30
- const desc: string = from_.toString()
31
- let clsName: string|null = null
32
- for (const k of desc.split(" ")) {
33
- if (k.substring(0, 7) == "GIName:") {
34
- clsName = k.substring(7)
35
- break
36
- }
37
- }
38
- const toName = to_.name.replace("_", ".")
39
-
40
- if (toName === clsName)
41
- return ((from_ as any) as T)
42
-
43
- if (clsName) {
44
- const parents = inheritanceTable[clsName]
45
- if (parents) {
46
- if (parents.indexOf(toName) >= 0)
47
- return ((from_ as any) as T)
48
- }
49
- }
50
-
51
- throw Error("Invalid cast of " + desc + "(" + clsName + ") to " + toName)
52
- }