@ts-for-gir/cli 3.2.9 → 4.0.0-beta.1
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 +1 -58
- package/lib/commands/doc.js +8 -11
- package/lib/commands/doc.js.map +1 -1
- package/lib/commands/generate.js +32 -13
- package/lib/commands/generate.js.map +1 -1
- package/lib/commands/list.js.map +1 -1
- package/lib/config.d.ts +2 -13
- package/lib/config.js +4 -96
- package/lib/config.js.map +1 -1
- package/lib/generation-handler.d.ts +2 -3
- package/lib/generation-handler.js +18 -29
- package/lib/generation-handler.js.map +1 -1
- package/lib/module-loader.js +15 -6
- package/lib/module-loader.js.map +1 -1
- package/package.json +11 -11
- package/src/commands/doc.ts +16 -19
- package/src/commands/generate.ts +39 -18
- package/src/config.ts +5 -110
- package/src/generation-handler.ts +23 -31
- package/src/module-loader.ts +22 -7
|
@@ -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 {
|
|
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.
|
|
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
|
-
|
|
32
|
-
|
|
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
|
-
|
|
39
|
-
|
|
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
|
-
|
|
63
|
-
for (const girModule of girModules) girModule.init(inheritanceTable)
|
|
48
|
+
this.log.info(TSDATA_PARSING_DONE)
|
|
64
49
|
|
|
65
|
-
this.
|
|
50
|
+
if (this.config.outdir) {
|
|
51
|
+
await mkdir(this.config.outdir, { recursive: true })
|
|
52
|
+
}
|
|
66
53
|
|
|
67
|
-
this
|
|
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.
|
|
69
|
+
await this.generator.finish(registry)
|
|
78
70
|
|
|
79
71
|
this.log.success(GENERATING_TYPES_DONE)
|
|
80
72
|
}
|
package/src/module-loader.ts
CHANGED
|
@@ -7,7 +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
|
|
10
|
+
import { parser } from '@gi.ts/parser'
|
|
11
11
|
import {
|
|
12
12
|
DependencyManager,
|
|
13
13
|
ResolveType,
|
|
@@ -22,7 +22,6 @@ import { Config } from './config.js'
|
|
|
22
22
|
|
|
23
23
|
import type {
|
|
24
24
|
GirModulesGroupedMap,
|
|
25
|
-
ParsedGir,
|
|
26
25
|
GenerateConfig,
|
|
27
26
|
GirModuleResolvedBy,
|
|
28
27
|
GirModulesGrouped,
|
|
@@ -37,7 +36,7 @@ export class ModuleLoader {
|
|
|
37
36
|
/** Transitive module dependencies */
|
|
38
37
|
modDependencyMap: DependencyMap = {}
|
|
39
38
|
constructor(protected readonly config: GenerateConfig) {
|
|
40
|
-
this.log = new Logger(
|
|
39
|
+
this.log = new Logger(config.verbose, 'ModuleLoader')
|
|
41
40
|
this.dependencyManager = DependencyManager.getInstance(config)
|
|
42
41
|
}
|
|
43
42
|
|
|
@@ -386,8 +385,8 @@ export class ModuleLoader {
|
|
|
386
385
|
|
|
387
386
|
this.log.log(`Parsing ${dependency.path}...`)
|
|
388
387
|
const fileContents = await readFile(dependency.path, 'utf8')
|
|
389
|
-
const result =
|
|
390
|
-
const girModule =
|
|
388
|
+
const result = parser.parseGir(fileContents)
|
|
389
|
+
const girModule = GirModule.load(result, this.config, this.dependencyManager)
|
|
391
390
|
// Figure out transitive module dependencies
|
|
392
391
|
this.extendDependencyMapByGirModule(girModule)
|
|
393
392
|
return girModule
|
|
@@ -549,9 +548,25 @@ export class ModuleLoader {
|
|
|
549
548
|
ignore: string[] = [],
|
|
550
549
|
doNotAskForVersionOnConflict = true,
|
|
551
550
|
): Promise<{ keep: GirModuleResolvedBy[]; grouped: GirModulesGroupedMap; ignore: string[]; failed: Set<string> }> {
|
|
552
|
-
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
|
+
|
|
553
557
|
const dependencies = this.packageNamesToDependencies(foundPackageNames)
|
|
554
|
-
|
|
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
|
+
)
|
|
555
570
|
let keep: GirModuleResolvedBy[] = []
|
|
556
571
|
if (doNotAskForVersionOnConflict) {
|
|
557
572
|
keep = loaded
|