github.com/dahs81/otto@v0.2.1-0.20160126165905-6400716cf085/builtin/app/scriptpack/data/common/rebuild/rebuild.go.tpl (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"encoding/json"
     6  	"log"
     7  	"io/ioutil"
     8  	"os"
     9  	"path/filepath"
    10  
    11  	sp "{{ working_gopath }}"
    12  )
    13  
    14  const(
    15  	scriptpackDir = "_scriptpack_staging"
    16  )
    17  
    18  func main() {
    19  	// Logs don't matter for this since it should always work. If it
    20  	// doesn't, it will show up in the error output.
    21  	log.SetOutput(ioutil.Discard)
    22  
    23  	path := filepath.Join("{{ path.working }}", scriptpackDir)
    24  	if err := os.RemoveAll(path); err !=nil {
    25  		fmt.Fprintf(os.Stderr, err.Error()+"\n")
    26  		os.Exit(1)
    27  	}
    28  
    29  	if err := os.MkdirAll(path, 0755); err != nil {
    30  		fmt.Fprintf(os.Stderr, err.Error()+"\n")
    31  		os.Exit(1)
    32  	}
    33  
    34  	// Write the actual ScriptPack data
    35  	if err := sp.ScriptPack.Write(path); err !=nil {
    36  		fmt.Fprintf(os.Stderr, err.Error()+"\n")
    37  		os.Exit(1)
    38  	}
    39  
    40  	// Write the ScriptPack env vars
    41  	envPath := filepath.Join(path, "env")
    42  	output, err := json.MarshalIndent(
    43  		sp.ScriptPack.Env("/devroot/"+scriptpackDir), "", "\t")
    44  	if err != nil {
    45  		fmt.Fprintf(os.Stderr, err.Error()+"\n")
    46  		os.Exit(1)
    47  	}
    48  	if err := ioutil.WriteFile(envPath, output, 0644); err != nil {
    49  		fmt.Fprintf(os.Stderr, err.Error()+"\n")
    50  		os.Exit(1)
    51  	}
    52  }