这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ install:
- chmod +x $GOPATH/src/bosun.org/build/validate.sh
- go get golang.org/x/tools/cmd/vet
- go get github.com/captncraig/setStatus
- npm i -g typescript
- npm i -g typescript@1.5.3

script: $GOPATH/src/bosun.org/build/validate.sh
51 changes: 49 additions & 2 deletions cmd/bosun/web/embed.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package web

import (
"bufio"
"bytes"
"io"
"log"
"os"
Expand All @@ -14,19 +16,34 @@ import (

// Run esc to embed entire static directory into static.go
func RunEsc() {
run("esc", "-o", "web/static.go", "-pkg", "web", "-prefix", "web/static", "web/static")
run("esc", "-modtime", "0", "-o", "web/static.go", "-pkg", "web", "-prefix", "web/static", "web/static")
}

// Run tsc to compile all ts files into bosun.js
func RunTsc() {
base := filepath.Join("web", "static", "js")
tmp := filepath.Join(base, "bosun-new.js")
dst := filepath.Join(base, "bosun.js")
args := []string{
"--out", filepath.Join(base, "bosun.js"),
"--out", tmp,
}
matches, _ := filepath.Glob(filepath.Join(base, "*.ts"))
sort.Strings(matches)
args = append(args, matches...)
run("tsc", args...)
if _, err := os.Stat(dst); os.IsNotExist(err) {
overwriteFile(tmp, dst)
} else {
if deepCompareDifferent(tmp, dst) {
overwriteFile(tmp, dst)
} else {
err := os.Remove(tmp)
if err != nil {
log.Println(err)
return
}
}
}
}

func run(name string, arg ...string) {
Expand All @@ -50,3 +67,33 @@ func run(name string, arg ...string) {
}
log.Println("run complete:", name)
}

func deepCompareDifferent(file1, file2 string) bool {
sf, err := os.Open(file1)
if err != nil {
log.Fatal(err)
}
df, err := os.Open(file2)
if err != nil {
log.Fatal(err)
}
defer sf.Close()
defer df.Close()
sscan := bufio.NewScanner(sf)
dscan := bufio.NewScanner(df)
for sscan.Scan() {
dscan.Scan()
if !bytes.Equal(sscan.Bytes(), dscan.Bytes()) {
return true
}
}
return false
}

func overwriteFile(filesrc, filedst string) {
err := os.Rename(filesrc, filedst)
if err != nil {
log.Println(err)
return
}
}
Loading