Sourcery
所属分类:collect
开发工具:Swift
文件大小:0KB
下载次数:0
上传日期:2023-07-04 18:02:09
上 传 者:
sh-1993
说明: Swift的元编程,停止编写样板代码。,
(Meta-programming for Swift, stop writing boilerplate code.,)
文件列表:
.bundle/ (0, 2023-12-19)
.bundle/config (103, 2023-12-19)
.circleci/ (0, 2023-12-19)
.circleci/config.yml (1109, 2023-12-19)
.codecov.yml (198, 2023-12-19)
.jazzy.yaml (1054, 2023-12-19)
.pre-commit-hooks.yaml (210, 2023-12-19)
.ruby-version (5, 2023-12-19)
.sourcery.yml (112, 2023-12-19)
.swift-version (4, 2023-12-19)
.swiftlint.yml (1266, 2023-12-19)
.vscode/ (0, 2023-12-19)
.vscode/launch.json (868, 2023-12-19)
.vscode/settings.json (2, 2023-12-19)
ABOUT.md (1861, 2023-12-19)
CHANGELOG.md (41633, 2023-12-19)
CODE_OF_CONDUCT.md (3235, 2023-12-19)
CONTRIBUTING.md (957, 2023-12-19)
Dangerfile (1534, 2023-12-19)
Dockerfile (1225, 2023-12-19)
Funding.yml (71, 2023-12-19)
Gemfile (172, 2023-12-19)
Gemfile.lock (5068, 2023-12-19)
LICENSE (1081, 2023-12-19)
LINUX.md (3407, 2023-12-19)
LinuxMain.swift (3107, 2023-12-19)
Package.resolved (6251, 2023-12-19)
Package.swift (9750, 2023-12-19)
Plugins/ (0, 2023-12-19)
Plugins/SourceryCommandPlugin/ (0, 2023-12-19)
Plugins/SourceryCommandPlugin/SourceryCommandPlugin.swift (2602, 2023-12-19)
... ...
[![CircleCI](https://circleci.com/gh/krzysztofzablocki/Sourcery.svg?style=shield)](https://circleci.com/gh/krzysztofzablocki/Sourcery)
[![macOS](https://github.com/krzysztofzablocki/Sourcery/actions/workflows/macOS.yml/badge.svg)](https://github.com/krzysztofzablocki/Sourcery/actions/workflows/macOS.yml)
[![Ubuntu (Experimental)](https://github.com/krzysztofzablocki/Sourcery/actions/workflows/Ubuntu.yml/badge.svg)](https://github.com/krzysztofzablocki/Sourcery/actions/workflows/Ubuntu.yml)
[![docs](https://krzysztofzablocki.github.io/Sourcery/badge.svg)](https://krzysztofzablocki.github.io/Sourcery/index.html)
[![Version](https://img.shields.io/cocoapods/v/Sourcery.svg?style=flat)](http://cocoapods.org/pods/Sourcery)
[![License](https://img.shields.io/cocoapods/l/Sourcery.svg?style=flat)](http://cocoapods.org/pods/Sourcery)
[![Platform](https://img.shields.io/cocoapods/p/Sourcery.svg?style=flat)](http://cocoapods.org/pods/Sourcery)
[**In-Depth Sourcery guide is covered as part of my SwiftyStack engineering course.**](https://www.swiftystack.com/)
**Sourcery Pro provides a powerful Stencil editor and extends Xcode with the ability to handle live AST templates: [available on Mac App Store](https://apps.apple.com/us/app/sourcery-pro/id1561780836?mt=12)**
https://user-images.githubusercontent.com/1468993/114271090-f6c19200-9a0f-11eb-9bd8-d7bb15129eb2.mp4
[Learn more about Sourcery Pro](http://merowing.info/sourcery-pro/)
**Sourcery** is a code generator for Swift language, built on top of Apple's own SwiftSyntax. It extends the language abstractions to allow you to generate boilerplate code automatically.
It's used in over 40,000 projects on both iOS and macOS and it powers some of the most popular and critically-acclaimed apps you have used (including Airbnb, Bumble, New York Times). Its massive community adoption was one of the factors that pushed Apple to implement derived Equality and automatic Codable conformance. Sourcery is maintained by a growing community of [contributors](https://github.com/krzysztofzablocki/Sourcery/graphs/contributors).
Try **Sourcery** for your next project or add it to an existing one -- you'll save a lot of time and be happy you did!
## TL;DR
Sourcery allows you to get rid of repetitive code and create better architecture and developer workflows.
An example might be implementing `Mocks` for all your protocols, without Sourcery you will need to write **hundreds lines of code per each protocol** like this:
```swift
class MyProtocolMock: MyProtocol {
//MARK: - sayHelloWith
var sayHelloWithNameCallsCount = 0
var sayHelloWithNameCalled: Bool {
return sayHelloWithNameCallsCount > 0
}
var sayHelloWithNameReceivedName: String?
var sayHelloWithNameReceivedInvocations: [String] = []
var sayHelloWithNameClosure: ((String) -> Void)?
func sayHelloWith(name: String) {
sayHelloWithNameCallsCount += 1
sayHelloWithNameReceivedName = name
sayHelloWithNameReceivedInvocations.append(name)
sayHelloWithNameClosure?(name)
}
}
```
and with Sourcery ?
```swift
extension MyProtocol: AutoMockable {}
```
Sourcery removes the need to write any of the mocks code, how many protocols do you have in your project? Imagine how much time you'll save, using Sourcery will also make every single mock consistent and if you refactor or add properties, the mock code will be automatically updated for you, eliminating possible human errors.
Sourcery can be applied to arbitrary problems across your codebase, if you can describe an algorithm to another human, you can automate it using Sourcery.
Most common uses are:
- [Equality](https://krzysztofzablocki.github.io/Sourcery/equatable.html) & [Hashing](https://krzysztofzablocki.github.io/Sourcery/hashable.html)
- [Enum cases & Counts](https://krzysztofzablocki.github.io/Sourcery/enum-cases.html)
- [Lenses](https://krzysztofzablocki.github.io/Sourcery/lenses.html)
- [Mocks & Stubs](https://krzysztofzablocki.github.io/Sourcery/mocks.html)
- [LinuxMain](https://krzysztofzablocki.github.io/Sourcery/linuxmain.html)
- [Decorators](https://krzysztofzablocki.github.io/Sourcery/decorator.html)
- [Persistence and advanced Codable](https://krzysztofzablocki.github.io/Sourcery/codable.html)
- [Property level diffing](https://krzysztofzablocki.github.io/Sourcery/diffable.html)
But how about more specific use-cases, like automatically generating all the UI for your app `BetaSetting`? [you can use Sourcery for that too](https://github.com/krzysztofzablocki/AutomaticSettings)
Once you start writing your own template and learn the power of Sourcery you won't be able to live without it.
## How To Get Started
There are plenty of tutorials for different uses of Sourcery, and you can always ask for help in our [Swift Forum Category](https://forums.swift.org/c/related-projects/sourcery).
- [The Magic of Sourcery](https://www.caseyliss.com/2017/3/31/the-magic-of-sourcery) is a great starting tutorial
- [Generating Swift Code for iOS](https://www.raywenderlich.com/158803/sourcery-tutorial-generating-swift-code-ios) deals with JSON handling code
- [How To Automate Swift Boilerplate with Sourcery](https://atomicrobot.io/blog/sourcery/) generates conversions to dictionaries
- [Codable Enums](https://littlebitesofcocoa.com/318-codable-enums) implements Codable support for Enumerations
- [Sourcery Workshops](https://github.com/krzysztofzablocki/SourceryWorkshops)
### Quick Mocking Intro & Getting Started Video
You can also watch this quick getting started and intro to mocking video by Inside iOS Dev:
[![Watch the video](Resources/Inside-iOS-Dev-Sourcery-Intro-To-Mocking-Video-Thumbnail.png)](https://youtu.be/-ZbBNuttlt4?t=214)
## Installation
- _Binary form_
Download the latest release with the prebuilt binary from [release tab](https://github.com/krzysztofzablocki/Sourcery/releases/latest). Unzip the archive into the desired destination and run `bin/sourcery`
- _[Homebrew](https://brew.sh)_
`brew install sourcery`
- _[CocoaPods](https://cocoapods.org)_
Add `pod 'Sourcery'` to your `Podfile` and run `pod update Sourcery`. This will download the latest release binary and will put it in your project's CocoaPods path so you will run it with `$PODS_ROOT/Sourcery/bin/sourcery`
If you only want to install the `sourcery` binary, you may want to use the `CLI-Only` subspec: `pod 'Sourcery', :subspecs => ['CLI-Only']`.
- _[Mint](https://github.com/yonaskolb/Mint)_
`mint run krzysztofzablocki/Sourcery`
- _Building from Source_
Download the latest release source code from [the release tab](https://github.com/krzysztofzablocki/Sourcery/releases/latest) or clone the repository and build Sourcery manually.
- _Building with Swift Package Manager_
Run `swift build -c release` in the root folder and then copy `.build/release/sourcery` to your desired destination.
> Note: JS templates are not supported when building with SPM yet.
- _Building with Xcode_
Run `xcodebuild -scheme sourcery -destination generic/platform=macOS -archivePath sourcery.xcarchive archive` and export the binary from the archive.
- _SPM (for plugin use only)_
Add the package dependency to your `Package.swift` manifest from version `1.8.3`.
```
.package(url: "https://github.com/krzysztofzablocki/Sourcery.git", from: "1.8.3")
```
- _[pre-commit](https://pre-commit.com/)_
Add the dependency to `.pre-commit-config.yaml`.
```
- repo: https://github.com/krzysztofzablocki/Sourcery
rev: 1.9.1
hooks:
- id: sourcery
```
## Documentation
Full documentation for the latest release is available [here](http://merowing.info/Sourcery/).
## Linux Support
Linux support is [described on this page](LINUX.md).
## Usage
### Running the executable
Sourcery is a command line tool; you can either run it manually or in a custom build phase using the following command:
```
$ ./bin/sourcery --sources
--templates --output
近期下载者:
相关文件:
收藏者: