change build web

This commit is contained in:
YouROK
2021-04-27 12:09:19 +03:00
parent d71d998be3
commit 5889c2d143
2 changed files with 8 additions and 66 deletions

View File

@@ -14,16 +14,20 @@ GOBIN="/usr/local/go/bin/go"
$GOBIN version
$GOBIN run build_web.go
LDFLAGS="'-s -w'"
FAILURES=""
ROOT=${PWD}
OUTPUT="${ROOT}/dist/TorrServer"
cd "${ROOT}/server"
#### Build web
echo "Build web"
cd "${ROOT}/web"
npm run --silent build-js
cp ${ROOT}/web/dest/index.html ${ROOT}/server/web/pages/template/pages/
$GOBIN clean -i -r -cache --modcache
echo "Build server"
cd "${ROOT}/server"
$GOBIN clean -i -r -cache #--modcache
$GOBIN mod tidy
BUILD_FLAGS="-ldflags=${LDFLAGS}"

View File

@@ -1,62 +0,0 @@
package main
import (
"os"
"os/exec"
"path"
"path/filepath"
"strings"
)
func main() {
dir, _ := os.Getwd()
os.Chdir("web")
run("npm", "run", "build-js")
os.Chdir(dir)
run("cp", "web/dest/index.html", "server/web/pages/template/pages/")
// compileHtml := "web/dest/"
// fs, _ := ioutil.ReadDir(compileHtml)
// for _, f := range fs {
// if strings.HasSuffix(f.Name(), ".html") {
// name := filenameWithoutExtension(f.Name())
// fmt.Println("Create template go:", "server/web/pages/template/"+name+"_html.go")
// out, err := os.Create("server/web/pages/template/" + name + "_html.go")
// if err != nil {
// fmt.Println("Error create file", err)
// os.Exit(1)
// return
// }
//
// fmt.Println("Read html:", compileHtml+f.Name())
// buf, err := ioutil.ReadFile(compileHtml + f.Name())
// if err != nil {
// fmt.Println("Error read file", err)
// os.Exit(1)
// return
// }
// fmt.Println("Write template...")
// out.Write([]byte("package template \n\nvar " + strings.Title(name) + "Html = []byte{"))
// for _, b := range buf {
// out.Write([]byte(strconv.Itoa(int(b)) + ", "))
// }
// out.Write([]byte("}"))
// out.Close()
//
// fmt.Println("go fmt template...")
// run("go", "fmt", "server/web/pages/template/"+name+"_html.go")
// fmt.Println("Complete OK")
// }
// }
}
func run(name string, args ...string) {
cmd := exec.Command(name, args...)
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
cmd.Run()
}
func filenameWithoutExtension(fn string) string {
return strings.TrimSuffix(filepath.Base(fn), path.Ext(fn))
}