@ts-for-gir/cli 4.0.0-beta.4 → 4.0.0-beta.40
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 +185 -174
- package/bin/ts-for-gir +20593 -0
- package/bin/ts-for-gir-dev +43 -0
- package/package.json +37 -38
- package/src/commands/analyze.ts +344 -0
- package/src/commands/command-builder.ts +30 -0
- package/src/commands/copy.ts +71 -76
- package/src/commands/doc.ts +58 -46
- package/src/commands/generate.ts +97 -78
- package/src/commands/index.ts +6 -4
- package/src/commands/json.ts +104 -0
- package/src/commands/list.ts +71 -90
- package/src/config/config-loader.ts +203 -0
- package/src/config/config-writer.ts +52 -0
- package/src/config/defaults.ts +61 -0
- package/src/config/index.ts +8 -0
- package/src/config/options.ts +292 -0
- package/src/config.ts +3 -450
- package/src/formatters/typescript-formatter.ts +24 -0
- package/src/generation-handler.ts +122 -67
- package/src/index.ts +4 -4
- package/src/module-loader/dependency-resolver.ts +100 -0
- package/src/module-loader/file-finder.ts +65 -0
- package/src/module-loader/index.ts +8 -0
- package/src/module-loader/module-grouper.ts +77 -0
- package/src/module-loader/prompt-handler.ts +111 -0
- package/src/module-loader.ts +289 -578
- package/src/start.ts +17 -14
- package/src/types/command-args.ts +110 -0
- package/src/types/command-definition.ts +17 -0
- package/src/types/commands.ts +30 -0
- package/src/types/index.ts +15 -0
- package/src/types/report-types.ts +34 -0
- package/lib/commands/copy.d.ts +0 -12
- package/lib/commands/copy.js +0 -80
- package/lib/commands/copy.js.map +0 -1
- package/lib/commands/doc.d.ts +0 -12
- package/lib/commands/doc.js +0 -40
- package/lib/commands/doc.js.map +0 -1
- package/lib/commands/generate.d.ts +0 -12
- package/lib/commands/generate.js +0 -73
- package/lib/commands/generate.js.map +0 -1
- package/lib/commands/index.d.ts +0 -4
- package/lib/commands/index.js +0 -5
- package/lib/commands/index.js.map +0 -1
- package/lib/commands/list.d.ts +0 -12
- package/lib/commands/list.js +0 -81
- package/lib/commands/list.js.map +0 -1
- package/lib/config.d.ts +0 -104
- package/lib/config.js +0 -408
- package/lib/config.js.map +0 -1
- package/lib/generation-handler.d.ts +0 -10
- package/lib/generation-handler.js +0 -47
- package/lib/generation-handler.js.map +0 -1
- package/lib/index.d.ts +0 -4
- package/lib/index.js +0 -5
- package/lib/index.js.map +0 -1
- package/lib/module-loader.d.ts +0 -148
- package/lib/module-loader.js +0 -468
- package/lib/module-loader.js.map +0 -1
- package/lib/start.d.ts +0 -2
- package/lib/start.js +0 -16
- package/lib/start.js.map +0 -1
package/src/config.ts
CHANGED
|
@@ -1,454 +1,7 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
2
1
|
/**
|
|
3
2
|
* Default values, parse the config file and handle CLI flags
|
|
3
|
+
*
|
|
4
|
+
* This file re-exports all config functionality from the config module
|
|
4
5
|
*/
|
|
5
|
-
import { Options } from 'yargs'
|
|
6
|
-
import { cosmiconfig, Options as ConfigSearchOptions } from 'cosmiconfig'
|
|
7
|
-
import { join, extname, dirname, resolve } from 'path'
|
|
8
|
-
import { writeFile } from 'fs/promises'
|
|
9
|
-
import { existsSync } from 'fs'
|
|
10
|
-
import { merge, isEqual, Logger, APP_NAME, APP_USAGE, ERROR_CONFIG_EXTENSION_UNSUPPORTED } from '@ts-for-gir/lib'
|
|
11
6
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export class Config {
|
|
15
|
-
static appName = APP_NAME
|
|
16
|
-
|
|
17
|
-
static usage = APP_USAGE
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Default cli flag and argument values
|
|
21
|
-
*/
|
|
22
|
-
static defaults = {
|
|
23
|
-
print: false,
|
|
24
|
-
configName: '.ts-for-girrc.js',
|
|
25
|
-
root: process.cwd(),
|
|
26
|
-
outdir: './@types',
|
|
27
|
-
girDirectories: getDefaultGirDirectories(),
|
|
28
|
-
modules: ['*'],
|
|
29
|
-
ignore: [],
|
|
30
|
-
verbose: false,
|
|
31
|
-
ignoreVersionConflicts: false,
|
|
32
|
-
noNamespace: false,
|
|
33
|
-
noComments: false,
|
|
34
|
-
noDebugComments: false,
|
|
35
|
-
fixConflicts: true,
|
|
36
|
-
promisify: true,
|
|
37
|
-
npmScope: '@girs',
|
|
38
|
-
packageYarn: false,
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
static configFilePath = join(process.cwd(), Config.defaults.configName)
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* CLI options used in commands/generate.ts and commands/list.ts
|
|
45
|
-
*/
|
|
46
|
-
static options: { [name: string]: Options } = {
|
|
47
|
-
modules: {
|
|
48
|
-
description: "GIR modules to load, e.g. 'Gio-2.0'. Accepts multiple modules",
|
|
49
|
-
array: true,
|
|
50
|
-
default: Config.defaults.modules,
|
|
51
|
-
normalize: true,
|
|
52
|
-
},
|
|
53
|
-
girDirectories: {
|
|
54
|
-
type: 'string',
|
|
55
|
-
alias: 'g',
|
|
56
|
-
description: 'GIR directories',
|
|
57
|
-
array: true,
|
|
58
|
-
default: Config.defaults.girDirectories,
|
|
59
|
-
normalize: true,
|
|
60
|
-
},
|
|
61
|
-
root: {
|
|
62
|
-
type: 'string',
|
|
63
|
-
description: 'Root directory of your project',
|
|
64
|
-
default: Config.defaults.root,
|
|
65
|
-
normalize: true,
|
|
66
|
-
},
|
|
67
|
-
outdir: {
|
|
68
|
-
type: 'string',
|
|
69
|
-
alias: 'o',
|
|
70
|
-
description: 'Directory to output to',
|
|
71
|
-
default: Config.defaults.outdir,
|
|
72
|
-
normalize: true,
|
|
73
|
-
},
|
|
74
|
-
ignore: {
|
|
75
|
-
type: 'string',
|
|
76
|
-
alias: 'i',
|
|
77
|
-
description: 'Modules that should be ignored',
|
|
78
|
-
array: true,
|
|
79
|
-
default: Config.defaults.ignore,
|
|
80
|
-
normalize: true,
|
|
81
|
-
},
|
|
82
|
-
verbose: {
|
|
83
|
-
type: 'boolean',
|
|
84
|
-
alias: 'v',
|
|
85
|
-
description: 'Switch on/off the verbose mode',
|
|
86
|
-
default: Config.defaults.verbose,
|
|
87
|
-
normalize: true,
|
|
88
|
-
},
|
|
89
|
-
ignoreVersionConflicts: {
|
|
90
|
-
type: 'boolean',
|
|
91
|
-
description: 'Do not ask for package versions if multiple versions are found',
|
|
92
|
-
default: Config.defaults.ignoreVersionConflicts,
|
|
93
|
-
normalize: true,
|
|
94
|
-
},
|
|
95
|
-
print: {
|
|
96
|
-
type: 'boolean',
|
|
97
|
-
alias: 'p',
|
|
98
|
-
description: 'Print the output to console and create no files',
|
|
99
|
-
default: Config.defaults.print,
|
|
100
|
-
normalize: true,
|
|
101
|
-
},
|
|
102
|
-
configName: {
|
|
103
|
-
type: 'string',
|
|
104
|
-
description: 'Name of the config if you want to use a different name',
|
|
105
|
-
default: Config.defaults.configName,
|
|
106
|
-
normalize: true,
|
|
107
|
-
},
|
|
108
|
-
noNamespace: {
|
|
109
|
-
type: 'boolean',
|
|
110
|
-
alias: 'd',
|
|
111
|
-
description: 'Do not export all symbols for each module as a namespace',
|
|
112
|
-
default: Config.defaults.noNamespace,
|
|
113
|
-
normalize: true,
|
|
114
|
-
},
|
|
115
|
-
noComments: {
|
|
116
|
-
type: 'boolean',
|
|
117
|
-
alias: 'n',
|
|
118
|
-
description: 'Do not generate documentation comments',
|
|
119
|
-
default: Config.defaults.noComments,
|
|
120
|
-
normalize: true,
|
|
121
|
-
},
|
|
122
|
-
noDebugComments: {
|
|
123
|
-
type: 'boolean',
|
|
124
|
-
description: 'Do not generate debugging inline comments',
|
|
125
|
-
default: Config.defaults.noDebugComments,
|
|
126
|
-
normalize: true,
|
|
127
|
-
},
|
|
128
|
-
fixConflicts: {
|
|
129
|
-
type: 'boolean',
|
|
130
|
-
description: 'Fix Inheritance and implementation type conflicts',
|
|
131
|
-
default: Config.defaults.fixConflicts,
|
|
132
|
-
normalize: true,
|
|
133
|
-
},
|
|
134
|
-
promisify: {
|
|
135
|
-
type: 'boolean',
|
|
136
|
-
description: 'Generate promisified functions for async/finish calls',
|
|
137
|
-
default: Config.defaults.promisify,
|
|
138
|
-
normalize: true,
|
|
139
|
-
},
|
|
140
|
-
npmScope: {
|
|
141
|
-
type: 'string',
|
|
142
|
-
description: 'Scope of the generated NPM packages',
|
|
143
|
-
default: Config.defaults.npmScope,
|
|
144
|
-
normalize: true,
|
|
145
|
-
},
|
|
146
|
-
packageYarn: {
|
|
147
|
-
type: 'boolean',
|
|
148
|
-
description: 'Adds Yarn workspace support to the NPM packages',
|
|
149
|
-
default: Config.defaults.packageYarn,
|
|
150
|
-
normalize: true,
|
|
151
|
-
},
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* CLI flags used in commands/generate.ts
|
|
156
|
-
*/
|
|
157
|
-
static generateOptions = {
|
|
158
|
-
modules: this.options.modules,
|
|
159
|
-
girDirectories: this.options.girDirectories,
|
|
160
|
-
root: this.options.root,
|
|
161
|
-
outdir: this.options.outdir,
|
|
162
|
-
ignore: this.options.ignore,
|
|
163
|
-
verbose: this.options.verbose,
|
|
164
|
-
ignoreVersionConflicts: this.options.ignoreVersionConflicts,
|
|
165
|
-
print: this.options.print,
|
|
166
|
-
configName: this.options.configName,
|
|
167
|
-
noNamespace: this.options.noNamespace,
|
|
168
|
-
noComments: this.options.noComments,
|
|
169
|
-
noDebugComments: this.options.noDebugComments,
|
|
170
|
-
fixConflicts: this.options.fixConflicts,
|
|
171
|
-
promisify: this.options.promisify,
|
|
172
|
-
npmScope: this.options.npmScope,
|
|
173
|
-
packageYarn: this.options.packageYarn,
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
static listOptions = {
|
|
177
|
-
modules: this.options.modules,
|
|
178
|
-
girDirectories: Config.options.girDirectories,
|
|
179
|
-
root: this.options.root,
|
|
180
|
-
ignore: Config.options.ignore,
|
|
181
|
-
configName: Config.options.configName,
|
|
182
|
-
verbose: Config.options.verbose,
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
static copyOptions = {
|
|
186
|
-
modules: this.options.modules,
|
|
187
|
-
girDirectories: Config.options.girDirectories,
|
|
188
|
-
root: this.options.root,
|
|
189
|
-
outdir: Config.options.outdir,
|
|
190
|
-
ignore: Config.options.ignore,
|
|
191
|
-
configName: Config.options.configName,
|
|
192
|
-
verbose: Config.options.verbose,
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
static docOptions = {
|
|
196
|
-
modules: this.options.modules,
|
|
197
|
-
girDirectories: Config.options.girDirectories,
|
|
198
|
-
root: this.options.root,
|
|
199
|
-
outdir: Config.options.outdir,
|
|
200
|
-
ignore: Config.options.ignore,
|
|
201
|
-
verbose: Config.options.verbose,
|
|
202
|
-
ignoreVersionConflicts: Config.options.ignoreVersionConflicts,
|
|
203
|
-
configName: Config.options.configName,
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Overwrites values in the user config file
|
|
208
|
-
* @param configsToAdd
|
|
209
|
-
*/
|
|
210
|
-
public static async addToConfig(configsToAdd: Partial<UserConfig>, configName?: string): Promise<void> {
|
|
211
|
-
const userConfig = await this.loadConfigFile(configName)
|
|
212
|
-
const path = userConfig?.filepath || this.configFilePath
|
|
213
|
-
const configToStore = {}
|
|
214
|
-
merge(configToStore, userConfig?.config || {}, configsToAdd)
|
|
215
|
-
const fileExtension = extname(path)
|
|
216
|
-
let writeConfigString = ''
|
|
217
|
-
switch (fileExtension) {
|
|
218
|
-
case '.js':
|
|
219
|
-
writeConfigString = `export default ${JSON.stringify(configToStore, null, 4)}`
|
|
220
|
-
break
|
|
221
|
-
case '.json':
|
|
222
|
-
writeConfigString = `${JSON.stringify(configToStore, null, 4)}`
|
|
223
|
-
break
|
|
224
|
-
default:
|
|
225
|
-
Logger.error(ERROR_CONFIG_EXTENSION_UNSUPPORTED)
|
|
226
|
-
break
|
|
227
|
-
}
|
|
228
|
-
if (writeConfigString && path) {
|
|
229
|
-
return writeFile(path, writeConfigString)
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* The user can create a `.ts-for-girrc` file for his default configs,
|
|
235
|
-
* this method load this config file an returns the user configuration
|
|
236
|
-
* @param configName If the user uses a custom config file name
|
|
237
|
-
*/
|
|
238
|
-
private static async loadConfigFile(configName?: string): Promise<UserConfigLoadResult | null> {
|
|
239
|
-
const configSearchOptions: Partial<ConfigSearchOptions> = {
|
|
240
|
-
loaders: {
|
|
241
|
-
// ESM loader
|
|
242
|
-
'.js': async (filepath) => {
|
|
243
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
244
|
-
const file = await import(filepath)
|
|
245
|
-
|
|
246
|
-
// Files with `exports.default = { ... }`
|
|
247
|
-
if (file?.default?.default) {
|
|
248
|
-
return file.default.default as Partial<UserConfig>
|
|
249
|
-
}
|
|
250
|
-
// Files with `export default { ... }`
|
|
251
|
-
if (file?.default) {
|
|
252
|
-
return file.default as Partial<UserConfig>
|
|
253
|
-
}
|
|
254
|
-
// Files with `export { ... }`
|
|
255
|
-
return file as Partial<UserConfig>
|
|
256
|
-
},
|
|
257
|
-
},
|
|
258
|
-
}
|
|
259
|
-
if (configName) {
|
|
260
|
-
configSearchOptions.searchPlaces = [configName]
|
|
261
|
-
}
|
|
262
|
-
const configFile: UserConfigLoadResult | null = await cosmiconfig(Config.appName, configSearchOptions).search()
|
|
263
|
-
if (configFile?.filepath) {
|
|
264
|
-
Config.configFilePath = configFile.filepath
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
return configFile
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
public static getOptionsGeneration(config: UserConfig): OptionsGeneration {
|
|
271
|
-
const generateConfig: OptionsGeneration = {
|
|
272
|
-
girDirectories: config.girDirectories,
|
|
273
|
-
root: config.root,
|
|
274
|
-
outdir: config.outdir,
|
|
275
|
-
verbose: config.verbose,
|
|
276
|
-
noNamespace: config.noNamespace,
|
|
277
|
-
noComments: config.noComments,
|
|
278
|
-
noDebugComments: config.noDebugComments,
|
|
279
|
-
fixConflicts: config.fixConflicts,
|
|
280
|
-
promisify: config.promisify,
|
|
281
|
-
npmScope: config.npmScope,
|
|
282
|
-
packageYarn: config.packageYarn,
|
|
283
|
-
noPrettyPrint: false,
|
|
284
|
-
noAdvancedVariants: true,
|
|
285
|
-
}
|
|
286
|
-
return generateConfig
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
public static validate(config: UserConfig): UserConfig {
|
|
290
|
-
return config
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Loads the values of the config file and concatenate them with passed cli flags / arguments.
|
|
295
|
-
* The values from config file are preferred if the cli flag value is the default (and so not set / overwritten)
|
|
296
|
-
* @param options
|
|
297
|
-
*/
|
|
298
|
-
public static async load(options: ConfigFlags): Promise<UserConfig> {
|
|
299
|
-
const configFile = await this.loadConfigFile(options.configName)
|
|
300
|
-
const configFileData = configFile?.config || {}
|
|
301
|
-
|
|
302
|
-
const config: UserConfig = {
|
|
303
|
-
verbose: options.verbose,
|
|
304
|
-
ignoreVersionConflicts: options.ignoreVersionConflicts,
|
|
305
|
-
print: options.print,
|
|
306
|
-
root: options.root,
|
|
307
|
-
outdir: options.outdir,
|
|
308
|
-
girDirectories: options.girDirectories,
|
|
309
|
-
ignore: options.ignore,
|
|
310
|
-
modules: options.modules,
|
|
311
|
-
noNamespace: options.noNamespace,
|
|
312
|
-
noComments: options.noComments,
|
|
313
|
-
noDebugComments: options.noDebugComments,
|
|
314
|
-
fixConflicts: options.fixConflicts,
|
|
315
|
-
promisify: options.promisify,
|
|
316
|
-
npmScope: options.npmScope,
|
|
317
|
-
packageYarn: options.packageYarn,
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
if (configFileData) {
|
|
321
|
-
// verbose
|
|
322
|
-
if (config.verbose === Config.options.verbose.default && typeof configFileData.verbose === 'boolean') {
|
|
323
|
-
config.verbose = configFileData.verbose
|
|
324
|
-
}
|
|
325
|
-
// ignoreVersionConflicts
|
|
326
|
-
if (
|
|
327
|
-
config.ignoreVersionConflicts === Config.options.ignoreVersionConflicts.default &&
|
|
328
|
-
typeof configFileData.ignoreVersionConflicts === 'boolean'
|
|
329
|
-
) {
|
|
330
|
-
config.ignoreVersionConflicts = configFileData.ignoreVersionConflicts
|
|
331
|
-
}
|
|
332
|
-
// print
|
|
333
|
-
if (config.print === Config.options.print.default && typeof configFileData.print === 'boolean') {
|
|
334
|
-
config.print = configFileData.print
|
|
335
|
-
}
|
|
336
|
-
// root
|
|
337
|
-
if (config.root === Config.options.root.default && (configFileData.root || configFile?.filepath)) {
|
|
338
|
-
// Use the config file path as the root path if no root path is set
|
|
339
|
-
config.root =
|
|
340
|
-
configFileData.root ||
|
|
341
|
-
(configFile?.filepath ? dirname(configFile.filepath) : (Config.options.root.default as string))
|
|
342
|
-
}
|
|
343
|
-
// outdir
|
|
344
|
-
if (config.outdir === Config.options.outdir.default && configFileData.outdir) {
|
|
345
|
-
config.outdir = config.print ? null : configFileData.outdir
|
|
346
|
-
}
|
|
347
|
-
// girDirectories
|
|
348
|
-
if (config.girDirectories === Config.options.girDirectories.default && configFileData.girDirectories) {
|
|
349
|
-
config.girDirectories = configFileData.girDirectories
|
|
350
|
-
}
|
|
351
|
-
// ignore
|
|
352
|
-
if (
|
|
353
|
-
(!config.ignore || config.ignore.length <= 0 || isEqual(config.ignore, Config.defaults.ignore)) &&
|
|
354
|
-
configFileData.ignore
|
|
355
|
-
) {
|
|
356
|
-
config.ignore = configFileData.ignore
|
|
357
|
-
}
|
|
358
|
-
// modules
|
|
359
|
-
if (
|
|
360
|
-
(config.modules.length <= 0 || isEqual(config.modules, Config.defaults.modules)) &&
|
|
361
|
-
configFileData.modules
|
|
362
|
-
) {
|
|
363
|
-
config.modules = configFileData.modules
|
|
364
|
-
}
|
|
365
|
-
// noNamespace
|
|
366
|
-
if (
|
|
367
|
-
config.noNamespace === Config.options.noNamespace.default &&
|
|
368
|
-
typeof configFileData.noNamespace === 'boolean'
|
|
369
|
-
) {
|
|
370
|
-
config.noNamespace = configFileData.noNamespace
|
|
371
|
-
}
|
|
372
|
-
// noComments
|
|
373
|
-
if (
|
|
374
|
-
config.noComments === Config.options.noComments.default &&
|
|
375
|
-
typeof configFileData.noComments === 'boolean'
|
|
376
|
-
) {
|
|
377
|
-
config.noComments = configFileData.noComments
|
|
378
|
-
}
|
|
379
|
-
// noDebugComments
|
|
380
|
-
if (
|
|
381
|
-
config.noDebugComments === Config.options.noDebugComments.default &&
|
|
382
|
-
typeof configFileData.noDebugComments === 'boolean'
|
|
383
|
-
) {
|
|
384
|
-
config.noDebugComments = configFileData.noDebugComments
|
|
385
|
-
}
|
|
386
|
-
// fixConflicts
|
|
387
|
-
if (
|
|
388
|
-
config.fixConflicts === Config.options.fixConflicts.default &&
|
|
389
|
-
typeof configFileData.fixConflicts === 'boolean'
|
|
390
|
-
) {
|
|
391
|
-
config.fixConflicts = configFileData.fixConflicts
|
|
392
|
-
}
|
|
393
|
-
// promisify
|
|
394
|
-
if (
|
|
395
|
-
config.promisify === Config.options.promisify.default &&
|
|
396
|
-
typeof configFileData.promisify === 'boolean'
|
|
397
|
-
) {
|
|
398
|
-
config.promisify = configFileData.promisify
|
|
399
|
-
}
|
|
400
|
-
// npmScope
|
|
401
|
-
if (config.npmScope === Config.options.npmScope.default && configFileData.npmScope) {
|
|
402
|
-
config.npmScope = configFileData.npmScope
|
|
403
|
-
}
|
|
404
|
-
// packageYarn
|
|
405
|
-
if (
|
|
406
|
-
config.packageYarn === Config.options.packageYarn.default &&
|
|
407
|
-
typeof configFileData.packageYarn === 'boolean'
|
|
408
|
-
) {
|
|
409
|
-
config.packageYarn = configFileData.packageYarn
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
// If outdir is not absolute, make it absolute to the root path
|
|
414
|
-
if (config.outdir && !config.outdir?.startsWith('/')) {
|
|
415
|
-
config.outdir = resolve(config.root, config.outdir)
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
// Same for girDirectories
|
|
419
|
-
if (config.girDirectories) {
|
|
420
|
-
config.girDirectories = config.girDirectories.map((dir) => {
|
|
421
|
-
if (!dir.startsWith('/')) {
|
|
422
|
-
return resolve(config.root, dir)
|
|
423
|
-
}
|
|
424
|
-
return dir
|
|
425
|
-
})
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
return this.validate(config)
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
function getDefaultGirDirectories(): string[] {
|
|
433
|
-
const girDirectories = [
|
|
434
|
-
'/usr/local/share/gir-1.0',
|
|
435
|
-
'/usr/share/gir-1.0',
|
|
436
|
-
'/usr/share/*/gir-1.0',
|
|
437
|
-
'/usr/share/gnome-shell',
|
|
438
|
-
'/usr/share/gnome-shell/gir-1.0',
|
|
439
|
-
'/usr/lib64/mutter-*',
|
|
440
|
-
'/usr/lib/mutter-*',
|
|
441
|
-
'/usr/lib/x86_64-linux-gnu/mutter-*',
|
|
442
|
-
]
|
|
443
|
-
// NixOS and other distributions does not have a /usr/local/share directory.
|
|
444
|
-
// Instead, the nix store paths with Gir files are set as XDG_DATA_DIRS.
|
|
445
|
-
// See https://github.com/NixOS/nixpkgs/blob/96e18717904dfedcd884541e5a92bf9ff632cf39/pkgs/development/libraries/gobject-introspection/setup-hook.sh#L7-L10
|
|
446
|
-
const dataDirs = process.env['XDG_DATA_DIRS']?.split(':') || []
|
|
447
|
-
for (let dataDir of dataDirs) {
|
|
448
|
-
dataDir = join(dataDir, 'gir-1.0')
|
|
449
|
-
if (!girDirectories.includes(dataDir) && existsSync(dataDir)) {
|
|
450
|
-
girDirectories.push(dataDir)
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
return girDirectories
|
|
454
|
-
}
|
|
7
|
+
export * from "./config/index.ts";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript formatter using Prettier
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Formatter, Logger } from "@ts-for-gir/lib";
|
|
6
|
+
import prettier from "prettier";
|
|
7
|
+
|
|
8
|
+
const logger = new Logger(false, "TypeScriptFormatter");
|
|
9
|
+
|
|
10
|
+
export class TypeScriptFormatter extends Formatter {
|
|
11
|
+
format(input: string): Promise<string> {
|
|
12
|
+
try {
|
|
13
|
+
return prettier.format(input, {
|
|
14
|
+
singleQuote: true,
|
|
15
|
+
parser: "typescript",
|
|
16
|
+
printWidth: 120,
|
|
17
|
+
tabWidth: 4,
|
|
18
|
+
});
|
|
19
|
+
} catch (error) {
|
|
20
|
+
logger.warn("Failed to format with prettier, returning original input", error);
|
|
21
|
+
return Promise.resolve(input);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,71 +1,126 @@
|
|
|
1
|
-
import { mkdir } from
|
|
1
|
+
import { mkdir } from "node:fs/promises";
|
|
2
|
+
import { type Generator, GeneratorType } from "@ts-for-gir/generator-base";
|
|
3
|
+
import { HtmlDocGenerator } from "@ts-for-gir/generator-html-doc";
|
|
4
|
+
import { JsonDefinitionGenerator } from "@ts-for-gir/generator-json";
|
|
5
|
+
import { TypeDefinitionGenerator } from "@ts-for-gir/generator-typescript";
|
|
2
6
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
configureConflictsReporter,
|
|
8
|
+
ERROR_NO_MODULE_SPECIFIED,
|
|
9
|
+
FILE_PARSING_DONE,
|
|
10
|
+
GENERATING_TYPES_DONE,
|
|
11
|
+
type GirModule,
|
|
12
|
+
type NSRegistry,
|
|
13
|
+
type OptionsGeneration,
|
|
14
|
+
Reporter,
|
|
15
|
+
ReporterService,
|
|
16
|
+
START_MODULE,
|
|
17
|
+
TSDATA_PARSING_DONE,
|
|
18
|
+
TypeIdentifier,
|
|
19
|
+
} from "@ts-for-gir/lib";
|
|
16
20
|
|
|
17
21
|
export class GenerationHandler {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
22
|
+
log: Reporter;
|
|
23
|
+
generator: Generator;
|
|
24
|
+
protected readonly config: OptionsGeneration;
|
|
25
|
+
protected readonly registry: NSRegistry;
|
|
26
|
+
private readonly reporterService: ReporterService;
|
|
27
|
+
|
|
28
|
+
constructor(config: OptionsGeneration, type: GeneratorType, registry: NSRegistry) {
|
|
29
|
+
this.registry = registry;
|
|
30
|
+
this.config = config;
|
|
31
|
+
this.log = new Reporter(config.verbose, "GenerationHandler", config.reporter, config.reporterOutput);
|
|
32
|
+
this.reporterService = ReporterService.getInstance();
|
|
33
|
+
|
|
34
|
+
// Configure the reporter service
|
|
35
|
+
this.reporterService.configure(config.reporter, config.reporterOutput);
|
|
36
|
+
|
|
37
|
+
// Configure TypeIdentifier and ConflictsReporter globally
|
|
38
|
+
TypeIdentifier.configureReporter(config.reporter, config.reporterOutput);
|
|
39
|
+
configureConflictsReporter(config.reporter, config.reporterOutput);
|
|
40
|
+
|
|
41
|
+
// Register the main handler reporter
|
|
42
|
+
if (config.reporter) {
|
|
43
|
+
this.reporterService.registerReporter("GenerationHandler", this.log);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
switch (type) {
|
|
47
|
+
case GeneratorType.TYPES:
|
|
48
|
+
this.generator = new TypeDefinitionGenerator(config, this.registry);
|
|
49
|
+
break;
|
|
50
|
+
case GeneratorType.HTML_DOC:
|
|
51
|
+
this.generator = new HtmlDocGenerator(config, this.registry);
|
|
52
|
+
break;
|
|
53
|
+
case GeneratorType.JSON:
|
|
54
|
+
this.generator = new JsonDefinitionGenerator(config, this.registry);
|
|
55
|
+
break;
|
|
56
|
+
default:
|
|
57
|
+
throw new Error("Unknown Generator");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public async start(girModules: GirModule[]): Promise<void> {
|
|
62
|
+
this.log.info(START_MODULE);
|
|
63
|
+
|
|
64
|
+
if (girModules.length === 0) {
|
|
65
|
+
this.log.error(ERROR_NO_MODULE_SPECIFIED);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
this.log.info(FILE_PARSING_DONE);
|
|
69
|
+
|
|
70
|
+
this.log.info(TSDATA_PARSING_DONE);
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
if (this.config.outdir) {
|
|
74
|
+
await mkdir(this.config.outdir, { recursive: true });
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// TODO: Put this somewhere that makes sense
|
|
78
|
+
this.registry.transform({
|
|
79
|
+
inferGenerics: true,
|
|
80
|
+
verbose: this.config.verbose,
|
|
81
|
+
reporter: this.config.reporter,
|
|
82
|
+
reporterOutput: this.config.reporterOutput,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
await this.generator.start();
|
|
86
|
+
|
|
87
|
+
for (const girModule of girModules) {
|
|
88
|
+
this.log.log(` - ${girModule.packageName} ...`);
|
|
89
|
+
await this.generator.generate(girModule);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
await this.generator.finish(girModules);
|
|
93
|
+
|
|
94
|
+
this.log.success(GENERATING_TYPES_DONE);
|
|
95
|
+
} finally {
|
|
96
|
+
// Generate comprehensive report if reporter is enabled
|
|
97
|
+
// This will run even if there's an error
|
|
98
|
+
if (this.config.reporter) {
|
|
99
|
+
await this.generateComprehensiveReport();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private async generateComprehensiveReport(): Promise<void> {
|
|
105
|
+
try {
|
|
106
|
+
// Print comprehensive summary to console
|
|
107
|
+
this.reporterService.printComprehensiveSummary();
|
|
108
|
+
|
|
109
|
+
// Save comprehensive report to file
|
|
110
|
+
await this.reporterService.saveComprehensiveReport();
|
|
111
|
+
|
|
112
|
+
// Log final statistics
|
|
113
|
+
const report = this.reporterService.generateComprehensiveReport();
|
|
114
|
+
const totalProblems = report.statistics.totalProblems;
|
|
115
|
+
const modulesProcessed = this.reporterService.getReporters().size;
|
|
116
|
+
|
|
117
|
+
if (totalProblems > 0) {
|
|
118
|
+
this.log.info(`📊 Generated comprehensive report: ${totalProblems} issues across ${modulesProcessed} modules`);
|
|
119
|
+
} else {
|
|
120
|
+
this.log.success("🎉 Generation completed without any reported issues across all modules!");
|
|
121
|
+
}
|
|
122
|
+
} catch (error) {
|
|
123
|
+
this.log.danger(`Failed to generate comprehensive report: ${error}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
71
126
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from "./commands/index.ts";
|
|
2
|
+
export * from "./config.ts";
|
|
3
|
+
export * from "./generation-handler.ts";
|
|
4
|
+
export * from "./module-loader.ts";
|