丛林

Swift

Jungle 是一个 Swift 命令行工具,可以从 Cocoapods Xcode 项目或 SwiftPM 包中生成复杂度指标信息。目前,它可以做以下事情

您可以在我们的技术文章 “如何控制您的依赖关系” 中阅读更多关于依赖复杂度的信息。

目录

安装

Mint

mint install xing/jungle
mint run jungle help

手动

git clone https://github.com/xing/jungle
cd jungle
swift build -c release
.build/release/jungle help

用法

获取历史复杂度

OVERVIEW: Displays historic complexity of the dependency graph

USAGE: jungle history [--since <since>] [--module <module>] --target <target> [--output-format <output-format>] [<directory-path>]

ARGUMENTS:
  <directory-path>        Path to the directory where Podfile.lock is located (default: .)

OPTIONS:
  --since <since>         Equivalent to git-log --since: Eg: '6 months ago' (default: 6 months ago)
  --module <module>       The Module to compare. If you specify something, target parameter will be ommited
  --target <target>       The target in your Podfile or Package.swift file to be used (this can be a Product name in SPM)
  --output-format <output-format>
                          csv or json (default: csv)
  --version               Show the version.
  -h, --help              Show help information.

示例

jungle history --target App ProjectDirectory/ --since '1 week ago'

2022-08-30T15:12:14+02:00;cdb9d2ce64a;124;21063;Author;commit message
2022-09-02T11:02:12+02:00;4fdf3a157a4;124;21063;Author;commit message
Now;Current;124;21063;;

比较复杂度图

OVERVIEW: Compares the current complexity of the dependency graph to others versions in git

USAGE: jungle compare [--to <git-object> ...] [--module <module>] --target <target> [<directory-path>]

ARGUMENTS:
  <directory-path>        Path to the directory where Podfile.lock or Package.swift is located (default: .)

OPTIONS:
  --to <git-object>       The git objects to compare the current graph to. Eg: - 'main', 'my_branch', 'some_commit_hash'. (default: HEAD, main, master)
  --module <module>       The Module to compare. If you specify something, target parameter will be ommited
  --target <target>       The target in your Podfile or Package.swift file to be used (this can be a Product name in SPM)
  --version               Show the version.
  -h, --help              Show help information.

示例

jungle compare --target App ProjectDirectory/ --to main
[
  {
    "modules" : 124,
    "complexity" : 20063,
    "name" : "Current",
    "moduleCount" : 124
  },
  {
    "modules" : 124,
    "complexity" : 21063,
    "name" : "main",
    "moduleCount" : 124
  }
]

计算模块依赖关系

OVERVIEW: Outputs a sorted list of modules dependencies count of your project

USAGE: jungle modules --target <target> [<directory-path>]

ARGUMENTS:
  <directory-path>        Path to the directory where Podfile.lock or Package.swift is located (default: .)

OPTIONS:
  --target <target>       The target in your Podfile or Package.swift file to be used (this can be a Product name in SPM)
  --version               Show the version.
  -h, --help              Show help information.

示例

jungle modules --target jungle

4 - PodExtractor
3 - SPMExtractor
2 - DependencyGraph
0 - Shell
0 - ArgumentParser

获取依赖模块

OVERVIEW: Outputs a sorted list of targets that depends on the specified one in target

USAGE: jungle dependant --target <target> [--show-only-tests] [<directory-path>]

ARGUMENTS:
  <directory-path>        Path to the directory where Podfile.lock or Package.swift is located (default: .)

OPTIONS:
  --target <target>       The target in your Podfile or Package.swift file to be used (this can be a Product name in SPM)
  --show-only-tests       Show only Test targets
  --version               Show the version.
  -h, --help              Show help information.

示例

jungle dependant --target SamplePackage $HOME/Desktop/SamplePackage

Library, LibraryTests, SamplePackageTests


### Visualize Complexity Graphs

```shell
OVERVIEW: Outputs the dependency graph in DOT format

USAGE: jungle graph [--of <git-object>] [--module <module>] --target <target> [--use-multiedge] [--show-externals] [<directory-path>]

ARGUMENTS:
  <directory-path>        Path to the directory where Podfile.lock or Package.swift is located (default: .)

OPTIONS:
  --of <git-object>       A git object representing the version to draw the graph for. Eg: - 'main', 'my_branch', 'some_commit_hash'.
  --module <module>       The Module to compare. If you specify something, target parameter will be ommited
  --target <target>       The target in your Podfile or Package.swift file to be used (this can be a Product name in SPM)
  --use-multiedge         Use multi-edge or unique-edge configuration
  --show-externals        Show Externals modules dependencies
  --version               Show the version.
  -h, --help              Show help information.

输出 DOT 格式,可以使用 http://viz-js.com 查看

一些提示

💡 使用 pbcopy 将 CSV (粘贴到电子表格) 或 DOT (粘贴到 http://viz-js.com) 复制到剪贴板

jungle graph --target App ProjectDirectory/ | pbcopy
jungle history --target App ProjectDirectory/ | pbcopy

💡 使用 Graphviz 工具生成您自己的图表

brew install graphviz
jungle graph --target App ProjectDirectory/ | dot -Tpng -o graph.png && open graph.png

贡献

🎁 非常欢迎提交关于新功能/想法的错误报告和 pull request!

👷🏼 我们期待您的 pull request,我们很乐意提供帮助!

您可以通过执行以下任何操作来提供帮助

本项目旨在成为一个安全、友好的协作空间,贡献者应遵守 贡献者盟约 代码行为准则。

贡献者许可协议

对本项目的贡献必须附带一份贡献者许可协议。您(或您的雇主)保留对您贡献的版权,这仅仅是允许我们使用和重新分发您的贡献作为项目的一部分。在此处 查找 协议,并前往 贡献者页面 找到 XING 员工联系以获取进一步说明。

您通常只需要提交一次 CLA,因此如果您已经提交过一次(即使是针对不同的项目),您可能不需要再次提交。