Created
May 16, 2019 13:10
-
-
Save CaiJingLong/82a81afd95a4b2267ad705e7962ff320 to your computer and use it in GitHub Desktop.
根据传入的lock文件获取dart工程的依赖(不包含sdk), 以pubspec.yaml的格式输出
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "gopkg.in/yaml.v2" | |
| "io/ioutil" | |
| ) | |
| func main() { | |
| params := make(map[string]interface{}) | |
| bytes, _ := ioutil.ReadFile("/Users/caijinglong/Documents/GitHub/flutter_ijkplayer/example/pubspec.lock") | |
| _ = yaml.Unmarshal(bytes, ¶ms) | |
| packages := params["packages"].(map[interface{}]interface{}) | |
| fmt.Println("dependencies:") | |
| for k, v := range packages { | |
| name := k | |
| var version string | |
| itemMap := v.(map[interface{}]interface{}) | |
| switch itemMap["source"] { | |
| case "path": | |
| version = "\n" + | |
| " path: " + | |
| itemMap["description"].(map[interface{}]interface{})["path"].(string) | |
| break | |
| case "hosted": | |
| version = itemMap["version"].(string) | |
| break | |
| case "git": | |
| gitMap := itemMap["description"].(map[interface{}]interface{}) | |
| version = "\n git:\n" + | |
| " url: " + gitMap["url"].(string) | |
| if gitMap["ref"] != nil { | |
| version = version + "\n ref: " + | |
| gitMap["resolved-ref"].(string) | |
| } | |
| default: | |
| continue | |
| } | |
| fmt.Printf(" %s: %s\n", name, version) | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
这个用处是: 比如你的项目很庞大拥有众多package包,可以反向解析主工程的lock文件,以生成一个相对清晰的依赖引用列表