@ts-for-gir/generator-json 4.0.0-beta.26
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/package.json +48 -0
- package/src/index.ts +2 -0
- package/src/json-definition-generator.ts +61 -0
- package/src/json-generator.ts +425 -0
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ts-for-gir/generator-json",
|
|
3
|
+
"version": "4.0.0-beta.26",
|
|
4
|
+
"description": "JSON generator for ts-for-gir",
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"module": "src/index.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=18"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./src/index.ts"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"check": "tsc --noEmit"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/gjsify/ts-for-gir.git"
|
|
20
|
+
},
|
|
21
|
+
"author": "Pascal Garber <pascal@artandcode.studio>",
|
|
22
|
+
"files": [
|
|
23
|
+
"src"
|
|
24
|
+
],
|
|
25
|
+
"license": "Apache-2.0",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/gjsify/ts-for-gir/issues"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/gjsify/ts-for-gir#readme",
|
|
30
|
+
"keywords": [
|
|
31
|
+
"gjs",
|
|
32
|
+
"typescript",
|
|
33
|
+
"generate",
|
|
34
|
+
"gir",
|
|
35
|
+
"gobject-introspection",
|
|
36
|
+
"json"
|
|
37
|
+
],
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^24.2.1",
|
|
40
|
+
"typescript": "^5.9.2"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@gi.ts/parser": "^4.0.0-beta.26",
|
|
44
|
+
"@ts-for-gir/generator-base": "^4.0.0-beta.26",
|
|
45
|
+
"@ts-for-gir/lib": "^4.0.0-beta.26",
|
|
46
|
+
"@ts-for-gir/reporter": "^4.0.0-beta.26"
|
|
47
|
+
}
|
|
48
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type GirModule, type NSRegistry, type OptionsGeneration, Reporter, ReporterService } from "@ts-for-gir/lib";
|
|
2
|
+
import { JsonGenerator } from "./json-generator.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Generator interface implementation for JSON output
|
|
6
|
+
* This provides the high-level Generator interface that can be used by the CLI
|
|
7
|
+
*/
|
|
8
|
+
export class JsonDefinitionGenerator {
|
|
9
|
+
readonly log: Reporter;
|
|
10
|
+
readonly config: OptionsGeneration;
|
|
11
|
+
readonly registry: NSRegistry;
|
|
12
|
+
|
|
13
|
+
constructor(config: OptionsGeneration, registry: NSRegistry) {
|
|
14
|
+
this.config = config;
|
|
15
|
+
this.registry = registry;
|
|
16
|
+
this.log = new Reporter(
|
|
17
|
+
this.config.verbose,
|
|
18
|
+
JsonDefinitionGenerator.name,
|
|
19
|
+
this.config.reporter,
|
|
20
|
+
this.config.reporterOutput,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
// Register with reporter service if reporting is enabled
|
|
24
|
+
if (this.config.reporter) {
|
|
25
|
+
const reporterService = ReporterService.getInstance();
|
|
26
|
+
reporterService.registerReporter(JsonDefinitionGenerator.name, this.log);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public async generate(module: GirModule): Promise<void> {
|
|
31
|
+
const jsonGenerator = new JsonGenerator(module, this.config);
|
|
32
|
+
const output = await jsonGenerator.stringifyNamespace(module);
|
|
33
|
+
|
|
34
|
+
if (output) {
|
|
35
|
+
if (this.config.outdir) {
|
|
36
|
+
// Write to file
|
|
37
|
+
const fs = await import("node:fs/promises");
|
|
38
|
+
const path = await import("node:path");
|
|
39
|
+
|
|
40
|
+
const filename = `${module.packageName}.json`;
|
|
41
|
+
const filepath = path.join(this.config.outdir, filename);
|
|
42
|
+
|
|
43
|
+
await fs.writeFile(filepath, output, "utf8");
|
|
44
|
+
this.log.info(`Generated ${filename}`);
|
|
45
|
+
} else {
|
|
46
|
+
// Output to console
|
|
47
|
+
this.log.log(output);
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
this.log.error(`Failed to generate JSON for ${module.packageName}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public async start(): Promise<void> {
|
|
55
|
+
this.log.info("Starting JSON generation...");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public async finish(girModules: GirModule[]): Promise<void> {
|
|
59
|
+
this.log.success(`JSON generation completed for ${girModules.length} modules`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ArrayType,
|
|
3
|
+
ClosureType,
|
|
4
|
+
type GirModule,
|
|
5
|
+
type IntrospectedCallback,
|
|
6
|
+
type IntrospectedClassCallback,
|
|
7
|
+
type IntrospectedFunctionParameter,
|
|
8
|
+
type IntrospectedMetadata,
|
|
9
|
+
NativeType,
|
|
10
|
+
NullableType,
|
|
11
|
+
type OptionsGeneration,
|
|
12
|
+
OrType,
|
|
13
|
+
Reporter,
|
|
14
|
+
ReporterService,
|
|
15
|
+
TupleType,
|
|
16
|
+
TypeConflict,
|
|
17
|
+
type TypeExpression,
|
|
18
|
+
TypeIdentifier,
|
|
19
|
+
} from "@ts-for-gir/lib";
|
|
20
|
+
|
|
21
|
+
export enum NodeKind {
|
|
22
|
+
class = "class",
|
|
23
|
+
interface = "interface",
|
|
24
|
+
function = "function",
|
|
25
|
+
classFunction = "class_function",
|
|
26
|
+
staticClassFunction = "static_class_function",
|
|
27
|
+
virtualClassFunction = "virtual_class_function",
|
|
28
|
+
prop = "prop",
|
|
29
|
+
field = "field",
|
|
30
|
+
alias = "alias",
|
|
31
|
+
namespace = "namespace",
|
|
32
|
+
callback = "callback",
|
|
33
|
+
constant = "constant",
|
|
34
|
+
record = "record",
|
|
35
|
+
constructor = "constructor",
|
|
36
|
+
propertiesConstructor = "properties_constructor",
|
|
37
|
+
parameter = "parameter",
|
|
38
|
+
enum = "enum",
|
|
39
|
+
enumMember = "enum_member",
|
|
40
|
+
error = "error",
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type Primitive = string[] | number[] | boolean[] | null | string | number | boolean;
|
|
44
|
+
export type Json = {
|
|
45
|
+
[key: string]: Primitive | Json | Json[];
|
|
46
|
+
};
|
|
47
|
+
export type NodeJson = {
|
|
48
|
+
kind: NodeKind;
|
|
49
|
+
doc: string | null;
|
|
50
|
+
metadata: MetadataJson | null;
|
|
51
|
+
private: boolean;
|
|
52
|
+
} & Json;
|
|
53
|
+
|
|
54
|
+
export enum TypeKind {
|
|
55
|
+
or = "or",
|
|
56
|
+
tuple = "tuple",
|
|
57
|
+
identifier = "identifier",
|
|
58
|
+
native = "native",
|
|
59
|
+
array = "array",
|
|
60
|
+
nulled = "null",
|
|
61
|
+
closure = "closure",
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function generateType(type: TypeExpression): TypeJson {
|
|
65
|
+
if (type instanceof TypeIdentifier) {
|
|
66
|
+
return {
|
|
67
|
+
kind: TypeKind.identifier,
|
|
68
|
+
name: type.name,
|
|
69
|
+
namespace: type.namespace,
|
|
70
|
+
};
|
|
71
|
+
} else if (type instanceof NativeType) {
|
|
72
|
+
return {
|
|
73
|
+
kind: TypeKind.native,
|
|
74
|
+
type: type.expression(),
|
|
75
|
+
};
|
|
76
|
+
} else if (type instanceof ClosureType) {
|
|
77
|
+
return {
|
|
78
|
+
kind: TypeKind.closure,
|
|
79
|
+
type: generateType(type.type),
|
|
80
|
+
user_data: type.user_data,
|
|
81
|
+
};
|
|
82
|
+
} else if (type instanceof ArrayType) {
|
|
83
|
+
return {
|
|
84
|
+
kind: TypeKind.array,
|
|
85
|
+
type: generateType(type.type),
|
|
86
|
+
depth: type.arrayDepth,
|
|
87
|
+
};
|
|
88
|
+
} else if (type instanceof NullableType) {
|
|
89
|
+
return {
|
|
90
|
+
kind: TypeKind.nulled,
|
|
91
|
+
type: generateType(type.type),
|
|
92
|
+
};
|
|
93
|
+
} else if (type instanceof TypeConflict) {
|
|
94
|
+
// Type conflicts aren't considered in JSON outputs.
|
|
95
|
+
return generateType(type.type);
|
|
96
|
+
} else if (type instanceof TupleType) {
|
|
97
|
+
return {
|
|
98
|
+
kind: TypeKind.tuple,
|
|
99
|
+
types: type.types.map((t) => generateType(t)),
|
|
100
|
+
};
|
|
101
|
+
} else if (type instanceof OrType) {
|
|
102
|
+
return {
|
|
103
|
+
kind: TypeKind.or,
|
|
104
|
+
types: type.types.map((t) => generateType(t)),
|
|
105
|
+
};
|
|
106
|
+
} else {
|
|
107
|
+
return {
|
|
108
|
+
kind: TypeKind.native,
|
|
109
|
+
type: "any",
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function _capitalize(str: string) {
|
|
115
|
+
if (str.length === 0) {
|
|
116
|
+
return "";
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (str.length === 1) {
|
|
120
|
+
return str[0].toUpperCase();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return str[0].toUpperCase() + str.substring(1).toLowerCase();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface ParameterJson extends NodeJson {
|
|
127
|
+
kind: NodeKind.parameter;
|
|
128
|
+
optional: boolean;
|
|
129
|
+
varargs: boolean;
|
|
130
|
+
name: string;
|
|
131
|
+
type: TypeJson;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export type TypeJson = Json &
|
|
135
|
+
(
|
|
136
|
+
| {
|
|
137
|
+
kind: TypeKind.native;
|
|
138
|
+
type: string;
|
|
139
|
+
}
|
|
140
|
+
| {
|
|
141
|
+
kind: TypeKind.array;
|
|
142
|
+
depth: number;
|
|
143
|
+
type: TypeJson;
|
|
144
|
+
}
|
|
145
|
+
| {
|
|
146
|
+
kind: TypeKind.or | TypeKind.tuple;
|
|
147
|
+
types: TypeJson[];
|
|
148
|
+
}
|
|
149
|
+
| {
|
|
150
|
+
kind: TypeKind.nulled;
|
|
151
|
+
type: TypeJson;
|
|
152
|
+
}
|
|
153
|
+
| {
|
|
154
|
+
kind: TypeKind.closure;
|
|
155
|
+
user_data: number | null;
|
|
156
|
+
type: TypeJson;
|
|
157
|
+
}
|
|
158
|
+
| {
|
|
159
|
+
kind: TypeKind.identifier;
|
|
160
|
+
namespace: string;
|
|
161
|
+
name: string;
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
export interface EnumMemberJson extends NodeJson {
|
|
166
|
+
kind: NodeKind.enumMember;
|
|
167
|
+
name: string;
|
|
168
|
+
value: string | null;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface EnumJson extends NodeJson {
|
|
172
|
+
kind: NodeKind.enum;
|
|
173
|
+
name: string;
|
|
174
|
+
members: EnumMemberJson[];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export interface CallbackJson extends NodeJson {
|
|
178
|
+
kind: NodeKind.callback;
|
|
179
|
+
name: string;
|
|
180
|
+
type: [Json, Json];
|
|
181
|
+
parameters: ParameterJson[];
|
|
182
|
+
returnType: TypeJson;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export interface PropertyJson extends NodeJson {
|
|
186
|
+
kind: NodeKind.prop;
|
|
187
|
+
name: string;
|
|
188
|
+
type: TypeJson;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export interface FieldJson extends NodeJson {
|
|
192
|
+
kind: NodeKind.field;
|
|
193
|
+
name: string;
|
|
194
|
+
type: TypeJson;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export interface MethodJson extends NodeJson {
|
|
198
|
+
kind: NodeKind.classFunction;
|
|
199
|
+
name: string;
|
|
200
|
+
parameters: ParameterJson[];
|
|
201
|
+
returnType: TypeJson[] | TypeJson;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface StaticMethodJson extends NodeJson {
|
|
205
|
+
kind: NodeKind.staticClassFunction;
|
|
206
|
+
name: string;
|
|
207
|
+
parameters: ParameterJson[];
|
|
208
|
+
returnType: TypeJson[] | TypeJson;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface VirtualMethodJson extends NodeJson {
|
|
212
|
+
kind: NodeKind.virtualClassFunction;
|
|
213
|
+
name: string;
|
|
214
|
+
parameters: ParameterJson[];
|
|
215
|
+
returnType: TypeJson[] | TypeJson;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export type MetadataJson = Json;
|
|
219
|
+
|
|
220
|
+
export interface ConstJson extends NodeJson {
|
|
221
|
+
kind: NodeKind.constant;
|
|
222
|
+
name: string;
|
|
223
|
+
type: TypeJson;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export interface InterfaceJson extends NodeJson {
|
|
227
|
+
kind: NodeKind.interface;
|
|
228
|
+
name: string;
|
|
229
|
+
extends: TypeJson | null;
|
|
230
|
+
type: TypeJson;
|
|
231
|
+
props: PropertyJson[];
|
|
232
|
+
methods: MethodJson[];
|
|
233
|
+
staticMethods: StaticMethodJson[];
|
|
234
|
+
virtualMethods: VirtualMethodJson[];
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export interface BaseClassJson extends NodeJson {
|
|
238
|
+
name: string;
|
|
239
|
+
type: TypeJson;
|
|
240
|
+
constructors: MethodJson[];
|
|
241
|
+
mainConstructor: PropertiesConstructorJson | ConstructorJson | null;
|
|
242
|
+
extends: TypeJson | null;
|
|
243
|
+
implements: TypeJson[];
|
|
244
|
+
props: PropertyJson[];
|
|
245
|
+
fields: FieldJson[];
|
|
246
|
+
methods: MethodJson[];
|
|
247
|
+
staticMethods: StaticMethodJson[];
|
|
248
|
+
virtualMethods: VirtualMethodJson[];
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export interface ClassJson extends BaseClassJson {
|
|
252
|
+
kind: NodeKind.class;
|
|
253
|
+
abstract: boolean;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export interface RecordJson extends BaseClassJson {
|
|
257
|
+
kind: NodeKind.record;
|
|
258
|
+
mainConstructor: ConstructorJson | null;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export interface ErrorJson extends BaseClassJson {
|
|
262
|
+
kind: NodeKind.error;
|
|
263
|
+
mainConstructor: ConstructorJson | null;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export interface FunctionJson extends NodeJson {
|
|
267
|
+
name: string;
|
|
268
|
+
kind: NodeKind.function;
|
|
269
|
+
parameters: ParameterJson[];
|
|
270
|
+
returnType: TypeJson[] | TypeJson;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface AliasJson extends NodeJson {
|
|
274
|
+
name: string;
|
|
275
|
+
kind: NodeKind.alias;
|
|
276
|
+
type: TypeJson;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export interface PropertiesConstructorJson extends NodeJson {
|
|
280
|
+
name: string;
|
|
281
|
+
kind: NodeKind.propertiesConstructor;
|
|
282
|
+
properties: ParameterJson[];
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export interface ConstructorJson extends NodeJson {
|
|
286
|
+
name: string;
|
|
287
|
+
kind: NodeKind.constructor;
|
|
288
|
+
parameters: ParameterJson[];
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export type ImportsJson = { [lib: string]: string };
|
|
292
|
+
|
|
293
|
+
export interface NamespaceJson extends Json {
|
|
294
|
+
kind: NodeKind.namespace;
|
|
295
|
+
imports: ImportsJson;
|
|
296
|
+
version: string;
|
|
297
|
+
name: string;
|
|
298
|
+
alias: AliasJson[];
|
|
299
|
+
enums: EnumJson[];
|
|
300
|
+
errors: ErrorJson[];
|
|
301
|
+
functions: FunctionJson[];
|
|
302
|
+
callbacks: CallbackJson[];
|
|
303
|
+
constants: ConstJson[];
|
|
304
|
+
records: RecordJson[];
|
|
305
|
+
interfaces: InterfaceJson[];
|
|
306
|
+
classes: ClassJson[];
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export class JsonGenerator {
|
|
310
|
+
readonly namespace: GirModule;
|
|
311
|
+
readonly options: OptionsGeneration;
|
|
312
|
+
readonly log: Reporter;
|
|
313
|
+
|
|
314
|
+
constructor(namespace: GirModule, options: OptionsGeneration) {
|
|
315
|
+
this.namespace = namespace;
|
|
316
|
+
this.options = options;
|
|
317
|
+
this.log = new Reporter(options.verbose, JsonGenerator.name, options.reporter, options.reporterOutput);
|
|
318
|
+
|
|
319
|
+
// Register with reporter service if reporting is enabled
|
|
320
|
+
if (options.reporter) {
|
|
321
|
+
const reporterService = ReporterService.getInstance();
|
|
322
|
+
reporterService.registerReporter(`${JsonGenerator.name}(${namespace.packageName})`, this.log);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
private generateDoc(doc: string): string {
|
|
327
|
+
const HTML_BREAK = /<br\/>\s?/gi;
|
|
328
|
+
const HTML_SQUASH = /<[^>]*>/gi;
|
|
329
|
+
return doc
|
|
330
|
+
.replaceAll(HTML_BREAK, "\n")
|
|
331
|
+
.replaceAll(HTML_SQUASH, "")
|
|
332
|
+
.replaceAll(/^\s*\*+\s*/gm, "")
|
|
333
|
+
.replaceAll(/^\s*\n/gm, "")
|
|
334
|
+
.trim();
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
private generateMetadata(metadata: IntrospectedMetadata): MetadataJson {
|
|
338
|
+
return JSON.parse(JSON.stringify(metadata));
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
private generateParameters(parameters: IntrospectedFunctionParameter[]): ParameterJson[] {
|
|
342
|
+
return parameters.map((param) => this.generateParameter(param));
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
generateParameter(node: IntrospectedFunctionParameter): ParameterJson {
|
|
346
|
+
const type = generateType(node.type);
|
|
347
|
+
|
|
348
|
+
return {
|
|
349
|
+
kind: NodeKind.parameter,
|
|
350
|
+
doc: node.doc ? this.generateDoc(node.doc) : null,
|
|
351
|
+
metadata: node.metadata ? this.generateMetadata(node.metadata) : null,
|
|
352
|
+
private: false,
|
|
353
|
+
optional: node.isOptional,
|
|
354
|
+
varargs: node.isVarArgs,
|
|
355
|
+
name: node.name,
|
|
356
|
+
type,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
generateCallbackType(_node: IntrospectedCallback | IntrospectedClassCallback): [Json, Json] {
|
|
361
|
+
return [{}, {}];
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
generateCallback(node: IntrospectedCallback): CallbackJson {
|
|
365
|
+
const parameters = this.generateParameters(node.parameters);
|
|
366
|
+
const returnType = generateType(node.return());
|
|
367
|
+
|
|
368
|
+
return {
|
|
369
|
+
kind: NodeKind.callback,
|
|
370
|
+
doc: node.doc ? this.generateDoc(node.doc) : null,
|
|
371
|
+
metadata: node.metadata ? this.generateMetadata(node.metadata) : null,
|
|
372
|
+
private: false,
|
|
373
|
+
name: node.name,
|
|
374
|
+
type: this.generateCallbackType(node),
|
|
375
|
+
parameters,
|
|
376
|
+
returnType,
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
generateClassCallback(node: IntrospectedClassCallback): CallbackJson {
|
|
381
|
+
const parameters = this.generateParameters(node.parameters);
|
|
382
|
+
const returnType = generateType(node.return());
|
|
383
|
+
|
|
384
|
+
return {
|
|
385
|
+
kind: NodeKind.callback,
|
|
386
|
+
doc: node.doc ? this.generateDoc(node.doc) : null,
|
|
387
|
+
metadata: node.metadata ? this.generateMetadata(node.metadata) : null,
|
|
388
|
+
private: false,
|
|
389
|
+
name: node.name,
|
|
390
|
+
type: this.generateCallbackType(node),
|
|
391
|
+
parameters,
|
|
392
|
+
returnType,
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// For now, simplified implementation - can be extended later with full methods
|
|
397
|
+
async generateNamespace(node: GirModule): Promise<NamespaceJson> {
|
|
398
|
+
// Basic structure - full implementation would iterate through all members
|
|
399
|
+
return {
|
|
400
|
+
kind: NodeKind.namespace,
|
|
401
|
+
imports: {},
|
|
402
|
+
version: node.version,
|
|
403
|
+
name: node.namespace,
|
|
404
|
+
alias: [],
|
|
405
|
+
enums: [],
|
|
406
|
+
errors: [],
|
|
407
|
+
functions: [],
|
|
408
|
+
callbacks: [],
|
|
409
|
+
constants: [],
|
|
410
|
+
records: [],
|
|
411
|
+
interfaces: [],
|
|
412
|
+
classes: [],
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
async stringifyNamespace(node: GirModule): Promise<string | null> {
|
|
417
|
+
try {
|
|
418
|
+
const namespace = await this.generateNamespace(node);
|
|
419
|
+
return JSON.stringify(namespace, null, 2);
|
|
420
|
+
} catch (error) {
|
|
421
|
+
this.log.error(`Failed to stringify namespace: ${error}`);
|
|
422
|
+
return null;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|