Compare commits
2 Commits
fix/string
...
187980933e
Author | SHA1 | Date | |
---|---|---|---|
187980933e | |||
a64a956254 |
@@ -36,7 +36,7 @@ swift run -c release ResgenSwift fonts $FORCE_FLAG "./Fonts/fonts.txt" \
|
|||||||
|
|
||||||
## Colors
|
## Colors
|
||||||
|
|
||||||
Colors generator generates an extension of `UIColor` (or a custom class) along with colorsets in specified xcassets.
|
Colors generator generates colorsets in specified xcassets and an extension of `Color` (or a custom class) associated to those colorsets. If the extension name is not specified, no extension will be generated.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
swift run -c release ResgenSwift colors $FORCE_FLAG "./Colors/colors.txt" \
|
swift run -c release ResgenSwift colors $FORCE_FLAG "./Colors/colors.txt" \
|
||||||
|
6
SampleFiles/Colors/colors.xcassets/Colors/Contents.json
Normal file
6
SampleFiles/Colors/colors.xcassets/Colors/Contents.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,6 @@
|
|||||||
// Generated by ResgenSwift.Analytics 2.1.0
|
// Generated by ResgenSwift.Analytics 2.1.0
|
||||||
|
|
||||||
|
import Foundation
|
||||||
import MatomoTracker
|
import MatomoTracker
|
||||||
import FirebaseAnalytics
|
import FirebaseAnalytics
|
||||||
|
|
||||||
@@ -254,20 +255,20 @@ class AnalyticsManager {
|
|||||||
|
|
||||||
// MARK: - section_one
|
// MARK: - section_one
|
||||||
|
|
||||||
static func logScreenS1DefOne(title: String) {
|
func logScreenS1DefOne(title: String) {
|
||||||
AnalyticsManager.shared.logScreen(
|
logScreen(
|
||||||
name: "s1 def one \(title)",
|
name: "s1 def one \(title)",
|
||||||
path: "s1_def_one/\(title)",
|
path: "s1_def_one/\(title)",
|
||||||
params: nil
|
params: nil
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func logEventS1DefTwo(
|
func logEventS1DefTwo(
|
||||||
title: String,
|
title: String,
|
||||||
count: String,
|
count: String,
|
||||||
test2: String = "test"
|
test2: String = "test"
|
||||||
) {
|
) {
|
||||||
AnalyticsManager.shared.logEvent(
|
logEvent(
|
||||||
name: "s1 def two",
|
name: "s1 def two",
|
||||||
action: "test",
|
action: "test",
|
||||||
category: "test",
|
category: "test",
|
||||||
@@ -282,8 +283,8 @@ class AnalyticsManager {
|
|||||||
|
|
||||||
// MARK: - section_two
|
// MARK: - section_two
|
||||||
|
|
||||||
static func logScreenS2DefOne() {
|
func logScreenS2DefOne() {
|
||||||
AnalyticsManager.shared.logScreen(
|
logScreen(
|
||||||
name: "s2 def one",
|
name: "s2 def one",
|
||||||
path: "s2_def_one/",
|
path: "s2_def_one/",
|
||||||
params: nil
|
params: nil
|
||||||
|
@@ -21,8 +21,6 @@ struct Colors: ParsableCommand {
|
|||||||
// MARK: - Static
|
// MARK: - Static
|
||||||
|
|
||||||
static let toolName = "Color"
|
static let toolName = "Color"
|
||||||
static let defaultExtensionName = "Color"
|
|
||||||
static let defaultExtensionNameUIKit = "UIColor"
|
|
||||||
static let assetsColorsFolderName = "Colors"
|
static let assetsColorsFolderName = "Colors"
|
||||||
|
|
||||||
// MARK: - Command options
|
// MARK: - Command options
|
||||||
@@ -57,22 +55,28 @@ struct Colors: ParsableCommand {
|
|||||||
// -> Time: 3.4505380392074585 seconds
|
// -> Time: 3.4505380392074585 seconds
|
||||||
|
|
||||||
// Generate extension
|
// Generate extension
|
||||||
ColorExtensionGenerator.writeExtensionFile(
|
if let extensionName = options.extensionName,
|
||||||
colors: parsedColors,
|
let extensionFilePath = options.extensionFilePath {
|
||||||
staticVar: options.staticMembers,
|
ColorExtensionGenerator.writeExtensionFile(
|
||||||
extensionName: options.extensionName,
|
colors: parsedColors,
|
||||||
extensionFilePath: options.extensionFilePath,
|
staticVar: options.staticMembers,
|
||||||
isSwiftUI: true
|
extensionName: extensionName,
|
||||||
)
|
extensionFilePath: extensionFilePath,
|
||||||
|
isSwiftUI: true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// Generate extension
|
// Generate extension
|
||||||
ColorExtensionGenerator.writeExtensionFile(
|
if let extensionNameUIKit = options.extensionNameUIKit,
|
||||||
colors: parsedColors,
|
let extensionFilePathUIKit = options.extensionFilePathUIKit {
|
||||||
staticVar: options.staticMembers,
|
ColorExtensionGenerator.writeExtensionFile(
|
||||||
extensionName: options.extensionNameUIKit,
|
colors: parsedColors,
|
||||||
extensionFilePath: options.extensionFilePathUIKit,
|
staticVar: options.staticMembers,
|
||||||
isSwiftUI: false
|
extensionName: extensionNameUIKit,
|
||||||
)
|
extensionFilePath: extensionFilePathUIKit,
|
||||||
|
isSwiftUI: false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
print("[\(Self.toolName)] Colors generated")
|
print("[\(Self.toolName)] Colors generated")
|
||||||
}
|
}
|
||||||
@@ -96,18 +100,29 @@ struct Colors: ParsableCommand {
|
|||||||
Self.exit(withError: error)
|
Self.exit(withError: error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extension for UIKit and SwiftUI should have different name
|
// Extension for UIKit and SwiftUI should have different name (if both are defined)
|
||||||
guard options.extensionName != options.extensionNameUIKit else {
|
if let extensionName = options.extensionName,
|
||||||
let error = ColorsToolError.extensionNamesCollision(options.extensionName)
|
let extensionNameUIKit = options.extensionNameUIKit {
|
||||||
print(error.description)
|
guard extensionName != extensionNameUIKit else {
|
||||||
Self.exit(withError: error)
|
let error = ColorsToolError.extensionNamesCollision(extensionName)
|
||||||
|
print(error.description)
|
||||||
|
Self.exit(withError: error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if needed to regenerate
|
// Check if needed to regenerate
|
||||||
|
let fileToCompareToInput: String = {
|
||||||
|
// If there is no extension file to compare
|
||||||
|
// Then check the xcassets file instead
|
||||||
|
if let extensionFilePath = options.extensionFilePath {
|
||||||
|
return extensionFilePath
|
||||||
|
}
|
||||||
|
return options.xcassetsPath
|
||||||
|
}()
|
||||||
guard GeneratorChecker.shouldGenerate(
|
guard GeneratorChecker.shouldGenerate(
|
||||||
force: options.forceGeneration,
|
force: options.forceGeneration,
|
||||||
inputFilePath: options.inputFile,
|
inputFilePath: options.inputFile,
|
||||||
extensionFilePath: options.extensionFilePath
|
extensionFilePath: fileToCompareToInput
|
||||||
) else {
|
) else {
|
||||||
print("[\(Self.toolName)] Colors are already up to date :) ")
|
print("[\(Self.toolName)] Colors are already up to date :) ")
|
||||||
return false
|
return false
|
||||||
|
@@ -30,11 +30,11 @@ struct ColorsToolOptions: ParsableArguments {
|
|||||||
@Option(help: "Tell if it will generate static properties or not")
|
@Option(help: "Tell if it will generate static properties or not")
|
||||||
var staticMembers: Bool = false
|
var staticMembers: Bool = false
|
||||||
|
|
||||||
@Option(help: "Extension name. If not specified, it will generate an Color extension.")
|
@Option(help: "Extension name. If not specified, no extension will be generated.")
|
||||||
var extensionName: String = Colors.defaultExtensionName
|
var extensionName: String?
|
||||||
|
|
||||||
@Option(help: "SwiftUI Extension name. If not specified, it will generate an UIColor extension.")
|
@Option(help: "SwiftUI Extension name. If not specified, no extension will be generated.")
|
||||||
var extensionNameUIKit: String = Colors.defaultExtensionNameUIKit
|
var extensionNameUIKit: String?
|
||||||
|
|
||||||
@Option(help: "Extension suffix. Ex: MyApp, it will generate {extensionName}+ColorsMyApp.swift")
|
@Option(help: "Extension suffix. Ex: MyApp, it will generate {extensionName}+ColorsMyApp.swift")
|
||||||
var extensionSuffix: String?
|
var extensionSuffix: String?
|
||||||
@@ -46,27 +46,35 @@ extension ColorsToolOptions {
|
|||||||
|
|
||||||
// MARK: - SwiftUI
|
// MARK: - SwiftUI
|
||||||
|
|
||||||
var extensionFileName: String {
|
var extensionFileName: String? {
|
||||||
|
guard let extensionName else { return nil }
|
||||||
|
|
||||||
if let extensionSuffix {
|
if let extensionSuffix {
|
||||||
return "\(extensionName)+\(extensionSuffix).swift"
|
return "\(extensionName)+\(extensionSuffix).swift"
|
||||||
}
|
}
|
||||||
return "\(extensionName).swift"
|
return "\(extensionName).swift"
|
||||||
}
|
}
|
||||||
|
|
||||||
var extensionFilePath: String {
|
var extensionFilePath: String? {
|
||||||
"\(extensionOutputPath)/\(extensionFileName)"
|
guard let extensionFileName else { return nil }
|
||||||
|
|
||||||
|
return "\(extensionOutputPath)/\(extensionFileName)"
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - UIKit
|
// MARK: - UIKit
|
||||||
|
|
||||||
var extensionFileNameUIKit: String {
|
var extensionFileNameUIKit: String? {
|
||||||
|
guard let extensionNameUIKit else { return nil }
|
||||||
|
|
||||||
if let extensionSuffix {
|
if let extensionSuffix {
|
||||||
return "\(extensionNameUIKit)+\(extensionSuffix).swift"
|
return "\(extensionNameUIKit)+\(extensionSuffix).swift"
|
||||||
}
|
}
|
||||||
return "\(extensionNameUIKit).swift"
|
return "\(extensionNameUIKit).swift"
|
||||||
}
|
}
|
||||||
|
|
||||||
var extensionFilePathUIKit: String {
|
var extensionFilePathUIKit: String? {
|
||||||
"\(extensionOutputPath)/\(extensionFileNameUIKit)"
|
guard let extensionFileNameUIKit else { return nil }
|
||||||
|
|
||||||
|
return "\(extensionOutputPath)/\(extensionFileNameUIKit)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user