fix(ci): sort lang json file

pull/2587/head
Noah Hsu 2022-12-05 14:39:18 +08:00
parent dc8d5106f9
commit bc6baf1be0
3 changed files with 8 additions and 10 deletions

View File

@ -8,6 +8,7 @@ on:
- 'drivers/**'
- 'internal/bootstrap/data/setting.go'
- 'internal/conf/const.go'
- 'cmd/lang.go'
workflow_dispatch:
jobs:
@ -43,14 +44,7 @@ jobs:
cd alist
go run ./main.go lang
cd ..
- name: Format lang file
run: |
for file in ./alist/lang/*.json
do
cp -f "$file" "$file.old" || :
jq --sort-keys . "$file.old" > "$file" || :
done
rm ./alist/lang/*.json.old
- name: Copy lang file
run: |
cp -f ./alist/lang/*.json ./alist-web/src/lang/en/ 2>/dev/null || :

View File

@ -71,7 +71,7 @@ func writeFile(name string, data interface{}) {
} else {
log.Infof("%s.json changed, update file", name)
//log.Infof("old: %+v\nnew:%+v", oldData, data)
utils.WriteJsonToFile(fmt.Sprintf("lang/%s.json", name), data)
utils.WriteJsonToFile(fmt.Sprintf("lang/%s.json", name), newData, true)
}
}

View File

@ -1,6 +1,7 @@
package utils
import (
stdjson "encoding/json"
"os"
json "github.com/json-iterator/go"
@ -10,8 +11,11 @@ import (
var Json = json.ConfigCompatibleWithStandardLibrary
// WriteJsonToFile write struct to json file
func WriteJsonToFile(dst string, data interface{}) bool {
func WriteJsonToFile(dst string, data interface{}, std ...bool) bool {
str, err := json.MarshalIndent(data, "", " ")
if len(std) > 0 && std[0] {
str, err = stdjson.MarshalIndent(data, "", " ")
}
if err != nil {
log.Errorf("failed convert Conf to []byte:%s", err.Error())
return false