From f329386ccf209132f8e4799a207622754a776c0e Mon Sep 17 00:00:00 2001 From: Thibaut Schmitt Date: Fri, 25 Jul 2025 16:14:36 +0200 Subject: [PATCH] feat(RES-58): Add new parameter "bundle" (#19) Add bundle parameter to define if resource should be load from Bundle.main (app) or Bundle.module (SPM package) Reviewed-on: https://gitea.openium.fr/openium/resgen.swift/pulls/19 --- README.md | 444 +++++++++++++----- Sources/ResgenSwift/Analytics/Analytics.swift | 2 +- .../Generator/AnalyticsGenerator.swift | 16 +- Sources/ResgenSwift/Colors/Colors.swift | 10 +- .../Colors/ColorsToolOptions.swift | 9 +- .../Generator/ColorExtensionGenerator.swift | 30 +- .../Colors/Model/ParsedColor.swift | 7 +- Sources/ResgenSwift/Fonts/Fonts.swift | 4 +- .../Generator/FontToolContentGenerator.swift | 12 +- .../Generate/Model/ConfigurationFile.swift | 12 + .../ColorsConfiguration+Runnable.swift | 1 + .../ImagesConfiguration+Runnable.swift | 1 + .../StringsConfiguration+Runnable.swift | 1 + .../Generator/ImageExtensionGenerator.swift | 35 +- Sources/ResgenSwift/Images/Images.swift | 10 +- .../ResgenSwift/Images/ImagesOptions.swift | 9 + .../Images/Model/ParsedImage.swift | 11 +- .../Generator/StringsFileGenerator.swift | 44 +- .../Strings/Generator/TagsGenerator.swift | 27 +- .../Strings/Model/Definition.swift | 79 +--- .../Strings/Stringium/Stringium.swift | 5 +- .../Strings/Stringium/StringiumOptions.swift | 5 + Sources/ResgenSwift/Strings/Tag/Tags.swift | 2 +- Sources/ToolCore/AssetBundle.swift | 26 + .../Analytics/AnalyticsGeneratorTests.swift | 6 +- .../Colors/ColorExtensionGeneratorTests.swift | 40 +- .../Colors/ParsedColorTests.swift | 20 +- .../Fonts/FontExtensionGeneratorTests.swift | 4 +- .../Generate/ColorsConfigurationTests.swift | 4 + .../Generate/ImagesConfigurationTests.swift | 4 + .../Generate/StringsConfigurationTests.swift | 4 + .../Images/ImageExtensionGeneratorTests.swift | 40 +- .../Images/ParsedImageTests.swift | 20 +- .../Strings/DefinitionTests.swift | 264 +++++++++-- ...ileGenerator+R2ExtensionsExpectation.swift | 21 +- .../StringsFileGeneratorTests.swift | 38 +- .../Strings/TagsGeneratorTests.swift | 2 +- 37 files changed, 866 insertions(+), 403 deletions(-) create mode 100644 Sources/ToolCore/AssetBundle.swift diff --git a/README.md b/README.md index 8beb9de..f37d7fd 100644 --- a/README.md +++ b/README.md @@ -10,57 +10,114 @@ Font generator generates an extension of `UIFont` and `Font` (or custom classes) iOS required to use the **real name** of the font, this name can be different from its filename. To get the **real name**, it uses `fc-scan`. So, be sure that your `$PATH` variable contains path of `fc-scan`. + +```sh +USAGE: +swift run -c release ResgenSwift fonts [-f] --extension-output-path \ + [--static-members ] \ + [--visibility ] \ + [--extension-name ] \ + [--extension-name-ui-kit ] \ + [--extension-suffix ] \ + [--info-plist-paths ] + +ARGUMENTS: + Input files where fonts ared defined. + +OPTIONS: + -f, -F Should force generation + --static-members + Tell if it will generate static properties or methods (default: false) + --visibility + Visibility of extension and properties. Possibles values: public, private, package, internal. Default is internal (default: internal) + --extension-output-path + Path where to generate the extension. + --extension-name + Extension name. If not specified, it will generate an Font extension. (default: Font) + --extension-name-ui-kit + Extension name. If not specified, no extension will be generated. + --extension-suffix + Extension suffix. Ex: MyApp, it will generate {extensionName}+FontsMyApp.swift + --info-plist-paths + Info.plist paths (array). Will be used to update UIAppFonts content + --version Show the version. + -h, --help Show help information. +``` + **Example** ```sh -swift run -c release ResgenSwift fonts $FORCE_FLAG "./Fonts/fonts.txt" \ +swift run -c release ResgenSwift fonts -f "./Fonts/fonts.txt" \ --extension-output-path "./Fonts/Generated" \ + --static-members true \ + --visibility "public" \ --extension-name "AppFont" \ --extension-name-ui-kit "UIAppFont" \ --extension-suffix "GreatApp" \ - --static-members true \ - --info-plist-paths "./path/one/to/Info.plist ./path/two/to/Info.plist" + --info-plist-paths "./path/one/to/Info.plist ./path/two/to/Info.plist" ``` -**Parameters** - -1. `-f`: force generation -2. Font input folder, it will search for every `.ttf` and `.otf` files specified in `fonts.txt` -3. `--extension-output-path`: path where to generate generated extension -4. `--extension-name` *(optional)* : name of the class to add SwiftUI getters -5. `--extension-name-ui-kit` *(optional)* : name of the class to add UIKit getters -6. `--extension-suffix` *(optional)* : additional text which is added to the filename (ex: `AppFont+GreatApp.swift`) -7. `--static-members` *(optional)*: generate static properties or not -8. `--info-plist-paths` *(optional)*: array of `.plist`, you can specify multiple `Info.plist` for multiple targets - - ## Colors 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 -swift run -c release ResgenSwift colors $FORCE_FLAG "./Colors/colors.txt" \ - --style all \ - --xcassets-path "./Colors/colors.xcassets" \ - --extension-output-path "./Colors/Generated/" \ - --extension-name "AppColor" \ - --extension-name-ui-kit "UIAppColor" \ - --extension-suffix "GreatApp" \ - --static-members true +USAGE: +swift run -c release ResgenSwift colors [-f] \ + --style