github.com/pojntfx/hydrapp/hydrapp@v0.0.0-20240516002902-d08759d6ca9f/pkg/renderers/flatpak/manifest.go (about)

     1  package flatpak
     2  
     3  import (
     4  	_ "embed"
     5  	"path"
     6  	"strings"
     7  
     8  	"github.com/pojntfx/hydrapp/hydrapp/pkg/renderers"
     9  )
    10  
    11  //go:embed manifest.yaml
    12  var manifestTemplate string
    13  
    14  type manifestData struct {
    15  	AppID      string
    16  	GoMain     string
    17  	GoFlags    string
    18  	GoGenerate string
    19  	SrcDir     string
    20  }
    21  
    22  func NewManifestRenderer(
    23  	appID string,
    24  	goMain string,
    25  	goFlags string,
    26  	goGenerate string,
    27  ) renderers.Renderer {
    28  	srcDir := "."
    29  	if goMain != "." {
    30  		goMainComponents := strings.Split(goMain, "/") // We use the UNIX file separator here since Go uses UNIX-style paths for module names
    31  
    32  		for i := range goMainComponents {
    33  			if i > 0 { // `goMain` always starts with "./", so skip the first folder
    34  				srcDir = path.Join(srcDir, "..")
    35  			}
    36  		}
    37  	}
    38  
    39  	return renderers.NewRenderer(
    40  		appID+".yaml",
    41  		manifestTemplate,
    42  		manifestData{appID, goMain, goFlags, goGenerate, srcDir},
    43  	)
    44  }