用于分析快速项目的 CLI 实用程序
斯瓦纳
Swana 是一个 Swift 项目分析器,它可以生成 Swift 项目的概述,包括有关类型、函数、属性和所用类型的信息。
特征
- 分析给定项目文件夹中的 Swift 源文件
- 生成类型、函数、属性和所用类型的概述
- 支持类、结构、枚举和协议
- 以人类可读的格式打印项目概述
要求
- macOS 13.0 或更高版本
- Swift 5.7 或更高版本
安装
-
克隆存储库:
git clone https://github.com/yourusername/swana.git
-
Build the project:
swift build -c release
-
Copy the executable to your desired location:
cp .build/release/Swana /usr/local/bin/swana
Usage
To analyze a Swift project, simply run the command followed by the path to your project folder:swana
swana /path/to/your/swift/project
Swana will then generate and print an overview of your project, including information about types, functions, properties, and used types.
Example Output
Files: /path/to/your/swift/project
File: SourceFile.swift
TypeName (class)
├───Functions:
│ ├───functionName
│ │ ├───Argument Types: Type1, Type2
│ │ ├───Return Type: ReturnType
│ │ └───Used Types: Type1, Type2, ReturnType
└───Properties:
│ └───propertyName: PropertyType
└───Used Types: Type1, Type2, ReturnType, PropertyType
Architecture
-
ProjectOverview class
: Represents an overview of a project, containing a URL for the project and dictionaries for the files and folders. Each file is represented by a object, with information about types, functions, and symbols in the file.FileOverview
-
TypeInformation class
: Represents information about a type, including its kind (class, struct, enum, or protocol), functions, properties, and used types. -
FunctionInformation class
: Represents information about a function, including its name, return type, argument types, and used types. -
PropertyInformation struct
: Represents information about a property, including its name and type. -
Parser enum
: Contains static functions for generating a project overview and analyzing a source file.generateProjectOverview
: Takes a URL for a project folder and returns a object representing the project.ProjectOverview
analyzeSourceFile
: Takes a object and returns a object representing the file.SourceFileSyntax
FileOverview
printProjectOverview
: Takes a object and prints information about the project to the console.ProjectOverview
-
SourceFileVisitor class
: A subclass that visits the nodes in a source file’s syntax tree and extracts information about the types, functions, and properties in the file. It maintains a stack of type names as it visits the nodes and uses this information to build up the and objects.SyntaxVisitor
ProjectOverview
FileOverview
License
This project is licensed under the MIT License. See the LICENSE file for details.