https://github.com/octree/yep
根据 Assets/.strings 文件,自动生成 Swift 代码
https://github.com/octree/yep
Last synced: 9 months ago
JSON representation
根据 Assets/.strings 文件,自动生成 Swift 代码
- Host: GitHub
- URL: https://github.com/octree/yep
- Owner: octree
- Created: 2019-07-04T12:41:42.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-08-28T05:15:40.000Z (almost 3 years ago)
- Last Synced: 2025-09-01T14:48:52.467Z (10 months ago)
- Language: Swift
- Homepage:
- Size: 47.9 KB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Yep
根据 XCAssets 内容,自动生成 Swift 代码。
- [x] 根据 `Assets` 生成 Images 代码
- [x] 根据 `Assets` 生成 Colors 代码
- [x] 根据 `.strings` 生成 i18n 代码
## 自动生成的代码示例
```swift
//
// I18n
//
// ⚠️ DO NOT EDIT.
// Code generated by Yep(https://github.com/octree/Yep) on 2019/7/5.
// Copyright © 2019 Octree. All rights reserved.
//
import UIKit
struct I18n {
/// "删除"
@inline(__always) static var delete: String {
return NSLocalizedString("delete", comment: "")
}
/// "置顶"
@inline(__always) static var pin: String {
return NSLocalizedString("pin", comment: "")
}
}
```
### Assets 支持 Namespace
```swift
//
// Images
//
// ⚠️ DO NOT EDIT.
// Code generated by Yep(https://github.com/octree/Yep) on 2019/7/5.
// Copyright © 2019 Octree. All rights reserved.
//
import SwiftUI
// MARK: - ImageRes
extension Image {
public enum Assets {
public enum CalendarUI {
public static var chevronLeft: Image {
return Image("CalendarUI/chevronLeft", bundle: .module)
}
}
}
}
```
## Usage
在工程目录创建 `.yep.json` 文件
```json
{
"assetPath": "./Sources/Assets/Resources/Media.xcassets",
"uiColorDestination": "./Sources/Assets/Generated/UIColor.Generated.swift",
"uiImageDestination": "./Sources/Assets/Generated/UIImage.Generated.swift",
"swiftUIColorDestination": "./Sources/Assets/Generated/Color.Generated.swift",
"swiftUIImageDestination": "./Sources/Assets/Generated/Image.Generated.swift",
"i18nStringsPath": "./Sources/Assets/Resources/en.lproj/Localizable.strings",
"i18nDestination": "./Sources/Assets/Generated/I18n.swift",
"isSPM": true
}
```
然后在工程目录执行命令即可
```shell
# just works
yep
```