@ts-for-gir/cli 3.3.0 → 4.0.0-beta.2

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.
@@ -10,71 +10,63 @@ import {
10
10
  } from '@ts-for-gir/lib'
11
11
  import { GeneratorType, Generator } from '@ts-for-gir/generator-base'
12
12
  import { TypeDefinitionGenerator } from '@ts-for-gir/generator-typescript'
13
- import { HtmlDocGenerator } from '@ts-for-gir/generator-html-doc'
13
+ // import { HtmlDocGenerator } from '@ts-for-gir/generator-html-doc'
14
14
 
15
- import type { InheritanceTable, GenerateConfig, GirModulesGrouped } from '@ts-for-gir/lib'
15
+ import type { GenerateConfig, NSRegistry } from '@ts-for-gir/lib'
16
16
 
17
17
  export class GenerationHandler {
18
18
  log: Logger
19
19
  generator: Generator
20
+
20
21
  constructor(
21
22
  private readonly config: GenerateConfig,
22
23
  type: GeneratorType,
23
24
  ) {
24
- this.log = new Logger(config.environment, config.verbose, 'GenerationHandler')
25
+ this.log = new Logger(config.verbose, 'GenerationHandler')
25
26
 
26
27
  switch (type) {
27
28
  case GeneratorType.TYPES:
28
29
  this.generator = new TypeDefinitionGenerator(config)
29
30
  break
30
- case GeneratorType.HTML_DOC:
31
- this.generator = new HtmlDocGenerator(config)
32
- break
31
+ // case GeneratorType.HTML_DOC:
32
+ // this.generator = new HtmlDocGenerator(config)
33
+ // break
33
34
  default:
34
35
  throw new Error('Unknown Generator')
35
36
  }
36
37
  }
37
38
 
38
- private finalizeInheritance(inheritanceTable: InheritanceTable): void {
39
- for (const clsName of Object.keys(inheritanceTable)) {
40
- let p: string | string[] = inheritanceTable[clsName][0]
41
- while (p) {
42
- p = inheritanceTable[p]
43
- if (p) {
44
- p = p[0]
45
- inheritanceTable[clsName].push(p)
46
- }
47
- }
48
- }
49
- }
50
-
51
- public async start(girModules: GirModule[], girModulesGrouped: GirModulesGrouped[]): Promise<void> {
52
- this.log.info(START_MODULE(this.config.environment, this.config.buildType))
39
+ public async start(girModules: GirModule[], registry: NSRegistry): Promise<void> {
40
+ this.log.info(START_MODULE)
53
41
 
54
42
  if (girModules.length == 0) {
55
43
  this.log.error(ERROR_NO_MODULE_SPECIFIED)
56
44
  }
57
45
 
58
- GirModule.allGirModules = girModules
59
-
60
46
  this.log.info(FILE_PARSING_DONE)
61
47
 
62
- const inheritanceTable: InheritanceTable = {}
63
- for (const girModule of girModules) girModule.init(inheritanceTable)
48
+ this.log.info(TSDATA_PARSING_DONE)
64
49
 
65
- this.finalizeInheritance(inheritanceTable)
50
+ if (this.config.outdir) {
51
+ await mkdir(this.config.outdir, { recursive: true })
52
+ }
66
53
 
67
- this.log.info(TSDATA_PARSING_DONE)
54
+ // TODO: Put this somewhere that makes sense
55
+ registry.transform({
56
+ inferGenerics: true,
57
+ verbose: this.config.verbose,
58
+ })
59
+
60
+ await this.generator.start(registry)
68
61
 
69
62
  for (const girModule of girModules) {
70
- if (this.config.outdir) {
71
- await mkdir(this.config.outdir, { recursive: true })
72
- }
73
63
  this.log.log(` - ${girModule.packageName} ...`)
74
64
  girModule.start(girModules)
65
+
66
+ await this.generator.generate(registry, girModule)
75
67
  }
76
68
 
77
- await this.generator.start(girModules, girModulesGrouped, inheritanceTable)
69
+ await this.generator.finish(registry)
78
70
 
79
71
  this.log.success(GENERATING_TYPES_DONE)
80
72
  }
@@ -7,6 +7,7 @@ import glob from 'tiny-glob'
7
7
  import { basename } from 'path'
8
8
  import { readFile } from 'fs/promises'
9
9
  import { bold } from 'colorette'
10
+ import { parser } from '@gi.ts/parser'
10
11
  import {
11
12
  DependencyManager,
12
13
  ResolveType,
@@ -15,7 +16,6 @@ import {
15
16
  splitModuleName,
16
17
  union,
17
18
  isIterable,
18
- girParser,
19
19
  WARN_NO_GIR_FILE_FOUND_FOR_PACKAGE,
20
20
  } from '@ts-for-gir/lib'
21
21
  import { Config } from './config.js'
@@ -36,7 +36,7 @@ export class ModuleLoader {
36
36
  /** Transitive module dependencies */
37
37
  modDependencyMap: DependencyMap = {}
38
38
  constructor(protected readonly config: GenerateConfig) {
39
- this.log = new Logger('', config.verbose, 'ModuleLoader')
39
+ this.log = new Logger(config.verbose, 'ModuleLoader')
40
40
  this.dependencyManager = DependencyManager.getInstance(config)
41
41
  }
42
42
 
@@ -385,8 +385,8 @@ export class ModuleLoader {
385
385
 
386
386
  this.log.log(`Parsing ${dependency.path}...`)
387
387
  const fileContents = await readFile(dependency.path, 'utf8')
388
- const result = girParser(fileContents)
389
- const girModule = new GirModule(result, this.config)
388
+ const result = parser.parseGir(fileContents)
389
+ const girModule = GirModule.load(result, this.config, this.dependencyManager)
390
390
  // Figure out transitive module dependencies
391
391
  this.extendDependencyMapByGirModule(girModule)
392
392
  return girModule
@@ -548,9 +548,25 @@ export class ModuleLoader {
548
548
  ignore: string[] = [],
549
549
  doNotAskForVersionOnConflict = true,
550
550
  ): Promise<{ keep: GirModuleResolvedBy[]; grouped: GirModulesGroupedMap; ignore: string[]; failed: Set<string> }> {
551
- const foundPackageNames = await this.findPackageNames(packageNames, ignore)
551
+ const foundPackageNames = await this.findPackageNames([...packageNames], ignore)
552
+ // Always require these because GJS does...
553
+ const GLib = this.dependencyManager.get('GLib', '2.0')
554
+ const Gio = this.dependencyManager.get('Gio', '2.0')
555
+ const GObject = this.dependencyManager.get('GObject', '2.0')
556
+
552
557
  const dependencies = this.packageNamesToDependencies(foundPackageNames)
553
- const { loaded, failed } = await this.loadGirModules(dependencies, ignore)
558
+
559
+ const { loaded, failed } = await this.loadGirModules(
560
+ [
561
+ GLib,
562
+ Gio,
563
+ GObject,
564
+ ...dependencies.filter(
565
+ (dep) => dep.namespace !== 'GLib' && dep.namespace !== 'Gio' && dep.namespace !== 'GObject',
566
+ ),
567
+ ],
568
+ ignore,
569
+ )
554
570
  let keep: GirModuleResolvedBy[] = []
555
571
  if (doNotAskForVersionOnConflict) {
556
572
  keep = loaded