@ts-for-gir/generator-typescript 4.0.0-beta.3 → 4.0.0-beta.30
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 +19 -2
- package/package.json +13 -28
- package/src/index.ts +4 -0
- package/src/module-generator-example.ts +68 -0
- package/src/module-generator.ts +1981 -0
- package/src/npm-package.ts +115 -0
- package/src/overrides/glib.ts +13 -0
- package/src/overrides/gobject.ts +52 -0
- package/src/template-processor.ts +216 -0
- package/src/type-definition-generator.ts +165 -0
- package/src/utils.ts +7 -0
- package/lib/index.d.ts +0 -3
- package/lib/index.js +0 -4
- package/lib/index.js.map +0 -1
- package/lib/package-data-parser.d.ts +0 -13
- package/lib/package-data-parser.js +0 -67
- package/lib/package-data-parser.js.map +0 -1
- package/lib/template-processor.d.ts +0 -110
- package/lib/template-processor.js +0 -239
- package/lib/template-processor.js.map +0 -1
- package/lib/type-definition-generator.d.ts +0 -157
- package/lib/type-definition-generator.js +0 -1413
- package/lib/type-definition-generator.js.map +0 -1
- package/lib/utils.d.ts +0 -2
- package/lib/utils.js +0 -7
- package/lib/utils.js.map +0 -1
- package/packages.xml +0 -1213
- package/templates/README.md +0 -92
- package/templates/cogl-2-0.d.ts +0 -0
- package/templates/gjs/README-GJS.md +0 -133
- package/templates/gjs/ambient.d.ts +0 -19
- package/templates/gjs/ambient.js +0 -1
- package/templates/gjs/cairo-1.0.d.ts +0 -9
- package/templates/gjs/cairo.d.ts +0 -4
- package/templates/gjs/cairo.js +0 -4
- package/templates/gjs/dom.d.ts +0 -316
- package/templates/gjs/dom.js +0 -1
- package/templates/gjs/gettext.d.ts +0 -41
- package/templates/gjs/gettext.js +0 -4
- package/templates/gjs/gio-2.0.d.ts +0 -36
- package/templates/gjs/gjs.d.ts +0 -459
- package/templates/gjs/gjs.js +0 -4
- package/templates/gjs/gobject-2.0.d.ts +0 -227
- package/templates/gjs/module-ambient.d.ts +0 -23
- package/templates/gjs/module-ambient.js +0 -1
- package/templates/gjs/module-import.d.ts +0 -16
- package/templates/gjs/module-import.js +0 -2
- package/templates/gjs/module-noNamespace.d.ts +0 -7
- package/templates/gjs/module.append.d.ts +0 -1
- package/templates/gjs/module.d.ts +0 -13
- package/templates/gjs/module.js +0 -5
- package/templates/gjs/system.d.ts +0 -175
- package/templates/gjs/system.js +0 -4
- package/templates/granite-1.0.d.ts +0 -7
- package/templates/granite-7.0.d.ts +0 -7
- package/templates/gstbase-0.10.d.ts +0 -5
- package/templates/package.json +0 -95
- package/templates/rygelserver-2.6.d.ts +0 -3
- package/templates/tsconfig.json +0 -30
- package/templates/typedoc.json +0 -26
package/README.md
CHANGED
|
@@ -16,5 +16,22 @@
|
|
|
16
16
|
<img src="https://raw.githubusercontent.com/gjsify/ts-for-gir/main/.github/feeling.gif" />
|
|
17
17
|
</p>
|
|
18
18
|
|
|
19
|
-
# Generator
|
|
20
|
-
|
|
19
|
+
# TypeScript Generator
|
|
20
|
+
|
|
21
|
+
TypeScript-specific generator for `ts-for-gir`. This package implements the actual generation of TypeScript declaration files (.d.ts) from the processed GIR data. It transforms the intermediate representation of GObject types into TypeScript type definitions.
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
- Generation of TypeScript declaration files (.d.ts) from GIR data
|
|
26
|
+
- Support for generating NPM packages with proper package.json configuration
|
|
27
|
+
- Template-based code generation using EJS templates
|
|
28
|
+
- Complete handling of complex type transformations:
|
|
29
|
+
- Classes, interfaces, and records
|
|
30
|
+
- Functions, methods, and constructors
|
|
31
|
+
- Properties, fields, and constants
|
|
32
|
+
- Enums and callbacks
|
|
33
|
+
- Signals and their event handlers
|
|
34
|
+
- Generation of proper JSDoc comments from GIR documentation
|
|
35
|
+
- Support for GJS-specific module formats and ambient type declarations
|
|
36
|
+
|
|
37
|
+
This package is responsible for the final output of the `ts-for-gir` toolchain, producing TypeScript definition files that can be used in GJS projects.
|
package/package.json
CHANGED
|
@@ -1,36 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-for-gir/generator-typescript",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.30",
|
|
4
4
|
"description": "TypeScript type definition generator for ts-for-gir",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"module": "src/index.ts",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"engines": {
|
|
9
9
|
"node": ">=18"
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
|
12
|
-
".":
|
|
13
|
-
"types": "./lib/index.d.ts",
|
|
14
|
-
"import": "./lib/index.js"
|
|
15
|
-
}
|
|
12
|
+
".": "./src/index.ts"
|
|
16
13
|
},
|
|
17
14
|
"scripts": {
|
|
18
|
-
"
|
|
19
|
-
"build:ts": "tsc",
|
|
20
|
-
"clear": "yarn clear:build",
|
|
21
|
-
"clear:build": "rimraf ./lib",
|
|
22
|
-
"watch": "yarn build:ts --watch",
|
|
23
|
-
"lint": "eslint . --ext .ts,.tsx --fix"
|
|
15
|
+
"check": "tsc --noEmit"
|
|
24
16
|
},
|
|
25
17
|
"repository": {
|
|
26
18
|
"type": "git",
|
|
27
19
|
"url": "git+https://github.com/gjsify/ts-for-gir.git"
|
|
28
20
|
},
|
|
29
|
-
"author": "Pascal Garber <pascal@
|
|
21
|
+
"author": "Pascal Garber <pascal@mailfreun.de>",
|
|
30
22
|
"files": [
|
|
31
|
-
"
|
|
32
|
-
"templates",
|
|
33
|
-
"packages.xml"
|
|
23
|
+
"src"
|
|
34
24
|
],
|
|
35
25
|
"license": "Apache-2.0",
|
|
36
26
|
"bugs": {
|
|
@@ -42,20 +32,15 @@
|
|
|
42
32
|
],
|
|
43
33
|
"devDependencies": {
|
|
44
34
|
"@types/ejs": "^3.1.5",
|
|
45
|
-
"@types/node": "^
|
|
35
|
+
"@types/node": "^24.2.1",
|
|
46
36
|
"@types/xml2js": "^0.4.14",
|
|
47
|
-
"
|
|
48
|
-
"@typescript-eslint/parser": "^7.7.0",
|
|
49
|
-
"eslint": "^8.57.0",
|
|
50
|
-
"eslint-config-prettier": "^9.1.0",
|
|
51
|
-
"eslint-plugin-prettier": "^5.1.3",
|
|
52
|
-
"prettier": "^3.2.5",
|
|
53
|
-
"rimraf": "^5.0.5",
|
|
54
|
-
"typescript": "^5.4.5"
|
|
37
|
+
"typescript": "^5.9.2"
|
|
55
38
|
},
|
|
56
39
|
"dependencies": {
|
|
57
|
-
"@ts
|
|
58
|
-
"@ts-for-gir/
|
|
40
|
+
"@gi.ts/parser": "^4.0.0-beta.30",
|
|
41
|
+
"@ts-for-gir/generator-base": "^4.0.0-beta.30",
|
|
42
|
+
"@ts-for-gir/lib": "^4.0.0-beta.30",
|
|
43
|
+
"@ts-for-gir/templates": "^4.0.0-beta.30",
|
|
59
44
|
"ejs": "^3.1.10",
|
|
60
45
|
"xml2js": "^0.6.2"
|
|
61
46
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example usage of the refactored ModuleGenerator
|
|
3
|
+
*
|
|
4
|
+
* This demonstrates how the unified ModuleGenerator now incorporates
|
|
5
|
+
* functionality from DtsGenerator and DtsModuleGenerator
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { GirModule, NSRegistry, OptionsGeneration } from "@ts-for-gir/lib";
|
|
9
|
+
import { ModuleGenerator } from "./module-generator.ts";
|
|
10
|
+
|
|
11
|
+
// Example: Using ModuleGenerator with different output formats
|
|
12
|
+
async function generateTypeDefinitions(girModule: GirModule, config: OptionsGeneration, registry: NSRegistry) {
|
|
13
|
+
// Create a ModuleGenerator instance
|
|
14
|
+
const generator = new ModuleGenerator(girModule, config, registry);
|
|
15
|
+
|
|
16
|
+
// 1. Generate as string array (default behavior)
|
|
17
|
+
const arrayOutput = await generator.generateModule(girModule);
|
|
18
|
+
console.log("String array output:", arrayOutput);
|
|
19
|
+
|
|
20
|
+
// 2. Generate as single string (DtsGenerator compatibility)
|
|
21
|
+
const stringOutput = await generator.generateModuleString(girModule);
|
|
22
|
+
console.log("String output:", stringOutput);
|
|
23
|
+
|
|
24
|
+
// 3. Generate as module declaration (DtsModuleGenerator compatibility)
|
|
25
|
+
const moduleDeclaration = await generator.generateModuleDeclaration(girModule);
|
|
26
|
+
console.log("Module declaration output:", moduleDeclaration);
|
|
27
|
+
|
|
28
|
+
// 4. Generate namespace as string
|
|
29
|
+
const namespaceString = await generator.generateNamespaceAsString(girModule);
|
|
30
|
+
console.log("Namespace string output:", namespaceString);
|
|
31
|
+
|
|
32
|
+
// 5. The AdvancedVariants feature is automatically applied
|
|
33
|
+
// when generating GLib or GObject modules (unless disabled with noAdvancedVariants option)
|
|
34
|
+
if (girModule.namespace === "GLib" && !config.noAdvancedVariants) {
|
|
35
|
+
console.log("GLib module will include advanced variant type definitions");
|
|
36
|
+
}
|
|
37
|
+
if (girModule.namespace === "GObject") {
|
|
38
|
+
console.log("GObject module will include registerClass overrides");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Example: Migrating from DtsGenerator
|
|
43
|
+
function migrateFromDtsGenerator(girModule: GirModule, config: OptionsGeneration, registry: NSRegistry) {
|
|
44
|
+
// Before (using DtsGenerator):
|
|
45
|
+
// const generator = new DtsGenerator(girModule, config);
|
|
46
|
+
// const output = await generator.generateNamespace(girModule);
|
|
47
|
+
|
|
48
|
+
// After (using ModuleGenerator):
|
|
49
|
+
const generator = new ModuleGenerator(girModule, config, registry);
|
|
50
|
+
const output = generator.generateNamespaceAsString(girModule);
|
|
51
|
+
|
|
52
|
+
return output;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Example: Migrating from DtsModuleGenerator
|
|
56
|
+
function migrateFromDtsModuleGenerator(girModule: GirModule, config: OptionsGeneration, registry: NSRegistry) {
|
|
57
|
+
// Before (using DtsModuleGenerator):
|
|
58
|
+
// const generator = new DtsModuleGenerator(girModule, config);
|
|
59
|
+
// const output = await generator.generateNamespace(girModule);
|
|
60
|
+
|
|
61
|
+
// After (using ModuleGenerator):
|
|
62
|
+
const generator = new ModuleGenerator(girModule, config, registry);
|
|
63
|
+
const output = generator.generateModuleDeclaration(girModule);
|
|
64
|
+
|
|
65
|
+
return output;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export { generateTypeDefinitions, migrateFromDtsGenerator, migrateFromDtsModuleGenerator };
|