-
Notifications
You must be signed in to change notification settings - Fork 0
/
converted_artifacts.go
52 lines (48 loc) · 1.65 KB
/
converted_artifacts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package builders
import (
"fmt"
"path/filepath"
"github.com/cardinalby/xgo-pack/pkg/imagemagick"
"github.com/cardinalby/xgo-pack/pkg/pipeline/buildctx"
)
func RegisterBuilders(ctx buildctx.Context) {
ctx.Artifacts.RegisterBuilder(buildctx.KindPngIcon, func(ctx buildctx.Context) (buildctx.Artifact, error) {
iconArtifact, err := ctx.Artifacts.Get(ctx, buildctx.KindIcon)
if err != nil {
return nil, fmt.Errorf("error getting icon artifact: %w", err)
}
if filepath.Ext(iconArtifact.GetPath()) == ".png" {
return iconArtifact, nil
}
tempPngIcon, err := ctx.NewTempFile("icon.png")
if err != nil {
return nil, fmt.Errorf("error creating temp png icon file path: %w", err)
}
if err := imagemagick.ToPng(ctx, buildctx.ImgSourcePath(iconArtifact.GetPath()), tempPngIcon.Path); err != nil {
return nil, fmt.Errorf("error converting icon to png: %w", err)
}
return tempPngIcon, nil
})
ctx.Artifacts.RegisterBuilder(buildctx.KindIcoIcon, func(ctx buildctx.Context) (buildctx.Artifact, error) {
iconArtifact, err := ctx.Artifacts.Get(ctx, buildctx.KindIcon)
if err != nil {
return nil, fmt.Errorf("error getting icon artifact: %w", err)
}
if filepath.Ext(iconArtifact.GetPath()) == ".ico" {
return iconArtifact, nil
}
tempIcoIcon, err := ctx.NewTempFile("icon.ico")
if err != nil {
return nil, fmt.Errorf("error creating temp ico icon file path: %w", err)
}
if err := imagemagick.ToIco(
ctx,
buildctx.ImgSourcePath(iconArtifact.GetPath()),
tempIcoIcon.Path,
[]int{16, 32, 48, 64, 128, 256},
); err != nil {
return nil, fmt.Errorf("error converting icon to ico: %w", err)
}
return tempIcoIcon, nil
})
}