add a way to add arbitrary plist contents
This commit is contained in:
@@ -13,12 +13,12 @@ Create a macOS Application from an executable (like a Go binary)
|
||||
To install `appify`:
|
||||
|
||||
```bash
|
||||
go get github.com/machinebox/appify
|
||||
go get git.yetaga.in/alazyreader/appify
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
```bash
|
||||
appify -name "My Go Application" -icon ./icon.png /path/to/bin
|
||||
```
|
||||
|
||||
|
13
main.go
13
main.go
@@ -29,6 +29,7 @@ func run() error {
|
||||
version = flag.String("version", "1.0", "app version")
|
||||
identifier = flag.String("id", "", "bundle identifier")
|
||||
icon = flag.String("icon", "", "icon image file (.icns|.png|.jpg|.jpeg)")
|
||||
extraPlist = flag.String("plist", "", "path to file with additional plist dict key/value items")
|
||||
)
|
||||
flag.Parse()
|
||||
args := flag.Args()
|
||||
@@ -70,6 +71,13 @@ func run() error {
|
||||
if id == "" {
|
||||
id = *author + "." + *name
|
||||
}
|
||||
if *extraPlist != "" {
|
||||
b, err := os.ReadFile(*extraPlist)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error reading plist location: "+*extraPlist)
|
||||
}
|
||||
*extraPlist = string(b)
|
||||
}
|
||||
info := infoListData{
|
||||
Name: *name,
|
||||
Executable: filepath.Join("MacOS", appname),
|
||||
@@ -77,6 +85,7 @@ func run() error {
|
||||
Version: *version,
|
||||
InfoString: *name + " by " + *author,
|
||||
ShortVersionString: *version,
|
||||
AdditionalPList: *extraPlist,
|
||||
}
|
||||
if *icon != "" {
|
||||
iconPath, err := prepareIcons(*icon, resouresPath)
|
||||
@@ -150,6 +159,7 @@ type infoListData struct {
|
||||
InfoString string
|
||||
ShortVersionString string
|
||||
IconFile string
|
||||
AdditionalPList string
|
||||
}
|
||||
|
||||
const infoPlistTemplate = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
@@ -176,6 +186,9 @@ const infoPlistTemplate = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>{{ .IconFile }}</string>
|
||||
{{- end }}
|
||||
{{- if .AdditionalPList -}}
|
||||
{{ .AdditionalPList -}}
|
||||
{{- end }}
|
||||
</dict>
|
||||
</plist>
|
||||
`
|
||||
|
39
main_test.go
39
main_test.go
@@ -51,6 +51,45 @@ func Test(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithPListInjection(t *testing.T) {
|
||||
is := is.New(t)
|
||||
out, err := exec.Command("./appify",
|
||||
"-name", "Test",
|
||||
"-icon", "testdata/machina-square.png",
|
||||
"-plist", "testdata/additionalplist.xml",
|
||||
"testdata/app").CombinedOutput()
|
||||
t.Logf("%q", string(out))
|
||||
is.NoErr(err)
|
||||
defer os.RemoveAll("Test.app")
|
||||
actualAppHash := filehash(t, "testdata/app")
|
||||
type file struct {
|
||||
path string
|
||||
perm string
|
||||
hash string
|
||||
}
|
||||
for _, f := range []file{
|
||||
{path: "Test.app", perm: "drwxr-xr-x"},
|
||||
{path: "Test.app/Contents", perm: "drwxr-xr-x"},
|
||||
{path: "Test.app/Contents/MacOS", perm: "drwxr-xr-x"},
|
||||
{path: "Test.app/Contents/MacOS/Test.app", perm: "-rwxr-xr-x", hash: actualAppHash},
|
||||
{path: "Test.app/Contents/Info.plist", perm: "-rw-r--r--", hash: "dd977257c7e77dc7739bb4ae70e5f697"},
|
||||
{path: "Test.app/Contents/README", perm: "-rw-r--r--", hash: "afeb10df47c7f189b848ae44a54e7e06"},
|
||||
{path: "Test.app/Contents/Resources", perm: "drwxr-xr-x"},
|
||||
{path: "Test.app/Contents/Resources/icon.icns", perm: "-rw-r--r--", hash: "23bdc36475094ed8886f319811d3a182"},
|
||||
} {
|
||||
t.Run(f.path, func(t *testing.T) {
|
||||
is := is.New(t)
|
||||
info, err := os.Stat(f.path)
|
||||
is.NoErr(err)
|
||||
is.Equal(info.Mode().String(), f.perm) // perm
|
||||
if f.hash != "" {
|
||||
actual := filehash(t, f.path)
|
||||
is.Equal(actual, f.hash) // hash
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// filehash gets an md5 hash of the file at path.
|
||||
func filehash(t *testing.T, path string) string {
|
||||
is := is.New(t)
|
||||
|
33
testdata/additionalplist.xml
vendored
Normal file
33
testdata/additionalplist.xml
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<key>CFBundleDocumentTypes</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>CFBundleTypeExtensions</key>
|
||||
<array>
|
||||
<string>jpg</string>
|
||||
<string>JPG</string>
|
||||
<string>jpeg</string>
|
||||
<string>JPEG</string>
|
||||
</array>
|
||||
<key>CFBundleTypeIconFile</key>
|
||||
<string>jpeg.icns</string>
|
||||
<key>CFBundleTypeMIMETypes</key>
|
||||
<array>
|
||||
<string>image/jpeg</string>
|
||||
</array>
|
||||
<key>CFBundleTypeName</key>
|
||||
<string>JPEG Image</string>
|
||||
<key>CFBundleTypeOSTypes</key>
|
||||
<array>
|
||||
<string>JPEG</string>
|
||||
<string>????</string>
|
||||
</array>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>Viewer</string>
|
||||
<key>LSItemContentTypes</key>
|
||||
<array>
|
||||
<string>public.jpeg</string>
|
||||
</array>
|
||||
<key>LSTypeIsPackage</key>
|
||||
<false/>
|
||||
</dict>
|
||||
</array>
|
Reference in New Issue
Block a user