Make application/controller/static.go the source code generate trigger instead of application/controller/static_pages.go

This commit is contained in:
NI
2020-07-18 18:33:48 +08:00
parent 6c7652ae30
commit 13542949c2
3 changed files with 27 additions and 183 deletions

View File

@@ -18,7 +18,6 @@
package main
import (
"bufio"
"bytes"
"compress/gzip"
"crypto/sha256"
@@ -40,6 +39,27 @@ const (
)
const (
staticListHeader = `// Sshwifty - A Web SSH client
//
// Copyright (C) 2019-2020 Rui NI <nirui@gmx.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package controller
`
staticListTemplate = `import "time"
var (
@@ -413,7 +433,7 @@ func main() {
destFolderPath, destFolderPathErr))
}
listFile, listFileErr := os.OpenFile(listFilePath, os.O_RDWR, 0666)
listFile, listFileErr := os.Create(listFilePath)
if listFileErr != nil {
panic(fmt.Sprintf("Unable to open destination list file %s: %s",
@@ -428,29 +448,7 @@ func main() {
panic(fmt.Sprintf("Unable to open dir: %s", dirOpenErr))
}
scanner := bufio.NewScanner(listFile)
destBytesByPass := int64(0)
foundLastLine := false
for scanner.Scan() {
text := scanner.Text()
if strings.Index(text, templateStarts) < 0 {
if foundLastLine {
break
}
destBytesByPass += int64(len(text) + 1)
continue
}
destBytesByPass += int64(len(text) + 1)
foundLastLine = true
}
listFile.Seek(destBytesByPass, 0)
listFile.Truncate(destBytesByPass)
listFile.WriteString(staticListHeader)
listFile.WriteString("\n// This file is generated by `go generate` at " +
time.Now().Format(time.RFC1123) + "\n// DO NOT EDIT!\n\n")
@@ -516,7 +514,7 @@ func main() {
}
listFile.WriteString(
"\nimport \"" + parentPackage + "/" + destFolderPackage + "\"\n\n")
"\nimport \"" + parentPackage + "/" + destFolderPackage + "\"\n")
tempBuildErr := buildListFile(listFile, parsedFiles)