diff --git a/cmd/gon/main.go b/cmd/gon/main.go index fb2bf26..2cf29c4 100644 --- a/cmd/gon/main.go +++ b/cmd/gon/main.go @@ -231,10 +231,15 @@ func realMain() int { color.New(color.Bold).Fprintf(os.Stdout, "==> %s Creating dmg...\n", iconPackage) color.New().Fprintf(os.Stdout, " This will open Finder windows momentarily.\n") err = dmg.Dmg(context.Background(), &dmg.Options{ - Files: cfg.Source, - OutputPath: cfg.Dmg.OutputPath, - VolumeName: cfg.Dmg.VolumeName, - Logger: logger.Named("dmg"), + Files: cfg.Source, + OutputPath: cfg.Dmg.OutputPath, + VolumeName: cfg.Dmg.VolumeName, + WindowPos: cfg.Dmg.WindowPos, + WindowSize: cfg.Dmg.WindowSize, + IconSize: cfg.Dmg.IconSize, + Icon: cfg.Dmg.Icon, + AppDropLink: cfg.Dmg.AppDropLink, + Logger: logger.Named("dmg"), }) if err != nil { fmt.Fprintf(os.Stdout, color.RedString("❗️ Error creating dmg:\n\n%s\n", err)) diff --git a/internal/config/config.go b/internal/config/config.go index 9c6f7e5..5059329 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -77,6 +77,21 @@ type Dmg struct { // Volume name is the name of the volume that shows up in the title // and sidebar after opening it. VolumeName string `hcl:"volume_name"` + + // Set position the folder window + WindowPos []string `hcl:"window_pos,optional"` + + // Set size of the folder window + WindowSize []string `hcl:"window_size,optional"` + + // Set window icons size + IconSize string `hcl:"icon_size,optional"` + + // Set position of the file's icon + Icon []string `hcl:"icon,optional"` + + // make a drop link to Applications, at location x, y + AppDropLink []string `hcl:"app_drop_link,optional"` } // Zip are the options for a zip file as output. diff --git a/internal/createdmg/bindata/bindata.go b/internal/createdmg/bindata/bindata.go index 3a46179..42aa8a6 100644 --- a/internal/createdmg/bindata/bindata.go +++ b/internal/createdmg/bindata/bindata.go @@ -1,20 +1,22 @@ -// Code generated for package bindata by go-bindata DO NOT EDIT. (@generated) +// Code generated by go-bindata. DO NOT EDIT. // sources: -// ../../../vendor/create-dmg/LICENSE -// ../../../vendor/create-dmg/Makefile -// ../../../vendor/create-dmg/README.md -// ../../../vendor/create-dmg/builder/create-dmg.builder -// ../../../vendor/create-dmg/create-dmg -// ../../../vendor/create-dmg/doc-project/Developer Notes.md -// ../../../vendor/create-dmg/doc-project/Release Checklist.md -// ../../../vendor/create-dmg/support/eula-resources-template.xml -// ../../../vendor/create-dmg/support/template.applescript -// ../../../vendor/create-dmg/.this-is-the-create-dmg-repo +// ../../../vendor/create-dmg/LICENSE (1.12kB) +// ../../../vendor/create-dmg/Makefile (885B) +// ../../../vendor/create-dmg/README.md (5.923kB) +// ../../../vendor/create-dmg/builder/create-dmg.builder (516B) +// ../../../vendor/create-dmg/create-dmg (18.411kB) +// ../../../vendor/create-dmg/doc-project/Developer Notes.md (1.412kB) +// ../../../vendor/create-dmg/doc-project/Release Checklist.md (325B) +// ../../../vendor/create-dmg/support/eula-resources-template.xml (2.372kB) +// ../../../vendor/create-dmg/support/template.applescript (1.828kB) +// ../../../vendor/create-dmg/.this-is-the-create-dmg-repo (128B) + package bindata import ( "bytes" "compress/gzip" + "crypto/sha256" "fmt" "io" "io/ioutil" @@ -27,7 +29,7 @@ import ( func bindataRead(data []byte, name string) ([]byte, error) { gz, err := gzip.NewReader(bytes.NewBuffer(data)) if err != nil { - return nil, fmt.Errorf("Read %q: %v", name, err) + return nil, fmt.Errorf("read %q: %v", name, err) } var buf bytes.Buffer @@ -35,7 +37,7 @@ func bindataRead(data []byte, name string) ([]byte, error) { clErr := gz.Close() if err != nil { - return nil, fmt.Errorf("Read %q: %v", name, err) + return nil, fmt.Errorf("read %q: %v", name, err) } if clErr != nil { return nil, err @@ -45,8 +47,9 @@ func bindataRead(data []byte, name string) ([]byte, error) { } type asset struct { - bytes []byte - info os.FileInfo + bytes []byte + info os.FileInfo + digest [sha256.Size]byte } type bindataFileInfo struct { @@ -56,32 +59,21 @@ type bindataFileInfo struct { modTime time.Time } -// Name return file name func (fi bindataFileInfo) Name() string { return fi.name } - -// Size return file size func (fi bindataFileInfo) Size() int64 { return fi.size } - -// Mode return file mode func (fi bindataFileInfo) Mode() os.FileMode { return fi.mode } - -// Mode return file modify time func (fi bindataFileInfo) ModTime() time.Time { return fi.modTime } - -// IsDir return file whether a directory func (fi bindataFileInfo) IsDir() bool { - return fi.mode&os.ModeDir != 0 + return false } - -// Sys return file is sys mode func (fi bindataFileInfo) Sys() interface{} { return nil } @@ -101,8 +93,8 @@ func license() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "LICENSE", size: 1120, mode: os.FileMode(420), modTime: time.Unix(1708947063, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "LICENSE", size: 1120, mode: os.FileMode(0644), modTime: time.Unix(1712862222, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x4b, 0xdb, 0x61, 0xf5, 0xfa, 0xc6, 0x9f, 0xd5, 0xcc, 0x3, 0x8, 0x53, 0x5f, 0xec, 0xbc, 0x4f, 0x22, 0xbb, 0x75, 0xa3, 0xe6, 0x15, 0xad, 0xbd, 0x5d, 0x73, 0x92, 0x37, 0x2f, 0xa, 0xc, 0xc3}} return a, nil } @@ -121,8 +113,8 @@ func makefile() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "Makefile", size: 885, mode: os.FileMode(420), modTime: time.Unix(1708947063, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "Makefile", size: 885, mode: os.FileMode(0644), modTime: time.Unix(1712862222, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xbd, 0xa7, 0xad, 0x61, 0x3, 0x5f, 0x45, 0xc6, 0x5c, 0x12, 0xeb, 0x9, 0xd0, 0x57, 0xac, 0x2e, 0xb2, 0xf3, 0x72, 0x3, 0x2d, 0xb5, 0x3f, 0xa8, 0xab, 0xcf, 0xb, 0x95, 0x6d, 0x3a, 0xca, 0xa8}} return a, nil } @@ -141,8 +133,8 @@ func readmeMd() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "README.md", size: 5923, mode: os.FileMode(420), modTime: time.Unix(1708947063, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "README.md", size: 5923, mode: os.FileMode(0644), modTime: time.Unix(1712862222, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xa5, 0x42, 0xf1, 0x6b, 0x75, 0x74, 0xe3, 0x57, 0x6a, 0xc1, 0x8, 0xe9, 0xd9, 0xbe, 0xae, 0x13, 0xc1, 0x0, 0x39, 0x6c, 0xf6, 0xe0, 0xbb, 0x8, 0x3, 0xe9, 0x4b, 0x45, 0xe, 0xdc, 0x95, 0xb2}} return a, nil } @@ -161,8 +153,8 @@ func builderCreateDmgBuilder() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "builder/create-dmg.builder", size: 516, mode: os.FileMode(420), modTime: time.Unix(1708947063, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "builder/create-dmg.builder", size: 516, mode: os.FileMode(0644), modTime: time.Unix(1711436763, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x45, 0x19, 0x22, 0x65, 0xf3, 0x99, 0x89, 0x73, 0x97, 0xd7, 0xcb, 0x8f, 0x52, 0xdf, 0x52, 0x7f, 0x54, 0x38, 0x3f, 0xee, 0x5f, 0xfc, 0xda, 0x21, 0x63, 0x94, 0xf9, 0x7, 0xd3, 0x15, 0x6d, 0x60}} return a, nil } @@ -181,8 +173,8 @@ func createDmg() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "create-dmg", size: 18411, mode: os.FileMode(493), modTime: time.Unix(1708947063, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "create-dmg", size: 18411, mode: os.FileMode(0755), modTime: time.Unix(1712862222, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x68, 0x28, 0xb9, 0xd, 0x86, 0x9c, 0xb4, 0x5f, 0x76, 0x5f, 0x84, 0x25, 0x34, 0xc3, 0xe1, 0xce, 0x32, 0x6f, 0xb2, 0xb7, 0x3d, 0xd6, 0x81, 0x13, 0x1a, 0xf0, 0xb3, 0xb1, 0x3f, 0xc3, 0x16, 0x23}} return a, nil } @@ -201,8 +193,8 @@ func docProjectDeveloperNotesMd() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "doc-project/Developer Notes.md", size: 1412, mode: os.FileMode(420), modTime: time.Unix(1708947063, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "doc-project/Developer Notes.md", size: 1412, mode: os.FileMode(0644), modTime: time.Unix(1712862222, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x6b, 0xce, 0x4, 0xaf, 0xe6, 0x3d, 0x60, 0x12, 0x7c, 0x46, 0x19, 0x81, 0x96, 0x2d, 0xa8, 0x25, 0xf3, 0x79, 0x1b, 0x5f, 0xbb, 0x73, 0x1c, 0xa3, 0xda, 0x4b, 0xed, 0x49, 0xcc, 0xfb, 0x8f, 0x9a}} return a, nil } @@ -221,8 +213,8 @@ func docProjectReleaseChecklistMd() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "doc-project/Release Checklist.md", size: 325, mode: os.FileMode(420), modTime: time.Unix(1708947063, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "doc-project/Release Checklist.md", size: 325, mode: os.FileMode(0644), modTime: time.Unix(1712862222, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x9c, 0x6a, 0x79, 0x7f, 0xa5, 0x52, 0x70, 0x39, 0xce, 0xeb, 0x4a, 0x97, 0x33, 0x8e, 0xda, 0xd2, 0x9a, 0x3d, 0xd4, 0xf7, 0x99, 0x4e, 0x48, 0x4, 0xd2, 0xb8, 0x4e, 0x99, 0x71, 0x86, 0xa5, 0xd5}} return a, nil } @@ -241,8 +233,8 @@ func supportEulaResourcesTemplateXml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "support/eula-resources-template.xml", size: 2372, mode: os.FileMode(420), modTime: time.Unix(1708947063, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "support/eula-resources-template.xml", size: 2372, mode: os.FileMode(0644), modTime: time.Unix(1712862222, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xa8, 0x4, 0xe5, 0x33, 0xe9, 0xc9, 0x94, 0x91, 0xa7, 0x4c, 0xb4, 0x50, 0x2c, 0x43, 0x5b, 0x0, 0xd9, 0x2, 0xdc, 0x7a, 0x45, 0xd3, 0x69, 0x30, 0x57, 0xa2, 0x96, 0x74, 0xe5, 0x84, 0xa7, 0xb}} return a, nil } @@ -261,8 +253,8 @@ func supportTemplateApplescript() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "support/template.applescript", size: 1828, mode: os.FileMode(420), modTime: time.Unix(1708947063, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "support/template.applescript", size: 1828, mode: os.FileMode(0644), modTime: time.Unix(1711436763, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x13, 0x72, 0x7c, 0x79, 0x30, 0xc5, 0xb, 0xe6, 0x39, 0xa1, 0xeb, 0x19, 0x1e, 0x89, 0x3f, 0x1e, 0xbc, 0x72, 0xc2, 0x70, 0x26, 0x8d, 0x46, 0x11, 0x39, 0x1b, 0x41, 0x41, 0xa, 0x3e, 0x86, 0x2a}} return a, nil } @@ -281,8 +273,8 @@ func ThisIsTheCreateDmgRepo() (*asset, error) { return nil, err } - info := bindataFileInfo{name: ".this-is-the-create-dmg-repo", size: 128, mode: os.FileMode(420), modTime: time.Unix(1708947063, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: ".this-is-the-create-dmg-repo", size: 128, mode: os.FileMode(0644), modTime: time.Unix(1712862222, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xfb, 0x24, 0x94, 0xeb, 0x10, 0x14, 0x6a, 0x84, 0xbb, 0xb2, 0xe, 0xbb, 0x19, 0x8c, 0x2a, 0x9, 0xfb, 0x72, 0xae, 0xd1, 0x19, 0x70, 0x6d, 0xc5, 0x5b, 0x6e, 0xc3, 0x64, 0x40, 0x18, 0x38, 0x3f}} return a, nil } @@ -290,8 +282,8 @@ func ThisIsTheCreateDmgRepo() (*asset, error) { // It returns an error if the asset could not be found or // could not be loaded. func Asset(name string) ([]byte, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { + canonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[canonicalName]; ok { a, err := f() if err != nil { return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err) @@ -301,6 +293,12 @@ func Asset(name string) ([]byte, error) { return nil, fmt.Errorf("Asset %s not found", name) } +// AssetString returns the asset contents as a string (instead of a []byte). +func AssetString(name string) (string, error) { + data, err := Asset(name) + return string(data), err +} + // MustAsset is like Asset but panics when Asset would return an error. // It simplifies safe initialization of global variables. func MustAsset(name string) []byte { @@ -312,12 +310,18 @@ func MustAsset(name string) []byte { return a } +// MustAssetString is like AssetString but panics when Asset would return an +// error. It simplifies safe initialization of global variables. +func MustAssetString(name string) string { + return string(MustAsset(name)) +} + // AssetInfo loads and returns the asset info for the given name. // It returns an error if the asset could not be found or // could not be loaded. func AssetInfo(name string) (os.FileInfo, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { + canonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[canonicalName]; ok { a, err := f() if err != nil { return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err) @@ -327,6 +331,33 @@ func AssetInfo(name string) (os.FileInfo, error) { return nil, fmt.Errorf("AssetInfo %s not found", name) } +// AssetDigest returns the digest of the file with the given name. It returns an +// error if the asset could not be found or the digest could not be loaded. +func AssetDigest(name string) ([sha256.Size]byte, error) { + canonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[canonicalName]; ok { + a, err := f() + if err != nil { + return [sha256.Size]byte{}, fmt.Errorf("AssetDigest %s can't read by error: %v", name, err) + } + return a.digest, nil + } + return [sha256.Size]byte{}, fmt.Errorf("AssetDigest %s not found", name) +} + +// Digests returns a map of all known files and their checksums. +func Digests() (map[string][sha256.Size]byte, error) { + mp := make(map[string][sha256.Size]byte, len(_bindata)) + for name := range _bindata { + a, err := _bindata[name]() + if err != nil { + return nil, err + } + mp[name] = a.digest + } + return mp, nil +} + // AssetNames returns the names of the assets. func AssetNames() []string { names := make([]string, 0, len(_bindata)) @@ -338,16 +369,25 @@ func AssetNames() []string { // _bindata is a table, holding each asset generator, mapped to its name. var _bindata = map[string]func() (*asset, error){ - "LICENSE": license, - "Makefile": makefile, - "README.md": readmeMd, - "builder/create-dmg.builder": builderCreateDmgBuilder, - "create-dmg": createDmg, - "doc-project/Developer Notes.md": docProjectDeveloperNotesMd, - "doc-project/Release Checklist.md": docProjectReleaseChecklistMd, + "LICENSE": license, + + "Makefile": makefile, + + "README.md": readmeMd, + + "builder/create-dmg.builder": builderCreateDmgBuilder, + + "create-dmg": createDmg, + + "doc-project/Developer Notes.md": docProjectDeveloperNotesMd, + + "doc-project/Release Checklist.md": docProjectReleaseChecklistMd, + "support/eula-resources-template.xml": supportEulaResourcesTemplateXml, - "support/template.applescript": supportTemplateApplescript, - ".this-is-the-create-dmg-repo": ThisIsTheCreateDmgRepo, + + "support/template.applescript": supportTemplateApplescript, + + ".this-is-the-create-dmg-repo": ThisIsTheCreateDmgRepo, } // AssetDir returns the file names below a certain @@ -359,15 +399,15 @@ var _bindata = map[string]func() (*asset, error){ // img/ // a.png // b.png -// then AssetDir("data") would return []string{"foo.txt", "img"} -// AssetDir("data/img") would return []string{"a.png", "b.png"} -// AssetDir("foo.txt") and AssetDir("notexist") would return an error +// then AssetDir("data") would return []string{"foo.txt", "img"}, +// AssetDir("data/img") would return []string{"a.png", "b.png"}, +// AssetDir("foo.txt") and AssetDir("notexist") would return an error, and // AssetDir("") will return []string{"data"}. func AssetDir(name string) ([]string, error) { node := _bintree if len(name) != 0 { - cannonicalName := strings.Replace(name, "\\", "/", -1) - pathList := strings.Split(cannonicalName, "/") + canonicalName := strings.Replace(name, "\\", "/", -1) + pathList := strings.Split(canonicalName, "/") for _, p := range pathList { node = node.Children[p] if node == nil { @@ -409,7 +449,7 @@ var _bintree = &bintree{nil, map[string]*bintree{ }}, }} -// RestoreAsset restores an asset under the given directory +// RestoreAsset restores an asset under the given directory. func RestoreAsset(dir, name string) error { data, err := Asset(name) if err != nil { @@ -427,14 +467,10 @@ func RestoreAsset(dir, name string) error { if err != nil { return err } - err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) - if err != nil { - return err - } - return nil + return os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) } -// RestoreAssets restores an asset under the given directory recursively +// RestoreAssets restores an asset under the given directory recursively. func RestoreAssets(dir, name string) error { children, err := AssetDir(name) // File @@ -452,6 +488,6 @@ func RestoreAssets(dir, name string) error { } func _filePath(dir, name string) string { - cannonicalName := strings.Replace(name, "\\", "/", -1) - return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) + canonicalName := strings.Replace(name, "\\", "/", -1) + return filepath.Join(append([]string{dir}, strings.Split(canonicalName, "/")...)...) } diff --git a/package/dmg/dmg.go b/package/dmg/dmg.go index 078c089..2b7c9a8 100644 --- a/package/dmg/dmg.go +++ b/package/dmg/dmg.go @@ -49,6 +49,21 @@ type Options struct { // VolumeName is the name of the dmg volume when mounted. VolumeName string + // Set position the folder window + WindowPos []string + + // Set size of the folder window + WindowSize []string + + // Set window icons size + IconSize string + + // Set position of the file's icon + Icon []string + + // make a drop link to Applications, at location x, y + AppDropLink []string + // Logger is the logger to use. If this is nil then no logging will be done. Logger hclog.Logger @@ -92,6 +107,30 @@ func Dmg(ctx context.Context, opts *Options) error { args = append(args, "--add-file", filepath.Base(f), f, "0", "0") } + if opts.WindowPos != nil { + args = append(args, "--window-pos") + args = append(args, opts.WindowPos...) + } + + if opts.WindowSize != nil { + args = append(args, "--window-size") + args = append(args, opts.WindowSize...) + } + + if opts.IconSize != "" { + args = append(args, "--icon-size", opts.IconSize) + } + + if opts.Icon != nil { + args = append(args, "--icon") + args = append(args, opts.Icon...) + } + + if opts.AppDropLink != nil { + args = append(args, "--app-drop-link") + args = append(args, opts.AppDropLink...) + } + // Set our root directory. If one wasn't specified, we create an empty // temporary directory to act as our root and we just use the flags to // inject our files.