diff --git a/Package.resolved b/Package.resolved index 60ab9d4..621eec8 100644 --- a/Package.resolved +++ b/Package.resolved @@ -18,6 +18,15 @@ "version" : "1.8.0" } }, + { + "identity" : "pathkit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/kylef/PathKit.git", + "state" : { + "revision" : "3bfd2737b700b9a36565a8c94f4ad2b050a5e574", + "version" : "1.0.1" + } + }, { "identity" : "sourcekitten", "kind" : "remoteSourceControl", @@ -27,6 +36,24 @@ "version" : "0.34.1" } }, + { + "identity" : "spectre", + "kind" : "remoteSourceControl", + "location" : "https://github.com/kylef/Spectre.git", + "state" : { + "revision" : "26cc5e9ae0947092c7139ef7ba612e34646086c7", + "version" : "0.10.1" + } + }, + { + "identity" : "stencil", + "kind" : "remoteSourceControl", + "location" : "https://github.com/stencilproject/Stencil.git", + "state" : { + "revision" : "4f222ac85d673f35df29962fc4c36ccfdaf9da5b", + "version" : "0.15.1" + } + }, { "identity" : "swift-argument-parser", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index f9cc54c..d062302 100644 --- a/Package.swift +++ b/Package.swift @@ -11,6 +11,7 @@ let package = Package( .package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"), .package(url: "https://github.com/jpsim/Yams.git", from: "5.0.1"), .package(url: "https://github.com/realm/SwiftLint.git", .upToNextMajor(from: "0.54.0")), + .package(url: "https://github.com/stencilproject/Stencil.git", .upToNextMajor(from: "0.15.1")), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. @@ -20,7 +21,8 @@ let package = Package( dependencies: [ "ToolCore", .product(name: "ArgumentParser", package: "swift-argument-parser"), - "Yams" + "Yams", + "Stencil", ], plugins: [.plugin(name: "SwiftLintPlugin", package: "SwiftLint")] ), diff --git a/SampleFiles/Colors/Generated/ColorYolo+GenAllScript.swift b/SampleFiles/Colors/Generated/ColorYolo+GenAllScript.swift index 6856326..ba7105e 100644 --- a/SampleFiles/Colors/Generated/ColorYolo+GenAllScript.swift +++ b/SampleFiles/Colors/Generated/ColorYolo+GenAllScript.swift @@ -4,18 +4,25 @@ import SwiftUI extension ColorYolo { - /// Color red is #FF0000 (light) or #FF0000 (dark)" + + /// Color red is #FF0000 #FF0000 or #FF0000 #FF0000" var red: Color { Color("red") } + - /// Color green_alpha_50 is #A000FF00 (light) or #A000FF00 (dark)" + + /// Color green_alpha_50 is #A000FF00 #A000FF00 or #A000FF00 #A000FF00" var green_alpha_50: Color { Color("green_alpha_50") } + - /// Color blue_light_dark is #0000FF (light) or #0000AA (dark)" + + /// Color blue_light_dark is #0000FF #0000FF or #0000AA #0000AA" var blue_light_dark: Color { Color("blue_light_dark") } + + } diff --git a/SampleFiles/Colors/Generated/UIColorYolo+GenAllScript.swift b/SampleFiles/Colors/Generated/UIColorYolo+GenAllScript.swift index d2c7564..bbf9332 100644 --- a/SampleFiles/Colors/Generated/UIColorYolo+GenAllScript.swift +++ b/SampleFiles/Colors/Generated/UIColorYolo+GenAllScript.swift @@ -4,18 +4,25 @@ import UIKit extension UIColorYolo { - /// Color red is #FF0000 (light) or #FF0000 (dark)" + + /// Color red is #FF0000 #FF0000 or #FF0000 #FF0000" @objc var red: UIColor { UIColor(named: "red")! } + - /// Color green_alpha_50 is #A000FF00 (light) or #A000FF00 (dark)" + + /// Color green_alpha_50 is #A000FF00 #A000FF00 or #A000FF00 #A000FF00" @objc var green_alpha_50: UIColor { UIColor(named: "green_alpha_50")! } + - /// Color blue_light_dark is #0000FF (light) or #0000AA (dark)" + + /// Color blue_light_dark is #0000FF #0000FF or #0000AA #0000AA" @objc var blue_light_dark: UIColor { UIColor(named: "blue_light_dark")! } + + } diff --git a/SampleFiles/Colors/Generated/UIhkjhkColorYolo+GenAllScript.swift b/SampleFiles/Colors/Generated/UIhkjhkColorYolo+GenAllScript.swift new file mode 100644 index 0000000..e45a4cb --- /dev/null +++ b/SampleFiles/Colors/Generated/UIhkjhkColorYolo+GenAllScript.swift @@ -0,0 +1,32 @@ +// Generated by ResgenSwift.Color 1.2 + +import UIKit + + +extension UIhkjhkColorYolo { + + + /// Color red is #FF0000 #FF0000 or #FF0000 #FF0000" +@objc var red: UIColor { + UIColor(named: "red")! +} + + + + + /// Color green_alpha_50 is #A000FF00 #A000FF00 or #A000FF00 #A000FF00" +@objc var green_alpha_50: UIColor { + UIColor(named: "green_alpha_50")! +} + + + + + /// Color blue_light_dark is #0000FF #0000FF or #0000AA #0000AA" +@objc var blue_light_dark: UIColor { + UIColor(named: "blue_light_dark")! +} + + + +} diff --git a/SampleFiles/genAllRessources.sh b/SampleFiles/genAllRessources.sh index 63c1949..0f94d80 100755 --- a/SampleFiles/genAllRessources.sh +++ b/SampleFiles/genAllRessources.sh @@ -12,14 +12,14 @@ FORCE_FLAG="$1" # #echo "\n-------------------------\n" # -## Color -#swift run -c release ResgenSwift colors $FORCE_FLAG "./Colors/sampleColors1.txt" \ -# --style all \ -# --xcassets-path "./Colors/colors.xcassets" \ -# --extension-output-path "./Colors/Generated/" \ -# --extension-name "ColorYolo" \ -# --extension-name-ui-kit "UIhkjhkColorYolo" \ -# --extension-suffix "GenAllScript" +# Color +swift run -c release ResgenSwift colors $FORCE_FLAG "./Colors/sampleColors1.txt" \ + --style all \ + --xcassets-path "./Colors/colors.xcassets" \ + --extension-output-path "./Colors/Generated/" \ + --extension-name "ColorYolo" \ + --extension-name-ui-kit "UIColorYolo" \ + --extension-suffix "GenAllScript" # #echo "\n-------------------------\n" # @@ -52,12 +52,12 @@ FORCE_FLAG="$1" #echo "\n-------------------------\n" -# Analytics -swift run -c release ResgenSwift analytics $FORCE_FLAG "./Tags/sampleTags.yml" \ - --target "matomo firebase" \ - --extension-output-path "./Tags/Generated" \ - --extension-name "Analytics" \ - --extension-suffix "GenAllScript" +## Analytics +#swift run -c release ResgenSwift analytics $FORCE_FLAG "./Tags/sampleTags.yml" \ +# --target "matomo firebase" \ +# --extension-output-path "./Tags/Generated" \ +# --extension-name "Analytics" \ +# --extension-suffix "GenAllScript" #echo "\n-------------------------\n" # diff --git a/Sources/ResgenSwift/Colors/Generator/ColorExtensionGenerator.swift b/Sources/ResgenSwift/Colors/Generator/ColorExtensionGenerator.swift index f974b05..2e0be29 100644 --- a/Sources/ResgenSwift/Colors/Generator/ColorExtensionGenerator.swift +++ b/Sources/ResgenSwift/Colors/Generator/ColorExtensionGenerator.swift @@ -41,12 +41,28 @@ struct ColorExtensionGenerator { staticVar: Bool, extensionName: String, isSwiftUI: Bool) -> String { - [ - Self.getHeader(extensionClassname: extensionName, isSwiftUI: isSwiftUI), - Self.getProperties(for: colors, withStaticVar: staticVar, isSwiftUI: isSwiftUI), - Self.getFooter() - ] - .joined(separator: "\n") +// [ +// Self.getHeader(extensionClassname: extensionName, isSwiftUI: isSwiftUI), +// Self.getProperties(for: colors, withStaticVar: staticVar, isSwiftUI: isSwiftUI), +// Self.getFooter() +// ] +// .joined(separator: "\n") + do { + let context: [String: Any] = [ + "colors": colors, + "isStatic": staticVar, + "isSwiftUI": isSwiftUI, + "toolName": Colors.toolName, + "resgenVersion": ResgenSwiftVersion, + "extensionClassname": extensionName + ] + + return try ResgenSwift.environment.renderTemplate(name: "Colors/main_template", context: context) + } catch { +// let error = ColorsToolError.writeExtension(extensionFilePath, error.localizedDescription) +// print(error.description) + Colors.exit(withError: error) + } } private static func getHeader(extensionClassname: String, isSwiftUI: Bool) -> String { diff --git a/Sources/ResgenSwift/main.swift b/Sources/ResgenSwift/main.swift index 01bd9c2..89cdbfe 100644 --- a/Sources/ResgenSwift/main.swift +++ b/Sources/ResgenSwift/main.swift @@ -8,6 +8,8 @@ import ToolCore import Foundation import ArgumentParser +import Stencil +import PathKit struct ResgenSwift: ParsableCommand { @@ -32,6 +34,20 @@ struct ResgenSwift: ParsableCommand { // subcommand is not given on the command line. //defaultSubcommand: Twine.self ) + + static let projectDirectory = URL(fileURLWithPath: #file) // ProjectDir/Sources/ResgenSwift/main.swift + .deletingLastPathComponent() // ProjectDir/Sources/ResgenSwift/ + .deletingLastPathComponent() // ProjectDir/Sources/ + .deletingLastPathComponent() // ProjectDir/ + + static let environment = Environment( + loader: FileSystemLoader( + paths: [ + Path("\(projectDirectory.path)/Templates/") + ] + ) + ) } +print(ResgenSwift.projectDirectory.path) ResgenSwift.main() diff --git a/Templates/Colors/json_template b/Templates/Colors/json_template new file mode 100644 index 0000000..e69de29 diff --git a/Templates/Colors/main_template b/Templates/Colors/main_template new file mode 100644 index 0000000..bc14e80 --- /dev/null +++ b/Templates/Colors/main_template @@ -0,0 +1,21 @@ +// Generated by ResgenSwift.{{ toolName }} {{ resgenVersion }} +{% if isSwiftUI %} +import SwiftUI +{% else %} +import UIKit +{% endif %} +extension {{ extensionClassname }} { +{% for color in colors %} + {% if isSwiftUI %} + /// Color {{ color.name }} is {{ color.light }} {{ color.light }} or {{ color.dark }} {{ color.dark }}" + {% if isStatic %}static {% endif %}var {{ color.name }}: Color { + Color("{{ color.name }}") + } + {% else %} + /// Color {{ color.name }} is {{ color.light }} {{ color.light }} or {{ color.dark }} {{ color.dark }}" + {% if isStatic %}static {% else %}@objc {% endif %}var {{ color.name }}: UIColor { + UIColor(named: "{{ color.name }}")! + } + {% endif %} +{% endfor %} +} diff --git a/Templates/Colors/swiftui_template b/Templates/Colors/swiftui_template new file mode 100644 index 0000000..196367a --- /dev/null +++ b/Templates/Colors/swiftui_template @@ -0,0 +1,4 @@ + /// Color {{ color.name }} is {{ color.light }} {{ color.light }} or {{ color.dark }} {{ color.dark }}" + {% if isStatic %}static {% endif %}var {{ color.name }}: Color { + Color("{{ color.name }}") + } diff --git a/Templates/Colors/uikit_template b/Templates/Colors/uikit_template new file mode 100644 index 0000000..108da0d --- /dev/null +++ b/Templates/Colors/uikit_template @@ -0,0 +1,4 @@ + /// Color {{ color.name }} is {{ color.light }} {{ color.light }} or {{ color.dark }} {{ color.dark }}" + {% if isStatic %}static {% else %}@objc {% endif %}var {{ color.name }}: UIColor { + UIColor(named: "{{ color.name }}")! + }