Skip to content

Commit

Permalink
Doesn work with generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Abelson Sahlen authored and Martin Abelson Sahlen committed Mar 23, 2017
1 parent 5433d63 commit 33b3c2e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
3 changes: 1 addition & 2 deletions cmd.go
Expand Up @@ -27,8 +27,7 @@ func parseTemplate(templateString string, data interface{}) (string, error) {
return b.String(), nil
}

var buildSh = `GOOS=linux go build -o {{.TargetDir}}/{{.ExecutableName}}
cp index.js {{.TargetDir}}`
var buildSh = `GOOS=linux go build -o {{.TargetDir}}/{{.ExecutableName}}`
var deploySh = `gcloud beta functions deploy {{.FunctionName}} {{if .TriggerHTTP}}--trigger-http{{end}} --stage-bucket {{.StageBucket}} --local-path {{.TargetDir}}`
var httpJs = `const spawnSync = require('child_process').spawnSync;
Expand Down
57 changes: 34 additions & 23 deletions main.go
@@ -1,8 +1,8 @@
package main

import (
"io/ioutil"
"os"
"log"
"os/exec"

docopt "github.com/docopt/docopt-go"
)
Expand All @@ -11,11 +11,16 @@ func main() {
usage := `go-cloud-fn.
Usage:
go-cloud-fn init <function-name>
go-cloud-fn build <function-name>
go-cloud-fn build <function-name> --production
go-cloud-fn build <function-name> --development
go-cloud-fn deploy <function-name> <stage-bucket>
Options:
-h --help Show this screen.
--version Show version.`
-h --help Show this screen.
-p --production Deploy for production
-d --development Deploy for local development
--version Show version.`

arguments, err := docopt.Parse(usage, nil, true, "go-cloud-fn 0.0 Pre-Alpha", false)

Expand All @@ -25,6 +30,9 @@ Options:

functionName := arguments["<function-name>"].(string)

//build := arguments["build"].(bool)
//build := arguments["deploy"].(bool)

conf := config{
FunctionName: functionName,
TargetDir: "target",
Expand All @@ -37,26 +45,29 @@ Options:
buildOut, err := parseTemplate(buildSh, conf)
if err != nil {
panic(err)
}
} /*
httpOut, err := parseTemplate(httpJs, conf)
if err != nil {
panic(err)
}
httpOut, err := parseTemplate(httpJs, conf)
if err != nil {
panic(err)
}
deployOut, err := parseTemplate(deploySh, conf)
if err != nil {
panic(err)
}
err = ioutil.WriteFile("deploy.sh", []byte(deployOut), os.ModePerm)
if err != nil {
panic(err)
}
err = ioutil.WriteFile("build.sh", []byte(buildOut), os.ModePerm)
if err != nil {
panic(err)
}
err = ioutil.WriteFile("index.js", []byte(httpOut), os.ModePerm)
deployOut, err := parseTemplate(deploySh, conf)
if err != nil {
panic(err)
}*/
log.Println(buildOut)
out, err := exec.Command(buildOut).Output()
if err != nil {
panic(err)
}
log.Println(out)
/*
err = ioutil.WriteFile("build.sh", []byte(buildOut), os.ModePerm)
if err != nil {
panic(err)
}
err = ioutil.WriteFile(conf.TargetDir+"/index.js", []byte(httpOut), os.ModePerm)
if err != nil {
panic(err)
}*/
}
2 changes: 2 additions & 0 deletions shim/bucket.go
@@ -1 +1,3 @@
package shim

func HandleBucketEvent() {}

0 comments on commit 33b3c2e

Please sign in to comment.