5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 20:10:00 +08:00
wails/cmd/package.go
Lea Anthony 94c56115a5
Release v0.19.0 (#285)
* feat: attempt to support Zorin

* chore: bump version

* Add support for Gentoo

* docs: update contributors

* feat: test support for Fedora

* chore: version bump

* Update README.md

* feat: major refactor

* fix: config errors

* fix: capitalisation and binding fix

* fix: lint

* fix: linting

* config: eslint

* fix: more lint fixes

* fix: linting for hound

* Even more fixes

* chore: bump version

* fix: eslintrc config

* fix: renamed global logger

* fix: Print stdout on error :rolleyes:

* fix: add promises polyfill for the windows target

* style: replace double quotes with single quotes

* Update contributors

* feat: significant overhaul of runtime

* chore: Version Bump

* Fix Masterminds/semver reference import path (case-sensitivity)

* drop lsb_release

Signed-off-by: Chronophylos <nikolai@chronophylos.com>

* change DistributionID to NAME=

Signed-off-by: Chronophylos <nikolai@chronophylos.com>

* show distro id when creating a issue

Signed-off-by: Chronophylos <nikolai@chronophylos.com>

* fix assumption

Signed-off-by: Chronophylos <nikolai@chronophylos.com>

* docs: updated contributors

* fix: add support back for ubuntu, redhat

* chore: version bump

* fix(linux): fedora & centos support

* feat: gcc,npm,node versions on issues

* linux working

* darwin working

* feat: show gcc, node, npm version on issue report

* Delete npm-debug.log

* fix: crashing typo

* trim gcc string

* chore: version bump

* fix: gitbash fixes

* chore: hotfix

* fix: issue report

* fix: typo

* chore: hotfix version bump

* 179 parrot distributionsupport (#181)

* feat: parrot support && git push

* feat: parrot support

* feat: parrot support

* fix: arch support

* fix: gentoos support

* Update README.md

* Update README.md

* chore: bump version

* Linux db (#182)

* feat: refactor linux distro detection

* linux db updates

* feat: add gccversioncommand + windows support

* fix: build-essential

* chore: linter fixes (#185)

* 182 linux bd (#183)

* fix: linuxdb.yaml entries

* fix: typo

* fix: yaml syntax error

* 188 support distribution linux mint (#189)

* chore: update linux db

* chore: bump version

* chore: merge webview back in

* chore: rename webview for clarity

* chore: add stale issue bot config

* chore: add inprogress label

* Azure Pipelines (#192)

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* test: azure pipeline

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* feat: azure pipelines

* chore: remove unused mewn file

* chore: deduplicate library verificaation code

* Update contributors

* fix: undefined: webview during build

* feat: VoidLinux support

* Yaml bug (#207)

* test: azure pipeline

* fix: azure pipeline yaml

* feat: elementary support

* feat: opensuse support

* fix: 0_setup.go line 27

* fix: 0_setup.go line 27

* fix: opensuse yaml

* fix: opensuse yaml

* fix: opensuse yaml

* fix: opensuse yaml

* fix: opensuse yaml

* fix: opensuse yaml

* fix: yaml

* fix: yaml

* fix: yaml

* fix: opensuse yaml

* fix: opensuse

* fix: opensuse

* fix: opensuse

* fix: opensuse

* fix: string trim os osRelease field NAME

* fix: 0_setup.go if err typo

* test

* test

* fix: typo in linux.go

* test: remove quotes from opensuse case

* test: revert

* test: ""

* test: ""

* test: ""

* test: ""

* fix: replace trim with replace

* fix: drop 0_setup.go and run checks by system.go

* fix: elementary os yaml name

* fix: open suse yaml entry

* fix: commented out result.Release = version

* fix: commented out result.Release = version

* fix: revert Replace to Trim

* fix: Linux Mint yaml entry

* fix: capitalize distros entries

* fix: capitalize distros entries

* fix: capitalize distros entries

* test

* test

* fix: open suse yaml entry

* fix: yaml entris

* test

* test

* test

* test

* test

* test

* branch changing

* fix: bug in setup process

* debugging

* debugging

* debugging

* debugging

* fix: yaml entries & err == nil bug

* Update prerequisites.go

* fix: bug

* fix: 0_setup.go

* fix: yaml bug

* fix: yaml bug

* chore: bump version

* Elementary support + readme update (#210)

* test: azure pipeline

* fix: azure pipeline yaml

* feat: elementary support+readme udpate

* fix: upgrade eslint

* 215 support distribution kali (#219)

* test: azure pipeline

* fix: azure pipeline yaml

* feat: kali linux support

* feat: kali linux support

* fix: allow 0 return types

* duplicate code spotted  (#221)

* fix: duplicate code

* chore: release v0.17.14-pre

* chore: remove debug output

*  (FIX) 215 support distribution kali (#224)

* fix: kali support

* docs: add Mattn

* feat: KDE neon support (#234)

* chore: version bump

* chore: remove some debug output

* fix: binding more than one struct method (#245)

* feat: add runtime typings

* fix: multiple runtime fixes

* manjaro (#248)

* manjaro

* Update go.mod

* chore: version bump

* fix: update runtime

* chore: version bump

* cmd/wails: report error status code to OS (#252)

Fixes #251.

* Update CONTRIBUTORS.md

* chore: version bump

* fix: importing runtime (#254)

* chore: supress warnings

* Patch for file dialog on OSX (#258)

* Patch for file dialog on OSX

* Update CONTRIBUTORS.md

* 262 add wails shutdown method (#264)

* feat: support close in bridge mode

* feat: WailsShutdown callback

Now handles proper shutdown through:
  * runtime.Window.Close()
  * Killing the main window
  * Ctrl-C

* chore: version bump

* fix: force install when node_modules missing (#268)

* fix: detect encoding on windows (#266)

* fix: linting

* chore: bump version

* Migrate tool (#270)

Experimental migration tool for projects < v1.0.0

* chore: version bump

* fix: add flag to fix windows builds (#272)

* Bump version to v0.18.9-pre

* 261 korean fonts (#273)

* fix: linting

* chore: bump version

* fix: unicode text for Windows

* release v0.18.10-pre

* 274 support spaces in windows paths (#275)

* fix: escape windows commands

* fix: allow spaces in path to windres

* Update go.mod

* release v0.18.11-pre

* 261 korean fonts (#276)

* fix: linting

* chore: bump version

* fix: unicode text for Windows

* fix: re-add webview_set_title

* release v0.18.12-pre

* hotfix: build issue for windows

* fix: npm/node version reporting

* fix: debug build should use terminal

* fix: make binary name more os specific

* Backport (#283)

* Develop (#265)


* Patch for file dialog on OSX

* Update CONTRIBUTORS.md

* 262 add wails shutdown method (#264)

* feat: support close in bridge mode

* feat: WailsShutdown callback

Now handles proper shutdown through:
  * runtime.Window.Close()
  * Killing the main window
  * Ctrl-C

* chore: version bump

* chore: version bump

* feat: adjust binary name for OS

* fix: allow spaces in gcc path

* feat: migrate command

* fix: npm/node versions

* fix: allow IE for serve

* feat: go build script

* fix: make runtime ES2015 compliant

* fix: remove invoke patch

* fix: allow any line endings

* chore: remove legacy bridge files

* chore: latest assets

* v0.18.15-pre

* fix: remove unicode flag

* chore: bump version

* release v0.19.0
2019-11-05 14:47:05 +11:00

267 lines
6.3 KiB
Go

package cmd
import (
"bytes"
"fmt"
"image"
"io/ioutil"
"os"
"path"
"path/filepath"
"runtime"
"strings"
"text/template"
"time"
"github.com/jackmordaunt/icns"
)
// PackageHelper helps with the 'wails package' command
type PackageHelper struct {
fs *FSHelper
log *Logger
system *SystemHelper
}
// NewPackageHelper creates a new PackageHelper!
func NewPackageHelper() *PackageHelper {
return &PackageHelper{
fs: NewFSHelper(),
log: NewLogger(),
system: NewSystemHelper(),
}
}
type plistData struct {
Title string
Exe string
PackageID string
Version string
Author string
Date string
}
func newPlistData(title, exe, packageID, version, author string) *plistData {
now := time.Now().Format(time.RFC822)
return &plistData{
Title: title,
Exe: exe,
Version: version,
PackageID: packageID,
Author: author,
Date: now,
}
}
func defaultString(val string, defaultVal string) string {
if val != "" {
return val
}
return defaultVal
}
func (b *PackageHelper) getPackageFileBaseDir() string {
// Calculate template base dir
_, filename, _, _ := runtime.Caller(1)
return filepath.Join(path.Dir(filename), "packages", runtime.GOOS)
}
// Package the application into a platform specific package
func (b *PackageHelper) Package(po *ProjectOptions) error {
switch runtime.GOOS {
case "darwin":
// Check we have the exe
if !b.fs.FileExists(po.BinaryName) {
return fmt.Errorf("cannot bundle non-existent binary file '%s'. Please build with 'wails build' first", po.BinaryName)
}
return b.packageOSX(po)
case "windows":
return b.PackageWindows(po, false)
case "linux":
return fmt.Errorf("linux is not supported at this time. Please see https://github.com/wailsapp/wails/issues/2")
default:
return fmt.Errorf("platform '%s' not supported for bundling yet", runtime.GOOS)
}
}
// Package the application for OSX
func (b *PackageHelper) packageOSX(po *ProjectOptions) error {
system := NewSystemHelper()
config, err := system.LoadConfig()
if err != nil {
return err
}
name := defaultString(po.Name, "WailsTest")
exe := defaultString(po.BinaryName, name)
version := defaultString(po.Version, "0.1.0")
author := defaultString(config.Name, "Anonymous")
packageID := strings.Join([]string{"wails", name, version}, ".")
plistData := newPlistData(name, exe, packageID, version, author)
appname := po.Name + ".app"
// Check binary exists
source := path.Join(b.fs.Cwd(), exe)
if !b.fs.FileExists(source) {
// We need to build!
return fmt.Errorf("Target '%s' not available. Has it been compiled yet?", exe)
}
// Remove the existing package
os.RemoveAll(appname)
exeDir := path.Join(b.fs.Cwd(), appname, "/Contents/MacOS")
b.fs.MkDirs(exeDir, 0755)
resourceDir := path.Join(b.fs.Cwd(), appname, "/Contents/Resources")
b.fs.MkDirs(resourceDir, 0755)
tmpl := template.New("infoPlist")
plistFile := filepath.Join(b.getPackageFileBaseDir(), "info.plist")
infoPlist, err := ioutil.ReadFile(plistFile)
if err != nil {
return err
}
tmpl.Parse(string(infoPlist))
// Write the template to a buffer
var tpl bytes.Buffer
err = tmpl.Execute(&tpl, plistData)
if err != nil {
return err
}
filename := path.Join(b.fs.Cwd(), appname, "Contents", "Info.plist")
err = ioutil.WriteFile(filename, tpl.Bytes(), 0644)
if err != nil {
return err
}
// Copy executable
target := path.Join(exeDir, exe)
err = b.fs.CopyFile(source, target)
if err != nil {
return err
}
err = os.Chmod(target, 0755)
if err != nil {
return err
}
err = b.packageIconOSX(resourceDir)
return err
}
// PackageWindows packages the application for windows platforms
func (b *PackageHelper) PackageWindows(po *ProjectOptions, cleanUp bool) error {
basename := strings.TrimSuffix(po.BinaryName, ".exe")
// Copy icon
tgtIconFile := filepath.Join(b.fs.Cwd(), basename+".ico")
if !b.fs.FileExists(tgtIconFile) {
srcIconfile := filepath.Join(b.getPackageFileBaseDir(), "wails.ico")
err := b.fs.CopyFile(srcIconfile, tgtIconFile)
if err != nil {
return err
}
}
// Copy manifest
tgtManifestFile := filepath.Join(b.fs.Cwd(), basename+".exe.manifest")
if !b.fs.FileExists(tgtManifestFile) {
srcManifestfile := filepath.Join(b.getPackageFileBaseDir(), "wails.exe.manifest")
err := b.fs.CopyFile(srcManifestfile, tgtManifestFile)
if err != nil {
return err
}
}
// Copy rc file
tgtRCFile := filepath.Join(b.fs.Cwd(), basename+".rc")
if !b.fs.FileExists(tgtRCFile) {
srcRCfile := filepath.Join(b.getPackageFileBaseDir(), "wails.rc")
rcfilebytes, err := ioutil.ReadFile(srcRCfile)
if err != nil {
return err
}
rcfiledata := strings.Replace(string(rcfilebytes), "$NAME$", basename, -1)
err = ioutil.WriteFile(tgtRCFile, []byte(rcfiledata), 0755)
if err != nil {
return err
}
}
// Build syso
sysofile := filepath.Join(b.fs.Cwd(), basename+"-res.syso")
batfile, err := fs.LocalDir(".")
if err != nil {
return err
}
windresBatFile := filepath.Join(batfile.fullPath, "windres.bat")
windresCommand := []string{windresBatFile, sysofile, tgtRCFile}
err = NewProgramHelper().RunCommandArray(windresCommand)
if err != nil {
return err
}
// clean up
if cleanUp {
filesToDelete := []string{tgtIconFile, tgtManifestFile, tgtRCFile, sysofile}
err := b.fs.RemoveFiles(filesToDelete)
if err != nil {
return err
}
}
return nil
}
func (b *PackageHelper) copyIcon(resourceDir string) (string, error) {
// TODO: Read this from project.json
const appIconFilename = "appicon.png"
srcIcon := path.Join(b.fs.Cwd(), appIconFilename)
// Check if appicon.png exists
if !b.fs.FileExists(srcIcon) {
// Install default icon
iconfile := filepath.Join(b.getPackageFileBaseDir(), "icon.png")
iconData, err := ioutil.ReadFile(iconfile)
if err != nil {
return "", err
}
err = ioutil.WriteFile(srcIcon, iconData, 0644)
if err != nil {
return "", err
}
}
return srcIcon, nil
}
func (b *PackageHelper) packageIconOSX(resourceDir string) error {
srcIcon, err := b.copyIcon(resourceDir)
if err != nil {
return err
}
tgtBundle := path.Join(resourceDir, "iconfile.icns")
imageFile, err := os.Open(srcIcon)
if err != nil {
return err
}
defer imageFile.Close()
srcImg, _, err := image.Decode(imageFile)
if err != nil {
return err
}
dest, err := os.Create(tgtBundle)
if err != nil {
return err
}
defer dest.Close()
return icns.Encode(dest, srcImg)
}