Last active
May 10, 2019 14:07
-
-
Save kjintroverted/8113a98ca5861324692da8935d08a460 to your computer and use it in GitHub Desktop.
Quick deploy script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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