From 9aff99a78c5b4b7276251f0f5143f71544e4c1dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L!=CE=B5sA=CE=BC=CE=B5r?= Date: Fri, 14 Aug 2020 20:28:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=B1=BB=E5=BA=93=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E5=8C=96=E8=B5=84=E6=BA=90=E5=AD=98=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Release ## 优化 1. 优化类库本地化资源存放 2. Fix #10 --- CHANGELOG.md | 5 ++ Common/Common.props | 2 +- .../NetCoreBeautyTest.csproj | 2 +- src/manager/manager.go | 48 ++++++++++++++++++- src/util/util.go | 29 +++++++++++ 5 files changed, 83 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3c7cb4..c60d80e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Change Log +### v1.2.9 +#### 优化 +1. 优化类库本地化资源存放 +2. Fix #10 + ### v1.2.8 #### 修复 1. 修复没有指定`excludes`时所有文件都被忽略的问题 diff --git a/Common/Common.props b/Common/Common.props index 1c46bfa..5cf96c4 100644 --- a/Common/Common.props +++ b/Common/Common.props @@ -2,7 +2,7 @@ .nupkg - 1.2.8 + 1.2.9 nulastudio LiesAuer diff --git a/NetCoreBeautyNugetTest/NetCoreBeautyTest.csproj b/NetCoreBeautyNugetTest/NetCoreBeautyTest.csproj index 637c031..c058f83 100644 --- a/NetCoreBeautyNugetTest/NetCoreBeautyTest.csproj +++ b/NetCoreBeautyNugetTest/NetCoreBeautyTest.csproj @@ -21,7 +21,7 @@ - + diff --git a/src/manager/manager.go b/src/manager/manager.go index 7e3e0cb..67b72d5 100644 --- a/src/manager/manager.go +++ b/src/manager/manager.go @@ -495,6 +495,24 @@ func FixDeps(deps string) ([]string, string, string) { return nil, "", "" } + dir := filepath.Dir(deps) + resources := map[string][]string{} + if sdir, err := util.ReadAllDir(dir); err == nil { + for _, d := range sdir { + if files, err := util.ReadAllFile(filepath.Join(dir, d)); err == nil { + for _, file := range files { + if strings.HasSuffix(file, ".resources.dll") { + assembly := strings.TrimSuffix(file, ".resources.dll") + if _, ok := resources[assembly]; !ok { + resources[assembly] = make([]string, 0) + } + resources[assembly] = append(resources[assembly], d) + } + } + } + } + } + files := []string{} rid := "" fxrVersion := "" @@ -535,16 +553,44 @@ func FixDeps(deps string) ([]string, string, string) { "compile": 1, "resources": 2, } + assemblies := make([]string, 0) for cname, segments := range components { component := depsObj.(map[string]interface{})[cname] + if component == nil && cname == "resources" { + component = make(map[string]interface{}) + } if component != nil { newComponent := make(map[string]interface{}) for k := range component.(map[string]interface{}) { components := strings.Split(strings.ReplaceAll(k, "\\", "/"), "/") length := len(components) fileName := strings.Join(components[length-segments:], "/") + assembly := strings.TrimSuffix(fileName, ".dll") files = append(files, fileName) - newComponent["./"+fileName] = make(map[string]interface{}) + if cname == "runtime" { + assemblies = append(assemblies, assembly) + } + // resources不清空 + if cname == "resources" { + newComponent["./"+fileName] = component.(map[string]interface{})[k] + } else { + newComponent["./"+fileName] = make(map[string]interface{}) + } + } + if cname == "resources" { + for _, assembly := range assemblies { + if cultures, ok := resources[assembly]; ok { + for _, culture := range cultures { + k := "./" + culture + "/" + assembly + ".resources.dll" + if _, ok := newComponent[k]; !ok { + v := make(map[string]interface{}) + v["locale"] = culture + newComponent[k] = v + files = append(files, strings.TrimPrefix(k, "./")) + } + } + } + } } depsObj.(map[string]interface{})[cname] = newComponent } diff --git a/src/util/util.go b/src/util/util.go index bafade3..94d456e 100644 --- a/src/util/util.go +++ b/src/util/util.go @@ -3,6 +3,7 @@ package util import ( "errors" "io" + "io/ioutil" "os" "path/filepath" ) @@ -43,3 +44,31 @@ func CopyFile(src string, des string) (written int64, err error) { return io.Copy(desFile, srcFile) } + +func ReadAllDir(dir string) (paths []string, err error) { + fd, err := ioutil.ReadDir(dir) + paths = make([]string, 0) + if err != nil { + return paths, err + } + for _, fi := range fd { + if fi.IsDir() { + paths = append(paths, fi.Name()) + } + } + return paths, nil +} + +func ReadAllFile(dir string) (paths []string, err error) { + fd, err := ioutil.ReadDir(dir) + paths = make([]string, 0) + if err != nil { + return paths, err + } + for _, fi := range fd { + if !fi.IsDir() { + paths = append(paths, fi.Name()) + } + } + return paths, nil +}