diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/codegen.iml b/.idea/codegen.iml new file mode 100644 index 0000000..5e764c4 --- /dev/null +++ b/.idea/codegen.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/git_toolbox_blame.xml b/.idea/git_toolbox_blame.xml new file mode 100644 index 0000000..7dc1249 --- /dev/null +++ b/.idea/git_toolbox_blame.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..2457806 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/codegen/generate_i18n.go b/codegen/generate_i18n.go index 2d977e4..29c1b2a 100644 --- a/codegen/generate_i18n.go +++ b/codegen/generate_i18n.go @@ -4,6 +4,7 @@ import ( "github.com/lazygophers/codegen/state" "github.com/lazygophers/log" "github.com/lazygophers/utils/anyx" + "github.com/lazygophers/utils/candy" "github.com/lazygophers/utils/osx" "github.com/pterm/pterm" "io/fs" @@ -110,6 +111,13 @@ func GenerateI18nConst(dstLocalize map[string]any, path string) (err error) { deepKeys([]string{}, dstLocalize) + //sort + keys := make([]string, 0) + for k, _ := range localize { + keys = append(keys, k) + } + keys = candy.Sort(keys) + tpl, err := GetTemplate(TemplateTypeI18nConst) if err != nil { log.Errorf("err:%v", err) @@ -133,6 +141,7 @@ func GenerateI18nConst(dstLocalize map[string]any, path string) (err error) { "DirName": filepath.Base(filepath.Dir(path)), "Localize": localize, "DeepLocalize": dstLocalize, + "SortedKeys": keys, }) if err != nil { log.Errorf("err:%v", err) diff --git a/codegen/template/i18n_const.gtpl b/codegen/template/i18n_const.gtpl index c5ab299..c572298 100644 --- a/codegen/template/i18n_const.gtpl +++ b/codegen/template/i18n_const.gtpl @@ -1,5 +1,5 @@ package {{ .DirName }} -const ({{ range $key, $value := .Localize}} - I18nTag{{ ToCamel $key }} = `{{ $key }}`{{ end }} +const ({{ range $value := .SortedKeys}} + I18nTag{{ ToCamel $value }} = `{{ $value }}`{{ end }} ) diff --git a/debug.goreleaser.yaml b/debug.goreleaser.yaml new file mode 100644 index 0000000..0e88a8e --- /dev/null +++ b/debug.goreleaser.yaml @@ -0,0 +1,62 @@ +project_name: codegen +version: 2 +env: + - GO111MODULE=on + - GOSUMDB=sum.golang.google.cn + - CGO_ENABLED=0 + +builds: + - id: cli + binary: "{{ .ProjectName }}" + tags: + - debug + ldflags: + - -s -w + - --extldflags "-static -fpic" + - -X github.com/lazygophers/utils/app.Name={{ .ProjectName }} + - -X github.com/lazygophers/utils/app.Commit={{ .FullCommit }} + - -X github.com/lazygophers/utils/app.ShortCommit={{ .ShortCommit }} + - -X github.com/lazygophers/utils/app.Branch={{ .Branch }} + - -X github.com/lazygophers/utils/app.Version={{ .Version }} + - -X github.com/lazygophers/utils/app.Tag={{ .Tag }} + - -X github.com/lazygophers/utils/app.BuildDate={{ .Date }} + - -X github.com/lazygophers/utils/app.GoVersion={{ .Env.GOVERSION }} + - -X github.com/lazygophers/utils/app.GoOS={{ .Os }} + - -X github.com/lazygophers/utils/app.Goarch={{ .Arch }} + - -X github.com/lazygophers/utils/app.Goarm={{ .Arm }} + - -X github.com/lazygophers/utils/app.Goamd64={{ .Amd64 }} + - -X github.com/lazygophers/utils/app.Gomips={{ .Mips }} + gcflags: + - -N -l + main: ./cmd/ + targets: + - linux_amd64_v3 + - linux_arm64 + - windows_amd64 + - darwin_amd64_v3 + - darwin_arm64 + +archives: + - formats: tar.gz + name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}' + format_overrides: + - goos: windows + formats: zip + files: + - LICENSE + - README.md + - example.codegen.cfg.yaml + +#checksum: +# algorithm: sha512 +# name_template: '{{ .ProjectName }}_{{ .Version }}.sha512' + +source: + enabled: false + files: + - LICENSE + - README.md + - conf.example.yaml + - '*.go' + +report_sizes: true diff --git a/go.mod b/go.mod index 5beb1fa..51e12a6 100644 --- a/go.mod +++ b/go.mod @@ -7,9 +7,9 @@ require ( github.com/emicklei/proto v1.14.1 github.com/go-git/go-git/v5 v5.16.0 github.com/gookit/color v1.5.5-0.20240610061437-fedc17449eaf - github.com/lazygophers/log v0.0.0-20250409033028-0656cc92f9c3 - github.com/lazygophers/lrpc v0.0.0-20250420020031-b78cbbe23aaf - github.com/lazygophers/utils v0.0.0-20250430052029-57f0cb71ff66 + github.com/lazygophers/log v0.0.0-20250509113414-7f7294f75e89 + github.com/lazygophers/lrpc v0.0.0-20250430104923-8731b1b844d6 + github.com/lazygophers/utils v0.0.0-20250513102512-2a123236f271 github.com/pelletier/go-toml/v2 v2.2.4 github.com/pterm/pterm v0.12.80 github.com/spf13/cobra v1.9.1 @@ -49,7 +49,7 @@ require ( github.com/lestrrat-go/strftime v1.1.0 // indirect github.com/lithammer/fuzzysearch v1.1.8 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect - github.com/petermattis/goid v0.0.0-20250319124200-ccd6737f222a // indirect + github.com/petermattis/goid v0.0.0-20250508124226-395b08cebbdb // indirect github.com/pjbgf/sha1cd v0.3.2 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/rivo/uniseg v0.4.7 // indirect diff --git a/go.sum b/go.sum index c9239ae..5be129a 100644 --- a/go.sum +++ b/go.sum @@ -99,10 +99,16 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lazygophers/log v0.0.0-20250409033028-0656cc92f9c3 h1:AVJN7JSbMbGMz8fUUMKQUGkbBeGfAmXQP5OM+3524pc= github.com/lazygophers/log v0.0.0-20250409033028-0656cc92f9c3/go.mod h1:VAgZBW99hWCtU8di03N2znbFaAkPd8OBUkTwuDAaXrs= +github.com/lazygophers/log v0.0.0-20250509113414-7f7294f75e89 h1:a12LqG5jT0tGCCD59KLoEmEJ2rzQLkX8mR25FP2LJEM= +github.com/lazygophers/log v0.0.0-20250509113414-7f7294f75e89/go.mod h1:wunnxf+6ECN2bt8908dbXQmg7TG4W5wvvK/3mEUkKoI= github.com/lazygophers/lrpc v0.0.0-20250420020031-b78cbbe23aaf h1:5lQJTYRJzPBj2ltUBgaCOK/wDSgtNSpnOEZd6lKmNfE= github.com/lazygophers/lrpc v0.0.0-20250420020031-b78cbbe23aaf/go.mod h1:OU+hxE/MGkQPmcW4Uqk7g0J7TjgXEybUKIq9fukDi3w= +github.com/lazygophers/lrpc v0.0.0-20250430104923-8731b1b844d6 h1:5895+3o6MOCQYcICi8yHX9pQ1W6XCYIaL1S/iHAsrC0= +github.com/lazygophers/lrpc v0.0.0-20250430104923-8731b1b844d6/go.mod h1:7psAKbQyIMKBF17bTnYkpkxcKAuO2jGA0h3HkGOp5Do= github.com/lazygophers/utils v0.0.0-20250430052029-57f0cb71ff66 h1:7ZuyULuOJK+FxXJRJzMGxySHM2pMYfSy0JVtJWHeQA4= github.com/lazygophers/utils v0.0.0-20250430052029-57f0cb71ff66/go.mod h1:SnvRknWaFvV57m3DdfAu8j5msmo6PODjuWOsWpOGrXQ= +github.com/lazygophers/utils v0.0.0-20250513102512-2a123236f271 h1:0DMW9g7fq+PbKh+H7uks6HtZRpNwxvfI3I3cV6gCEfY= +github.com/lazygophers/utils v0.0.0-20250513102512-2a123236f271/go.mod h1:cDHEQbFtDqV8hePzGAtvpHnBGRYCZwqEXnUDhgWVVpg= github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc h1:RKf14vYWi2ttpEmkA4aQ3j4u9dStX2t4M8UM6qqNsG8= github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is= github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible h1:Y6sqxHMyB1D2YSzWkLibYKgg+SwmyFU9dF2hn6MdTj4= @@ -120,6 +126,8 @@ github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0 github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= github.com/petermattis/goid v0.0.0-20250319124200-ccd6737f222a h1:S+AGcmAESQ0pXCUNnRH7V+bOUIgkSX5qVt2cNKCrm0Q= github.com/petermattis/goid v0.0.0-20250319124200-ccd6737f222a/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= +github.com/petermattis/goid v0.0.0-20250508124226-395b08cebbdb h1:3PrKuO92dUTMrQ9dx0YNejC6U/Si6jqKmyQ9vWjwqR4= +github.com/petermattis/goid v0.0.0-20250508124226-395b08cebbdb/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= github.com/pjbgf/sha1cd v0.3.2 h1:a9wb0bp1oC2TGwStyn0Umc/IGKQnEgF0vVaZ8QF8eo4= github.com/pjbgf/sha1cd v0.3.2/go.mod h1:zQWigSxVmsHEZow5qaLtPYxpcKMMQpa09ixqBxuCS6A= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= diff --git a/state/i18n_const.gen.go b/state/i18n_const.gen.go index cf6c17d..0007f09 100644 --- a/state/i18n_const.gen.go +++ b/state/i18n_const.gen.go @@ -1,8 +1,8 @@ // Code generated by codegen. DO NOT EDIT. // versions: -// codegen v0.0.0-SNAPSHOT-e90a52b -// go go1.22.3 -// update: 1724602134 +// codegen v0.0.0-SNAPSHOT-ba02f3d +// go go1.24.3 +// update: 1747448827 package state