github.com/bosssauce/ponzu@v0.11.1-0.20200102001432-9bc41b703131/cmd/ponzu/build.go (about)

     1  package main
     2  
     3  import (
     4  	"path/filepath"
     5  	"strings"
     6  
     7  	"github.com/spf13/cobra"
     8  )
     9  
    10  func buildPonzuServer() error {
    11  	// copy all ./content files to internal vendor directory
    12  	src := "content"
    13  	dst := filepath.Join("cmd", "ponzu", "vendor", "github.com", "ponzu-cms", "ponzu", "content")
    14  	err := emptyDir(dst)
    15  	if err != nil {
    16  		return err
    17  	}
    18  	err = copyFilesWarnConflicts(src, dst, []string{"doc.go"})
    19  	if err != nil {
    20  		return err
    21  	}
    22  
    23  	// copy all ./addons files & dirs to internal vendor directory
    24  	src = "addons"
    25  	dst = filepath.Join("cmd", "ponzu", "vendor")
    26  	err = copyFilesWarnConflicts(src, dst, nil)
    27  	if err != nil {
    28  		return err
    29  	}
    30  
    31  	// execute go build -o ponzu-cms cmd/ponzu/*.go
    32  	cmdPackageName := strings.Join([]string{".", "cmd", "ponzu"}, "/")
    33  	buildOptions := []string{"build", "-o", buildOutputName(), cmdPackageName}
    34  	return execAndWait(gocmd, buildOptions...)
    35  }
    36  
    37  var buildCmd = &cobra.Command{
    38  	Use:   "build [flags]",
    39  	Short: "build will build/compile the project to then be run.",
    40  	Long: `From within your Ponzu project directory, running build will copy and move
    41  the necessary files from your workspace into the vendored directory, and
    42  will build/compile the project to then be run.
    43  
    44  By providing the 'gocmd' flag, you can specify which Go command to build the
    45  project, if testing a different release of Go.
    46  
    47  Errors will be reported, but successful build commands return nothing.`,
    48  	Example: `$ ponzu build
    49  (or)
    50  $ ponzu build --gocmd=go1.8rc1`,
    51  	RunE: func(cmd *cobra.Command, args []string) error {
    52  		return buildPonzuServer()
    53  	},
    54  }
    55  
    56  func init() {
    57  	RegisterCmdlineCommand(buildCmd)
    58  }