build, cmd/strelaypoolsrv: Build assets using standard script
This commit is contained in:
parent
59370588dd
commit
ce9dc809bc
9
build.go
9
build.go
|
@ -563,16 +563,17 @@ func listFiles(dir string) []string {
|
||||||
|
|
||||||
func rebuildAssets() {
|
func rebuildAssets() {
|
||||||
runPipe("lib/auto/gui.files.go", "go", "run", "script/genassets.go", "gui")
|
runPipe("lib/auto/gui.files.go", "go", "run", "script/genassets.go", "gui")
|
||||||
|
runPipe("cmd/strelaypoolsrv/auto/gui.go", "go", "run", "script/genassets.go", "cmd/strelaypoolsrv/gui")
|
||||||
}
|
}
|
||||||
|
|
||||||
func lazyRebuildAssets() {
|
func lazyRebuildAssets() {
|
||||||
if shouldRebuildAssets() {
|
if shouldRebuildAssets("lib/auto/gui.files.go", "gui") || shouldRebuildAssets("cmd/strelaypoolsrv/auto/gui.go", "cmd/strelaypoolsrv/auto/gui") {
|
||||||
rebuildAssets()
|
rebuildAssets()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func shouldRebuildAssets() bool {
|
func shouldRebuildAssets(target, srcdir string) bool {
|
||||||
info, err := os.Stat("lib/auto/gui.files.go")
|
info, err := os.Stat(target)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If the file doesn't exist, we must rebuild it
|
// If the file doesn't exist, we must rebuild it
|
||||||
return true
|
return true
|
||||||
|
@ -582,7 +583,7 @@ func shouldRebuildAssets() bool {
|
||||||
// so we should rebuild it.
|
// so we should rebuild it.
|
||||||
currentBuild := info.ModTime()
|
currentBuild := info.ModTime()
|
||||||
assetsAreNewer := false
|
assetsAreNewer := false
|
||||||
filepath.Walk("gui", func(path string, info os.FileInfo, err error) error {
|
filepath.Walk(srcdir, func(path string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
gui.go
|
File diff suppressed because one or more lines are too long
|
@ -194,11 +194,6 @@ func handleAssets(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Header.Get("If-Modified-Since") == auto.AssetsBuildDate {
|
|
||||||
w.WriteHeader(http.StatusNotModified)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
mtype := mimeTypeForFile(path)
|
mtype := mimeTypeForFile(path)
|
||||||
if len(mtype) != 0 {
|
if len(mtype) != 0 {
|
||||||
w.Header().Set("Content-Type", mtype)
|
w.Header().Set("Content-Type", mtype)
|
||||||
|
@ -214,8 +209,6 @@ func handleAssets(w http.ResponseWriter, r *http.Request) {
|
||||||
gr.Close()
|
gr.Close()
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(bs)))
|
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(bs)))
|
||||||
w.Header().Set("Last-Modified", auto.AssetsBuildDate)
|
|
||||||
w.Header().Set("Cache-Control", "public")
|
|
||||||
|
|
||||||
w.Write(bs)
|
w.Write(bs)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue