HackMan 是一个简单的工具,用于直接通过命令行生成样板代码。
让 hackman
完成枯燥的工作,并节省一些时间。Hackman 的灵感很大程度上来自于 rails
命令。
git clone git@github.com:Cosmo/HackMan.git
cd HackMan
swift build -c release
PATH=$PATH:$(pwd)/.build/release
或使其持久化
对于 zsh
用户 (macOS Catalina 上的默认 shell)
echo "export PATH=\"\$PATH:$(pwd)/.build/release\"" >> ~/.zshrc
对于 bash
用户 (macOS Mojave 上的默认 shell)
echo "export PATH=\"\$PATH:$(pwd)/.build/release\"" >> ~/.bash_profile
# Create new project directory including a "project.yml" for xcodegen
hackman new APP_NAME
# Change into your project directory
cd APP_NAME
在您的项目目录中运行这些生成器。
# Create an AppDelegate
hackman generate app_delegate
Options
--coordinator, -c
Adds coordinator support
--force, -f
Force override existing files
# Create an empty AssetCatalog
hackman generate asset_catalog
Options
--force, -f
Force override existing files
# Create a LaunchScreen-Storyboard
hackman generate launch_screen
Options
--force, -f
Force override existing files
# Create a ReusableView protocol and useful extensions for UICollectionViews and UITableViews
hackman generate reusable_view
Options
--force, -f
Force override existing files
# Create a Coordinator protocol
hackman generate coordinator
Options
--force, -f
Force override existing files
# Create a MainCoordinator
hackman generate coordinator_main NAME NAME …
Options
--force, -f
Force override existing files
--include=NAME,NAME,…
Include ViewControllers that were not generated via scaffold.
Names must be separated with commas. Spaces between names are not allowed.
# Create a Child-Coordinator with the given name
hackman generate coordinator_child NAME
Options
--force, -f
Force override existing files
# Create a Model with the given name and properties
hackman generate model NAME [PROPERTY[:TYPE] PROPERTY[:TYPE]] …
Options
--force, -f
Force override existing files
# Create a UIViewController-Subclass with the given name
hackman generate view_controller NAME
Options
--coordinator, -c
Adds coordinator support
--force, -f
Force override existing files
# Create a ViewControllerCollection (UIViewController-Subclass with a UICollectionView) and UICollectionViewDataSource
hackman generate view_controller_collection NAME [PROPERTY[:TYPE] PROPERTY[:TYPE]] …
Options
--coordinator, -c
Adds coordinator support
--force, -f
Force override existing files
# Create a UICollectionViewCell-Subclass with the given namen and properties as UILabels
hackman generate collection_view_cell NAME [PROPERTY[:TYPE] PROPERTY[:TYPE]] …
Options
--force, -f
Force override existing files
# Create a ViewControllerTable (UIViewController-Subclass with a UITableView) and UITableViewDataSource
hackman generate view_controller_table NAME [PROPERTY[:TYPE] PROPERTY[:TYPE]] …
Options
--coordinator, -c
Adds coordinator support
--force, -f
Force override existing files
# Create a UITableViewCell-Subclass with the given namen and properties as UILabels
hackman generate table_view_cell NAME [PROPERTY[:TYPE] PROPERTY[:TYPE]] …
Options
--force, -f
Force override existing files
# Create a ViewControllerDetail (UIViewController-Subclass) with the given namen and properties as UILabels
hackman generate view_controller_detail NAME [PROPERTY[:TYPE] PROPERTY[:TYPE]] …
Options
--coordinator, -c
Adds coordinator support
--force, -f
Force override existing files
# Create a UIViewController-Subclass with a UIWebView
hackman generate view_controller_web
Options
--coordinator, -c
Adds coordinator support
--force, -f
Force override existing files
# Create a UIViewController-Subclass with entry points for legal documents
hackman generate view_controller_information
Options
--coordinator, -c
Adds coordinator support
--force, -f
Force override existing files
# Create Model, UICollectionView/UITableView Extensions, UIViewController with UICollectionView/UITableView, ViewControllerDetail, ChildCoordinator, Coordinator Protocol and ReusableView Protocol
hackman generate scaffold NAME [PROPERTY[:TYPE] PROPERTY[:TYPE]] …
# By default, the scaffold will be UICollectionView based.
# In order to create UITableView based scaffolds, pass the --view=table at the end.
# Like so:
hackman generate scaffold song title:string year:int --view=table
Options
--coordinator, -c
Adds coordinator support
--force, -f
Force override existing files
您也可以使用 hackman g
代替 hackman generate
。
当创建脚手架、模型、控制器时,您还可以指定要自动生成的多个字段
hackman g scaffold author name:string birthday:date
此命令除其他外,还创建一个类型为 Author
的结构体,并包含以下属性。
let name: String
let birthday: Date
您也可以引用您的自定义类型。
hackman g scaffold Article title:string body:string published_at:date author:author
这将在 Article
模型内部生成以下属性。
let title: String
let body: String
let publishedAt: Date
let author: Author
如果您省略属性类型,hackman
假定您想要 String
类型的属性。
hackman g scaffold article title body published_at:date author:author
hackman new MusicApp
cd MusicApp
hackman g app_delegate --coordinator
hackman g asset_catalog
hackman g launch_screen
hackman g scaffold artist name --coordinator
hackman g scaffold song title year:int --coordinator
hackman g scaffold album name uuid artist:artist created_at:date updated_at:date --coordinator
hackman g view_controller_information --coordinator
hackman g coordinator_main song artist album --include=information
xcodegen
open MusicApp.xcodeproj
HackMan 根据 MIT 许可证发布。