5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-21 11:29:29 +08:00

Taskfile Refactor (#3748)

* Refactor taskfile

* Fix escaping

* Fix event error

* Fix dev mode

* Fixes for Windows

* Add docs. Improve docs build system

* Update v3/internal/commands/build_assets/Taskfile.darwin.yml

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update v3/internal/commands/build_assets/Taskfile.linux.yml

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Improve docs

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
Lea Anthony 2024-09-21 20:49:25 +10:00 committed by GitHub
parent 860d02d1fe
commit 5367d056e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 469 additions and 607 deletions

View File

@ -17,6 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Changed
- Taskfile refactor by [leaanthony](https://github.com/leaanthony) in [#3748](https://github.com/wailsapp/wails/pull/3748)
## v3.0.0-alpha.7 - 2024-09-18 ## v3.0.0-alpha.7 - 2024-09-18
### Added ### Added

View File

@ -0,0 +1,215 @@
# Wails v3 Build System
## Overview
The Wails v3 build system is a flexible and powerful tool designed to streamline the build process for your Wails applications.
It leverages [Task](https://taskfile.dev), a task runner that allows you to define and run tasks easily.
While the v3 build system is the default, Wails encourages a "bring your own tooling" approach, allowing developers to customize their build process as needed.
Learn more about how to use Task in the [official documentation](https://taskfile.dev/usage/).
## Task: The Heart of the Build System
[Task](https://taskfile.dev) is a modern alternative to Make, written in Go. It uses a YAML file to define tasks and their dependencies. In the Wails v3 build system, [Task](https://taskfile.dev) plays a central role in orchestrating the build process.
The main `Taskfile.yml` is located in the project root, while platform-specific tasks are defined in `build/Taskfile.<platform>.yml` files.
```
Project Root
├── Taskfile.yml
└── build
├── Taskfile.windows.yml
├── Taskfile.darwin.yml
├── Taskfile.linux.yml
└── Taskfile.common.yml
```
The `Taskfile.common.yml` file contains common tasks that are shared across platforms.
## Taskfile.yml
The `Taskfile.yml` file is the main entry point for the build system. It defines the tasks and their dependencies. Here's the default ``Taskfile.yml`` file:
```yaml
version: '3'
includes:
common: ./build/Taskfile.common.yml
windows: ./build/Taskfile.windows.yml
darwin: ./build/Taskfile.darwin.yml
linux: ./build/Taskfile.linux.yml
vars:
APP_NAME: "{{.ProjectName}}"
BIN_DIR: "bin"
VITE_PORT: '{{.WAILS_VITE_PORT | default 9245}}'
tasks:
build:
summary: Builds the application
cmds:
- task: "{{OS}}:build"
package:
summary: Packages a production build of the application
cmds:
- task: "{{OS}}:package"
run:
summary: Runs the application
cmds:
- task: "{{OS}}:run"
dev:
summary: Runs the application in development mode
cmds:
- wails3 dev -config ./build/devmode.config.yaml -port {{.VITE_PORT}}
dev:reload:
summary: Reloads the application
cmds:
- task: run
```
## Platform-Specific Taskfiles
Each platform has its own Taskfile, located in the `build` directory. These files define the core tasks for that
platform. Each taskfile includes common tasks from the `Taskfile.common.yml` file.
### Windows
Location: `build/Taskfile.windows.yml`
The Windows-specific Taskfile includes tasks for building, packaging, and running the application on Windows. Key features include:
- Building with optional production flags
- Generating Windows ``.syso`` file
- Creating an NSIS installer for packaging
### Linux
Location: `build/Taskfile.linux.yml`
The Linux-specific Taskfile includes tasks for building, packaging, and running the application on Linux. Key features include:
- Building with optional production flags
- Creating an AppImage for packaging
- Generating ``.desktop`` file for Linux applications
### macOS
Location: `build/Taskfile.darwin.yml`
The macOS-specific Taskfile includes tasks for building, packaging, and running the application on macOS. Key features include:
- Building with optional production flags
- Creating an ``.app`` bundle for packaging
- Setting macOS-specific build flags and environment variables
## Wails3 Commands and Task Execution
The `wails3 task` command is an embedded version of taskfile.dev, which executes the tasks defined in your Taskfile.yml.
The `wails3 build` and `wails3 package` commands are aliases for `wails3 task build` and `wails3 task package` respectively. When you run these commands, Wails internally translates them to the appropriate task execution:
- `wails3 build``wails3 task build`
- `wails3 package``wails3 task package`
## Common Build Process
Across all platforms, the build process typically includes the following steps:
1. Tidying Go modules
2. Building the frontend
3. Generating icons
4. Compiling the Go code with platform-specific flags
5. Packaging the application (platform-specific)
## Customising the Build Process
While the v3 build system provides a solid default configuration, you can easily customise it to fit your project's needs. By modifying the `Taskfile.yml` and platform-specific Taskfiles, you can:
- Add new tasks
- Modify existing tasks
- Change the order of task execution
- Integrate with other tools and scripts
This flexibility allows you to tailor the build process to your specific requirements while still benefiting from the structure provided by the Wails v3 build system.
## Development Mode
The Wails v3 build system includes a powerful development mode that enhances the developer experience by providing live reloading and hot module replacement.
This mode is activated using the `wails3 dev` command.
### How It Works
When you run `wails3 dev`, the following process occurs:
1. The command checks for an available port, defaulting to 9245 if not specified.
2. It sets up the environment variables for the frontend dev server (Vite).
3. It starts the file watcher using the `refresh` library.
The [refresh](https://github.com/atterpac/refresh) library is responsible for monitoring file changes and triggering rebuilds.
It uses a configuration file, typically located at `./build/devmode.config.yaml`, to determine which files to watch and what
actions to take when changes are detected.
### Configuration
The development mode can be configured using the `devmode.config.yaml` file. Here's an example of its structure:
```yaml
config:
root_path: .
log_level: warn
debounce: 1000
ignore:
dir:
- .git
- node_modules
- frontend
- bin
file:
- .DS_Store
- .gitignore
- .gitkeep
watched_extension:
- "*.go"
git_ignore: true
executes:
- cmd: wails3 task common:install:frontend:deps
type: once
- cmd: wails3 task common:dev:frontend
type: background
- cmd: go mod tidy
type: blocking
- cmd: wails3 task build
type: blocking
- cmd: wails3 task run
type: primary
```
This configuration file allows you to:
- Set the root path for file watching
- Configure logging level
- Set a debounce time for file change events
- Ignore specific directories, files, or file extensions
- Define commands to execute on file changes
### Customising Development Mode
You can customise the development mode experience by modifying the `devmode.config.yaml` file.
Some ways to customise include:
1. Changing the watched directories or files
2. Adjusting the debounce time to control how quickly the system responds to changes
3. Adding or modifying the execute commands to fit your project's needs
You can also specify a custom configuration file and port:
```shell
wails3 dev -config ./path/to/custom/config.yaml -port 8080
```

View File

@ -1,176 +0,0 @@
# Wails v3 Plugin Guide
Wails v3 introduces the concept of plugins. A plugin is a self-contained module that can extend the functionality of your Wails application.
This guide will walk you through the structure and functionality of a Wails plugin.
## Plugin Structure
A Wails plugin is a standard Go module, typically consisting of the following files:
- `plugin.go`: This is the main Go file where the plugin's functionality is implemented.
- `plugin.yaml`: This is the plugin's metadata file. It contains information about the plugin such as its name, author, version, and more.
- `assets/`: This directory contains any static assets that the plugin might need.
- `README.md`: This file provides documentation for the plugin.
## Plugin Implementation
In `plugin.go`, a plugin is defined as a struct that implements the `application.Plugin` interface. This interface requires the following methods:
- `Init()`: This method is called when the plugin is initialized.
- `Shutdown()`: This method is called when the application is shutting down.
- `Name()`: This method returns the name of the plugin.
- `CallableByJS()`: This method returns a list of method names that can be called from the frontend.
In addition to these methods, you can define any number of additional methods that implement the plugin's functionality.
These methods can be called from the frontend using the `wails.Plugin()` function.
## Plugin Metadata
The `plugin.yaml` file contains metadata about the plugin. This includes the plugin's name, description, author, version, website, repository, and license.
## Plugin Assets
Any static assets that the plugin needs can be placed in the `assets/` directory.
These assets can be accessed by the frontend by requesting them at the plugin base path.
This path is `/wails/plugins/<plugin-name>/`.
### Example
If a plugin named `logopack` has an asset named `logo.png`, the frontend can access it at `/wails/plugins/logopack/logo.png`.
## Plugin Documentation
The `README.md` file provides documentation for the plugin. This should include instructions on how to install and use the plugin, as well as any other information that users of the plugin might find useful.
## Example
Here's the Log plugin implementation:
```go
package log
import (
"embed"
_ "embed"
"github.com/wailsapp/wails/v3/pkg/application"
"io/fs"
"log/slog"
)
//go:embed assets/*
var assets embed.FS
// ---------------- Plugin Setup ----------------
// This is the main plugin struct. It can be named anything you like.
// It must implement the application.Plugin interface.
// Both the Init() and Shutdown() methods are called synchronously when the app starts and stops.
type Config struct {
// Logger is the logger to use. If not set, a default logger will be used.
Logger *slog.Logger
// LogLevel defines the log level of the logger.
LogLevel slog.Level
// Handles errors that occur when writing to the log
ErrorHandler func(err error)
}
type Plugin struct {
config *Config
app *application.App
level slog.LevelVar
}
func NewPluginWithConfig(config *Config) *Plugin {
if config.Logger == nil {
config.Logger = application.DefaultLogger(config.LogLevel)
}
result := &Plugin{
config: config,
}
result.level.Set(config.LogLevel)
return result
}
func NewPlugin() *Plugin {
return NewPluginWithConfig(&Config{})
}
// Shutdown is called when the app is shutting down
// You can use this to clean up any resources you have allocated
func (p *Plugin) Shutdown() error { return nil }
// Name returns the name of the plugin.
// You should use the go module format e.g. github.com/myuser/myplugin
func (p *Plugin) Name() string {
return "github.com/wailsapp/wails/v3/plugins/log"
}
func (p *Plugin) Init(api application.PluginAPI) error {
return nil
}
// CallableByJS returns a list of methods that can be called from the frontend
func (p *Plugin) CallableByJS() []string {
return []string{
"Debug",
"Info",
"Warning",
"Error",
"SetLogLevel",
}
}
func (p *Plugin) Assets() fs.FS {
return assets
}
// ---------------- Plugin Methods ----------------
// Plugin methods are just normal Go methods. You can add as many as you like.
// The only requirement is that they are exported (start with a capital letter).
// You can also return any type that is JSON serializable.
// See https://golang.org/pkg/encoding/json/#Marshal for more information.
func (p *Plugin) Debug(message string, args ...any) {
p.config.Logger.Debug(message, args...)
}
func (p *Plugin) Info(message string, args ...any) {
p.config.Logger.Info(message, args...)
}
func (p *Plugin) Warning(message string, args ...any) {
p.config.Logger.Warn(message, args...)
}
func (p *Plugin) Error(message string, args ...any) {
p.config.Logger.Error(message, args...)
}
func (p *Plugin) SetLogLevel(level slog.Level) {
p.level.Set(level)
}
```
This plugin can be added to the application like this:
```go
Plugins: map[string]application.Plugin{
"log": log.NewPlugin(),
},
```
And here's how you can call a plugin method from the frontend:
```js
wails.Plugin("log","Debug","hello world")
```
## Support
If you encounter any issues with a plugin, please raise a ticket in the plugin's repository.
!!! note
The Wails team does not provide support for third-party plugins.

View File

@ -32,6 +32,7 @@ theme:
- content.tabs.annotation - content.tabs.annotation
- content.tabs.copy - content.tabs.copy
- content.code.copy - content.code.copy
- content.code.annotate
- content.action.edit - content.action.edit
language: en language: en
palette: palette:
@ -64,6 +65,7 @@ markdown_extensions:
- attr_list - attr_list
- admonition - admonition
- footnotes - footnotes
- md_in_html
- toc: - toc:
permalink: '#' permalink: '#'
- pymdownx.emoji: - pymdownx.emoji:
@ -145,7 +147,7 @@ nav:
- Learn More: - Learn More:
- Services: learn/services.md - Services: learn/services.md
- Runtime: learn/runtime.md - Runtime: learn/runtime.md
- Plugins: learn/plugins.md - Build System: learn/build.md
- Guides: - Guides:
- Customising Windows: learn/guides/customising-windows.md - Customising Windows: learn/guides/customising-windows.md
- Feedback: getting-started/feedback.md - Feedback: getting-started/feedback.md

View File

@ -176,13 +176,17 @@ tasks:
contextmenus contextmenus
dialogs dialogs
drag-n-drop drag-n-drop
environment
events events
frameless frameless
hide-window hide-window
ignore-mouse
keybindings keybindings
menu menu
plain plain
raw-message
screen screen
services
show-macos-toolbar show-macos-toolbar
systray systray
video video

View File

@ -217,8 +217,6 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tc-hib/winres v0.3.1 h1:CwRjEGrKdbi5CvZ4ID+iyVhgyfatxFoizjPhzez9Io4= github.com/tc-hib/winres v0.3.1 h1:CwRjEGrKdbi5CvZ4ID+iyVhgyfatxFoizjPhzez9Io4=
github.com/tc-hib/winres v0.3.1/go.mod h1:C/JaNhH3KBvhNKVbvdlDWkbMDO9H4fKKDaN7/07SSuk= github.com/tc-hib/winres v0.3.1/go.mod h1:C/JaNhH3KBvhNKVbvdlDWkbMDO9H4fKKDaN7/07SSuk=
github.com/wailsapp/go-webview2 v1.0.11 h1:CDbU4UQpaERY6M/FGObPGzUsFOHH3Yz+go12qnJINNY=
github.com/wailsapp/go-webview2 v1.0.11/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo=
github.com/wailsapp/go-webview2 v1.0.15 h1:IeQFoWmsHp32y64I41J+Zod3SopjHs918KSO4jUqEnY= github.com/wailsapp/go-webview2 v1.0.15 h1:IeQFoWmsHp32y64I41J+Zod3SopjHs918KSO4jUqEnY=
github.com/wailsapp/go-webview2 v1.0.15/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= github.com/wailsapp/go-webview2 v1.0.15/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo=
github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs= github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs=

View File

@ -0,0 +1,69 @@
version: '3'
tasks:
go:mod:tidy:
summary: Runs `go mod tidy`
internal: true
generates:
- go.sum
sources:
- go.mod
cmds:
- go mod tidy
install:frontend:deps:
summary: Install frontend dependencies
dir: frontend
sources:
- package.json
- package-lock.json
generates:
- node_modules/*
preconditions:
- sh: npm version
msg: "Looks like npm isn't installed. Npm is part of the Node installer: https://nodejs.org/en/download/"
cmds:
- npm install
build:frontend:
summary: Build the frontend project
dir: frontend
sources:
- "**/*"
generates:
- dist/*
deps:
- task: install:frontend:deps
- task: generate:bindings
cmds:
- npm run build -q
generate:bindings:
summary: Generates bindings for the frontend
sources:
- "**/*.go"
- go.mod
- go.sum
generates:
- "frontend/bindings/**/*"
cmds:
- wails3 generate bindings -f '{{.BUILD_FLAGS}}'{{if .UseTypescript}} -ts{{end}}
generate:icons:
summary: Generates Windows `.ico` and Mac `.icns` files from an image
dir: build
sources:
- "appicon.png"
generates:
- "icons.icns"
- "icons.ico"
cmds:
- wails3 generate icons -input appicon.png
dev:frontend:
summary: Runs the frontend in development mode
dir: frontend
deps:
- task: install:frontend:deps
cmds:
- npm run dev -- --port {{.VITE_PORT}} --strictPort

View File

@ -0,0 +1,45 @@
version: '3'
includes:
common: Taskfile.common.yml
tasks:
build:
summary: Creates a production build of the application
deps:
- task: common:go:mod:tidy
- task: common:build:frontend
- task: common:generate:icons
cmds:
- go build {{.BUILD_FLAGS}} -o {{.BIN_DIR}}/{{.APP_NAME}}
vars:
BUILD_FLAGS: '{{if eq .PRODUCTION "true"}}-tags production -trimpath -ldflags="-w -s"{{else}}-gcflags=all="-l"{{end}}'
env:
GOOS: darwin
CGO_ENABLED: 1
GOARCH: '{{.ARCH | default ARCH}}'
CGO_CFLAGS: "-mmacosx-version-min=10.15"
CGO_LDFLAGS: "-mmacosx-version-min=10.15"
MACOSX_DEPLOYMENT_TARGET: "10.15"
PRODUCTION: '{{.PRODUCTION | default "false"}}'
package:
summary: Packages a production build of the application into a `.app` bundle
deps:
- task: build
vars:
PRODUCTION: "true"
cmds:
- task: create:app:bundle
create:app:bundle:
summary: Creates an `.app` bundle
cmds:
- mkdir -p {{.BIN_DIR}}/{{.APP_NAME}}.app/Contents/{MacOS,Resources}
- cp build/icons.icns {{.BIN_DIR}}/{{.APP_NAME}}.app/Contents/Resources
- cp {{.BIN_DIR}}/{{.APP_NAME}} {{.BIN_DIR}}/{{.APP_NAME}}.app/Contents/MacOS
- cp build/Info.plist {{.BIN_DIR}}/{{.APP_NAME}}.app/Contents
run:
cmds:
- '{{.BIN_DIR}}/{{.APP_NAME}}'

View File

@ -0,0 +1,66 @@
version: '3'
includes:
common: Taskfile.common.yml
tasks:
build:
summary: Builds the application for Linux
deps:
- task: common:go:mod:tidy
- task: common:build:frontend
- task: common:generate:icons
cmds:
- go build {{.BUILD_FLAGS}} -o {{.BIN_DIR}}/{{.APP_NAME}}
vars:
BUILD_FLAGS: '{{if eq .PRODUCTION "true"}}-tags production -trimpath -ldflags="-w -s"{{else}}-gcflags=all="-l"{{end}}'
env:
GOOS: linux
CGO_ENABLED: 1
GOARCH: '{{.ARCH | default ARCH}}'
PRODUCTION: '{{.PRODUCTION | default "false"}}'
package:
summary: Packages a production build of the application for Linux
deps:
- task: build
vars:
PRODUCTION: "true"
cmds:
- task: create:appimage
create:appimage:
summary: Creates an AppImage
dir: build/appimage
deps:
- task: build
vars:
PRODUCTION: "true"
- task: generate:dotdesktop
cmds:
- cp {{.APP_BINARY}} {{.APP_NAME}}
- cp ../appicon.png appicon.png
- wails3 generate appimage -binary {{.APP_NAME}} -icon {{.ICON}} -desktopfile {{.DESKTOP_FILE}} -outputdir {{.OUTPUT_DIR}} -builddir {{.ROOT_DIR}}/build/appimage
vars:
APP_NAME: '{{.APP_NAME}}'
APP_BINARY: '../../bin/{{.APP_NAME}}'
ICON: '../appicon.png'
DESKTOP_FILE: '{{.APP_NAME}}.desktop'
OUTPUT_DIR: '../../bin'
generate:dotdesktop:
summary: Generates a `.desktop` file
dir: build
cmds:
- mkdir -p {{.ROOT_DIR}}/build/appimage
- wails3 generate .desktop -name "{{.APP_NAME}}" -exec "{{.EXEC}}" -icon "{{.ICON}}" -outputfile {{.ROOT_DIR}}/build/appimage/{{.APP_NAME}}.desktop -categories "{{.CATEGORIES}}"
vars:
APP_NAME: '{{.APP_NAME}}'
EXEC: '{{.APP_NAME}}'
ICON: 'appicon'
CATEGORIES: 'Development;'
OUTPUTFILE: '{{.ROOT_DIR}}/build/appimage/{{.APP_NAME}}.desktop'
run:
cmds:
- '{{.BIN_DIR}}/{{.APP_NAME}}'

View File

@ -0,0 +1,52 @@
version: '3'
includes:
common: Taskfile.common.yml
tasks:
build:
summary: Builds the application for Windows
deps:
- task: common:go:mod:tidy
- task: common:build:frontend
- task: common:generate:icons
- task: generate:syso
cmds:
- go build {{.BUILD_FLAGS}} -o {{.BIN_DIR}}/{{.APP_NAME}}.exe
vars:
BUILD_FLAGS: '{{if eq .PRODUCTION "true"}}-tags production -trimpath -ldflags="-w -s -H windowsgui"{{else}}-gcflags=all="-l"{{end}}'
env:
GOOS: windows
CGO_ENABLED: 0
GOARCH: '{{.ARCH | default ARCH}}'
PRODUCTION: '{{.PRODUCTION | default "false"}}'
package:
summary: Packages a production build of the application into a `.exe` bundle
cmds:
- task: create:nsis:installer
generate:syso:
summary: Generates Windows `.syso` file
dir: build
cmds:
- wails3 generate syso -arch {{.ARCH}} -icon icon.ico -manifest wails.exe.manifest -info info.json -out ../wails.syso
vars:
ARCH: '{{.ARCH | default ARCH}}'
create:nsis:installer:
summary: Creates an NSIS installer
dir: build/nsis
deps:
- task: build
vars:
PRODUCTION: "true"
cmds:
- makensis -DARG_WAILS_{{.ARG_FLAG}}_BINARY="{{.ROOT_DIR}}\{{.BIN_DIR}}\{{.APP_NAME}}.exe" project.nsi
vars:
ARCH: '{{.ARCH | default ARCH}}'
ARG_FLAG: '{{if eq .ARCH "amd64"}}AMD64{{else}}ARM64{{end}}'
run:
cmds:
- '{{.BIN_DIR}}\\{{.APP_NAME}}.exe'

View File

@ -16,9 +16,9 @@ config:
- "*.go" - "*.go"
git_ignore: true git_ignore: true
executes: executes:
- cmd: wails3 task install:frontend:deps - cmd: wails3 task common:install:frontend:deps
type: once type: once
- cmd: wails3 task dev:frontend - cmd: wails3 task common:dev:frontend
type: background type: background
- cmd: go mod tidy - cmd: go mod tidy
type: blocking type: blocking

View File

@ -1,449 +1,33 @@
version: '3' version: '3'
includes:
common: ./build/Taskfile.common.yml
windows: ./build/Taskfile.windows.yml
darwin: ./build/Taskfile.darwin.yml
linux: ./build/Taskfile.linux.yml
vars: vars:
APP_NAME: "{{.ProjectName}}" APP_NAME: "{{.ProjectName}}"
BIN_DIR: "bin" BIN_DIR: "bin"
VITE_PORT: {{ "'{{.WAILS_VITE_PORT | default 9245}}'" }} VITE_PORT: {{ "'{{.WAILS_VITE_PORT | default 9245}}'" }}
tasks: tasks:
## -------------------------- Build -------------------------- ##
build: build:
summary: Builds the application summary: Builds the application
cmds: cmds:
# Build for current OS - task: "{{ "{{OS}}" }}:build"
- task: build:{{ "{{OS}}" }}
# Uncomment to build for specific OSes
# - task: build:linux
# - task: build:windows
# - task: build:darwin
## ------> Windows <-------
build:windows:
summary: Builds the application for Windows
deps:
- task: go:mod:tidy
- task: build:frontend
vars:
BUILD_FLAGS: {{ "'{{.BUILD_FLAGS}}'" }}
- task: generate:icons
- task: generate:syso
vars:
ARCH: {{ "'{{.ARCH}}'" }}
cmds:
- go build {{ "{{.BUILD_FLAGS}}" }} -o {{ "{{.BIN_DIR}}" }}/{{.ProjectName}}.exe
vars:
BUILD_FLAGS: {{ "'{{if eq .PRODUCTION \"true\"}}-tags production -trimpath -ldflags=\"-w -s -H windowsgui\"{{else}}-gcflags=all=\"-l\"{{end}}'" }}
env:
GOOS: windows
CGO_ENABLED: 0
GOARCH: {{ "'{{.ARCH | default ARCH}}'" }}
PRODUCTION: {{ "'{{.PRODUCTION | default \"false\"}}'" }}
build:windows:prod:arm64:
summary: Creates a production build of the application
cmds:
- task: build:windows
vars:
ARCH: arm64
PRODUCTION: "true"
build:windows:prod:amd64:
summary: Creates a production build of the application
cmds:
- task: build:windows
vars:
ARCH: amd64
PRODUCTION: "true"
build:windows:debug:arm64:
summary: Creates a debug build of the application
cmds:
- task: build:windows
vars:
ARCH: arm64
build:windows:debug:amd64:
summary: Creates a debug build of the application
cmds:
- task: build:windows
vars:
ARCH: amd64
## ------> Darwin <-------
build:darwin:
summary: Creates a production build of the application
deps:
- task: go:mod:tidy
- task: build:frontend
vars:
BUILD_FLAGS: {{ "'{{.BUILD_FLAGS}}'" }}
- task: generate:icons
cmds:
- go build {{ "{{.BUILD_FLAGS}}" }} -o {{ "{{.BIN_DIR}}" }}/{{ "{{.APP_NAME}}" }}
vars:
BUILD_FLAGS: {{ "'{{if eq .PRODUCTION \"true\"}}-tags production -trimpath -ldflags=\"-w -s\"{{else}}-gcflags=all=\"-l\"{{end}}'" }}
env:
GOOS: darwin
CGO_ENABLED: 1
GOARCH: {{ "'{{.ARCH | default ARCH}}'" }}
CGO_CFLAGS: "-mmacosx-version-min=10.15"
CGO_LDFLAGS: "-mmacosx-version-min=10.15"
MACOSX_DEPLOYMENT_TARGET: "10.15"
PRODUCTION: {{ "'{{.PRODUCTION | default \"false\"}}'" }}
build:darwin:prod:arm64:
summary: Creates a production build of the application
cmds:
- task: build:darwin
vars:
ARCH: arm64
PRODUCTION: "true"
build:darwin:prod:amd64:
summary: Creates a production build of the application
cmds:
- task: build:darwin
vars:
ARCH: amd64
PRODUCTION: "true"
build:darwin:debug:arm64:
summary: Creates a debug build of the application
cmds:
- task: build:darwin
vars:
ARCH: arm64
build:darwin:debug:amd64:
summary: Creates a debug build of the application
cmds:
- task: build:darwin
vars:
ARCH: amd64
## ------> Linux <-------
build:linux:
summary: Builds the application for Linux
deps:
- task: go:mod:tidy
- task: build:frontend
vars:
BUILD_FLAGS: {{ "'{{.BUILD_FLAGS}}'" }}
- task: generate:icons
vars:
ARCH: {{ "'{{.ARCH}}'" }}
cmds:
- go build {{ "{{.BUILD_FLAGS}}" }} -o {{ "{{.BIN_DIR}}" }}/{{.ProjectName}}
vars:
BUILD_FLAGS: {{ "'{{if eq .PRODUCTION \"true\"}}-tags production -trimpath -ldflags=\"-w -s\"{{else}}-gcflags=all=\"-l\"{{end}}'" }}
env:
GOOS: linux
CGO_ENABLED: 1
GOARCH: {{ "'{{.ARCH | default ARCH}}'" }}
PRODUCTION: {{ "'{{.PRODUCTION | default \"false\"}}'" }}
build:linux:prod:arm64:
summary: Creates a production build of the application
cmds:
- task: build:linux
vars:
ARCH: arm64
PRODUCTION: "true"
build:linux:prod:amd64:
summary: Creates a production build of the application
cmds:
- task: build:linux
vars:
ARCH: amd64
PRODUCTION: "true"
build:linux:debug:arm64:
summary: Creates a debug build of the application
cmds:
- task: build:linux
vars:
ARCH: arm64
build:linux:debug:amd64:
summary: Creates a debug build of the application
cmds:
- task: build:linux
vars:
ARCH: amd64
## -------------------------- Package -------------------------- ##
package: package:
summary: Packages a production build of the application into a bundle summary: Packages a production build of the application
cmds: cmds:
- task: "{{ "{{OS}}" }}:package"
# Package for current OS
- task: package:{{ "{{OS}}" }}
# Package for specific os/arch
# - task: package:darwin:arm64
# - task: package:darwin:amd64
# - task: package:windows:arm64
# - task: package:windows:amd64
## ------> Windows <------
package:windows:
summary: Packages a production build of the application into a `.exe` bundle
cmds:
- task: create:nsis:installer
vars:
ARCH: {{ "'{{.ARCH}}'" }}
vars:
ARCH: {{ "'{{.ARCH | default ARCH}}'" }}
package:windows:arm64:
summary: Packages a production build of the application into a `.exe` bundle
cmds:
- task: package:windows
vars:
ARCH: arm64
package:windows:amd64:
summary: Packages a production build of the application into a `.exe` bundle
cmds:
- task: package:windows
vars:
ARCH: amd64
generate:syso:
summary: Generates Windows `.syso` file
dir: build
cmds:
- wails3 generate syso -arch {{ "{{.ARCH}}" }} -icon icon.ico -manifest wails.exe.manifest -info info.json -out ../wails.syso
vars:
ARCH: {{ "'{{.ARCH | default ARCH}}'" }}
create:nsis:installer:
summary: Creates an NSIS installer
label: "NSIS Installer ({{ "{{.ARCH}}"}})"
dir: build/nsis
sources:
- "{{ "{{.ROOT_DIR}}"}}\\bin\\{{ "{{.APP_NAME}}"}}.exe"
generates:
- "{{ "{{.ROOT_DIR}}"}}\\bin\\{{ "{{.APP_NAME}}"}}-{{ "{{.ARCH}}"}}-installer.exe"
deps:
- task: build:windows
vars:
PRODUCTION: "true"
ARCH: {{ "'{{.ARCH}}'" }}
cmds:
- makensis -DARG_WAILS_{{ "'{{.ARG_FLAG}}'" }}_BINARY="{{ "{{.ROOT_DIR}}"}}\{{ "{{.BIN_DIR}}" }}\{{ "{{.APP_NAME}}"}}.exe" project.nsi
vars:
ARCH: {{ "'{{.ARCH | default ARCH}}'" }}
ARG_FLAG: {{ "'{{if eq .ARCH \"amd64\"}}AMD64{{else}}ARM64{{end}}'" }}
## ------> Darwin <------
package:darwin:
summary: Packages a production build of the application into a `.app` bundle
platforms: [ darwin ]
deps:
- task: build:darwin
vars:
PRODUCTION: "true"
cmds:
- task: create:app:bundle
package:darwin:arm64:
summary: Packages a production build of the application into a `.app` bundle
platforms: [ darwin/arm64 ]
deps:
- task: package:darwin
vars:
ARCH: arm64
package:darwin:amd64:
summary: Packages a production build of the application into a `.app` bundle
platforms: [ darwin/amd64 ]
deps:
- task: package:darwin
vars:
ARCH: amd64
create:app:bundle:
summary: Creates an `.app` bundle
cmds:
- mkdir -p {{ "{{.BIN_DIR}}" }}/{{ "{{.APP_NAME}}" }}.app/Contents/{MacOS,Resources}
- cp build/icons.icns {{ "{{.BIN_DIR}}" }}/{{ "{{.APP_NAME}}" }}.app/Contents/Resources
- cp {{ "{{.BIN_DIR}}" }}/{{ "{{.APP_NAME}}" }} {{ "{{.BIN_DIR}}" }}/{{ "{{.APP_NAME}}" }}.app/Contents/MacOS
- cp build/Info.plist {{ "{{.BIN_DIR}}" }}/{{ "{{.APP_NAME}}" }}.app/Contents
## ------> Linux <------
package:linux:
summary: Packages a production build of the application for Linux
platforms: [ linux ]
deps:
- task: build:linux
vars:
PRODUCTION: "true"
cmds:
- task: create:appimage
create:appimage:
summary: Creates an AppImage
dir: build/appimage
platforms: [ linux ]
deps:
- task: build:linux
vars:
PRODUCTION: "true"
- task: generate:linux:dotdesktop
cmds:
# Copy binary + icon to appimage dir
- cp {{ "{{.APP_BINARY}}" }} {{ "{{.APP_NAME}}" }}
- cp ../appicon.png appicon.png
# Generate AppImage
- wails3 generate appimage -binary {{ "{{.APP_NAME}}" }} -icon {{ "{{.ICON}}" }} -desktopfile {{ "{{.DESKTOP_FILE}}" }} -outputdir {{ "{{.OUTPUT_DIR}}" }} -builddir {{ "{{.ROOT_DIR}}" }}/build/appimage
vars:
APP_NAME: '{{ "{{.APP_NAME}}" }}'
APP_BINARY: '../../bin/{{ "{{.APP_NAME}}" }}'
ICON: '../appicon.png'
DESKTOP_FILE: '{{ "{{.APP_NAME}}" }}.desktop'
OUTPUT_DIR: '../../bin'
generate:linux:dotdesktop:
summary: Generates a `.desktop` file
dir: build
sources:
- "appicon.png"
generates:
- '{{ "{{.ROOT_DIR}}"}}/build/appimage/{{ "{{.APP_NAME}}" }}.desktop'
cmds:
- mkdir -p {{ "{{.ROOT_DIR}}"}}/build/appimage
# Run `wails3 generate .desktop -help` for all the options
- wails3 generate .desktop -name "{{ "{{.APP_NAME}}" }}" -exec "{{ "{{.EXEC}}" }}" -icon "{{ "{{.ICON}}" }}" -outputfile {{ "{{.ROOT_DIR}}"}}/build/appimage/{{ "{{.APP_NAME}}" }}.desktop -categories "{{ "{{.CATEGORIES}}" }}"
# -comment "A comment"
# -terminal "true"
# -version "1.0"
# -genericname "Generic Name"
# -keywords "keyword1;keyword2;"
# -startupnotify "true"
# -mimetype "application/x-extension1;application/x-extension2;"
vars:
APP_NAME: '{{ "{{.APP_NAME}}" }}'
EXEC: '{{ "{{.APP_NAME}}" }}'
ICON: 'appicon'
CATEGORIES: 'Development;'
OUTPUTFILE: '{{ "{{.ROOT_DIR}}"}}/build/appimage/{{ "{{.APP_NAME}}" }}.desktop'
## -------------------------- Misc -------------------------- ##
generate:icons:
summary: Generates Windows `.ico` and Mac `.icns` files from an image
dir: build
sources:
- "appicon.png"
generates:
- "icons.icns"
- "icons.ico"
cmds:
# Generates both .ico and .icns files
- wails3 generate icons -input appicon.png
install:frontend:deps:
summary: Install frontend dependencies
dir: frontend
sources:
- package.json
- package-lock.json
generates:
- node_modules/*
preconditions:
- sh: npm version
msg: "Looks like npm isn't installed. Npm is part of the Node installer: https://nodejs.org/en/download/"
cmds:
# - npm install --silent --no-progress
- npm install
build:frontend:
summary: Build the frontend project
dir: frontend
sources:
- "**/*"
generates:
- dist/*
deps:
- install:frontend:deps
- task: generate:bindings
vars:
BUILD_FLAGS: {{ "'{{.BUILD_FLAGS}}'" }}
cmds:
- npm run build -q
generate:bindings:
summary: Generates bindings for the frontend
sources:
- "**/*.go"
- go.mod
- go.sum
generates:
- "frontend/bindings/**/*"
cmds:
# For a complete list of options, run `wails3 generate bindings -help`
- wails3 generate bindings -f '{{ "{{.BUILD_FLAGS}}" }}'{{if .UseTypescript}} -ts{{end}}
go:mod:tidy:
summary: Runs `go mod tidy`
internal: true
generates:
- go.sum
sources:
- go.mod
cmds:
- go mod tidy
# ----------------------- dev ----------------------- #
run: run:
summary: Runs the application summary: Runs the application
cmds: cmds:
- task: run:{{ "{{OS}}" }} - task: "{{ "{{OS}}" }}:run"
run:windows:
cmds:
- {{ "'{{.BIN_DIR}}\\\\{{.APP_NAME}}.exe'" }}
run:linux:
cmds:
- {{ "'{{.BIN_DIR}}/{{.APP_NAME}}'" }}
run:darwin:
cmds:
- {{ "'{{.BIN_DIR}}/{{.APP_NAME}}'" }}
dev:frontend:
summary: Runs the frontend in development mode
dir: frontend
deps:
- task: install:frontend:deps
cmds:
- npm run dev -- --port {{ "{{.VITE_PORT}}" }} --strictPort
dev: dev:
summary: Runs the application in development mode summary: Runs the application in development mode
cmds: cmds:
- wails3 dev -config ./build/devmode.config.yaml -port {{ "{{.VITE_PORT}}" }} - wails3 dev -config ./build/devmode.config.yaml -port {{ "{{.VITE_PORT}}" }}
dev:reload:
summary: Reloads the application
cmds:
- task: run