mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
change script
This commit is contained in:
29
build_web.go
29
build_web.go
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@@ -11,32 +12,54 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
fs, _ := ioutil.ReadDir("web")
|
||||
dir, _ := os.Getwd()
|
||||
os.Chdir("web")
|
||||
run("npm", "run", "build-js")
|
||||
os.Chdir(dir)
|
||||
|
||||
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:", "src/server/web/pages/template/"+name+"_html.go")
|
||||
out, err := os.Create("src/server/web/pages/template/" + name + "_html.go")
|
||||
if err != nil {
|
||||
fmt.Println("Error create file", err)
|
||||
os.Exit(1)
|
||||
return
|
||||
}
|
||||
out.Write([]byte("package template \n\nvar " + strings.Title(name) + "Html = []byte{"))
|
||||
buf, err := ioutil.ReadFile("web/" + f.Name())
|
||||
|
||||
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", "src/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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user