upgrade icns, remove pkg/errors

This commit is contained in:
2025-05-19 10:08:04 -04:00
parent 2827ce38d9
commit fd64435af3
3 changed files with 25 additions and 31 deletions

5
go.mod
View File

@@ -2,9 +2,6 @@ module git.yetaga.in/alazyreader/appify
go 1.24.2 go 1.24.2
require ( require github.com/jackmordaunt/icns/v2 v2.2.7
github.com/JackMordaunt/icns v1.0.0
github.com/pkg/errors v0.9.1
)
require github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect require github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect

6
go.sum
View File

@@ -1,6 +1,4 @@
github.com/JackMordaunt/icns v1.0.0 h1:41cNyWyQrG6beMw7m93LFK5o1GhefflsBTkauUkUtG8= github.com/jackmordaunt/icns/v2 v2.2.7 h1:K/RbfvuzjmjVY5y4g+XENRs8ZZatwz4YnLHypa2KwQg=
github.com/JackMordaunt/icns v1.0.0/go.mod h1:ubRqphS0f2OD07BuNaQSuw9uHUVQNBX5g38n6i2bdqM= github.com/jackmordaunt/icns/v2 v2.2.7/go.mod h1:ovoTxGguSuoUGKMk5Nn3R7L7BgMQkylsO+bblBuI22A=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=

45
main.go
View File

@@ -11,8 +11,7 @@ import (
"strings" "strings"
"text/template" "text/template"
"github.com/JackMordaunt/icns" "github.com/jackmordaunt/icns/v2"
"github.com/pkg/errors"
) )
func main() { func main() {
@@ -34,7 +33,7 @@ func run() error {
flag.Parse() flag.Parse()
args := flag.Args() args := flag.Args()
if len(args) < 1 { if len(args) < 1 {
return errors.New("missing executable argument") return fmt.Errorf("missing executable argument")
} }
bin := args[0] bin := args[0]
appname := *name + ".app" appname := *name + ".app"
@@ -43,29 +42,29 @@ func run() error {
resouresPath := filepath.Join(contentsPath, "Resources") resouresPath := filepath.Join(contentsPath, "Resources")
binPath := filepath.Join(appPath, appname) binPath := filepath.Join(appPath, appname)
if err := os.MkdirAll(appPath, 0777); err != nil { if err := os.MkdirAll(appPath, 0777); err != nil {
return errors.Wrap(err, "os.MkdirAll appPath") return fmt.Errorf("os.MkdirAll appPath: %w", err)
} }
fdst, err := os.Create(binPath) fdst, err := os.Create(binPath)
if err != nil { if err != nil {
return errors.Wrap(err, "create bin") return fmt.Errorf("create bin: %w", err)
} }
defer fdst.Close() defer fdst.Close()
fsrc, err := os.Open(bin) fsrc, err := os.Open(bin)
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return errors.New(bin + " not found") return fmt.Errorf("%s not found", bin)
} }
return errors.Wrap(err, "os.Open") return fmt.Errorf("os.Open: %w", err)
} }
defer fsrc.Close() defer fsrc.Close()
if _, err := io.Copy(fdst, fsrc); err != nil { if _, err := io.Copy(fdst, fsrc); err != nil {
return errors.Wrap(err, "copy bin") return fmt.Errorf("copy bin: %w", err)
} }
if err := exec.Command("chmod", "+x", appPath).Run(); err != nil { if err := exec.Command("chmod", "+x", appPath).Run(); err != nil {
return errors.Wrap(err, "chmod: "+appPath) return fmt.Errorf("chmod %s: %w", appPath, err)
} }
if err := exec.Command("chmod", "+x", binPath).Run(); err != nil { if err := exec.Command("chmod", "+x", binPath).Run(); err != nil {
return errors.Wrap(err, "chmod: "+binPath) return fmt.Errorf("chmod %s: %w", binPath, err)
} }
id := *identifier id := *identifier
if id == "" { if id == "" {
@@ -74,7 +73,7 @@ func run() error {
if *extraPlist != "" { if *extraPlist != "" {
b, err := os.ReadFile(*extraPlist) b, err := os.ReadFile(*extraPlist)
if err != nil { if err != nil {
return errors.Wrap(err, "error reading plist location: "+*extraPlist) return fmt.Errorf("error reading plist location %s: %w", *extraPlist, err)
} }
*extraPlist = string(b) *extraPlist = string(b)
} }
@@ -90,21 +89,21 @@ func run() error {
if *icon != "" { if *icon != "" {
iconPath, err := prepareIcons(*icon, resouresPath) iconPath, err := prepareIcons(*icon, resouresPath)
if err != nil { if err != nil {
return errors.Wrap(err, "icon") return fmt.Errorf("icon: %w", err)
} }
info.IconFile = filepath.Base(iconPath) info.IconFile = filepath.Base(iconPath)
} }
tpl, err := template.New("template").Parse(infoPlistTemplate) tpl, err := template.New("template").Parse(infoPlistTemplate)
if err != nil { if err != nil {
return errors.Wrap(err, "infoPlistTemplate") return fmt.Errorf("infoPlistTemplate: %w", err)
} }
fplist, err := os.Create(filepath.Join(contentsPath, "Info.plist")) fplist, err := os.Create(filepath.Join(contentsPath, "Info.plist"))
if err != nil { if err != nil {
return errors.Wrap(err, "create Info.plist") return fmt.Errorf("create Info.plist: %w", err)
} }
defer fplist.Close() defer fplist.Close()
if err := tpl.Execute(fplist, info); err != nil { if err := tpl.Execute(fplist, info); err != nil {
return errors.Wrap(err, "execute Info.plist template") return fmt.Errorf("execute Info.plist template: %w", err)
} }
return nil return nil
} }
@@ -114,36 +113,36 @@ func prepareIcons(iconPath, resourcesPath string) (string, error) {
fsrc, err := os.Open(iconPath) fsrc, err := os.Open(iconPath)
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return "", errors.New("icon file not found") return "", fmt.Errorf("icon file not found")
} }
return "", errors.Wrap(err, "open icon file") return "", fmt.Errorf("open icon file: %w", err)
} }
defer fsrc.Close() defer fsrc.Close()
if err := os.MkdirAll(resourcesPath, 0777); err != nil { if err := os.MkdirAll(resourcesPath, 0777); err != nil {
return "", errors.Wrap(err, "os.MkdirAll resourcesPath") return "", fmt.Errorf("os.MkdirAll resourcesPath: %w", err)
} }
destFile := filepath.Join(resourcesPath, "icon.icns") destFile := filepath.Join(resourcesPath, "icon.icns")
fdst, err := os.Create(destFile) fdst, err := os.Create(destFile)
if err != nil { if err != nil {
return "", errors.Wrap(err, "create icon.icns file") return "", fmt.Errorf("create icon.icns file: %w", err)
} }
defer fdst.Close() defer fdst.Close()
switch ext { switch ext {
case ".icns": // just copy the .icns file case ".icns": // just copy the .icns file
_, err := io.Copy(fdst, fsrc) _, err := io.Copy(fdst, fsrc)
if err != nil { if err != nil {
return destFile, errors.Wrap(err, "copying "+iconPath) return destFile, fmt.Errorf("copying %s: %w", iconPath, err)
} }
case ".png", ".jpg", ".jpeg", ".gif": // process any images case ".png", ".jpg", ".jpeg", ".gif": // process any images
srcImg, _, err := image.Decode(fsrc) srcImg, _, err := image.Decode(fsrc)
if err != nil { if err != nil {
return destFile, errors.Wrap(err, "decode image") return destFile, fmt.Errorf("decode image: %w", err)
} }
if err := icns.Encode(fdst, srcImg); err != nil { if err := icns.Encode(fdst, srcImg); err != nil {
return destFile, errors.Wrap(err, "generate icns file") return destFile, fmt.Errorf("generate icns file: %w", err)
} }
default: default:
return destFile, errors.New(ext + " icons not supported") return destFile, fmt.Errorf("%s icons not supported", ext)
} }
return destFile, nil return destFile, nil
} }