Skip to content

JHKits/TRSEPlugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TRSEPlugin

TRSEPlugin Tag

πŸ“– Overview

Tuist Resource Synthesizers Extension Plugin

TRSEPlugin is a Tuist plugin that extends the capabilities of the built-in ResourceSynthesizers, providing additional functionality for managing assets and fonts in modular Swift projects.


πŸ§‘β€πŸ’» Development Environment

Swift mise/Tuist



πŸ› οΈ Prepare

To do this, open your Tuist project for editing by running the following command in your project directory: tuist edit

To start using TRSEPlugin, follow these steps:

1. Add the plugin to your project configuration

In your Tuist/Config.swift file:

// Example
let config = Config(
    plugins: [
        .git(url: "https://github.com/JHKits/TRSEPlugin", tag: "1.0.0") // TRSEPlugin
    ],
    generationOptions: .options()
)

2. Use the plugin in your Project.swift manifest

Import the plugin and apply the extended resource synthesizers:

import TRSEPlugin

let project: Project = Project(name: "projectName",
                               resourceSynthesizers: [
                                   .assetsWithExtension(), // Generated by TRSEPlugin
                                   .fontsWithExtension(), // Generated by TRSEPlugin
                                   .stringCatalogWithExtension() // Generated by TRSEPlugin
                               ])


πŸš€ Usage

Once configured, Tuist will automatically generate extended resource access code based on your Assets and Fonts.

Assets

`assetsWithExtension()` generates image and color resources:
#if os(macOS)

public extension NSImage {
    enum assets {
        public static let {{imageName}} = {{projectName}}Asset.{{imageName}}.image
    }
    
}

public extension NSColor {
    enum assets {
        public static let {{colorName}} = {{projectName}}Asset.{{colorName}}.color
    }
}

#elseif os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)

public extension UIImage {
    enum assets {
        public static let {{imageName}} = {{projectName}}Asset.{{imageName}}.image
    }

}

public extension UIColor {
    enum assets {
         public static let {{colorName}} = {{projectName}}Asset.{{colorName}}.color
    }
}

#endif

#if canImport(SwiftUI)

public extension Image {
    enum assets {
        public static let {{imageName}} = {{projectName}}Asset.{{imageName}}.swiftUIImage
    }
}

public extension Color {
    enum assets {
        public static let {{colorName}} = {{projectName}}Asset.{{colorName}}.swiftUIColor
    }
}

#endif
// macOS
let image = NSImage.assets.imageName
let color = NSColor.assets.colorName

// iOS / tvOS / watchOS / visionOS
let image = UIImage.assets.imageName
let color = UIColor.assets.colorName

// SwiftUI
let image = Image.assets.imageName
let color = Color.assets.colorName

Fonts

`fontsWithExtension()` generates font accessors
Platform {{projectName}}FontConvertible.Font
macOS NSFont
iOS / tvOS / watchOS / visionOS UIFont
#if os(macOS)

public extension NSFont {
    static func {{fontName}}(weight: {{projectName}}FontFamily.{{fontName}}Weight, size: CGFloat) -> {{projectName}}FontConvertible.Font {
        return {{projectName}}FontFamily.{{fontName}}(weight: weight).font(size: size)
    }
}

#elseif os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)

public extension UIFont {
    static func {{fontName}}(weight: {{projectName}}FontFamily.{{fontName}}Weight, size: CGFloat) -> {{projectName}}FontConvertible.Font {
        return {{projectName}}FontFamily.{{fontName}}(weight: weight).font(size: size)
    }
}

#endif

#if canImport(SwiftUI)

public extension Font {
    static func {{fontName}}(weight: {{projectName}}FontFamily.{{fontName}}Weight, size: CGFloat) -> Font {
        return {{projectName}}FontFamily.{{fontName}}(weight: weight).swiftUIFont(size: size)
    }
}

#endif
// macOS
let font = NSFont.fontName(weight: .regular, size: 20)

// iOS / tvOS / watchOS / visionOS
let font = UIFont.fontName(weight: .regular, size: 20)

// SwiftUI
let font = Font.fontName(weight: .regular, size: 20)

String Catalog

`stringCatalogWithExtension()` generates localized string resources:

The string format specifiers in the StringCatalog are replaced with "Arg", which generates the catalogKeyFunctionName.

public extension String {
    enum catalogs {
        public static func {{catalogKeyFunctionName}}(_ args: any CVarArg...) -> String {
            {{projectName}}StringCatalog.{{catalogKeyFunctionName}}(args).localized
        }
    }
}

public enum SharedDesignSystemStringCatalog {
    public static func {{catalogKeyFunctionName}}(_ args: any CVarArg...) -> SharedDesignSystemLocalizedStringConvertible {
        SharedDesignSystemLocalizedStringConvertible(localized: {{catalogKeyString}}, table: {{tableName}}, args: args)
    }
}
let localizedString = String.catalogs.catalogKeyFunctionName(args)

let localizedString = {{projectName}}StringCatalog.catalogKeyFunctionName(args)


πŸ”— References



πŸ“ƒ License

TRSEPlugin is available under the MIT license.
See the LICENSE file for more information.


πŸ“¬ Contact

If you have any questions, suggestions, or issues, feel free to reach out:
Email: [email protected]


πŸ™Œ Contribute

You're more than welcome to submit a pull request or open an issue.
Community contributions are always appreciated!


About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages