@ts-for-gir/cli 4.0.0-beta.1 → 4.0.0-beta.11
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 +43 -140
- package/lib/commands/copy.d.ts +12 -0
- package/lib/commands/copy.js +80 -0
- package/lib/commands/copy.js.map +1 -0
- package/lib/commands/doc.js +1 -1
- package/lib/commands/doc.js.map +1 -1
- package/lib/commands/generate.js +3 -8
- package/lib/commands/generate.js.map +1 -1
- package/lib/commands/index.d.ts +1 -0
- package/lib/commands/index.js +1 -0
- package/lib/commands/index.js.map +1 -1
- package/lib/commands/list.js +8 -1
- package/lib/commands/list.js.map +1 -1
- package/lib/config.d.ts +23 -8
- package/lib/config.js +85 -73
- package/lib/config.js.map +1 -1
- package/lib/generation-handler.d.ts +2 -2
- package/lib/generation-handler.js +5 -5
- package/lib/generation-handler.js.map +1 -1
- package/lib/module-loader.d.ts +13 -10
- package/lib/module-loader.js +47 -58
- package/lib/module-loader.js.map +1 -1
- package/lib/start.js +2 -1
- package/lib/start.js.map +1 -1
- package/package.json +14 -14
- package/src/commands/copy.ts +94 -0
- package/src/commands/doc.ts +1 -1
- package/src/commands/generate.ts +4 -8
- package/src/commands/index.ts +1 -0
- package/src/commands/list.ts +9 -1
- package/src/config.ts +96 -79
- package/src/generation-handler.ts +7 -9
- package/src/module-loader.ts +54 -67
- package/src/start.ts +2 -1
package/src/config.ts
CHANGED
|
@@ -6,9 +6,10 @@ import { Options } from 'yargs'
|
|
|
6
6
|
import { cosmiconfig, Options as ConfigSearchOptions } from 'cosmiconfig'
|
|
7
7
|
import { join, extname, dirname, resolve } from 'path'
|
|
8
8
|
import { writeFile } from 'fs/promises'
|
|
9
|
+
import { existsSync } from 'fs'
|
|
9
10
|
import { merge, isEqual, Logger, APP_NAME, APP_USAGE, ERROR_CONFIG_EXTENSION_UNSUPPORTED } from '@ts-for-gir/lib'
|
|
10
11
|
|
|
11
|
-
import type { UserConfig, ConfigFlags, UserConfigLoadResult,
|
|
12
|
+
import type { UserConfig, ConfigFlags, UserConfigLoadResult, OptionsGeneration } from '@ts-for-gir/lib'
|
|
12
13
|
|
|
13
14
|
export class Config {
|
|
14
15
|
static appName = APP_NAME
|
|
@@ -30,11 +31,16 @@ export class Config {
|
|
|
30
31
|
ignoreVersionConflicts: false,
|
|
31
32
|
noNamespace: false,
|
|
32
33
|
noComments: false,
|
|
33
|
-
noDebugComments: false,
|
|
34
|
-
fixConflicts: true,
|
|
35
34
|
promisify: true,
|
|
36
35
|
npmScope: '@girs',
|
|
37
|
-
|
|
36
|
+
workspace: false,
|
|
37
|
+
onlyVersionPrefix: false,
|
|
38
|
+
noPrettyPrint: false,
|
|
39
|
+
// Disabled by default because advanced variants are complicated,
|
|
40
|
+
// it does impact performance (especially on older typescript versions)
|
|
41
|
+
// and we'd need to test it works with the updated bindings
|
|
42
|
+
noAdvancedVariants: true,
|
|
43
|
+
package: false,
|
|
38
44
|
}
|
|
39
45
|
|
|
40
46
|
static configFilePath = join(process.cwd(), Config.defaults.configName)
|
|
@@ -87,7 +93,7 @@ export class Config {
|
|
|
87
93
|
},
|
|
88
94
|
ignoreVersionConflicts: {
|
|
89
95
|
type: 'boolean',
|
|
90
|
-
description: '
|
|
96
|
+
description: 'Skip prompts for library version selection when multiple versions are detected',
|
|
91
97
|
default: Config.defaults.ignoreVersionConflicts,
|
|
92
98
|
normalize: true,
|
|
93
99
|
},
|
|
@@ -100,7 +106,7 @@ export class Config {
|
|
|
100
106
|
},
|
|
101
107
|
configName: {
|
|
102
108
|
type: 'string',
|
|
103
|
-
description: '
|
|
109
|
+
description: 'Specify a custom name for the configuration file',
|
|
104
110
|
default: Config.defaults.configName,
|
|
105
111
|
normalize: true,
|
|
106
112
|
},
|
|
@@ -118,18 +124,6 @@ export class Config {
|
|
|
118
124
|
default: Config.defaults.noComments,
|
|
119
125
|
normalize: true,
|
|
120
126
|
},
|
|
121
|
-
noDebugComments: {
|
|
122
|
-
type: 'boolean',
|
|
123
|
-
description: 'Do not generate debugging inline comments',
|
|
124
|
-
default: Config.defaults.noDebugComments,
|
|
125
|
-
normalize: true,
|
|
126
|
-
},
|
|
127
|
-
fixConflicts: {
|
|
128
|
-
type: 'boolean',
|
|
129
|
-
description: 'Fix Inheritance and implementation type conflicts',
|
|
130
|
-
default: Config.defaults.fixConflicts,
|
|
131
|
-
normalize: true,
|
|
132
|
-
},
|
|
133
127
|
promisify: {
|
|
134
128
|
type: 'boolean',
|
|
135
129
|
description: 'Generate promisified functions for async/finish calls',
|
|
@@ -142,10 +136,36 @@ export class Config {
|
|
|
142
136
|
default: Config.defaults.npmScope,
|
|
143
137
|
normalize: true,
|
|
144
138
|
},
|
|
145
|
-
|
|
139
|
+
workspace: {
|
|
140
|
+
type: 'boolean',
|
|
141
|
+
description:
|
|
142
|
+
'Uses the workspace protocol for the generated packages which can be used with package managers like Yarn and PNPM',
|
|
143
|
+
default: Config.defaults.workspace,
|
|
144
|
+
normalize: true,
|
|
145
|
+
},
|
|
146
|
+
onlyVersionPrefix: {
|
|
147
|
+
type: 'boolean',
|
|
148
|
+
description:
|
|
149
|
+
'Only use the version prefix for the ambient module exports. This is useful if, for whatever reason, you want to use different library versions of the same library in your project.',
|
|
150
|
+
default: Config.defaults.onlyVersionPrefix,
|
|
151
|
+
normalize: true,
|
|
152
|
+
},
|
|
153
|
+
noPrettyPrint: {
|
|
146
154
|
type: 'boolean',
|
|
147
|
-
description: '
|
|
148
|
-
default: Config.defaults.
|
|
155
|
+
description: 'Do not prettify the generated types',
|
|
156
|
+
default: Config.defaults.noPrettyPrint,
|
|
157
|
+
normalize: true,
|
|
158
|
+
},
|
|
159
|
+
noAdvancedVariants: {
|
|
160
|
+
type: 'boolean',
|
|
161
|
+
description: 'Disable GLib.Variant class with string parsing',
|
|
162
|
+
default: Config.defaults.noAdvancedVariants,
|
|
163
|
+
normalize: true,
|
|
164
|
+
},
|
|
165
|
+
package: {
|
|
166
|
+
type: 'boolean',
|
|
167
|
+
description: 'Generate the typescript types with package.json support',
|
|
168
|
+
default: Config.defaults.package,
|
|
149
169
|
normalize: true,
|
|
150
170
|
},
|
|
151
171
|
}
|
|
@@ -165,16 +185,29 @@ export class Config {
|
|
|
165
185
|
configName: this.options.configName,
|
|
166
186
|
noNamespace: this.options.noNamespace,
|
|
167
187
|
noComments: this.options.noComments,
|
|
168
|
-
noDebugComments: this.options.noDebugComments,
|
|
169
|
-
fixConflicts: this.options.fixConflicts,
|
|
170
188
|
promisify: this.options.promisify,
|
|
171
189
|
npmScope: this.options.npmScope,
|
|
172
|
-
|
|
190
|
+
workspace: this.options.workspace,
|
|
191
|
+
onlyVersionPrefix: this.options.onlyVersionPrefix,
|
|
192
|
+
noPrettyPrint: this.options.noPrettyPrint,
|
|
193
|
+
noAdvancedVariants: this.options.noAdvancedVariants,
|
|
194
|
+
package: this.options.package,
|
|
173
195
|
}
|
|
174
196
|
|
|
175
197
|
static listOptions = {
|
|
176
198
|
modules: this.options.modules,
|
|
177
199
|
girDirectories: Config.options.girDirectories,
|
|
200
|
+
root: this.options.root,
|
|
201
|
+
ignore: Config.options.ignore,
|
|
202
|
+
configName: Config.options.configName,
|
|
203
|
+
verbose: Config.options.verbose,
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
static copyOptions = {
|
|
207
|
+
modules: this.options.modules,
|
|
208
|
+
girDirectories: Config.options.girDirectories,
|
|
209
|
+
root: this.options.root,
|
|
210
|
+
outdir: Config.options.outdir,
|
|
178
211
|
ignore: Config.options.ignore,
|
|
179
212
|
configName: Config.options.configName,
|
|
180
213
|
verbose: Config.options.verbose,
|
|
@@ -183,6 +216,7 @@ export class Config {
|
|
|
183
216
|
static docOptions = {
|
|
184
217
|
modules: this.options.modules,
|
|
185
218
|
girDirectories: Config.options.girDirectories,
|
|
219
|
+
root: this.options.root,
|
|
186
220
|
outdir: Config.options.outdir,
|
|
187
221
|
ignore: Config.options.ignore,
|
|
188
222
|
verbose: Config.options.verbose,
|
|
@@ -254,21 +288,9 @@ export class Config {
|
|
|
254
288
|
return configFile
|
|
255
289
|
}
|
|
256
290
|
|
|
257
|
-
public static
|
|
258
|
-
const generateConfig:
|
|
259
|
-
|
|
260
|
-
root: config.root,
|
|
261
|
-
outdir: config.outdir,
|
|
262
|
-
verbose: config.verbose,
|
|
263
|
-
noNamespace: config.noNamespace,
|
|
264
|
-
noComments: config.noComments,
|
|
265
|
-
noDebugComments: config.noDebugComments,
|
|
266
|
-
fixConflicts: config.fixConflicts,
|
|
267
|
-
promisify: config.promisify,
|
|
268
|
-
npmScope: config.npmScope,
|
|
269
|
-
packageYarn: config.packageYarn,
|
|
270
|
-
noPrettyPrint: false,
|
|
271
|
-
noAdvancedVariants: true,
|
|
291
|
+
public static getOptionsGeneration(config: UserConfig): OptionsGeneration {
|
|
292
|
+
const generateConfig: OptionsGeneration = {
|
|
293
|
+
...config,
|
|
272
294
|
}
|
|
273
295
|
return generateConfig
|
|
274
296
|
}
|
|
@@ -287,21 +309,7 @@ export class Config {
|
|
|
287
309
|
const configFileData = configFile?.config || {}
|
|
288
310
|
|
|
289
311
|
const config: UserConfig = {
|
|
290
|
-
|
|
291
|
-
ignoreVersionConflicts: options.ignoreVersionConflicts,
|
|
292
|
-
print: options.print,
|
|
293
|
-
root: options.root,
|
|
294
|
-
outdir: options.outdir,
|
|
295
|
-
girDirectories: options.girDirectories,
|
|
296
|
-
ignore: options.ignore,
|
|
297
|
-
modules: options.modules,
|
|
298
|
-
noNamespace: options.noNamespace,
|
|
299
|
-
noComments: options.noComments,
|
|
300
|
-
noDebugComments: options.noDebugComments,
|
|
301
|
-
fixConflicts: options.fixConflicts,
|
|
302
|
-
promisify: options.promisify,
|
|
303
|
-
npmScope: options.npmScope,
|
|
304
|
-
packageYarn: options.packageYarn,
|
|
312
|
+
...options,
|
|
305
313
|
}
|
|
306
314
|
|
|
307
315
|
if (configFileData) {
|
|
@@ -363,20 +371,6 @@ export class Config {
|
|
|
363
371
|
) {
|
|
364
372
|
config.noComments = configFileData.noComments
|
|
365
373
|
}
|
|
366
|
-
// noDebugComments
|
|
367
|
-
if (
|
|
368
|
-
config.noDebugComments === Config.options.noDebugComments.default &&
|
|
369
|
-
typeof configFileData.noDebugComments === 'boolean'
|
|
370
|
-
) {
|
|
371
|
-
config.noDebugComments = configFileData.noDebugComments
|
|
372
|
-
}
|
|
373
|
-
// fixConflicts
|
|
374
|
-
if (
|
|
375
|
-
config.fixConflicts === Config.options.fixConflicts.default &&
|
|
376
|
-
typeof configFileData.fixConflicts === 'boolean'
|
|
377
|
-
) {
|
|
378
|
-
config.fixConflicts = configFileData.fixConflicts
|
|
379
|
-
}
|
|
380
374
|
// promisify
|
|
381
375
|
if (
|
|
382
376
|
config.promisify === Config.options.promisify.default &&
|
|
@@ -388,12 +382,37 @@ export class Config {
|
|
|
388
382
|
if (config.npmScope === Config.options.npmScope.default && configFileData.npmScope) {
|
|
389
383
|
config.npmScope = configFileData.npmScope
|
|
390
384
|
}
|
|
391
|
-
//
|
|
385
|
+
// workspace
|
|
386
|
+
if (
|
|
387
|
+
config.workspace === Config.options.workspace.default &&
|
|
388
|
+
typeof configFileData.workspace === 'boolean'
|
|
389
|
+
) {
|
|
390
|
+
config.workspace = configFileData.workspace
|
|
391
|
+
}
|
|
392
|
+
// onlyVersionPrefix
|
|
392
393
|
if (
|
|
393
|
-
config.
|
|
394
|
-
typeof configFileData.
|
|
394
|
+
config.onlyVersionPrefix === Config.options.onlyVersionPrefix.default &&
|
|
395
|
+
typeof configFileData.onlyVersionPrefix === 'boolean'
|
|
395
396
|
) {
|
|
396
|
-
config.
|
|
397
|
+
config.onlyVersionPrefix = configFileData.onlyVersionPrefix
|
|
398
|
+
}
|
|
399
|
+
// noPrettyPrint
|
|
400
|
+
if (
|
|
401
|
+
config.noPrettyPrint === Config.options.noPrettyPrint.default &&
|
|
402
|
+
typeof configFileData.noPrettyPrint === 'boolean'
|
|
403
|
+
) {
|
|
404
|
+
config.noPrettyPrint = configFileData.noPrettyPrint
|
|
405
|
+
}
|
|
406
|
+
// noAdvancedVariants
|
|
407
|
+
if (
|
|
408
|
+
config.noAdvancedVariants === Config.options.noAdvancedVariants.default &&
|
|
409
|
+
typeof configFileData.noAdvancedVariants === 'boolean'
|
|
410
|
+
) {
|
|
411
|
+
config.noAdvancedVariants = configFileData.noAdvancedVariants
|
|
412
|
+
}
|
|
413
|
+
// package
|
|
414
|
+
if (config.package === Config.options.package.default && typeof configFileData.package === 'boolean') {
|
|
415
|
+
config.package = configFileData.package
|
|
397
416
|
}
|
|
398
417
|
}
|
|
399
418
|
|
|
@@ -420,14 +439,12 @@ function getDefaultGirDirectories(): string[] {
|
|
|
420
439
|
const girDirectories = [
|
|
421
440
|
'/usr/local/share/gir-1.0',
|
|
422
441
|
'/usr/share/gir-1.0',
|
|
442
|
+
'/usr/share/*/gir-1.0',
|
|
423
443
|
'/usr/share/gnome-shell',
|
|
424
444
|
'/usr/share/gnome-shell/gir-1.0',
|
|
425
|
-
'/usr/lib64/mutter
|
|
426
|
-
'/usr/
|
|
427
|
-
'/usr/
|
|
428
|
-
'/usr/lib/x86_64-linux-gnu/mutter-10',
|
|
429
|
-
'/usr/lib/x86_64-linux-gnu/mutter-11',
|
|
430
|
-
'/usr/lib/x86_64-linux-gnu/mutter-12',
|
|
445
|
+
'/usr/lib64/mutter-*',
|
|
446
|
+
'/usr/lib/mutter-*',
|
|
447
|
+
'/usr/lib/x86_64-linux-gnu/mutter-*',
|
|
431
448
|
]
|
|
432
449
|
// NixOS and other distributions does not have a /usr/local/share directory.
|
|
433
450
|
// Instead, the nix store paths with Gir files are set as XDG_DATA_DIRS.
|
|
@@ -435,7 +452,7 @@ function getDefaultGirDirectories(): string[] {
|
|
|
435
452
|
const dataDirs = process.env['XDG_DATA_DIRS']?.split(':') || []
|
|
436
453
|
for (let dataDir of dataDirs) {
|
|
437
454
|
dataDir = join(dataDir, 'gir-1.0')
|
|
438
|
-
if (!girDirectories.includes(dataDir)) {
|
|
455
|
+
if (!girDirectories.includes(dataDir) && existsSync(dataDir)) {
|
|
439
456
|
girDirectories.push(dataDir)
|
|
440
457
|
}
|
|
441
458
|
}
|
|
@@ -10,16 +10,16 @@ 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
|
-
|
|
13
|
+
import { HtmlDocGenerator } from '@ts-for-gir/generator-html-doc'
|
|
14
14
|
|
|
15
|
-
import type {
|
|
15
|
+
import type { OptionsGeneration, NSRegistry } from '@ts-for-gir/lib'
|
|
16
16
|
|
|
17
17
|
export class GenerationHandler {
|
|
18
18
|
log: Logger
|
|
19
19
|
generator: Generator
|
|
20
20
|
|
|
21
21
|
constructor(
|
|
22
|
-
private readonly config:
|
|
22
|
+
private readonly config: OptionsGeneration,
|
|
23
23
|
type: GeneratorType,
|
|
24
24
|
) {
|
|
25
25
|
this.log = new Logger(config.verbose, 'GenerationHandler')
|
|
@@ -28,9 +28,9 @@ export class GenerationHandler {
|
|
|
28
28
|
case GeneratorType.TYPES:
|
|
29
29
|
this.generator = new TypeDefinitionGenerator(config)
|
|
30
30
|
break
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
case GeneratorType.HTML_DOC:
|
|
32
|
+
this.generator = new HtmlDocGenerator(config)
|
|
33
|
+
break
|
|
34
34
|
default:
|
|
35
35
|
throw new Error('Unknown Generator')
|
|
36
36
|
}
|
|
@@ -61,12 +61,10 @@ export class GenerationHandler {
|
|
|
61
61
|
|
|
62
62
|
for (const girModule of girModules) {
|
|
63
63
|
this.log.log(` - ${girModule.packageName} ...`)
|
|
64
|
-
girModule.start(girModules)
|
|
65
|
-
|
|
66
64
|
await this.generator.generate(registry, girModule)
|
|
67
65
|
}
|
|
68
66
|
|
|
69
|
-
await this.generator.finish(registry)
|
|
67
|
+
await this.generator.finish(registry, girModules)
|
|
70
68
|
|
|
71
69
|
this.log.success(GENERATING_TYPES_DONE)
|
|
72
70
|
}
|
package/src/module-loader.ts
CHANGED
|
@@ -3,11 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import inquirer, { ListQuestion, Answers } from 'inquirer'
|
|
6
|
-
import glob from '
|
|
7
|
-
import { basename } from 'path'
|
|
8
|
-
import { readFile } from 'fs/promises'
|
|
6
|
+
import { glob } from 'glob'
|
|
7
|
+
import { basename, join } from 'path'
|
|
9
8
|
import { bold } from 'colorette'
|
|
10
|
-
import { parser } from '@gi.ts/parser'
|
|
11
9
|
import {
|
|
12
10
|
DependencyManager,
|
|
13
11
|
ResolveType,
|
|
@@ -22,7 +20,7 @@ import { Config } from './config.js'
|
|
|
22
20
|
|
|
23
21
|
import type {
|
|
24
22
|
GirModulesGroupedMap,
|
|
25
|
-
|
|
23
|
+
OptionsGeneration,
|
|
26
24
|
GirModuleResolvedBy,
|
|
27
25
|
GirModulesGrouped,
|
|
28
26
|
DependencyMap,
|
|
@@ -35,7 +33,7 @@ export class ModuleLoader {
|
|
|
35
33
|
dependencyManager: DependencyManager
|
|
36
34
|
/** Transitive module dependencies */
|
|
37
35
|
modDependencyMap: DependencyMap = {}
|
|
38
|
-
constructor(protected readonly config:
|
|
36
|
+
constructor(protected readonly config: OptionsGeneration) {
|
|
39
37
|
this.log = new Logger(config.verbose, 'ModuleLoader')
|
|
40
38
|
this.dependencyManager = DependencyManager.getInstance(config)
|
|
41
39
|
}
|
|
@@ -176,7 +174,7 @@ export class ModuleLoader {
|
|
|
176
174
|
* @param girModulesGroupedMap
|
|
177
175
|
* @param packageName
|
|
178
176
|
*/
|
|
179
|
-
protected
|
|
177
|
+
protected findGirFilesDependOnPackage(
|
|
180
178
|
girModulesGroupedMap: GirModulesGroupedMap,
|
|
181
179
|
packageName: string,
|
|
182
180
|
): GirModuleResolvedBy[] {
|
|
@@ -201,13 +199,13 @@ export class ModuleLoader {
|
|
|
201
199
|
* @param girModulesGroupedMap
|
|
202
200
|
* @param packageName
|
|
203
201
|
*/
|
|
204
|
-
protected
|
|
202
|
+
protected findGirFilesDependOnPackages(
|
|
205
203
|
girModulesGroupedMap: GirModulesGroupedMap,
|
|
206
204
|
packageNames: string[],
|
|
207
205
|
): GirModuleResolvedBy[] {
|
|
208
206
|
let girModules: GirModuleResolvedBy[] = []
|
|
209
207
|
for (const packageName of packageNames) {
|
|
210
|
-
girModules = girModules
|
|
208
|
+
girModules = [...girModules, ...this.findGirFilesDependOnPackage(girModulesGroupedMap, packageName)]
|
|
211
209
|
}
|
|
212
210
|
return girModules
|
|
213
211
|
}
|
|
@@ -270,10 +268,7 @@ export class ModuleLoader {
|
|
|
270
268
|
while (goBack) {
|
|
271
269
|
versionAnswer = await this.askForVersionsPrompt(girModulesGrouped)
|
|
272
270
|
// Check modules that depend on the unchosen modules
|
|
273
|
-
wouldIgnoreDeps = this.
|
|
274
|
-
girModulesGroupedMap,
|
|
275
|
-
versionAnswer.unselected,
|
|
276
|
-
)
|
|
271
|
+
wouldIgnoreDeps = this.findGirFilesDependOnPackages(girModulesGroupedMap, versionAnswer.unselected)
|
|
277
272
|
// Do not check dependencies that have already been ignored
|
|
278
273
|
wouldIgnoreDeps = wouldIgnoreDeps.filter((dep) => !ignore.includes(dep.packageName))
|
|
279
274
|
ignoreDepsAnswer = await this.askIgnoreDepsPrompt(wouldIgnoreDeps)
|
|
@@ -356,7 +351,7 @@ export class ModuleLoader {
|
|
|
356
351
|
* @param girModule
|
|
357
352
|
*/
|
|
358
353
|
protected extendDependencyMapByGirModule(girModule: GirModule): void {
|
|
359
|
-
this.modDependencyMap[girModule.packageName] = girModule.dependencies
|
|
354
|
+
this.modDependencyMap[girModule.packageName] = girModule.dependencies!
|
|
360
355
|
}
|
|
361
356
|
|
|
362
357
|
/**
|
|
@@ -364,11 +359,11 @@ export class ModuleLoader {
|
|
|
364
359
|
* is required so that all dependencies can be found internally when generating the dependency imports for the module .d.ts file
|
|
365
360
|
* @param girModules
|
|
366
361
|
*/
|
|
367
|
-
protected
|
|
362
|
+
protected async initGirModules(girModules: GirModuleResolvedBy[]): Promise<void> {
|
|
368
363
|
for (const girModule of girModules) {
|
|
369
364
|
const result: { [name: string]: Dependency } = {}
|
|
370
365
|
this.traverseDependencies(girModule.packageName, result)
|
|
371
|
-
girModule.module.
|
|
366
|
+
await girModule.module.initTransitiveDependencies(Object.values(result))
|
|
372
367
|
}
|
|
373
368
|
}
|
|
374
369
|
|
|
@@ -383,10 +378,8 @@ export class ModuleLoader {
|
|
|
383
378
|
return null
|
|
384
379
|
}
|
|
385
380
|
|
|
386
|
-
this.log.log(`
|
|
387
|
-
const
|
|
388
|
-
const result = parser.parseGir(fileContents)
|
|
389
|
-
const girModule = GirModule.load(result, this.config, this.dependencyManager)
|
|
381
|
+
this.log.log(`Loading ${dependency.packageName}...`)
|
|
382
|
+
const girModule = await GirModule.load(dependency, this.config, this.dependencyManager)
|
|
390
383
|
// Figure out transitive module dependencies
|
|
391
384
|
this.extendDependencyMapByGirModule(girModule)
|
|
392
385
|
return girModule
|
|
@@ -451,6 +444,7 @@ export class ModuleLoader {
|
|
|
451
444
|
packageName: girModule.packageName,
|
|
452
445
|
module: girModule,
|
|
453
446
|
resolvedBy,
|
|
447
|
+
path: dependency.path,
|
|
454
448
|
}
|
|
455
449
|
girModules.push(addModule)
|
|
456
450
|
newModuleFound = true
|
|
@@ -466,21 +460,13 @@ export class ModuleLoader {
|
|
|
466
460
|
}
|
|
467
461
|
|
|
468
462
|
// Figure out transitive module dependencies
|
|
469
|
-
this.
|
|
463
|
+
await this.initGirModules(girModules)
|
|
470
464
|
|
|
471
465
|
// Load girModules for dependencies
|
|
472
466
|
for (const girModule of girModules) {
|
|
473
467
|
// Load dependencies
|
|
474
468
|
const transitiveDependencies = girModule.module.transitiveDependencies
|
|
475
469
|
if (transitiveDependencies.length > 0) {
|
|
476
|
-
for (const transitiveDependency of transitiveDependencies) {
|
|
477
|
-
if (ignoreDependencies.includes(transitiveDependency.packageName)) {
|
|
478
|
-
this.log.warn(
|
|
479
|
-
`Load dependency "${transitiveDependency.packageName}" which is in the ignore list, if this should really be ignored also ignore "${girModule.packageName}"`,
|
|
480
|
-
)
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
|
|
484
470
|
await this.loadGirModules(
|
|
485
471
|
transitiveDependencies,
|
|
486
472
|
ignoreDependencies,
|
|
@@ -490,6 +476,7 @@ export class ModuleLoader {
|
|
|
490
476
|
)
|
|
491
477
|
}
|
|
492
478
|
}
|
|
479
|
+
|
|
493
480
|
return {
|
|
494
481
|
loaded: girModules,
|
|
495
482
|
failed: failedGirModules,
|
|
@@ -501,60 +488,53 @@ export class ModuleLoader {
|
|
|
501
488
|
* @param modules
|
|
502
489
|
* @param ignore
|
|
503
490
|
*/
|
|
504
|
-
protected async
|
|
505
|
-
const
|
|
506
|
-
|
|
507
|
-
for (let i = 0; i < modules.length; i++) {
|
|
508
|
-
if (modules[i]) {
|
|
509
|
-
const filename = `${modules[i]}.gir`
|
|
510
|
-
let files: string[] = []
|
|
511
|
-
for (const girDirectory of this.config.girDirectories) {
|
|
512
|
-
try {
|
|
513
|
-
files = files.concat(await glob(filename, { cwd: girDirectory }))
|
|
514
|
-
} catch (error) {
|
|
515
|
-
this.log.warn(`Error on finding "${filename}" in "${girDirectory}"`, error)
|
|
516
|
-
}
|
|
517
|
-
}
|
|
491
|
+
protected async findGirFiles(globPackageNames: string[], ignore: string[] = []): Promise<Set<string>> {
|
|
492
|
+
const foundFiles = new Set<string>()
|
|
518
493
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
const isIgnored = ignore.includes(mod)
|
|
523
|
-
if (isIgnored) {
|
|
524
|
-
this.log.warn(`Ignore ${mod}`)
|
|
525
|
-
}
|
|
526
|
-
return !isIgnored
|
|
527
|
-
})
|
|
528
|
-
globModules.forEach((mod) => foundModules.add(mod))
|
|
494
|
+
for (let i = 0; i < globPackageNames.length; i++) {
|
|
495
|
+
if (!globPackageNames[i]) {
|
|
496
|
+
continue
|
|
529
497
|
}
|
|
498
|
+
const filename = `${globPackageNames[i]}.gir`
|
|
499
|
+
const pattern = this.config.girDirectories.map((girDirectory) => join(girDirectory, filename))
|
|
500
|
+
const ignoreGirs = ignore.map((girDirectory) => girDirectory + '.gir')
|
|
501
|
+
const files = await glob(pattern, { ignore: ignoreGirs })
|
|
502
|
+
files.forEach((file) => foundFiles.add(file))
|
|
530
503
|
}
|
|
531
|
-
|
|
504
|
+
|
|
505
|
+
return foundFiles
|
|
532
506
|
}
|
|
533
507
|
|
|
534
|
-
protected
|
|
535
|
-
|
|
508
|
+
protected async girFilePathToDependencies(girFiles: Set<string>): Promise<Dependency[]> {
|
|
509
|
+
const dependencies: Dependency[] = []
|
|
510
|
+
for (const girFile of girFiles) {
|
|
511
|
+
const packageName = basename(girFile, '.gir')
|
|
536
512
|
const { namespace, version } = splitModuleName(packageName)
|
|
537
|
-
|
|
538
|
-
|
|
513
|
+
const dep = await this.dependencyManager.get(namespace, version)
|
|
514
|
+
dependencies.push(dep)
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
return dependencies
|
|
539
518
|
}
|
|
540
519
|
|
|
541
520
|
/**
|
|
542
|
-
* Loads all found `packageNames`
|
|
521
|
+
* Loads all found `packageNames`
|
|
543
522
|
* @param girDirectories
|
|
544
523
|
* @param packageNames
|
|
524
|
+
* @param doNotAskForVersionOnConflict Set this to false if you want to get a prompt for each version conflict
|
|
545
525
|
*/
|
|
546
526
|
public async getModulesResolved(
|
|
547
527
|
packageNames: string[],
|
|
548
528
|
ignore: string[] = [],
|
|
549
529
|
doNotAskForVersionOnConflict = true,
|
|
550
530
|
): Promise<{ keep: GirModuleResolvedBy[]; grouped: GirModulesGroupedMap; ignore: string[]; failed: Set<string> }> {
|
|
551
|
-
const
|
|
531
|
+
const girFiles = await this.findGirFiles([...packageNames], ignore)
|
|
552
532
|
// 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')
|
|
533
|
+
const GLib = await this.dependencyManager.get('GLib', '2.0')
|
|
534
|
+
const Gio = await this.dependencyManager.get('Gio', '2.0')
|
|
535
|
+
const GObject = await this.dependencyManager.get('GObject', '2.0')
|
|
556
536
|
|
|
557
|
-
const dependencies = this.
|
|
537
|
+
const dependencies = await this.girFilePathToDependencies(girFiles)
|
|
558
538
|
|
|
559
539
|
const { loaded, failed } = await this.loadGirModules(
|
|
560
540
|
[
|
|
@@ -582,7 +562,7 @@ export class ModuleLoader {
|
|
|
582
562
|
}
|
|
583
563
|
|
|
584
564
|
/**
|
|
585
|
-
* Find modules
|
|
565
|
+
* Find modules
|
|
586
566
|
* @param girDirectories
|
|
587
567
|
* @param modules
|
|
588
568
|
*/
|
|
@@ -590,10 +570,17 @@ export class ModuleLoader {
|
|
|
590
570
|
modules: string[],
|
|
591
571
|
ignore: string[] = [],
|
|
592
572
|
): Promise<{ grouped: GirModulesGroupedMap; loaded: GirModuleResolvedBy[]; failed: string[] }> {
|
|
593
|
-
const
|
|
594
|
-
const dependencies = this.
|
|
573
|
+
const girFiles = await this.findGirFiles(modules, ignore)
|
|
574
|
+
const dependencies = await this.girFilePathToDependencies(girFiles)
|
|
595
575
|
const { loaded, failed } = await this.loadGirModules(dependencies, ignore)
|
|
596
576
|
const grouped = this.groupGirFiles(loaded)
|
|
597
577
|
return { grouped, loaded, failed: Array.from(failed) }
|
|
598
578
|
}
|
|
579
|
+
|
|
580
|
+
/** Start parsing the gir modules */
|
|
581
|
+
public parse(girModules: GirModuleResolvedBy[]): void {
|
|
582
|
+
for (const girModule of girModules) {
|
|
583
|
+
girModule.module.parse()
|
|
584
|
+
}
|
|
585
|
+
}
|
|
599
586
|
}
|
package/src/start.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import yargs from 'yargs'
|
|
3
3
|
import { hideBin } from 'yargs/helpers'
|
|
4
4
|
|
|
5
|
-
import { generate, list, doc } from './commands/index.js'
|
|
5
|
+
import { generate, list, doc, copy } from './commands/index.js'
|
|
6
6
|
import { Config } from './config.js'
|
|
7
7
|
|
|
8
8
|
void yargs(hideBin(process.argv))
|
|
@@ -11,6 +11,7 @@ void yargs(hideBin(process.argv))
|
|
|
11
11
|
.usage(Config.usage)
|
|
12
12
|
.command(generate.command, generate.description, generate.builder, generate.handler)
|
|
13
13
|
.command(list.command, list.description, list.builder, list.handler)
|
|
14
|
+
.command(copy.command, copy.description, copy.builder, copy.handler)
|
|
14
15
|
.command(doc.command, doc.description, doc.builder, doc.handler)
|
|
15
16
|
.demandCommand(1)
|
|
16
17
|
.help().argv
|