From c55f94a3dc94f8913dceac14d71160be24ae5c5c Mon Sep 17 00:00:00 2001 From: Will Andrews Date: Sat, 22 Oct 2022 11:04:18 +0100 Subject: [PATCH 1/3] [Docs] Add troubleshooting guide for unable to start service (#2001) * add troubleshooting * moved * Added to the docs repo Co-authored-by: Lea Anthony --- website/docs/guides/troubleshooting.mdx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/website/docs/guides/troubleshooting.mdx b/website/docs/guides/troubleshooting.mdx index 524d1a311..05cb9703c 100644 --- a/website/docs/guides/troubleshooting.mdx +++ b/website/docs/guides/troubleshooting.mdx @@ -159,3 +159,10 @@ This is _normally_ due to a mismatch with the OS version you are running and the installed. If you see an error like this, try upgrading your XCode Command Line Tools to the latest version. Source: https://github.com/wailsapp/wails/issues/1806 + +## Cannot start service: Host version "x.x.x does not match binary version "x.x.x" + +It's preferable to add `frontend/node_modules` and `frontend/package-lock.json` to your `.gitignore`. Otherwise when opening your repository on another machine +that may have different versions of Node installed, you may not be able to run your application. + +If this does happen, simply delete `frontend/node_modules` and `frontend/package-lock.json` and run your `wails build` or `wails dev` command again. \ No newline at end of file From dc65f77bafe97ee2d9e2711359f02d123470849d Mon Sep 17 00:00:00 2001 From: ParkourLiu <33681340+ParkourLiu@users.noreply.github.com> Date: Sat, 22 Oct 2022 18:04:49 +0800 Subject: [PATCH 2/3] repair panic (#1999) * repair panic * Add empty struct field test Co-authored-by: Lea Anthony --- v2/internal/binding/binding.go | 12 ++++- .../binding_test/binding_emptystruct_test.go | 53 +++++++++++++++++++ .../binding/binding_test/binding_test.go | 1 + 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 v2/internal/binding/binding_test/binding_emptystruct_test.go diff --git a/v2/internal/binding/binding.go b/v2/internal/binding/binding.go index d26242156..a51855ac9 100755 --- a/v2/internal/binding/binding.go +++ b/v2/internal/binding/binding.go @@ -187,7 +187,11 @@ func (b *Bindings) AddStructToGenerateTS(packageName string, structName string, continue } fqname := field.Type.String() - sName := strings.Split(fqname, ".")[1] + sNameSplit := strings.Split(fqname, ".") + if len(sNameSplit) < 2 { + continue + } + sName := sNameSplit[1] pName := getPackageName(fqname) a := reflect.New(field.Type) if b.hasExportedJSONFields(field.Type) { @@ -199,7 +203,11 @@ func (b *Bindings) AddStructToGenerateTS(packageName string, structName string, continue } fqname := field.Type.Elem().String() - sName := strings.Split(fqname, ".")[1] + sNameSplit := strings.Split(fqname, ".") + if len(sNameSplit) < 2 { + continue + } + sName := sNameSplit[1] pName := getPackageName(fqname) typ := field.Type.Elem() a := reflect.New(typ) diff --git a/v2/internal/binding/binding_test/binding_emptystruct_test.go b/v2/internal/binding/binding_test/binding_emptystruct_test.go new file mode 100644 index 000000000..46ff69adc --- /dev/null +++ b/v2/internal/binding/binding_test/binding_emptystruct_test.go @@ -0,0 +1,53 @@ +package binding_test + +type EmptyStruct struct { + Empty struct{} `json:"empty"` +} + +func (s EmptyStruct) Get() EmptyStruct { + return s +} + +var EmptyStructTest = BindingTest{ + name: "EmptyStruct", + structs: []interface{}{ + &EmptyStruct{}, + }, + exemptions: nil, + shouldError: false, + want: ` +export namespace binding_test { + export class EmptyStruct { + // Go type: struct {} + + empty: any; + + static createFrom(source: any = {}) { + return new EmptyStruct(source); + } + constructor(source: any = {}) { + if ('string' === typeof source) source = JSON.parse(source); + this.empty = this.convertValues(source["empty"], null); + } + convertValues(a: any, classs: any, asMap: boolean = false): any { + if (!a) { + return a; + } + + if (a.slice) { + return (a as any[]).map(elem => this.convertValues(elem, classs)); + } else if ("object" === typeof a) { + if (asMap) { + for (const key of Object.keys(a)) { + a[key] = new classs(a[key]); + } + return a; + } + return new classs(a); + } + return a; + } + } +} +`, +} diff --git a/v2/internal/binding/binding_test/binding_test.go b/v2/internal/binding/binding_test/binding_test.go index fb315ac1e..7a17ce6ca 100644 --- a/v2/internal/binding/binding_test/binding_test.go +++ b/v2/internal/binding/binding_test/binding_test.go @@ -29,6 +29,7 @@ func TestBindings_GenerateModels(t *testing.T) { NonStringMapKeyTest, SingleFieldTest, MultistructTest, + EmptyStructTest, } testLogger := &logger.Logger{} From 4bff4af2b034807a89f6a4d914f7c1b3480310d6 Mon Sep 17 00:00:00 2001 From: Binyamin Aron Green Date: Sat, 22 Oct 2022 06:07:37 -0400 Subject: [PATCH 3/3] Add JSON schema for config file (#1864) * Add JSON schema for config file * Fix typo in wails config schema * Update wails.tmpl.json * Update wails.tmpl.json * Add reference to schema in docs Co-authored-by: Lea Anthony --- .../generate/template/base/wails.tmpl.json | 1 + v2/pkg/templates/base/wails.tmpl.json | 1 + .../templates/generate/plain/wails.tmpl.json | 1 + .../templates/lit-ts/wails.tmpl.json | 1 + .../templates/templates/lit/wails.tmpl.json | 1 + .../templates/templates/plain/wails.tmpl.json | 1 + .../templates/preact-ts/wails.tmpl.json | 1 + .../templates/preact/wails.tmpl.json | 1 + .../templates/react-ts/wails.tmpl.json | 1 + .../templates/templates/react/wails.tmpl.json | 1 + .../templates/svelte-ts/wails.tmpl.json | 1 + .../templates/svelte/wails.tmpl.json | 1 + .../templates/vanilla-ts/wails.tmpl.json | 1 + .../templates/vanilla/wails.tmpl.json | 1 + .../templates/vue-ts/wails.tmpl.json | 1 + .../templates/templates/vue/wails.tmpl.json | 1 + website/docs/reference/project-config.mdx | 2 + website/static/schemas/config.v2.json | 206 ++++++++++++++++++ 18 files changed, 224 insertions(+) create mode 100644 website/static/schemas/config.v2.json diff --git a/v2/cmd/wails/internal/commands/generate/template/base/wails.tmpl.json b/v2/cmd/wails/internal/commands/generate/template/base/wails.tmpl.json index 63c4e6fe7..cdb10e346 100644 --- a/v2/cmd/wails/internal/commands/generate/template/base/wails.tmpl.json +++ b/v2/cmd/wails/internal/commands/generate/template/base/wails.tmpl.json @@ -1,4 +1,5 @@ { + "$schema": "https://wails.io/schemas/config.v2.json", "name": "{{.ProjectName}}", "outputfilename": "{{.BinaryName}}", "frontend:install": "npm install", diff --git a/v2/pkg/templates/base/wails.tmpl.json b/v2/pkg/templates/base/wails.tmpl.json index 0bba43da6..ce4ffe365 100644 --- a/v2/pkg/templates/base/wails.tmpl.json +++ b/v2/pkg/templates/base/wails.tmpl.json @@ -1,4 +1,5 @@ { + "$scheme": "https://wails.io/schemas/config.v2.json", "name": "{{.ProjectName}}", "outputfilename": "{{.BinaryName}}", "frontend:install": "npm install", diff --git a/v2/pkg/templates/generate/plain/wails.tmpl.json b/v2/pkg/templates/generate/plain/wails.tmpl.json index b010f3203..0168826bd 100644 --- a/v2/pkg/templates/generate/plain/wails.tmpl.json +++ b/v2/pkg/templates/generate/plain/wails.tmpl.json @@ -1,4 +1,5 @@ { + "$schema": "https://wails.io/schemas/config.v2.json", "name": "{{.ProjectName}}", "outputfilename": "{{.BinaryName}}", "wailsjsdir": "./frontend", diff --git a/v2/pkg/templates/templates/lit-ts/wails.tmpl.json b/v2/pkg/templates/templates/lit-ts/wails.tmpl.json index 0bba43da6..c39b2cb7d 100644 --- a/v2/pkg/templates/templates/lit-ts/wails.tmpl.json +++ b/v2/pkg/templates/templates/lit-ts/wails.tmpl.json @@ -1,4 +1,5 @@ { + "$schema": "https://wails.io/schemas/config.v2.json", "name": "{{.ProjectName}}", "outputfilename": "{{.BinaryName}}", "frontend:install": "npm install", diff --git a/v2/pkg/templates/templates/lit/wails.tmpl.json b/v2/pkg/templates/templates/lit/wails.tmpl.json index 0bba43da6..c39b2cb7d 100644 --- a/v2/pkg/templates/templates/lit/wails.tmpl.json +++ b/v2/pkg/templates/templates/lit/wails.tmpl.json @@ -1,4 +1,5 @@ { + "$schema": "https://wails.io/schemas/config.v2.json", "name": "{{.ProjectName}}", "outputfilename": "{{.BinaryName}}", "frontend:install": "npm install", diff --git a/v2/pkg/templates/templates/plain/wails.tmpl.json b/v2/pkg/templates/templates/plain/wails.tmpl.json index b010f3203..0168826bd 100644 --- a/v2/pkg/templates/templates/plain/wails.tmpl.json +++ b/v2/pkg/templates/templates/plain/wails.tmpl.json @@ -1,4 +1,5 @@ { + "$schema": "https://wails.io/schemas/config.v2.json", "name": "{{.ProjectName}}", "outputfilename": "{{.BinaryName}}", "wailsjsdir": "./frontend", diff --git a/v2/pkg/templates/templates/preact-ts/wails.tmpl.json b/v2/pkg/templates/templates/preact-ts/wails.tmpl.json index 0bba43da6..c39b2cb7d 100644 --- a/v2/pkg/templates/templates/preact-ts/wails.tmpl.json +++ b/v2/pkg/templates/templates/preact-ts/wails.tmpl.json @@ -1,4 +1,5 @@ { + "$schema": "https://wails.io/schemas/config.v2.json", "name": "{{.ProjectName}}", "outputfilename": "{{.BinaryName}}", "frontend:install": "npm install", diff --git a/v2/pkg/templates/templates/preact/wails.tmpl.json b/v2/pkg/templates/templates/preact/wails.tmpl.json index 0bba43da6..c39b2cb7d 100644 --- a/v2/pkg/templates/templates/preact/wails.tmpl.json +++ b/v2/pkg/templates/templates/preact/wails.tmpl.json @@ -1,4 +1,5 @@ { + "$schema": "https://wails.io/schemas/config.v2.json", "name": "{{.ProjectName}}", "outputfilename": "{{.BinaryName}}", "frontend:install": "npm install", diff --git a/v2/pkg/templates/templates/react-ts/wails.tmpl.json b/v2/pkg/templates/templates/react-ts/wails.tmpl.json index 0bba43da6..c39b2cb7d 100644 --- a/v2/pkg/templates/templates/react-ts/wails.tmpl.json +++ b/v2/pkg/templates/templates/react-ts/wails.tmpl.json @@ -1,4 +1,5 @@ { + "$schema": "https://wails.io/schemas/config.v2.json", "name": "{{.ProjectName}}", "outputfilename": "{{.BinaryName}}", "frontend:install": "npm install", diff --git a/v2/pkg/templates/templates/react/wails.tmpl.json b/v2/pkg/templates/templates/react/wails.tmpl.json index 0bba43da6..c39b2cb7d 100644 --- a/v2/pkg/templates/templates/react/wails.tmpl.json +++ b/v2/pkg/templates/templates/react/wails.tmpl.json @@ -1,4 +1,5 @@ { + "$schema": "https://wails.io/schemas/config.v2.json", "name": "{{.ProjectName}}", "outputfilename": "{{.BinaryName}}", "frontend:install": "npm install", diff --git a/v2/pkg/templates/templates/svelte-ts/wails.tmpl.json b/v2/pkg/templates/templates/svelte-ts/wails.tmpl.json index 0bba43da6..c39b2cb7d 100644 --- a/v2/pkg/templates/templates/svelte-ts/wails.tmpl.json +++ b/v2/pkg/templates/templates/svelte-ts/wails.tmpl.json @@ -1,4 +1,5 @@ { + "$schema": "https://wails.io/schemas/config.v2.json", "name": "{{.ProjectName}}", "outputfilename": "{{.BinaryName}}", "frontend:install": "npm install", diff --git a/v2/pkg/templates/templates/svelte/wails.tmpl.json b/v2/pkg/templates/templates/svelte/wails.tmpl.json index 0bba43da6..c39b2cb7d 100644 --- a/v2/pkg/templates/templates/svelte/wails.tmpl.json +++ b/v2/pkg/templates/templates/svelte/wails.tmpl.json @@ -1,4 +1,5 @@ { + "$schema": "https://wails.io/schemas/config.v2.json", "name": "{{.ProjectName}}", "outputfilename": "{{.BinaryName}}", "frontend:install": "npm install", diff --git a/v2/pkg/templates/templates/vanilla-ts/wails.tmpl.json b/v2/pkg/templates/templates/vanilla-ts/wails.tmpl.json index 0bba43da6..c39b2cb7d 100644 --- a/v2/pkg/templates/templates/vanilla-ts/wails.tmpl.json +++ b/v2/pkg/templates/templates/vanilla-ts/wails.tmpl.json @@ -1,4 +1,5 @@ { + "$schema": "https://wails.io/schemas/config.v2.json", "name": "{{.ProjectName}}", "outputfilename": "{{.BinaryName}}", "frontend:install": "npm install", diff --git a/v2/pkg/templates/templates/vanilla/wails.tmpl.json b/v2/pkg/templates/templates/vanilla/wails.tmpl.json index 0bba43da6..c39b2cb7d 100644 --- a/v2/pkg/templates/templates/vanilla/wails.tmpl.json +++ b/v2/pkg/templates/templates/vanilla/wails.tmpl.json @@ -1,4 +1,5 @@ { + "$schema": "https://wails.io/schemas/config.v2.json", "name": "{{.ProjectName}}", "outputfilename": "{{.BinaryName}}", "frontend:install": "npm install", diff --git a/v2/pkg/templates/templates/vue-ts/wails.tmpl.json b/v2/pkg/templates/templates/vue-ts/wails.tmpl.json index 0bba43da6..c39b2cb7d 100644 --- a/v2/pkg/templates/templates/vue-ts/wails.tmpl.json +++ b/v2/pkg/templates/templates/vue-ts/wails.tmpl.json @@ -1,4 +1,5 @@ { + "$schema": "https://wails.io/schemas/config.v2.json", "name": "{{.ProjectName}}", "outputfilename": "{{.BinaryName}}", "frontend:install": "npm install", diff --git a/v2/pkg/templates/templates/vue/wails.tmpl.json b/v2/pkg/templates/templates/vue/wails.tmpl.json index 0bba43da6..c39b2cb7d 100644 --- a/v2/pkg/templates/templates/vue/wails.tmpl.json +++ b/v2/pkg/templates/templates/vue/wails.tmpl.json @@ -1,4 +1,5 @@ { + "$schema": "https://wails.io/schemas/config.v2.json", "name": "{{.ProjectName}}", "outputfilename": "{{.BinaryName}}", "frontend:install": "npm install", diff --git a/website/docs/reference/project-config.mdx b/website/docs/reference/project-config.mdx index 9111e59af..1e2818145 100644 --- a/website/docs/reference/project-config.mdx +++ b/website/docs/reference/project-config.mdx @@ -52,3 +52,5 @@ This file is read by the Wails CLI when running `wails build` or `wails dev`. The `assetdir`, `reloaddirs`, `wailsjsdir`, `debounceMS`, `devserver` and `frontenddevserverurl` flags in `wails build/dev` will update the project config and thus become defaults for subsequent runs. + +The JSON Schema for this file is located [here](https://wails.io/schemas/config.v2.json). diff --git a/website/static/schemas/config.v2.json b/website/static/schemas/config.v2.json new file mode 100644 index 000000000..f5a6935a2 --- /dev/null +++ b/website/static/schemas/config.v2.json @@ -0,0 +1,206 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "https://wails.io/schemas/config.v2.json", + "required": [], + "title": "Wails configuration schema", + "description": "A JSON representation of a Wails project config file.", + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The project name", + "default": "wailsapp" + }, + "assetdir": { + "type": "string", + "description": "Relative path to the directory containing the compiled assets. This is normally inferred, and can be left empty." + }, + "reloaddirs": { + "type": "string", + "description": "Additional directories to trigger reloads (comma separated). Often, this is only used for advanced asset configurations." + }, + "frontend:install": { + "type": "string", + "description": "The command to install dependencies. Run in the frontend directory.", + "examples": [ "npm install" ] + }, + "frontend:build": { + "type": "string", + "description": "The command to build the assets. Run in the frontend directory.", + "examples": ["npm run build"] + }, + "frontend:dev": { + "type": "string", + "description": "[Deprecated] This command has been replaced by `frontend:dev:build`. If `frontend:dev:build` is not specified, Wails will fall back to this command. If this command is also not specified, Wails will fall back to `frontend:build`." + }, + "frontend:dev:build": { + "type": "string", + "description": "The equivalent of `frontend:build` during development. If not specified, it falls back to `frontend:dev`." + }, + "frontend:dev:install": { + "type": "string", + "description": "The equivalent of `frontend:install` during development. If not specified, it falls back to `frontend:install`." + }, + "frontend:dev:watcher": { + "type": "string", + "description": "This command is run in a separate process on `wails dev`. Useful for third-party watchers or for starting third-party dev servers." + }, + "frontend:dev:serverUrl": { + "type": "string", + "description": "URL to a 3rd party dev server to be used to serve assets (eg. Vite). If this is set to 'auto', then the devServerUrl will be inferred from the Vite output", + "examples": [ "auto", "http://localhost:3000" ], + "oneOf": [ + { "format": "uri" }, + { "const": "auto" } + ] + }, + "wailsjsdir": { + "type": "string", + "description": "Relative path to the directory where the auto-generated JS modules will be created.", + "format": "uri-reference", + "default": "./frontend" + }, + "version": { + "description": "Project config version", + "default": "2", + "enum": [ "2" ] + }, + "outputfilename": { + "type": "string", + "description": "The name of the binary" + }, + "debounceMS": { + "type": "number", + "description": "The debounce time for hot-reload of the built-in dev server. Measured in milliseconds.", + "default": 100 + }, + "devServer": { + "type": "string", + "description": "The address to bind the wails dev server to.", + "default": "localhost:34115", + "format": "uri" + }, + "appargs": { + "type": "string", + "description": "Arguments passed to the application in shell style when in dev mode." + }, + "runNonNativeBuildHooks": { + "type": "boolean", + "description": "Whether to run build hooks that are defined for an OS other than the host OS.", + "default": false + }, + "preBuildHooks": { + "$ref": "#/definitions/buildHooks" + }, + "postBuildHooks": { + "$ref": "#/definitions/buildHooks" + }, + "author": { + "type": "object", + "description": "The application author", + "properties": { + "name": { "type": "string" }, + "email": { + "type": "string", + "format": "email" + } + } + }, + "info": { + "type": "object", + "description": "Data used to populate manifests and version info.", + "properties": { + "companyName": { + "type": "string", + "description": "The company name. Defaults to the project name." + }, + "productName": { + "type": "string", + "description": "The product name. Defaults to the project name." + }, + "productVersion": { + "type": "string", + "description": "The version of the product", + "default": "1.0.0" + }, + "copyright": { + "type": "string", + "description": "A copyright string for the product", + "default": "Copyright........." + }, + "comments": { + "type": "string", + "description": "A short comment for the app", + "default": "Built using Wails (https://wails.io)" + } + } + }, + "nsisType": { + "type": "string", + "default": "multiple", + "description": "Type of NSIS Installer for Windows", + "oneOf": [ + { + "const": "multiple", + "description": "One installer per architecture" + }, + { + "const": "single", + "description": "Single universal installer for all architectures being built" + } + ] + }, + "obfuscated": { + "type": "boolean", + "default": false, + "description": "Whether the binary should be obfuscated. Uses ." + }, + "garbleargs": { + "type": "string", + "description": "The arguments to pass to the garble command when using the obfuscated flag" + } + }, + "dependencies": { + "garbleargs": ["obfuscated"] + }, + "definitions": { + "OsHook": { + "title": "GOOS/*", + "type": "string", + "description": "Executed at build level before/after a build of the specific platform" + }, + "OsArchHook": { + "title": "GOOS/GOARCH", + "type": "string", + "description": "Executed at build level before/after a build of the specific platform and arch" + }, + "buildHooks": { + "type": "object", + "description": "Build hooks for different targets.", + "additionalProperties": false, + "properties": { + "{GOOS}/{GOARCH}": { "$ref": "#/definitions/OsArchHook" }, + "{GOOS}/*": { "$ref": "#/definitions/OsHook" }, + "windows/*": { "$ref": "#/definitions/OsHook" }, + "linux/*": { "$ref": "#/definitions/OsHook" }, + "darwin/*": { "$ref": "#/definitions/OsHook" }, + "*/*": { + "type": "string", + "description": "Executed at build level before/after a build" + } + }, + "patternProperties": { + "^[a-zA-Z0-9]+/[a-zA-Z0-9]+$": { + "type": "string", + "title": "GOOS/GOARCH", + "description": "Executed at build level before/after a build of the specific platform and arch" + }, + "^[a-zA-Z0-9]+/\\*$": { + "type": "string", + "title": "GOOS/*", + "description": "Executed at build level before/after a build of the specific platform" + } + } + } + } +} \ No newline at end of file