Skip to content

Instantly share code, notes, and snippets.

@kjintroverted
Last active May 10, 2019 14:07
Show Gist options
  • Save kjintroverted/8113a98ca5861324692da8935d08a460 to your computer and use it in GitHub Desktop.
Save kjintroverted/8113a98ca5861324692da8935d08a460 to your computer and use it in GitHub Desktop.
Quick deploy script
package main
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
)
func main() {
var domain string
// GET DOMAIN FROM CNAME
if raw, err := ioutil.ReadFile("CNAME"); err == nil {
domain = string(raw)
}
// OVERRIDE WITH DOMAIN ARG IF PROVIDED
if len(os.Args) > 1 {
domain = os.Args[1]
}
createCNAME(domain)
fmt.Println("Running build.")
if err := exec.Command("npm", "run", "build").Run(); err != nil {
panic(err)
}
fmt.Println("Deploying to", domain)
if err := exec.Command("surge", "./build", domain).Run(); err != nil {
panic(err)
}
}
func createCNAME(domain string) {
os.Remove("CNAME")
f, _ := os.Create("CNAME")
defer f.Close()
f.WriteString(domain)
f.Sync()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment