Skip to content

Commit 59c407d

Browse files
author
jld3103
authored
Merge pull request #246 from go-flutter-desktop/fix/remove-go-rice
Use go embed instead of go rice
2 parents ec94119 + 43e8583 commit 59c407d

34 files changed

+25
-432
lines changed

assets/README.md

-11
This file was deleted.

assets/app/go.mod

Whitespace-only changes.

cmd/build.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ func assertTargetFileExists(targetFilename string) {
400400
if targetFilename == config.BuildTargetDefault {
401401
log.Warnf("Let hover add the \"lib/main_desktop.dart\" file? ")
402402
if askForConfirmation() {
403-
fileutils.CopyAsset("app/main_desktop.dart", filepath.Join("lib", "main_desktop.dart"), fileutils.AssetsBox())
403+
fileutils.CopyAsset("app/main_desktop.dart", filepath.Join("lib", "main_desktop.dart"))
404404
log.Infof("Target file \"lib/main_desktop.dart\" has been created.")
405405
log.Infof(" Depending on your project, you might want to tweak it.")
406406
return

cmd/init-plugin.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ var createPluginCmd = &cobra.Command{
4848
"urlVSCRepo": vcsPath,
4949
}
5050

51-
fileutils.ExecuteTemplateFromAssetsBox("plugin/plugin.go.tmpl", filepath.Join(build.BuildPath, "plugin.go"), fileutils.AssetsBox(), templateData)
52-
fileutils.ExecuteTemplateFromAssetsBox("plugin/README.md.tmpl", filepath.Join(build.BuildPath, "README.md"), fileutils.AssetsBox(), templateData)
53-
fileutils.ExecuteTemplateFromAssetsBox("plugin/import.go.tmpl.tmpl", filepath.Join(build.BuildPath, "import.go.tmpl"), fileutils.AssetsBox(), templateData)
51+
fileutils.ExecuteTemplateFromAssets("plugin/plugin.go.tmpl", filepath.Join(build.BuildPath, "plugin.go"), templateData)
52+
fileutils.ExecuteTemplateFromAssets("plugin/README.md.tmpl", filepath.Join(build.BuildPath, "README.md"), templateData)
53+
fileutils.ExecuteTemplateFromAssets("plugin/import.go.tmpl.tmpl", filepath.Join(build.BuildPath, "import.go.tmpl"), templateData)
5454

5555
dlibPath := filepath.Join(build.BuildPath, "dlib")
5656
err = os.Mkdir(dlibPath, 0775)
5757
if err != nil {
5858
log.Errorf("Failed to create '%s' directory: %v", dlibPath, err)
5959
os.Exit(1)
6060
}
61-
fileutils.ExecuteTemplateFromAssetsBox("plugin/README.md.dlib.tmpl", filepath.Join(dlibPath, "README.md"), fileutils.AssetsBox(), templateData)
61+
fileutils.ExecuteTemplateFromAssets("plugin/README.md.dlib.tmpl", filepath.Join(dlibPath, "README.md"), templateData)
6262

6363
platforms := []string{"darwin", "linux", "windows"}
6464
for _, platform := range platforms {

cmd/init.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ var initCmd = &cobra.Command{
6565

6666
emptyConfig := config.Config{}
6767

68-
fileutils.CopyAsset("app/main.go", filepath.Join(desktopCmdPath, "main.go"), fileutils.AssetsBox())
69-
fileutils.CopyAsset("app/options.go", filepath.Join(desktopCmdPath, "options.go"), fileutils.AssetsBox())
70-
fileutils.CopyAsset("app/icon.png", filepath.Join(desktopAssetsPath, "icon.png"), fileutils.AssetsBox())
71-
fileutils.CopyAsset("app/gitignore", filepath.Join(build.BuildPath, ".gitignore"), fileutils.AssetsBox())
72-
fileutils.ExecuteTemplateFromAssetsBox("app/hover.yaml.tmpl", filepath.Join(build.BuildPath, "hover.yaml"), fileutils.AssetsBox(), map[string]string{
68+
fileutils.CopyAsset("app/main.go.tmpl", filepath.Join(desktopCmdPath, "main.go"))
69+
fileutils.CopyAsset("app/options.go.tmpl", filepath.Join(desktopCmdPath, "options.go"))
70+
fileutils.CopyAsset("app/icon.png", filepath.Join(desktopAssetsPath, "icon.png"))
71+
fileutils.CopyAsset("app/gitignore", filepath.Join(build.BuildPath, ".gitignore"))
72+
fileutils.ExecuteTemplateFromAssets("app/hover.yaml.tmpl", filepath.Join(build.BuildPath, "hover.yaml"), map[string]string{
7373
"applicationName": emptyConfig.GetApplicationName(projectName),
7474
"executableName": emptyConfig.GetExecutableName(projectName),
7575
"packageName": emptyConfig.GetPackageName(projectName),

cmd/packaging/packaging.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (t *packagingTask) init(ignoreAlreadyExists bool) {
128128
log.Errorf("Failed to create directory %s: %v", filepath.Dir(destinationFile), err)
129129
os.Exit(1)
130130
}
131-
fileutils.CopyAsset(fmt.Sprintf("packaging/%s", sourceFile), destinationFile, fileutils.AssetsBox())
131+
fileutils.CopyAsset(fmt.Sprintf("packaging/%s", sourceFile), destinationFile)
132132
}
133133
if t.generateInitFiles != nil {
134134
log.Infof("Generating dynamic init files")

go.mod

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module github.com/go-flutter-desktop/hover
33
go 1.18
44

55
require (
6-
github.com/GeertJohan/go.rice v1.0.2
76
github.com/JackMordaunt/icns v1.0.0
87
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9
98
github.com/google/uuid v1.3.0
@@ -20,7 +19,6 @@ require (
2019
)
2120

2221
require (
23-
github.com/daaku/go.zipexe v1.0.1 // indirect
2422
github.com/davecgh/go-spew v1.1.1 // indirect
2523
github.com/google/go-github v17.0.0+incompatible // indirect
2624
github.com/google/go-querystring v1.1.0 // indirect

go.sum

-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
2-
github.com/GeertJohan/go.rice v1.0.2 h1:PtRw+Tg3oa3HYwiDBZyvOJ8LdIyf6lAovJJtr7YOAYk=
3-
github.com/GeertJohan/go.rice v1.0.2/go.mod h1:af5vUNlDNkCjOZeSGFgIJxDje9qdjsO6hshx0gTmZt4=
41
github.com/JackMordaunt/icns v1.0.0 h1:41cNyWyQrG6beMw7m93LFK5o1GhefflsBTkauUkUtG8=
52
github.com/JackMordaunt/icns v1.0.0/go.mod h1:ubRqphS0f2OD07BuNaQSuw9uHUVQNBX5g38n6i2bdqM=
63
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9 h1:1ltqoej5GtaWF8jaiA49HwsZD459jqm9YFz9ZtMFpQA=
74
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9/go.mod h1:7uhhqiBaR4CpN0k9rMjOtjpcfGd6DG2m04zQxKnWQ0I=
8-
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
95
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
10-
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
11-
github.com/daaku/go.zipexe v1.0.1 h1:wV4zMsDOI2SZ2m7Tdz1Ps96Zrx+TzaK15VbUaGozw0M=
12-
github.com/daaku/go.zipexe v1.0.1/go.mod h1:5xWogtqlYnfBXkSB1o9xysukNP9GTvaNkqzUZbt3Bw8=
136
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
147
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
158
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -25,12 +18,10 @@ github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mO
2518
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
2619
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
2720
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
28-
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
2921
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
3022
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
3123
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
3224
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
33-
github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc=
3425
github.com/otiai10/copy v1.7.0 h1:hVoPiN+t+7d2nzzwMiDHPSOogsWAStewq3TwU05+clE=
3526
github.com/otiai10/copy v1.7.0/go.mod h1:rmRl6QPdJj6EiUqXQ/4Nn2lLXoNQjFCQbbNrxgc/t3U=
3627
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
@@ -54,8 +45,6 @@ github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PK
5445
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
5546
github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e h1:IWllFTiDjjLIf2oeKxpIUmtiDV5sn71VgeQgg6vcE7k=
5647
github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e/go.mod h1:d7u6HkTYKSv5m6MCKkOQlHwaShTMl3HjqSGW3XtVhXM=
57-
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
58-
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
5948
golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
6049
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
6150
golang.org/x/net v0.0.0-20220708220712-1185a9018129 h1:vucSRfWwTsoXro7P+3Cjlr6flUMtzCwzlvkxEQtHHB0=

internal/fileutils/assets.go

-28
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

internal/fileutils/embed.go

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package fileutils
2+
3+
import "embed"
4+
5+
//go:embed assets
6+
var assets embed.FS

internal/fileutils/file.go

+8-17
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"strings"
1212
"text/template"
1313

14-
rice "github.com/GeertJohan/go.rice"
15-
1614
"github.com/go-flutter-desktop/hover/internal/log"
1715
)
1816

@@ -214,31 +212,24 @@ func ExecuteTemplateFromFile(boxed, to string, templateData interface{}) {
214212
executeTemplateFromString(string(templateString), to, templateData)
215213
}
216214

217-
// ExecuteTemplateFromAssetsBox create file from a template asset
218-
func ExecuteTemplateFromAssetsBox(boxed, to string, assetsBox *rice.Box, templateData interface{}) {
219-
templateString, err := assetsBox.String(boxed)
215+
// ExecuteTemplateFromAssets create file from a template asset
216+
func ExecuteTemplateFromAssets(name, to string, templateData interface{}) {
217+
data, err := assets.ReadFile(fmt.Sprintf("assets/%s", name))
220218
if err != nil {
221219
log.Errorf("Failed to find template file: %v\n", err)
222220
os.Exit(1)
223221
}
224-
executeTemplateFromString(templateString, to, templateData)
222+
executeTemplateFromString(string(data), to, templateData)
225223
}
226224

227225
// CopyAsset copies a file from asset
228-
func CopyAsset(boxed, to string, assetsBox *rice.Box) {
229-
file, err := os.Create(to)
230-
if err != nil {
231-
log.Errorf("Failed to create %s: %v", to, err)
232-
os.Exit(1)
233-
}
234-
defer file.Close()
235-
boxedFile, err := assetsBox.Open(boxed)
226+
func CopyAsset(name, to string) {
227+
data, err := assets.ReadFile(fmt.Sprintf("assets/%s", name))
236228
if err != nil {
237-
log.Errorf("Failed to find boxed file %s: %v", boxed, err)
229+
log.Errorf("Failed to find asset file %s: %v", name, err)
238230
os.Exit(1)
239231
}
240-
defer boxedFile.Close()
241-
_, err = io.Copy(file, boxedFile)
232+
err = os.WriteFile(to, data, 0o600)
242233
if err != nil {
243234
log.Errorf("Failed to write file %s: %v", to, err)
244235
os.Exit(1)

0 commit comments

Comments
 (0)