[v3] Fix binding generator output and import paths (#3334)

* Fix relative import path computation

* Fix models output path

* Add option to generate bindings using bundled runtime

* Update binding example

* Fix testdata

* Update changelog

---------

Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
This commit is contained in:
Fabio Massaioli
2024-03-22 21:18:04 +11:00
committed by GitHub
co-authored by Lea Anthony
parent f0986a6441
commit 45b2681dfc
56 changed files with 364 additions and 372 deletions
@@ -0,0 +1,28 @@
// @ts-check
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
// Person holds someone's most important attributes
export const Person = class {
/**
* Creates a new Person instance.
* @constructor
* @param {Object} source - The source object to create the Person.
* @param {string} source.Name
*/
constructor(source = {}) {
const { name = "" } = source;
this.name = name;
}
/**
* Creates a new Person instance from a string or object.
* @param {string|object} source - The source data to create a Person instance from.
* @returns {Person} A new Person instance.
*/
static createFrom(source) {
let parsedSource = typeof source === 'string' ? JSON.parse(source) : source;
return new Person(parsedSource);
}
};
@@ -0,0 +1,28 @@
// @ts-check
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
import {Call} from '/wails/runtime.js';
/**
* @typedef {import('../data/models').Person} dataPerson
*/
/**
* Greet greets a person
* @function Greet
* @param name {string}
* @returns {Promise<string>}
**/
export async function Greet(name) {
return Call.ByName("main.GreetService.Greet", ...Array.prototype.slice.call(arguments, 0));
}
/**
* GreetPerson greets a person
* @function GreetPerson
* @param person {dataPerson}
* @returns {Promise<string>}
**/
export async function GreetPerson(person) {
return Call.ByName("main.GreetService.GreetPerson", ...Array.prototype.slice.call(arguments, 0));
}
@@ -1,26 +0,0 @@
// @ts-check
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
window.go = window.go || {};
window.go.main = {
GreetService: {
/**
* GreetService.Greet
* Greet greets a person
* @param name {string}
* @returns {Promise<string>}
**/
Greet: function(name) { return wails.Call.ByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); },
/**
* GreetService.GreetPerson
* GreetPerson greets a person
* @param person {main.Person}
* @returns {Promise<string>}
**/
GreetPerson: function(person) { return wails.Call.ByID(4021313248, ...Array.prototype.slice.call(arguments, 0)); },
},
};
+9 -10
View File
@@ -78,18 +78,17 @@
<div class="result" id="result">Please enter your name below 👇</div>
<div class="input-box" id="input">
<input autofocus autocomplete="off" class="input" id="name" type="text"/>
<button class="btn" onclick="greet()">Greet</button>
<button class="btn" id="greet-btn">Greet</button>
</div>
<script type="module" src='/wails/runtime.js'></script>
<script src='bindings_main.js'></script>
<script>
let resultText = "";
let name = "";
<script type="module">
import * as GreetService from "./bindings/main/GreetService.js";
function greet() {
window.go.main.GreetService.Greet(document.getElementById("name").value).then((result) =>
document.getElementById("result").innerHTML = result);
}
async function greet() {
document.getElementById("result").innerHTML =
await GreetService.Greet(document.getElementById("name").value);
}
document.getElementById("greet-btn").onclick = greet;
</script>
</body>
</html>
-27
View File
@@ -1,27 +0,0 @@
// @ts-check
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
/**
* @typedef {import('./models').main.Person} mainPerson
*/
export const GreetService = {
/**
* GreetService.Greet
* Greet greets a person
* @param name {string}
* @returns {Promise<string>}
**/
Greet: function(name) { return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); },
/**
* GreetService.GreetPerson
* GreetPerson greets a person
* @param person {mainPerson}
* @returns {Promise<string>}
**/
GreetPerson: function(person) { return wails.CallByID(4021313248, ...Array.prototype.slice.call(arguments, 0)); },
};
-23
View File
@@ -1,23 +0,0 @@
// @ts-check
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
export namespace main {
export class Person {
name: string; // Warning: this is unexported in the Go struct.
constructor(source: Partial<Person> = {}) {
const { name = "" } = source;
this.name = name;
}
static createFrom(source: string | object = {}): Person {
let parsedSource = typeof source === 'string' ? JSON.parse(source) : source;
return new Person(parsedSource as Partial<Person>);
}
}
}