feat(RES-58): Add new parameter "bundle" (#19)
All checks were successful
gitea-openium/resgen.swift/pipeline/head This commit looks good
All checks were successful
gitea-openium/resgen.swift/pipeline/head This commit looks good
Add bundle parameter to define if resource should be load from Bundle.main (app) or Bundle.module (SPM package) Reviewed-on: #19
This commit is contained in:
432
README.md
432
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] <input-file> --extension-output-path <extension-output-path> \
|
||||
[--static-members <static-members>] \
|
||||
[--visibility <visibility>] \
|
||||
[--extension-name <extension-name>] \
|
||||
[--extension-name-ui-kit <extension-name-ui-kit>] \
|
||||
[--extension-suffix <extension-suffix>] \
|
||||
[--info-plist-paths <info-plist-paths>]
|
||||
|
||||
ARGUMENTS:
|
||||
<input-file> Input files where fonts ared defined.
|
||||
|
||||
OPTIONS:
|
||||
-f, -F Should force generation
|
||||
--static-members <static-members>
|
||||
Tell if it will generate static properties or methods (default: false)
|
||||
--visibility <visibility>
|
||||
Visibility of extension and properties. Possibles values: public, private, package, internal. Default is internal (default: internal)
|
||||
--extension-output-path <extension-output-path>
|
||||
Path where to generate the extension.
|
||||
--extension-name <extension-name>
|
||||
Extension name. If not specified, it will generate an Font extension. (default: Font)
|
||||
--extension-name-ui-kit <extension-name-ui-kit>
|
||||
Extension name. If not specified, no extension will be generated.
|
||||
--extension-suffix <extension-suffix>
|
||||
Extension suffix. Ex: MyApp, it will generate {extensionName}+FontsMyApp.swift
|
||||
--info-plist-paths <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"
|
||||
```
|
||||
|
||||
**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] <input-file> \
|
||||
--style <style> \
|
||||
--xcassets-path <xcassets-path> \
|
||||
[--static-members <static-members>] \
|
||||
[--visibility <visibility>] \
|
||||
[--asset-bundle <asset-bundle>] \
|
||||
[--extension-output-path <extension-output-path>] \
|
||||
[--extension-name <extension-name>] \
|
||||
[--extension-name-ui-kit <extension-name-ui-kit>] \
|
||||
[--extension-suffix <extension-suffix>]
|
||||
|
||||
ARGUMENTS:
|
||||
<input-file> Input files where colors ared defined.
|
||||
|
||||
OPTIONS:
|
||||
-f, -F Should force generation
|
||||
--style <style> Color style to generate: light for light colors only, or all for dark and light colors (values: light, all)
|
||||
--xcassets-path <xcassets-path>
|
||||
Path of xcassets where to generate colors
|
||||
--static-members <static-members>
|
||||
Tell if it will generate static properties or not (default: false)
|
||||
--visibility <visibility>
|
||||
Visibility of extension and properties. Possibles values: public, private, package, internal. Default is internal (default: internal)
|
||||
--asset-bundle <asset-bundle>
|
||||
Bundle where the asset are generated (default: main)
|
||||
--extension-output-path <extension-output-path>
|
||||
Path where to generate the extension.
|
||||
--extension-name <extension-name>
|
||||
SwiftUI extension name. If not specified, no extension will be generated.
|
||||
--extension-name-ui-kit <extension-name-ui-kit>
|
||||
UIKit extension name. If not specified, no extension will be generated.
|
||||
--extension-suffix <extension-suffix>
|
||||
Extension suffix. Ex: MyApp, it will generate {extensionName}+ColorsMyApp.swift
|
||||
--version Show the version.
|
||||
-h, --help Show help information.
|
||||
```
|
||||
|
||||
**Parameters**
|
||||
|
||||
1. `-f`: force generation
|
||||
2. Input colors file
|
||||
3. `--style` can be `all` or `light`
|
||||
4. `--extension-output-path` *(optional)* : path where to generate generated extension
|
||||
5. `--extension-name` *(optional)* : name of the class to add SwiftUI getters
|
||||
6. `--extension-name-ui-kit` *(optional)* : name of the class to add UIKit getters
|
||||
7. `--extension-suffix` *(optional)* : additional text which is added to filename (ex: `AppColor+GreatApp.swift`)
|
||||
8. `--static-members` *(optional)*: generate static properties or not
|
||||
**Example**
|
||||
|
||||
> ⚠️ Passing a `extensionOutputPath` without any `extensionName` does not generate extension. **But** passing an `extensionName` without `extensionOutputPath` will result in a error.
|
||||
```sh
|
||||
swift run -c release ResgenSwift colors -f "./Colors/colors.txt" \
|
||||
--style all \
|
||||
--xcassets-path "./Colors/colors.xcassets" \
|
||||
--static-members true \
|
||||
--visibility internal \
|
||||
--asset-bundle "main" \
|
||||
--extension-output-path "./Colors/Generated/" \
|
||||
--extension-name "AppColor \
|
||||
--extension-name-ui-kit "UIAppColor" \
|
||||
--extension-suffix "GreatApp"
|
||||
```
|
||||
|
||||
> ⚠️ Option `extensionOutputPath` will require an `extensionName` or `extensionNameUIKit` to generate extension files. Passing an `extensionName` or `extensionNameUIKit` without `extensionOutputPath` will not generate any extension file.
|
||||
|
||||
## Strings
|
||||
|
||||
@@ -69,94 +126,190 @@ Strings command allows to generate `strings` files along with extensions to acce
|
||||
### Twine (not recommended)
|
||||
|
||||
```sh
|
||||
swift run -c release ResgenSwift strings twine $FORCE_FLAG "./Twine/strings.txt" \
|
||||
USAGE:
|
||||
swift run -c release ResgenSwift strings twine [-f] <input-file> \
|
||||
--output-path <output-path> \
|
||||
--langs <langs> \
|
||||
--default-lang <default-lang> \
|
||||
--extension-output-path <extension-output-path>
|
||||
|
||||
ARGUMENTS:
|
||||
<input-file> Input files where strings ared defined.
|
||||
|
||||
OPTIONS:
|
||||
-f, -F Should force generation
|
||||
--output-path <output-path>
|
||||
Path where to strings file.
|
||||
--langs <langs> Langs to generate.
|
||||
--default-lang <default-lang>
|
||||
Default langs.
|
||||
--extension-output-path <extension-output-path>
|
||||
Path where to generate the extension.
|
||||
--version Show the version.
|
||||
-h, --help Show help information.
|
||||
```
|
||||
|
||||
**Example**
|
||||
|
||||
```sh
|
||||
swift run -c release ResgenSwift strings twine -f "./Twine/strings.txt" \
|
||||
--output-path "./Twine/Generated" \
|
||||
--langs "fr en en-us" \
|
||||
--default-lang "en" \
|
||||
--extension-output-path "./Twine/Generated"
|
||||
```
|
||||
|
||||
**Parameters**
|
||||
|
||||
1. `-f`: force generation
|
||||
2. Input translations file (must be Twine formatted)
|
||||
3. `--langs`: langs to generate (string with space between each lang)
|
||||
4. `--default-lang`: default lang that will be in `Base.lproj`. It must be in `langs` as well
|
||||
5. `--extension-output-path`: path where to generate generated extension
|
||||
|
||||
### Stringium (recommended)
|
||||
|
||||
```sh
|
||||
swift run -c release ResgenSwift strings stringium $FORCE_FLAG "./Strings/strings.txt" \
|
||||
--output-path "./Strings/Generated" \
|
||||
--langs "fr en en-us" \
|
||||
--default-lang "en" \
|
||||
--extension-output-path "./Strings/Generated" \
|
||||
--extension-name "AppString" \
|
||||
--extension-suffix "GreatApp" \
|
||||
--xcStrings true
|
||||
--static-members true
|
||||
USAGE:
|
||||
swift run -c release ResgenSwift strings stringium [-f] <input-file> \
|
||||
--output-path <output-path> \
|
||||
--langs <langs> \
|
||||
--default-lang <default-lang> \
|
||||
[--tags <tags>] \
|
||||
[--static-members <static-members>] \
|
||||
[--xc-strings <xc-strings>] \
|
||||
[--visibility <visibility>] \
|
||||
[--asset-bundle <asset-bundle>] \
|
||||
[--extension-output-path <extension-output-path>] \
|
||||
[--extension-name <extension-name>] \
|
||||
[--extension-suffix <extension-suffix>]
|
||||
|
||||
ARGUMENTS:
|
||||
<input-file> Input files where strings are defined.
|
||||
|
||||
OPTIONS:
|
||||
-f, -F Should force generation
|
||||
--output-path <output-path>
|
||||
Path where to find the .xcStrings file or the lproj folders.
|
||||
--langs <langs> Langs to generate.
|
||||
--default-lang <default-lang>
|
||||
Default langs.
|
||||
--tags <tags> Tags to generate. (default: ios iosonly iosOnly notranslation)
|
||||
--static-members <static-members>
|
||||
Generate static properties. False by default (default: false)
|
||||
--xc-strings <xc-strings>
|
||||
Tell if it will generate xcStrings file or lproj file. True by default (default: true)
|
||||
--visibility <visibility>
|
||||
Visibility of extension and properties. Possibles values: public, private, package, internal. Default is internal (default: internal)
|
||||
--asset-bundle <asset-bundle>
|
||||
Bundle where the asset are generated (default: main)
|
||||
--extension-output-path <extension-output-path>
|
||||
Path where to generate the extension.
|
||||
--extension-name <extension-name>
|
||||
Extension name. If not specified, no extension will be generated.
|
||||
--extension-suffix <extension-suffix>
|
||||
Extension suffix: {extensionName}+{extensionSuffix}.swift
|
||||
--version Show the version.
|
||||
-h, --help Show help information.
|
||||
```
|
||||
|
||||
**Parameters**
|
||||
|
||||
1. `-f`: force generation
|
||||
2. Input translations file (must be Twine formatted)
|
||||
3. `--langs`: langs to generate (string with space between each lang)
|
||||
4. `--default-lang`: default lang that will be in `Base.lproj`. It must be in `langs` as well
|
||||
4. `--extension-output-path`: path where to generate generated extension
|
||||
5. `--extension-name` *(optional)* : name of class to add the extension
|
||||
6. `--extension-suffix` *(optional)* : additional text which is added to filename (ex: `AppString+GreatApp.swift`)
|
||||
6. `--xcStrings`*(optional)* : generate string catalog
|
||||
7. `--static-members` *(optional)*: generate static properties or not
|
||||
**Example**
|
||||
|
||||
```sh
|
||||
swift run -c release ResgenSwift strings stringium -f "./Strings/strings.txt" \
|
||||
--output-path "./Strings/Generated" \
|
||||
--langs "fr en en-us" \
|
||||
--default-lang "en \
|
||||
--tags "ios iosonly iosOnly notranslation" \
|
||||
--static-members true \
|
||||
--xc-strings true \
|
||||
--visibility "package" \
|
||||
--asset-bundle "module" \
|
||||
--extension-output-path "./Strings/Generated" \
|
||||
--extension-name "AppString \
|
||||
--extension-suffix "GreatApp"
|
||||
```
|
||||
|
||||
> ⚠️ Option `extensionOutputPath` will require an `extensionName` or `extensionNameUIKit` to generate extension files. Passing an `extensionName` or `extensionNameUIKit` without `extensionOutputPath` will not generate any extension file.
|
||||
|
||||
## Tags
|
||||
|
||||
Tags is also a subcommand of `Strings`. Input files are formatted the same way. Tags will generate properties which return exactly what is specified in the input file. It was designed to be used for analytics purpose and to be shared with any other platform to have the same analytics keys.
|
||||
|
||||
```sh
|
||||
swift run -c release ResgenSwift strings tags $FORCE_FLAG "./Tags/tags.txt" \
|
||||
--lang "ium" \
|
||||
--extension-output-path "./Tags/Generated" \
|
||||
--extension-name "AppTags" \
|
||||
--extension-suffix "GreatApp" \
|
||||
--static-members true
|
||||
USAGE:
|
||||
swift run -c release ResgenSwift strings tags [-f] <input-file> \
|
||||
--extension-output-path <extension-output-path> \
|
||||
[--lang <lang>] \
|
||||
[--visibility <visibility>] \
|
||||
[--static-members <static-members>] \
|
||||
[--extension-name <extension-name>] \
|
||||
[--extension-suffix <extension-suffix>]
|
||||
|
||||
ARGUMENTS:
|
||||
<input-file> Input files where tags ared defined.
|
||||
|
||||
OPTIONS:
|
||||
-f, -F Should force generation
|
||||
--lang <lang> Lang to generate. ("ium" by default) (default: ium)
|
||||
--visibility <visibility>
|
||||
Visibility of extension and properties. Possibles values: public, private, package, internal. Default is internal (default: internal)
|
||||
--extension-output-path <extension-output-path>
|
||||
Path where to generate the extension.
|
||||
--static-members <static-members>
|
||||
Tell if it will generate static properties or not (default: false)
|
||||
--extension-name <extension-name>
|
||||
Extension name. If not specified, it will generate a Tag extension. (default: Tags)
|
||||
--extension-suffix <extension-suffix>
|
||||
Extension suffix. Ex: MyApp, it will generate {extensionName}+Tag{extensionSuffix}.swift
|
||||
--version Show the version.
|
||||
-h, --help Show help information.
|
||||
```
|
||||
|
||||
**Parameters**
|
||||
**Example**
|
||||
|
||||
1. `-f`: force generation
|
||||
2. Input tags file (must be Twine formatted)
|
||||
3. `--lang`: langs to look at in input file
|
||||
4. `--extension-output-path`: path where to generate generated extension
|
||||
5. `--extension-name` *(optional)* : name of class to add the extension
|
||||
6. `--extension-suffix` *(optional)* : additional text which is added to filename (ex: `AppTags+GreatApp.swift`)
|
||||
7. `--static-members` *(optional)*: generate static properties or not
|
||||
```sh
|
||||
swift run -c release ResgenSwift strings tags -f "./Tags/tags.txt" \
|
||||
--extension-output-path "./Tags/Generated" \
|
||||
--lang "ium" \
|
||||
--visibility "public" \
|
||||
--static-members true \
|
||||
--extension-name "AppTags" \
|
||||
--extension-suffix "GreatApp"
|
||||
```
|
||||
|
||||
> ⚠️ If extension name is not set or is `Tags`, it will generate the following typealias `typealias Tags = String`.
|
||||
|
||||
|
||||
## Analytics
|
||||
|
||||
Analytics will generate all you need to analyze UX with Matomo or Firebase Analytics. Input files are formatted in YAML. This command will generate a manager for each target and an AnalyticsManager. This is this one you will need to use. And it will generate a method for all tags you have declared in the YAML file. Next, you will need to use the `configure()` method of AnalyticsManager and if you want to use matomo to set up the `siteId` and the `url` of the site.
|
||||
|
||||
```sh
|
||||
swift run -c release ResgenSwift analytics $FORCE_FLAG "./Tags/analytics.yml" \
|
||||
--target "matomo firebase" \
|
||||
--output-file "./Analytics/Generated/AppAnalytics+GreatApp.swift" \
|
||||
--static-members true
|
||||
USAGE:
|
||||
swift run -c release ResgenSwift analytics [-f] <input-file> \
|
||||
--target <target> \
|
||||
--output-file <output-file> \
|
||||
[--static-members <static-members>] \
|
||||
[--visibility <visibility>]
|
||||
|
||||
ARGUMENTS:
|
||||
<input-file> Input files where tags ared defined.
|
||||
|
||||
OPTIONS:
|
||||
-f, -F Should force generation
|
||||
--target <target> Target(s) analytics to generate. ("matomo" | "firebase")
|
||||
--output-file <output-file>
|
||||
Where to generate the analytics manager (path with filename)
|
||||
--static-members <static-members>
|
||||
Tell if it will generate static properties or not (default: false)
|
||||
--visibility <visibility>
|
||||
Visibility of extension and properties. Possibles values: public, private, package, internal. Default is internal (default: internal)
|
||||
--version Show the version.
|
||||
-h, --help Show help information.
|
||||
```
|
||||
|
||||
**Parameters**
|
||||
**Example**
|
||||
|
||||
1. `-f`: force generation
|
||||
2. Input tags file (must be YAML formatted)
|
||||
3. `--target`: target with you will log UX
|
||||
4. `--output-file`: file where where to generate generated code, must contains path and filename (ex: `./Analytics/Generated/AppAnalytics+GreatApp.swift`)
|
||||
7. `--static-members` *(optional)*: generate static properties or not
|
||||
|
||||
> ⚠️ If extension name is not set or is `Analytics`, it will generate the following typealias `typealias Analytics = String`.
|
||||
```sh
|
||||
swift run -c release ResgenSwift analytics -f "./Tags/analytics.yml" \
|
||||
--target "matomo firebase" \
|
||||
--output-file "./Analytics/Generated/AppAnalytics+GreatApp.swift" \
|
||||
--static-members false \
|
||||
--visibility "public"
|
||||
```
|
||||
|
||||
### YAML
|
||||
|
||||
@@ -266,27 +419,59 @@ events:
|
||||
Images generator will generate images assets along with extensions to access those images easily. If the extension name is not specified, no extension will be generated.
|
||||
|
||||
```sh
|
||||
swift run -c release ResgenSwift images $FORCE_FLAG "./Images/images.txt" \
|
||||
USAGE:
|
||||
resgen-swift images [-f] [-F] <input-file> \
|
||||
--xcassets-path <xcassets-path> \
|
||||
[--static-members <static-members>] \
|
||||
[--visibility <visibility>] \
|
||||
[--asset-bundle <asset-bundle>] \
|
||||
[--extension-output-path <extension-output-path>] \
|
||||
[--extension-name <extension-name>] \
|
||||
[--extension-name-ui-kit <extension-name-ui-kit>] \
|
||||
[--extension-suffix <extension-suffix>]
|
||||
|
||||
ARGUMENTS:
|
||||
<input-file> Input files where strings ared defined.
|
||||
|
||||
OPTIONS:
|
||||
-f Should force script execution
|
||||
-F Regenerate all images
|
||||
--xcassets-path <xcassets-path>
|
||||
Xcassets path where to generate images.
|
||||
--static-members <static-members>
|
||||
Tell if it will generate static properties or not (default: false)
|
||||
--visibility <visibility>
|
||||
Visibility of extension and properties. Possibles values: public, private, package, internal. Default is internal (default: internal)
|
||||
--asset-bundle <asset-bundle>
|
||||
Bundle where the asset are generated (default: main)
|
||||
--extension-output-path <extension-output-path>
|
||||
Path where to generate the extension.
|
||||
--extension-name <extension-name>
|
||||
SwiftUI extension name. If not specified, no extension will be generated.
|
||||
--extension-name-ui-kit <extension-name-ui-kit>
|
||||
UIKit extension name. If not specified, no extension will be generated.
|
||||
--extension-suffix <extension-suffix>
|
||||
Extension suffix. Ex: MyApp, it will generate {extensionName}+Image{extensionSuffix}.swift
|
||||
--version Show the version.
|
||||
-h, --help Show help information.
|
||||
```
|
||||
|
||||
**Example**
|
||||
|
||||
```sh
|
||||
swift run -c release ResgenSwift images -F "./Images/images.txt" \
|
||||
--xcassets-path "./Images/app.xcassets" \
|
||||
--static-members false \
|
||||
--visibility "public" \
|
||||
--asset-bundle "module" \
|
||||
--extension-output-path "./Images/Generated" \
|
||||
--extension-name "AppImage" \
|
||||
--extension-name-ui-kit "UIAppImage" \
|
||||
--extension-suffix "GreatApp" \
|
||||
--static-members true
|
||||
--extension-suffix "GreatApp"
|
||||
```
|
||||
|
||||
**Parameters**
|
||||
> ⚠️ Option `extensionOutputPath` will require an `extensionName` or `extensionNameUIKit` to generate extension files. Passing an `extensionName` or `extensionNameUIKit` without `extensionOutputPath` will not generate any extension file.
|
||||
|
||||
1. `-f`: force generation
|
||||
2. Input images definitions file
|
||||
3. `--xcassets-path`: xcasset path where to generate imagesets
|
||||
4. `--extension-output-path` *(optional)* : path where to generate generated extension
|
||||
5. `--extension-name` *(optional)* : name of the class to add SwiftUI getters
|
||||
6. `--extension-name-ui-kit` *(optional)* : name of the class to add UIKit getters
|
||||
6. `--extension-suffix` *(optional)* : additional text which is added to filename (ex: `AppImage+GreatApp.swift`)
|
||||
7. `--static-members` *(optional)*: generate static properties or not
|
||||
|
||||
> ⚠️ Passing a `extensionOutputPath` without any `extensionName` does not generate extension. **But** passing an `extensionName` without `extensionOutputPath` will result in a error.
|
||||
> ⚠️ Svg images will be copied in the assets and rendered as "Original", however if those images are not rendered correctly you can force the png generation by adding the key word "png" like this: id arrow_back 15 ? png
|
||||
|
||||
## All at once
|
||||
@@ -302,13 +487,15 @@ All parameters can be specified in a configuration file in `Yaml`:
|
||||
colors:
|
||||
-
|
||||
inputFile: String
|
||||
style: [light/all]
|
||||
style: String
|
||||
xcassetsPath: String
|
||||
extensionOutputPath: String
|
||||
extensionName: String?
|
||||
extensionNameUIKit: String?
|
||||
extensionSuffix: String?
|
||||
staticMembers: Bool?
|
||||
visiblity: String?
|
||||
assetBundle: String?
|
||||
|
||||
fonts:
|
||||
-
|
||||
@@ -318,6 +505,7 @@ fonts:
|
||||
extensionNameUIKit: String?
|
||||
extensionSuffix: String?
|
||||
staticMembers: Bool?
|
||||
visiblity: String?
|
||||
infoPlistPaths: [String]
|
||||
|
||||
images:
|
||||
@@ -329,6 +517,8 @@ images:
|
||||
extensionNameUIKit: String?
|
||||
extensionSuffix: String?
|
||||
staticMembers: Bool?
|
||||
visiblity: String?
|
||||
assetBundle: String?
|
||||
|
||||
strings:
|
||||
-
|
||||
@@ -340,6 +530,9 @@ strings:
|
||||
extensionName: String?
|
||||
extensionSuffix: String?
|
||||
staticMembers: Bool?
|
||||
visiblity: String?
|
||||
assetBundle: String?
|
||||
xcStrings: Bool?
|
||||
|
||||
tags:
|
||||
-
|
||||
@@ -349,14 +542,14 @@ tags:
|
||||
extensionName: String?
|
||||
extensionSuffix: String?
|
||||
staticMembers: Bool?
|
||||
visiblity: String?
|
||||
|
||||
analytics:
|
||||
-
|
||||
inputFile: String
|
||||
target: String
|
||||
extensionOutputPath: String
|
||||
extensionName: String?
|
||||
extensionSuffix: String?
|
||||
outputFile: String
|
||||
visibility: String?
|
||||
staticMembers: Bool?
|
||||
```
|
||||
|
||||
@@ -371,22 +564,26 @@ Sample for 2 colors configurations:
|
||||
colors:
|
||||
-
|
||||
inputFile: String
|
||||
style: [light/all]
|
||||
style: String
|
||||
xcassetsPath: String
|
||||
extensionOutputPath: String
|
||||
extensionName: String?
|
||||
extensionNameUIKit: String?
|
||||
extensionSuffix: String?
|
||||
staticMembers: Bool?
|
||||
visiblity: String?
|
||||
assetBundle: String?
|
||||
-
|
||||
inputFile: String
|
||||
style: [light/all]
|
||||
style: String
|
||||
xcassetsPath: String
|
||||
extensionOutputPath: String
|
||||
extensionName: String?
|
||||
extensionNameUIKit: String?
|
||||
extensionSuffix: String?
|
||||
staticMembers: Bool?
|
||||
visiblity: String?
|
||||
assetBundle: String?
|
||||
...
|
||||
```
|
||||
|
||||
@@ -430,8 +627,9 @@ architecture:
|
||||
```
|
||||
|
||||
This will generate a file named as the architecture classname: `R.swift`. Based on the previous architecture, it will generate:
|
||||
```
|
||||
class R {
|
||||
|
||||
```swift
|
||||
class R: Sendable {
|
||||
static let images = R2Image()
|
||||
static let strings = R2String()
|
||||
static let fonts = R2Font()
|
||||
@@ -439,25 +637,25 @@ class R {
|
||||
static let uikit = R2UI()
|
||||
}
|
||||
|
||||
class R2Image {}
|
||||
class R2Image: Sendable {}
|
||||
|
||||
class R2String {}
|
||||
class R2String: Sendable {}
|
||||
|
||||
class R2Font {}
|
||||
class R2Font: Sendable {}
|
||||
|
||||
class R2Image {}
|
||||
class R2Image: Sendable {}
|
||||
|
||||
class R2UI {
|
||||
class R2UI: Sendable {
|
||||
let images = R2UIImage()
|
||||
let fonts = R2UIFont()
|
||||
let images = R2UIImage()
|
||||
}
|
||||
|
||||
class R2UIImage {}
|
||||
class R2UIImage: Sendable {}
|
||||
|
||||
class R2UIFont {}
|
||||
class R2UIFont: Sendable {}
|
||||
|
||||
class R2UIImage {}
|
||||
class R2UIImage: Sendable {}
|
||||
```
|
||||
|
||||
|
||||
|
@@ -49,7 +49,7 @@ struct Analytics: ParsableCommand {
|
||||
sections: sections,
|
||||
target: options.target,
|
||||
tags: ["ios", "iosonly"],
|
||||
staticVar: options.staticMembers,
|
||||
isStatic: options.staticMembers,
|
||||
outputFile: options.outputFile,
|
||||
visibility: options.extensionVisibility
|
||||
)
|
||||
|
@@ -22,7 +22,7 @@ enum AnalyticsGenerator {
|
||||
sections: [AnalyticsCategory],
|
||||
target: String,
|
||||
tags: [String],
|
||||
staticVar: Bool,
|
||||
isStatic: Bool,
|
||||
outputFile: String,
|
||||
visibility: ExtensionVisibility
|
||||
) {
|
||||
@@ -43,7 +43,7 @@ enum AnalyticsGenerator {
|
||||
targets: targets,
|
||||
sections: sections,
|
||||
tags: tags,
|
||||
staticVar: staticVar,
|
||||
isStatic: isStatic,
|
||||
visibility: visibility
|
||||
)
|
||||
|
||||
@@ -64,19 +64,19 @@ enum AnalyticsGenerator {
|
||||
targets: [TrackerType],
|
||||
sections: [AnalyticsCategory],
|
||||
tags: [String],
|
||||
staticVar: Bool,
|
||||
isStatic: Bool,
|
||||
visibility: ExtensionVisibility
|
||||
) -> String {
|
||||
[
|
||||
getHeader(
|
||||
targets: targets,
|
||||
staticVar: staticVar,
|
||||
isStatic: isStatic,
|
||||
visibility: visibility
|
||||
),
|
||||
getProperties(
|
||||
sections: sections,
|
||||
tags: tags,
|
||||
staticVar: staticVar,
|
||||
isStatic: isStatic,
|
||||
visibility: visibility
|
||||
),
|
||||
getFooter()
|
||||
@@ -88,7 +88,7 @@ enum AnalyticsGenerator {
|
||||
|
||||
private static func getHeader(
|
||||
targets: [TrackerType],
|
||||
staticVar: Bool,
|
||||
isStatic: Bool,
|
||||
visibility: ExtensionVisibility
|
||||
) -> String {
|
||||
"""
|
||||
@@ -306,7 +306,7 @@ enum AnalyticsGenerator {
|
||||
private static func getProperties(
|
||||
sections: [AnalyticsCategory],
|
||||
tags: [String],
|
||||
staticVar: Bool,
|
||||
isStatic: Bool,
|
||||
visibility: ExtensionVisibility
|
||||
) -> String {
|
||||
sections
|
||||
@@ -322,7 +322,7 @@ enum AnalyticsGenerator {
|
||||
return // Go to next definition
|
||||
}
|
||||
|
||||
if staticVar {
|
||||
if isStatic {
|
||||
res += "\n\n\(definition.getStaticProperty(visibility: visibility))"
|
||||
} else {
|
||||
res += "\n\n\(definition.getProperty(visibility: visibility))"
|
||||
|
@@ -59,11 +59,12 @@ struct Colors: ParsableCommand {
|
||||
let extensionFilePath = options.extensionFilePath {
|
||||
ColorExtensionGenerator.writeExtensionFile(
|
||||
colors: parsedColors,
|
||||
staticVar: options.staticMembers,
|
||||
isStatic: options.staticMembers,
|
||||
extensionName: extensionName,
|
||||
extensionFilePath: extensionFilePath,
|
||||
isSwiftUI: true,
|
||||
visibility: options.extensionVisibility
|
||||
visibility: options.extensionVisibility,
|
||||
assetBundle: options.assetBundle
|
||||
)
|
||||
}
|
||||
|
||||
@@ -72,11 +73,12 @@ struct Colors: ParsableCommand {
|
||||
let extensionFilePathUIKit = options.extensionFilePathUIKit {
|
||||
ColorExtensionGenerator.writeExtensionFile(
|
||||
colors: parsedColors,
|
||||
staticVar: options.staticMembers,
|
||||
isStatic: options.staticMembers,
|
||||
extensionName: extensionNameUIKit,
|
||||
extensionFilePath: extensionFilePathUIKit,
|
||||
isSwiftUI: false,
|
||||
visibility: options.extensionVisibility
|
||||
visibility: options.extensionVisibility,
|
||||
assetBundle: options.assetBundle
|
||||
)
|
||||
}
|
||||
|
||||
|
@@ -5,6 +5,8 @@
|
||||
// Created by Thibaut Schmitt on 17/01/2022.
|
||||
//
|
||||
|
||||
// CPD-OFF
|
||||
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
import ToolCore
|
||||
@@ -44,6 +46,11 @@ struct ColorsToolOptions: ParsableArguments {
|
||||
)
|
||||
var extensionVisibility: ExtensionVisibility = .internal
|
||||
|
||||
@Option(
|
||||
help: "Bundle where the asset are generated"
|
||||
)
|
||||
var assetBundle: AssetBundle = .main
|
||||
|
||||
@Option(
|
||||
help: "Path where to generate the extension.",
|
||||
transform: { $0.replaceTiltWithHomeDirectoryPath() }
|
||||
@@ -97,4 +104,4 @@ extension ColorsToolOptions {
|
||||
|
||||
return "\(extensionOutputPath)/\(extensionFileNameUIKit)"
|
||||
}
|
||||
}
|
||||
}// CPD-ON
|
||||
|
@@ -17,19 +17,21 @@ struct ColorExtensionGenerator {
|
||||
|
||||
static func writeExtensionFile(
|
||||
colors: [ParsedColor],
|
||||
staticVar: Bool,
|
||||
isStatic: Bool,
|
||||
extensionName: String,
|
||||
extensionFilePath: String,
|
||||
isSwiftUI: Bool,
|
||||
visibility: ExtensionVisibility
|
||||
visibility: ExtensionVisibility,
|
||||
assetBundle: AssetBundle
|
||||
) {
|
||||
// Create extension content
|
||||
let extensionContent = Self.getExtensionContent(
|
||||
colors: colors,
|
||||
staticVar: staticVar,
|
||||
isStatic: isStatic,
|
||||
extensionName: extensionName,
|
||||
isSwiftUI: isSwiftUI,
|
||||
visibility: visibility
|
||||
visibility: visibility,
|
||||
assetBundle: assetBundle
|
||||
)
|
||||
|
||||
// Write content
|
||||
@@ -45,10 +47,11 @@ struct ColorExtensionGenerator {
|
||||
|
||||
static func getExtensionContent(
|
||||
colors: [ParsedColor],
|
||||
staticVar: Bool,
|
||||
isStatic: Bool,
|
||||
extensionName: String,
|
||||
isSwiftUI: Bool,
|
||||
visibility: ExtensionVisibility
|
||||
visibility: ExtensionVisibility,
|
||||
assetBundle: AssetBundle
|
||||
) -> String {
|
||||
[
|
||||
Self.getHeader(
|
||||
@@ -57,9 +60,10 @@ struct ColorExtensionGenerator {
|
||||
),
|
||||
Self.getProperties(
|
||||
for: colors,
|
||||
withStaticVar: staticVar,
|
||||
withIsStatic: isStatic,
|
||||
isSwiftUI: isSwiftUI,
|
||||
visibility: visibility
|
||||
visibility: visibility,
|
||||
assetBundle: assetBundle
|
||||
),
|
||||
Self.getFooter()
|
||||
]
|
||||
@@ -85,15 +89,17 @@ struct ColorExtensionGenerator {
|
||||
|
||||
private static func getProperties(
|
||||
for colors: [ParsedColor],
|
||||
withStaticVar staticVar: Bool,
|
||||
withIsStatic isStatic: Bool,
|
||||
isSwiftUI: Bool,
|
||||
visibility: ExtensionVisibility
|
||||
visibility: ExtensionVisibility,
|
||||
assetBundle: AssetBundle
|
||||
) -> String {
|
||||
colors.map {
|
||||
$0.getColorProperty(
|
||||
isStatic: staticVar,
|
||||
isStatic: isStatic,
|
||||
isSwiftUI: isSwiftUI,
|
||||
visibility: visibility
|
||||
visibility: visibility,
|
||||
assetBundle: assetBundle
|
||||
)
|
||||
}
|
||||
.joined(separator: "\n\n")
|
||||
|
@@ -83,20 +83,21 @@ struct ParsedColor {
|
||||
func getColorProperty(
|
||||
isStatic: Bool,
|
||||
isSwiftUI: Bool,
|
||||
visibility: ExtensionVisibility
|
||||
visibility: ExtensionVisibility,
|
||||
assetBundle: AssetBundle
|
||||
) -> String {
|
||||
if isSwiftUI {
|
||||
return """
|
||||
/// Color \(name) is \(light) (light) or \(dark) (dark)"
|
||||
\(visibility) \(isStatic ? "static " : "")var \(name): Color {
|
||||
Color("\(name)")
|
||||
Color("\(name)", bundle: Bundle.\(assetBundle))
|
||||
}
|
||||
"""
|
||||
}
|
||||
return """
|
||||
/// Color \(name) is \(light) (light) or \(dark) (dark)"
|
||||
\(isStatic ? "" : "@objc ")\(visibility) \(isStatic ? "static " : "")var \(name): UIColor {
|
||||
UIColor(named: "\(name)")!
|
||||
UIColor(named: "\(name)", in: Bundle.\(assetBundle), compatibleWith: nil)!
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
@@ -54,7 +54,7 @@ struct Fonts: ParsableCommand {
|
||||
// Generate extension
|
||||
FontExtensionGenerator.writeExtensionFile(
|
||||
fontsNames: fontsNames,
|
||||
staticVar: options.staticMembers,
|
||||
isStatic: options.staticMembers,
|
||||
extensionName: options.extensionName,
|
||||
extensionFilePath: options.extensionFilePath,
|
||||
isSwiftUI: true,
|
||||
@@ -65,7 +65,7 @@ struct Fonts: ParsableCommand {
|
||||
let extensionFilePathUIKit = options.extensionFilePathUIKit {
|
||||
FontExtensionGenerator.writeExtensionFile(
|
||||
fontsNames: fontsNames,
|
||||
staticVar: options.staticMembers,
|
||||
isStatic: options.staticMembers,
|
||||
extensionName: extensionNameUIKit,
|
||||
extensionFilePath: extensionFilePathUIKit,
|
||||
isSwiftUI: false,
|
||||
|
@@ -26,7 +26,7 @@ enum FontExtensionGenerator {
|
||||
|
||||
static func writeExtensionFile(
|
||||
fontsNames: [FontName],
|
||||
staticVar: Bool,
|
||||
isStatic: Bool,
|
||||
extensionName: String,
|
||||
extensionFilePath: String,
|
||||
isSwiftUI: Bool,
|
||||
@@ -35,7 +35,7 @@ enum FontExtensionGenerator {
|
||||
// Create extension content
|
||||
let extensionContent = Self.getExtensionContent(
|
||||
fontsNames: fontsNames,
|
||||
staticVar: staticVar,
|
||||
isStatic: isStatic,
|
||||
extensionName: extensionName,
|
||||
isSwiftUI: isSwiftUI,
|
||||
visibility: visibility
|
||||
@@ -54,7 +54,7 @@ enum FontExtensionGenerator {
|
||||
|
||||
static func getExtensionContent(
|
||||
fontsNames: [FontName],
|
||||
staticVar: Bool,
|
||||
isStatic: Bool,
|
||||
extensionName: String,
|
||||
isSwiftUI: Bool,
|
||||
visibility: ExtensionVisibility
|
||||
@@ -70,7 +70,7 @@ enum FontExtensionGenerator {
|
||||
),
|
||||
Self.getFontMethods(
|
||||
fontsNames: fontsNames,
|
||||
staticVar: staticVar,
|
||||
isStatic: isStatic,
|
||||
isSwiftUI: isSwiftUI,
|
||||
visibility: visibility
|
||||
),
|
||||
@@ -94,7 +94,7 @@ enum FontExtensionGenerator {
|
||||
|
||||
private static func getFontMethods(
|
||||
fontsNames: [FontName],
|
||||
staticVar: Bool,
|
||||
isStatic: Bool,
|
||||
isSwiftUI: Bool,
|
||||
visibility: ExtensionVisibility
|
||||
) -> String {
|
||||
@@ -104,7 +104,7 @@ enum FontExtensionGenerator {
|
||||
.unique()
|
||||
.map {
|
||||
$0.getProperty(
|
||||
isStatic: staticVar,
|
||||
isStatic: isStatic,
|
||||
isSwiftUI: isSwiftUI,
|
||||
visibility: visibility
|
||||
)
|
||||
|
@@ -126,6 +126,7 @@ struct ColorsConfiguration: Codable, CustomDebugStringConvertible {
|
||||
let extensionNameUIKit: String?
|
||||
let extensionSuffix: String?
|
||||
let visibility: String?
|
||||
let assetBundle: String?
|
||||
let staticMembers: Bool?
|
||||
|
||||
internal init(
|
||||
@@ -137,6 +138,7 @@ struct ColorsConfiguration: Codable, CustomDebugStringConvertible {
|
||||
extensionNameUIKit: String?,
|
||||
extensionSuffix: String?,
|
||||
visibility: String?,
|
||||
assetBundle: String?,
|
||||
staticMembers: Bool?
|
||||
) {
|
||||
self.inputFile = inputFile
|
||||
@@ -147,6 +149,7 @@ struct ColorsConfiguration: Codable, CustomDebugStringConvertible {
|
||||
self.extensionNameUIKit = extensionNameUIKit
|
||||
self.extensionSuffix = extensionSuffix
|
||||
self.visibility = visibility
|
||||
self.assetBundle = assetBundle
|
||||
self.staticMembers = staticMembers
|
||||
}
|
||||
|
||||
@@ -161,6 +164,7 @@ struct ColorsConfiguration: Codable, CustomDebugStringConvertible {
|
||||
- Extension name UIKit: \(extensionNameUIKit ?? "-")
|
||||
- Extension suffix: \(extensionSuffix ?? "-")
|
||||
- Visiblity: \(visibility ?? "default")
|
||||
- Asset Bundle: \(assetBundle ?? "default")
|
||||
- Static members: \(staticMembers != nil ? "\(String(describing: staticMembers))" : "default")
|
||||
"""
|
||||
}
|
||||
@@ -221,6 +225,7 @@ struct ImagesConfiguration: Codable, CustomDebugStringConvertible {
|
||||
let extensionNameUIKit: String?
|
||||
let extensionSuffix: String?
|
||||
let visibility: String?
|
||||
let assetBundle: String?
|
||||
let staticMembers: Bool?
|
||||
|
||||
internal init(
|
||||
@@ -231,6 +236,7 @@ struct ImagesConfiguration: Codable, CustomDebugStringConvertible {
|
||||
extensionNameUIKit: String?,
|
||||
extensionSuffix: String?,
|
||||
visibility: String?,
|
||||
assetBundle: String?,
|
||||
staticMembers: Bool?
|
||||
) {
|
||||
self.inputFile = inputFile
|
||||
@@ -240,6 +246,7 @@ struct ImagesConfiguration: Codable, CustomDebugStringConvertible {
|
||||
self.extensionNameUIKit = extensionNameUIKit
|
||||
self.extensionSuffix = extensionSuffix
|
||||
self.visibility = visibility
|
||||
self.assetBundle = assetBundle
|
||||
self.staticMembers = staticMembers
|
||||
}
|
||||
|
||||
@@ -253,6 +260,7 @@ struct ImagesConfiguration: Codable, CustomDebugStringConvertible {
|
||||
- Extension name UIKit: \(extensionNameUIKit ?? "-")
|
||||
- Extension suffix: \(extensionSuffix ?? "-")
|
||||
- Visiblity: \(visibility ?? "default")
|
||||
- Asset Bundle: \(assetBundle ?? "default")
|
||||
- Static members: \(staticMembers != nil ? "\(String(describing: staticMembers))" : "default")
|
||||
"""
|
||||
}
|
||||
@@ -268,6 +276,7 @@ struct StringsConfiguration: Codable, CustomDebugStringConvertible {
|
||||
let extensionName: String?
|
||||
let extensionSuffix: String?
|
||||
let visibility: String?
|
||||
let assetBundle: String?
|
||||
let staticMembers: Bool?
|
||||
let xcStrings: Bool?
|
||||
|
||||
@@ -280,6 +289,7 @@ struct StringsConfiguration: Codable, CustomDebugStringConvertible {
|
||||
extensionName: String?,
|
||||
extensionSuffix: String?,
|
||||
visibility: String?,
|
||||
assetBundle: String?,
|
||||
staticMembers: Bool?,
|
||||
xcStrings: Bool?
|
||||
) {
|
||||
@@ -291,6 +301,7 @@ struct StringsConfiguration: Codable, CustomDebugStringConvertible {
|
||||
self.extensionName = extensionName
|
||||
self.extensionSuffix = extensionSuffix
|
||||
self.visibility = visibility
|
||||
self.assetBundle = assetBundle
|
||||
self.staticMembers = staticMembers
|
||||
self.xcStrings = xcStrings
|
||||
}
|
||||
@@ -306,6 +317,7 @@ struct StringsConfiguration: Codable, CustomDebugStringConvertible {
|
||||
- Extension name: \(extensionName ?? "-")
|
||||
- Extension suffix: \(extensionSuffix ?? "-")
|
||||
- Visiblity: \(visibility ?? "default")
|
||||
- Asset Bundle: \(assetBundle ?? "default")
|
||||
- Static members: \(staticMembers != nil ? "\(String(describing: staticMembers))" : "default")
|
||||
- XC Strings: \(xcStrings != nil ? "\(String(describing: xcStrings))" : "default")
|
||||
"""
|
||||
|
@@ -36,6 +36,7 @@ extension ColorsConfiguration: Runnable {
|
||||
("--extension-name-ui-kit", extensionNameUIKit),
|
||||
("--extension-suffix", extensionSuffix),
|
||||
("--visibility", visibility),
|
||||
("--asset-bundle", assetBundle),
|
||||
("--static-members", staticMembers?.description)
|
||||
].forEach { argumentName, argumentValue in
|
||||
if let argumentValue {
|
||||
|
@@ -34,6 +34,7 @@ extension ImagesConfiguration: Runnable {
|
||||
("--extension-name-ui-kit", extensionNameUIKit),
|
||||
("--extension-suffix", extensionSuffix),
|
||||
("--visibility", visibility),
|
||||
("--asset-bundle", assetBundle),
|
||||
("--static-members", staticMembers?.description)
|
||||
].forEach { argumentName, argumentValue in
|
||||
if let argumentValue {
|
||||
|
@@ -37,6 +37,7 @@ extension StringsConfiguration: Runnable {
|
||||
("--extension-name", extensionName),
|
||||
("--extension-suffix", extensionSuffix),
|
||||
("--visibility", visibility),
|
||||
("--asset-bundle", assetBundle),
|
||||
("--xc-strings", staticMembers?.description),
|
||||
("--static-members", xcStrings?.description)
|
||||
].forEach { argumentName, argumentValue in
|
||||
|
@@ -14,21 +14,23 @@ enum ImageExtensionGenerator {
|
||||
|
||||
static func generateExtensionFile(
|
||||
images: [ParsedImage],
|
||||
staticVar: Bool,
|
||||
isStatic: Bool,
|
||||
inputFilename: String,
|
||||
extensionName: String,
|
||||
extensionFilePath: String,
|
||||
isSwiftUI: Bool,
|
||||
visibility: ExtensionVisibility
|
||||
visibility: ExtensionVisibility,
|
||||
assetBundle: AssetBundle
|
||||
) {
|
||||
// Create extension conten1t
|
||||
let extensionContent = Self.getExtensionContent(
|
||||
images: images,
|
||||
staticVar: staticVar,
|
||||
isStatic: isStatic,
|
||||
extensionName: extensionName,
|
||||
inputFilename: inputFilename,
|
||||
isSwiftUI: isSwiftUI,
|
||||
visibility: visibility
|
||||
visibility: visibility,
|
||||
assetBundle: assetBundle
|
||||
)
|
||||
|
||||
// Write content
|
||||
@@ -44,11 +46,12 @@ enum ImageExtensionGenerator {
|
||||
|
||||
static func getExtensionContent(
|
||||
images: [ParsedImage],
|
||||
staticVar: Bool,
|
||||
isStatic: Bool,
|
||||
extensionName: String,
|
||||
inputFilename: String,
|
||||
isSwiftUI: Bool,
|
||||
visibility: ExtensionVisibility
|
||||
visibility: ExtensionVisibility,
|
||||
assetBundle: AssetBundle
|
||||
) -> String {
|
||||
[
|
||||
Self.getHeader(
|
||||
@@ -58,9 +61,10 @@ enum ImageExtensionGenerator {
|
||||
),
|
||||
Self.getProperties(
|
||||
images: images,
|
||||
staticVar: staticVar,
|
||||
isStatic: isStatic,
|
||||
isSwiftUI: isSwiftUI,
|
||||
visibility: visibility
|
||||
visibility: visibility,
|
||||
assetBundle: assetBundle
|
||||
),
|
||||
Self.getFooter()
|
||||
]
|
||||
@@ -84,13 +88,20 @@ enum ImageExtensionGenerator {
|
||||
|
||||
private static func getProperties(
|
||||
images: [ParsedImage],
|
||||
staticVar: Bool,
|
||||
isStatic: Bool,
|
||||
isSwiftUI: Bool,
|
||||
visibility: ExtensionVisibility
|
||||
visibility: ExtensionVisibility,
|
||||
assetBundle: AssetBundle
|
||||
) -> String {
|
||||
images
|
||||
.map {
|
||||
"\n\($0.getImageProperty(isStatic: staticVar, isSwiftUI: isSwiftUI, visibility: visibility))"
|
||||
.map { parsedImage in
|
||||
let property = parsedImage.getImageProperty(
|
||||
isStatic: isStatic,
|
||||
isSwiftUI: isSwiftUI,
|
||||
visibility: visibility,
|
||||
assetBundle: assetBundle
|
||||
)
|
||||
return "\n\(property)"
|
||||
}
|
||||
.joined(separator: "\n")
|
||||
}
|
||||
|
@@ -57,12 +57,13 @@ struct Images: ParsableCommand {
|
||||
let extensionFilePath = options.extensionFilePath {
|
||||
ImageExtensionGenerator.generateExtensionFile(
|
||||
images: imagesToGenerate,
|
||||
staticVar: options.staticMembers,
|
||||
isStatic: options.staticMembers,
|
||||
inputFilename: options.inputFilenameWithoutExt,
|
||||
extensionName: extensionName,
|
||||
extensionFilePath: extensionFilePath,
|
||||
isSwiftUI: true,
|
||||
visibility: options.extensionVisibility
|
||||
visibility: options.extensionVisibility,
|
||||
assetBundle: options.assetBundle
|
||||
)
|
||||
}
|
||||
|
||||
@@ -70,12 +71,13 @@ struct Images: ParsableCommand {
|
||||
let extensionFilePathUIKit = options.extensionFilePathUIKit {
|
||||
ImageExtensionGenerator.generateExtensionFile(
|
||||
images: imagesToGenerate,
|
||||
staticVar: options.staticMembers,
|
||||
isStatic: options.staticMembers,
|
||||
inputFilename: options.inputFilenameWithoutExt,
|
||||
extensionName: extensionNameUIKit,
|
||||
extensionFilePath: extensionFilePathUIKit,
|
||||
isSwiftUI: false,
|
||||
visibility: options.extensionVisibility
|
||||
visibility: options.extensionVisibility,
|
||||
assetBundle: options.assetBundle
|
||||
)
|
||||
}
|
||||
|
||||
|
@@ -5,6 +5,8 @@
|
||||
// Created by Thibaut Schmitt on 24/01/2022.
|
||||
//
|
||||
|
||||
// CPD-OFF
|
||||
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
import ToolCore
|
||||
@@ -51,6 +53,11 @@ struct ImagesOptions: ParsableArguments {
|
||||
)
|
||||
var extensionVisibility: ExtensionVisibility = .internal
|
||||
|
||||
@Option(
|
||||
help: "Bundle where the asset are generated"
|
||||
)
|
||||
var assetBundle: AssetBundle = .main
|
||||
|
||||
@Option(
|
||||
help: "Path where to generate the extension.",
|
||||
transform: { $0.replaceTiltWithHomeDirectoryPath() }
|
||||
@@ -113,3 +120,5 @@ extension ImagesOptions {
|
||||
.lastPathComponent
|
||||
}
|
||||
}
|
||||
|
||||
// CPD-ON
|
||||
|
@@ -130,17 +130,22 @@ struct ParsedImage {
|
||||
|
||||
// MARK: - Extension property
|
||||
|
||||
func getImageProperty(isStatic: Bool, isSwiftUI: Bool, visibility: ExtensionVisibility) -> String {
|
||||
func getImageProperty(
|
||||
isStatic: Bool,
|
||||
isSwiftUI: Bool,
|
||||
visibility: ExtensionVisibility,
|
||||
assetBundle: AssetBundle
|
||||
) -> String {
|
||||
if isSwiftUI {
|
||||
return """
|
||||
\(visibility) \(isStatic ? "static " : "")var \(name): Image {
|
||||
Image("\(name)")
|
||||
Image("\(name)", bundle: Bundle.\(assetBundle))
|
||||
}
|
||||
"""
|
||||
}
|
||||
return """
|
||||
\(visibility) \(isStatic ? "static " : "")var \(name): UIImage {
|
||||
UIImage(named: "\(name)")!
|
||||
UIImage(named: "\(name)", in: Bundle.\(assetBundle), with: nil)!
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
@@ -247,23 +247,25 @@ enum StringsFileGenerator {
|
||||
sections: [Section],
|
||||
defaultLang lang: String,
|
||||
tags: [String],
|
||||
staticVar: Bool,
|
||||
isStatic: Bool,
|
||||
inputFilename: String,
|
||||
extensionName: String,
|
||||
extensionFilePath: String,
|
||||
extensionSuffix: String,
|
||||
visibility: ExtensionVisibility
|
||||
visibility: ExtensionVisibility,
|
||||
assetBundle: AssetBundle
|
||||
) {
|
||||
// Get extension content
|
||||
let extensionFileContent = Self.getExtensionContent(
|
||||
sections: sections,
|
||||
defaultLang: lang,
|
||||
tags: tags,
|
||||
staticVar: staticVar,
|
||||
isStatic: isStatic,
|
||||
inputFilename: inputFilename,
|
||||
extensionName: extensionName,
|
||||
extensionSuffix: extensionSuffix,
|
||||
visibility: visibility
|
||||
visibility: visibility,
|
||||
assetBundle: assetBundle
|
||||
)
|
||||
|
||||
// Write content
|
||||
@@ -283,11 +285,12 @@ enum StringsFileGenerator {
|
||||
sections: [Section],
|
||||
defaultLang lang: String,
|
||||
tags: [String],
|
||||
staticVar: Bool,
|
||||
isStatic: Bool,
|
||||
inputFilename: String,
|
||||
extensionName: String,
|
||||
extensionSuffix: String,
|
||||
visibility: ExtensionVisibility
|
||||
visibility: ExtensionVisibility,
|
||||
assetBundle: AssetBundle
|
||||
) -> String {
|
||||
[
|
||||
Self.getHeader(
|
||||
@@ -305,8 +308,9 @@ enum StringsFileGenerator {
|
||||
sections: sections,
|
||||
defaultLang: lang,
|
||||
tags: tags,
|
||||
staticVar: staticVar,
|
||||
visibility: visibility
|
||||
isStatic: isStatic,
|
||||
visibility: visibility,
|
||||
assetBundle: assetBundle
|
||||
),
|
||||
Self.getFooter()
|
||||
]
|
||||
@@ -379,8 +383,9 @@ enum StringsFileGenerator {
|
||||
sections: [Section],
|
||||
defaultLang lang: String,
|
||||
tags: [String],
|
||||
staticVar: Bool,
|
||||
visibility: ExtensionVisibility
|
||||
isStatic: Bool,
|
||||
visibility: ExtensionVisibility,
|
||||
assetBundle: AssetBundle
|
||||
) -> String {
|
||||
sections.compactMap { section in
|
||||
// Check that at least one string will be generated
|
||||
@@ -394,19 +399,12 @@ enum StringsFileGenerator {
|
||||
return nil // Go to next definition
|
||||
}
|
||||
|
||||
let property: String = {
|
||||
if staticVar {
|
||||
definition.getNSLocalizedStringStaticProperty(
|
||||
forLang: lang,
|
||||
visibility: visibility
|
||||
)
|
||||
} else {
|
||||
definition.getNSLocalizedStringProperty(
|
||||
forLang: lang,
|
||||
visibility: visibility
|
||||
)
|
||||
}
|
||||
}()
|
||||
let property = definition.getNSLocalizedStringProperty(
|
||||
forLang: lang,
|
||||
isStatic: isStatic,
|
||||
visibility: visibility,
|
||||
assetBundle: assetBundle
|
||||
)
|
||||
|
||||
return "\n\(property)"
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ enum TagsGenerator {
|
||||
sections: [Section],
|
||||
lang: String,
|
||||
tags: [String],
|
||||
staticVar: Bool,
|
||||
isStatic: Bool,
|
||||
extensionName: String,
|
||||
extensionFilePath: String,
|
||||
visibility: ExtensionVisibility
|
||||
@@ -25,7 +25,7 @@ enum TagsGenerator {
|
||||
sections: sections,
|
||||
lang: lang,
|
||||
tags: tags,
|
||||
staticVar: staticVar,
|
||||
isStatic: isStatic,
|
||||
extensionName: extensionName,
|
||||
visibility: visibility
|
||||
)
|
||||
@@ -47,20 +47,20 @@ enum TagsGenerator {
|
||||
sections: [Section],
|
||||
lang: String,
|
||||
tags: [String],
|
||||
staticVar: Bool,
|
||||
isStatic: Bool,
|
||||
extensionName: String,
|
||||
visibility: ExtensionVisibility
|
||||
) -> String {
|
||||
[
|
||||
Self.getHeader(
|
||||
extensionClassname: extensionName,
|
||||
staticVar: staticVar
|
||||
isStatic: isStatic
|
||||
),
|
||||
Self.getProperties(
|
||||
sections: sections,
|
||||
lang: lang,
|
||||
tags: tags,
|
||||
staticVar: staticVar,
|
||||
isStatic: isStatic,
|
||||
visibility: visibility
|
||||
),
|
||||
Self.getFooter()
|
||||
@@ -70,11 +70,11 @@ enum TagsGenerator {
|
||||
|
||||
// MARK: - Extension part
|
||||
|
||||
private static func getHeader(extensionClassname: String, staticVar: Bool) -> String {
|
||||
private static func getHeader(extensionClassname: String, isStatic: Bool) -> String {
|
||||
"""
|
||||
// Generated by ResgenSwift.Strings.\(Tags.toolName) \(ResgenSwiftVersion)
|
||||
|
||||
\(staticVar ? "typelias Tags = String\n\n" : "")import UIKit
|
||||
\(isStatic ? "typelias Tags = String\n\n" : "")import UIKit
|
||||
|
||||
extension \(extensionClassname) {
|
||||
"""
|
||||
@@ -84,7 +84,7 @@ enum TagsGenerator {
|
||||
sections: [Section],
|
||||
lang: String,
|
||||
tags: [String],
|
||||
staticVar: Bool,
|
||||
isStatic: Bool,
|
||||
visibility: ExtensionVisibility
|
||||
) -> String {
|
||||
sections
|
||||
@@ -100,11 +100,12 @@ enum TagsGenerator {
|
||||
return // Go to next definition
|
||||
}
|
||||
|
||||
if staticVar {
|
||||
res += "\n\n\(definition.getStaticProperty(forLang: lang, visibility: visibility))"
|
||||
} else {
|
||||
res += "\n\n\(definition.getProperty(forLang: lang, visibility: visibility))"
|
||||
}
|
||||
let property = definition.getProperty(
|
||||
forLang: lang,
|
||||
visibility: visibility,
|
||||
isStatic: isStatic
|
||||
)
|
||||
res += "\n\n\(property)"
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
@@ -105,7 +105,8 @@ class Definition {
|
||||
translation: String,
|
||||
isStatic: Bool,
|
||||
comment: String?,
|
||||
visibility: ExtensionVisibility
|
||||
visibility: ExtensionVisibility,
|
||||
assetBundle: AssetBundle
|
||||
) -> String {
|
||||
"""
|
||||
/// Translation in \(lang) :
|
||||
@@ -114,7 +115,7 @@ class Definition {
|
||||
/// Comment :
|
||||
/// \(comment?.isEmpty == false ? comment! : "No comment")
|
||||
\(visibility) \(isStatic ? "static " : "")var \(name): String {
|
||||
NSLocalizedString("\(name)", tableName: kStringsFileName, bundle: Bundle.main, value: "\(translation)", comment: "\(comment ?? "")")
|
||||
NSLocalizedString("\(name)", tableName: kStringsFileName, bundle: Bundle.\(assetBundle), value: "\(translation)", comment: "\(comment ?? "")")
|
||||
}
|
||||
"""
|
||||
}
|
||||
@@ -141,7 +142,12 @@ class Definition {
|
||||
"""
|
||||
}
|
||||
|
||||
func getNSLocalizedStringProperty(forLang lang: String, visibility: ExtensionVisibility) -> String {
|
||||
func getNSLocalizedStringProperty(
|
||||
forLang lang: String,
|
||||
isStatic: Bool,
|
||||
visibility: ExtensionVisibility,
|
||||
assetBundle: AssetBundle
|
||||
) -> String {
|
||||
guard let translation = translations[lang] else {
|
||||
let error = StringiumError.langNotDefined(lang, name, reference != nil)
|
||||
print(error.description)
|
||||
@@ -152,9 +158,10 @@ class Definition {
|
||||
let property = getBaseProperty(
|
||||
lang: lang,
|
||||
translation: translation,
|
||||
isStatic: false,
|
||||
isStatic: isStatic,
|
||||
comment: self.comment,
|
||||
visibility: visibility
|
||||
visibility: visibility,
|
||||
assetBundle: assetBundle
|
||||
)
|
||||
|
||||
// Generate method
|
||||
@@ -163,40 +170,7 @@ class Definition {
|
||||
method = getBaseMethod(
|
||||
lang: lang,
|
||||
translation: translation,
|
||||
isStatic: false,
|
||||
inputParameters: parameters.inputParameters,
|
||||
translationArguments: parameters.translationArguments,
|
||||
comment: self.comment,
|
||||
visibility: visibility
|
||||
)
|
||||
}
|
||||
|
||||
return property + method
|
||||
}
|
||||
|
||||
func getNSLocalizedStringStaticProperty(forLang lang: String, visibility: ExtensionVisibility) -> String {
|
||||
guard let translation = translations[lang] else {
|
||||
let error = StringiumError.langNotDefined(lang, name, reference != nil)
|
||||
print(error.description)
|
||||
Stringium.exit(withError: error)
|
||||
}
|
||||
|
||||
// Generate property
|
||||
let property = getBaseProperty(
|
||||
lang: lang,
|
||||
translation: translation,
|
||||
isStatic: true,
|
||||
comment: self.comment,
|
||||
visibility: visibility
|
||||
)
|
||||
|
||||
// Generate method
|
||||
var method = ""
|
||||
if let parameters = self.getStringParameters(input: translation) {
|
||||
method = getBaseMethod(
|
||||
lang: lang,
|
||||
translation: translation,
|
||||
isStatic: true,
|
||||
isStatic: isStatic,
|
||||
inputParameters: parameters.inputParameters,
|
||||
translationArguments: parameters.translationArguments,
|
||||
comment: self.comment,
|
||||
@@ -209,7 +183,11 @@ class Definition {
|
||||
|
||||
// MARK: - Raw strings
|
||||
|
||||
func getProperty(forLang lang: String, visibility: ExtensionVisibility) -> String {
|
||||
func getProperty(
|
||||
forLang lang: String,
|
||||
visibility: ExtensionVisibility,
|
||||
isStatic: Bool
|
||||
) -> String {
|
||||
guard let translation = translations[lang] else {
|
||||
let error = StringiumError.langNotDefined(lang, name, reference != nil)
|
||||
print(error.description)
|
||||
@@ -222,26 +200,7 @@ class Definition {
|
||||
///
|
||||
/// Comment :
|
||||
/// \(comment?.isEmpty == false ? comment! : "No comment")
|
||||
\(visibility) var \(name): String {
|
||||
"\(translation)"
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
func getStaticProperty(forLang lang: String, visibility: ExtensionVisibility) -> String {
|
||||
guard let translation = translations[lang] else {
|
||||
let error = StringiumError.langNotDefined(lang, name, reference != nil)
|
||||
print(error.description)
|
||||
Stringium.exit(withError: error)
|
||||
}
|
||||
|
||||
return """
|
||||
/// Translation in \(lang) :
|
||||
/// \(translation)
|
||||
///
|
||||
/// Comment :
|
||||
/// \(comment?.isEmpty == false ? comment! : "No comment")
|
||||
\(visibility) static var \(name): String {
|
||||
\(visibility) \(isStatic ? "static " : "")var \(name): String {
|
||||
"\(translation)"
|
||||
}
|
||||
"""
|
||||
|
@@ -68,12 +68,13 @@ struct Stringium: ParsableCommand {
|
||||
sections: sections,
|
||||
defaultLang: options.defaultLang,
|
||||
tags: options.tags,
|
||||
staticVar: options.staticMembers,
|
||||
isStatic: options.staticMembers,
|
||||
inputFilename: options.inputFilenameWithoutExt,
|
||||
extensionName: extensionName,
|
||||
extensionFilePath: extensionFilePath,
|
||||
extensionSuffix: options.extensionSuffix ?? "",
|
||||
visibility: options.extensionVisibility
|
||||
visibility: options.extensionVisibility,
|
||||
assetBundle: options.assetBundle
|
||||
)
|
||||
}
|
||||
|
||||
|
@@ -57,6 +57,11 @@ struct StringiumOptions: ParsableArguments {
|
||||
)
|
||||
var extensionVisibility: ExtensionVisibility = .internal
|
||||
|
||||
@Option(
|
||||
help: "Bundle where the asset are generated"
|
||||
)
|
||||
var assetBundle: AssetBundle = .main
|
||||
|
||||
@Option(
|
||||
help: "Path where to generate the extension.",
|
||||
transform: { $0.replaceTiltWithHomeDirectoryPath() }
|
||||
|
@@ -47,7 +47,7 @@ struct Tags: ParsableCommand {
|
||||
sections: sections,
|
||||
lang: options.lang,
|
||||
tags: ["ios", "iosonly", Self.noTranslationTag],
|
||||
staticVar: options.staticMembers,
|
||||
isStatic: options.staticMembers,
|
||||
extensionName: options.extensionName,
|
||||
extensionFilePath: options.extensionFilePath,
|
||||
visibility: options.extensionVisibility
|
||||
|
26
Sources/ToolCore/AssetBundle.swift
Normal file
26
Sources/ToolCore/AssetBundle.swift
Normal file
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// AssetBundle.swift
|
||||
// ResgenSwift
|
||||
//
|
||||
// Created by Thibaut Schmitt on 21/07/2025.
|
||||
//
|
||||
|
||||
import ArgumentParser
|
||||
|
||||
package enum AssetBundle: String, CustomStringConvertible, ExpressibleByArgument {
|
||||
|
||||
case main
|
||||
case module
|
||||
|
||||
// MARK: - CustomStringConvertible
|
||||
|
||||
package var description: String {
|
||||
switch self {
|
||||
case .main:
|
||||
"main"
|
||||
|
||||
case .module:
|
||||
"module"
|
||||
}
|
||||
}
|
||||
}
|
@@ -233,7 +233,7 @@ final class AnalyticsGeneratorTests: XCTestCase {
|
||||
targets: [TrackerType.firebase],
|
||||
sections: [sectionOne, sectionTwo, sectionThree],
|
||||
tags: ["ios", "iosonly"],
|
||||
staticVar: false,
|
||||
isStatic: false,
|
||||
visibility: .public
|
||||
)
|
||||
|
||||
@@ -398,7 +398,7 @@ final class AnalyticsGeneratorTests: XCTestCase {
|
||||
targets: [TrackerType.matomo],
|
||||
sections: [sectionOne, sectionTwo, sectionThree],
|
||||
tags: ["ios", "iosonly"],
|
||||
staticVar: false,
|
||||
isStatic: false,
|
||||
visibility: .package
|
||||
)
|
||||
// Expect Analytics
|
||||
@@ -565,7 +565,7 @@ final class AnalyticsGeneratorTests: XCTestCase {
|
||||
targets: [TrackerType.matomo, TrackerType.firebase],
|
||||
sections: [sectionOne, sectionTwo, sectionThree],
|
||||
tags: ["ios", "iosonly"],
|
||||
staticVar: false,
|
||||
isStatic: false,
|
||||
visibility: .internal
|
||||
)
|
||||
|
||||
|
@@ -23,10 +23,11 @@ final class ColorExtensionGeneratorTests: XCTestCase {
|
||||
// When
|
||||
let extensionContent = ColorExtensionGenerator.getExtensionContent(
|
||||
colors: colors,
|
||||
staticVar: false,
|
||||
isStatic: false,
|
||||
extensionName: "GenColors",
|
||||
isSwiftUI: false,
|
||||
visibility: .public
|
||||
visibility: .public,
|
||||
assetBundle: .main
|
||||
)
|
||||
|
||||
// Expect
|
||||
@@ -39,12 +40,12 @@ final class ColorExtensionGeneratorTests: XCTestCase {
|
||||
|
||||
/// Color colorOne is #FF00FF (light) or #00FF00 (dark)"
|
||||
@objc public var colorOne: UIColor {
|
||||
UIColor(named: "colorOne")!
|
||||
UIColor(named: "colorOne", in: Bundle.main, compatibleWith: nil)!
|
||||
}
|
||||
|
||||
/// Color colorTwo is #F0F0F0 (light) or #0F0F0F (dark)"
|
||||
@objc public var colorTwo: UIColor {
|
||||
UIColor(named: "colorTwo")!
|
||||
UIColor(named: "colorTwo", in: Bundle.main, compatibleWith: nil)!
|
||||
}
|
||||
}
|
||||
"""
|
||||
@@ -52,7 +53,7 @@ final class ColorExtensionGeneratorTests: XCTestCase {
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func test_uiKit_GeneratedExtensionContentForStaticVar() {
|
||||
func test_uiKit_GeneratedExtensionContentForIsStatic() {
|
||||
// Given
|
||||
let colors = [
|
||||
ParsedColor(name: "colorOne", light: "#FF00FF", dark: "#00FF00"),
|
||||
@@ -62,10 +63,11 @@ final class ColorExtensionGeneratorTests: XCTestCase {
|
||||
// When
|
||||
let extensionContent = ColorExtensionGenerator.getExtensionContent(
|
||||
colors: colors,
|
||||
staticVar: true,
|
||||
isStatic: true,
|
||||
extensionName: "GenColor",
|
||||
isSwiftUI: false,
|
||||
visibility: .public
|
||||
visibility: .public,
|
||||
assetBundle: .module
|
||||
)
|
||||
|
||||
// Expect
|
||||
@@ -78,12 +80,12 @@ final class ColorExtensionGeneratorTests: XCTestCase {
|
||||
|
||||
/// Color colorOne is #FF00FF (light) or #00FF00 (dark)"
|
||||
public static var colorOne: UIColor {
|
||||
UIColor(named: "colorOne")!
|
||||
UIColor(named: "colorOne", in: Bundle.module, compatibleWith: nil)!
|
||||
}
|
||||
|
||||
/// Color colorTwo is #F0F0F0 (light) or #0F0F0F (dark)"
|
||||
public static var colorTwo: UIColor {
|
||||
UIColor(named: "colorTwo")!
|
||||
UIColor(named: "colorTwo", in: Bundle.module, compatibleWith: nil)!
|
||||
}
|
||||
}
|
||||
"""
|
||||
@@ -101,10 +103,11 @@ final class ColorExtensionGeneratorTests: XCTestCase {
|
||||
// When
|
||||
let extensionContent = ColorExtensionGenerator.getExtensionContent(
|
||||
colors: colors,
|
||||
staticVar: false,
|
||||
isStatic: false,
|
||||
extensionName: "GenColors",
|
||||
isSwiftUI: true,
|
||||
visibility: .package
|
||||
visibility: .package,
|
||||
assetBundle: .main
|
||||
)
|
||||
|
||||
// Expect
|
||||
@@ -117,12 +120,12 @@ final class ColorExtensionGeneratorTests: XCTestCase {
|
||||
|
||||
/// Color colorOne is #FF00FF (light) or #00FF00 (dark)"
|
||||
package var colorOne: Color {
|
||||
Color("colorOne")
|
||||
Color("colorOne", bundle: Bundle.main)
|
||||
}
|
||||
|
||||
/// Color colorTwo is #F0F0F0 (light) or #0F0F0F (dark)"
|
||||
package var colorTwo: Color {
|
||||
Color("colorTwo")
|
||||
Color("colorTwo", bundle: Bundle.main)
|
||||
}
|
||||
}
|
||||
"""
|
||||
@@ -130,7 +133,7 @@ final class ColorExtensionGeneratorTests: XCTestCase {
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func test_swiftUI_GeneratedExtensionContentForStaticVar() {
|
||||
func test_swiftUI_GeneratedExtensionContentForIsStatic() {
|
||||
// Given
|
||||
let colors = [
|
||||
ParsedColor(name: "colorOne", light: "#FF00FF", dark: "#00FF00"),
|
||||
@@ -140,10 +143,11 @@ final class ColorExtensionGeneratorTests: XCTestCase {
|
||||
// When
|
||||
let extensionContent = ColorExtensionGenerator.getExtensionContent(
|
||||
colors: colors,
|
||||
staticVar: true,
|
||||
isStatic: true,
|
||||
extensionName: "GenColor",
|
||||
isSwiftUI: true,
|
||||
visibility: .internal
|
||||
visibility: .internal,
|
||||
assetBundle: .module
|
||||
)
|
||||
|
||||
// Expect
|
||||
@@ -156,12 +160,12 @@ final class ColorExtensionGeneratorTests: XCTestCase {
|
||||
|
||||
/// Color colorOne is #FF00FF (light) or #00FF00 (dark)"
|
||||
internal static var colorOne: Color {
|
||||
Color("colorOne")
|
||||
Color("colorOne", bundle: Bundle.module)
|
||||
}
|
||||
|
||||
/// Color colorTwo is #F0F0F0 (light) or #0F0F0F (dark)"
|
||||
internal static var colorTwo: Color {
|
||||
Color("colorTwo")
|
||||
Color("colorTwo", bundle: Bundle.module)
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
@@ -20,14 +20,15 @@ final class ParsedColorTests: XCTestCase {
|
||||
let property = color.getColorProperty(
|
||||
isStatic: false,
|
||||
isSwiftUI: false,
|
||||
visibility: .public
|
||||
visibility: .public,
|
||||
assetBundle: .main
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
/// Color red is #FF0000 (light) or #0000FF (dark)"
|
||||
@objc public var red: UIColor {
|
||||
UIColor(named: "red")!
|
||||
UIColor(named: "red", in: Bundle.main, compatibleWith: nil)!
|
||||
}
|
||||
"""
|
||||
|
||||
@@ -42,14 +43,15 @@ final class ParsedColorTests: XCTestCase {
|
||||
let property = color.getColorProperty(
|
||||
isStatic: true,
|
||||
isSwiftUI: false,
|
||||
visibility: .private
|
||||
visibility: .private,
|
||||
assetBundle: .module
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
/// Color red is #FF0000 (light) or #0000FF (dark)"
|
||||
private static var red: UIColor {
|
||||
UIColor(named: "red")!
|
||||
UIColor(named: "red", in: Bundle.module, compatibleWith: nil)!
|
||||
}
|
||||
"""
|
||||
|
||||
@@ -64,14 +66,15 @@ final class ParsedColorTests: XCTestCase {
|
||||
let property = color.getColorProperty(
|
||||
isStatic: false,
|
||||
isSwiftUI: true,
|
||||
visibility: .package
|
||||
visibility: .package,
|
||||
assetBundle: .main
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
/// Color red is #FF0000 (light) or #0000FF (dark)"
|
||||
package var red: Color {
|
||||
Color("red")
|
||||
Color("red", bundle: Bundle.main)
|
||||
}
|
||||
"""
|
||||
|
||||
@@ -86,14 +89,15 @@ final class ParsedColorTests: XCTestCase {
|
||||
let property = color.getColorProperty(
|
||||
isStatic: true,
|
||||
isSwiftUI: true,
|
||||
visibility: .internal
|
||||
visibility: .internal,
|
||||
assetBundle: .module
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
/// Color red is #FF0000 (light) or #0000FF (dark)"
|
||||
internal static var red: Color {
|
||||
Color("red")
|
||||
Color("red", bundle: Bundle.module)
|
||||
}
|
||||
"""
|
||||
|
||||
|
@@ -23,7 +23,7 @@ final class FontExtensionGeneratorTests: XCTestCase {
|
||||
// When
|
||||
let extensionContent = FontExtensionGenerator.getExtensionContent(
|
||||
fontsNames: fontNames,
|
||||
staticVar: false,
|
||||
isStatic: false,
|
||||
extensionName: "GenFonts",
|
||||
isSwiftUI: false,
|
||||
visibility: .public
|
||||
@@ -69,7 +69,7 @@ final class FontExtensionGeneratorTests: XCTestCase {
|
||||
// When
|
||||
let extensionContent = FontExtensionGenerator.getExtensionContent(
|
||||
fontsNames: fontNames,
|
||||
staticVar: false,
|
||||
isStatic: false,
|
||||
extensionName: "GenFonts",
|
||||
isSwiftUI: true,
|
||||
visibility: .package
|
||||
|
@@ -25,6 +25,7 @@ final class ColorsConfigurationTests: XCTestCase {
|
||||
extensionNameUIKit: nil,
|
||||
extensionSuffix: nil,
|
||||
visibility: nil,
|
||||
assetBundle: nil,
|
||||
staticMembers: false
|
||||
)
|
||||
// When
|
||||
@@ -58,6 +59,7 @@ final class ColorsConfigurationTests: XCTestCase {
|
||||
extensionNameUIKit: "AppColor",
|
||||
extensionSuffix: "Testing",
|
||||
visibility: "public",
|
||||
assetBundle: "module",
|
||||
staticMembers: false
|
||||
)
|
||||
// When
|
||||
@@ -84,6 +86,8 @@ final class ColorsConfigurationTests: XCTestCase {
|
||||
"Testing",
|
||||
"--visibility",
|
||||
"public",
|
||||
"--asset-bundle",
|
||||
"module",
|
||||
"--static-members",
|
||||
"false"
|
||||
]
|
||||
|
@@ -24,6 +24,7 @@ final class ImagesConfigurationTests: XCTestCase {
|
||||
extensionNameUIKit: nil,
|
||||
extensionSuffix: nil,
|
||||
visibility: nil,
|
||||
assetBundle: nil,
|
||||
staticMembers: nil
|
||||
)
|
||||
|
||||
@@ -53,6 +54,7 @@ final class ImagesConfigurationTests: XCTestCase {
|
||||
extensionNameUIKit: "AppImage",
|
||||
extensionSuffix: "Testing",
|
||||
visibility: "private",
|
||||
assetBundle: "module",
|
||||
staticMembers: true
|
||||
)
|
||||
|
||||
@@ -78,6 +80,8 @@ final class ImagesConfigurationTests: XCTestCase {
|
||||
"Testing",
|
||||
"--visibility",
|
||||
"private",
|
||||
"--asset-bundle",
|
||||
"module",
|
||||
"--static-members",
|
||||
"true"
|
||||
]
|
||||
|
@@ -24,6 +24,7 @@ final class StringsConfigurationTests: XCTestCase {
|
||||
extensionName: nil, // String
|
||||
extensionSuffix: nil, // Testing
|
||||
visibility: nil, // "internal"
|
||||
assetBundle: nil, // .main
|
||||
staticMembers: nil, // true
|
||||
xcStrings: nil // true
|
||||
)
|
||||
@@ -59,6 +60,7 @@ final class StringsConfigurationTests: XCTestCase {
|
||||
extensionName: "AppString",
|
||||
extensionSuffix: "Testing",
|
||||
visibility: "internal",
|
||||
assetBundle: "module",
|
||||
staticMembers: true,
|
||||
xcStrings: true
|
||||
)
|
||||
@@ -87,6 +89,8 @@ final class StringsConfigurationTests: XCTestCase {
|
||||
"Testing",
|
||||
"--visibility",
|
||||
"internal",
|
||||
"--asset-bundle",
|
||||
"module",
|
||||
"--xc-strings",
|
||||
"true",
|
||||
"--static-members",
|
||||
|
@@ -23,11 +23,12 @@ final class ImageExtensionGeneratorTests: XCTestCase {
|
||||
// When
|
||||
let extensionContent = ImageExtensionGenerator.getExtensionContent(
|
||||
images: images,
|
||||
staticVar: false,
|
||||
isStatic: false,
|
||||
extensionName: "GenImages",
|
||||
inputFilename: "myInputFilename",
|
||||
isSwiftUI: false,
|
||||
visibility: .public
|
||||
visibility: .public,
|
||||
assetBundle: .main
|
||||
)
|
||||
|
||||
// Expect
|
||||
@@ -40,11 +41,11 @@ final class ImageExtensionGeneratorTests: XCTestCase {
|
||||
extension GenImages {
|
||||
|
||||
public var image_one: UIImage {
|
||||
UIImage(named: "image_one")!
|
||||
UIImage(named: "image_one", in: Bundle.main, with: nil)!
|
||||
}
|
||||
|
||||
public var image_two: UIImage {
|
||||
UIImage(named: "image_two")!
|
||||
UIImage(named: "image_two", in: Bundle.main, with: nil)!
|
||||
}
|
||||
}
|
||||
"""
|
||||
@@ -52,7 +53,7 @@ final class ImageExtensionGeneratorTests: XCTestCase {
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func test_uiKit_GeneratedExtensionContentForStaticVar() {
|
||||
func test_uiKit_GeneratedExtensionContentForIsStatic() {
|
||||
// Given
|
||||
let images = [
|
||||
ParsedImage(name: "image_one", tags: "id", width: 10, height: 10),
|
||||
@@ -62,11 +63,12 @@ final class ImageExtensionGeneratorTests: XCTestCase {
|
||||
// When
|
||||
let extensionContent = ImageExtensionGenerator.getExtensionContent(
|
||||
images: images,
|
||||
staticVar: true,
|
||||
isStatic: true,
|
||||
extensionName: "GenImages",
|
||||
inputFilename: "myInputFilename",
|
||||
isSwiftUI: false,
|
||||
visibility: .internal
|
||||
visibility: .internal,
|
||||
assetBundle: .module
|
||||
)
|
||||
|
||||
// Expect
|
||||
@@ -79,11 +81,11 @@ final class ImageExtensionGeneratorTests: XCTestCase {
|
||||
extension GenImages {
|
||||
|
||||
internal static var image_one: UIImage {
|
||||
UIImage(named: "image_one")!
|
||||
UIImage(named: "image_one", in: Bundle.module, with: nil)!
|
||||
}
|
||||
|
||||
internal static var image_two: UIImage {
|
||||
UIImage(named: "image_two")!
|
||||
UIImage(named: "image_two", in: Bundle.module, with: nil)!
|
||||
}
|
||||
}
|
||||
"""
|
||||
@@ -101,11 +103,12 @@ final class ImageExtensionGeneratorTests: XCTestCase {
|
||||
// When
|
||||
let extensionContent = ImageExtensionGenerator.getExtensionContent(
|
||||
images: images,
|
||||
staticVar: false,
|
||||
isStatic: false,
|
||||
extensionName: "GenImages",
|
||||
inputFilename: "myInputFilename",
|
||||
isSwiftUI: true,
|
||||
visibility: .public
|
||||
visibility: .public,
|
||||
assetBundle: .main
|
||||
)
|
||||
|
||||
// Expect
|
||||
@@ -118,11 +121,11 @@ final class ImageExtensionGeneratorTests: XCTestCase {
|
||||
extension GenImages {
|
||||
|
||||
public var image_one: Image {
|
||||
Image("image_one")
|
||||
Image("image_one", bundle: Bundle.main)
|
||||
}
|
||||
|
||||
public var image_two: Image {
|
||||
Image("image_two")
|
||||
Image("image_two", bundle: Bundle.main)
|
||||
}
|
||||
}
|
||||
"""
|
||||
@@ -130,7 +133,7 @@ final class ImageExtensionGeneratorTests: XCTestCase {
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func test_swiftUI_GeneratedExtensionContentForStaticVar() {
|
||||
func test_swiftUI_GeneratedExtensionContentForIsStatic() {
|
||||
// Given
|
||||
let images = [
|
||||
ParsedImage(name: "image_one", tags: "id", width: 10, height: 10),
|
||||
@@ -140,11 +143,12 @@ final class ImageExtensionGeneratorTests: XCTestCase {
|
||||
// When
|
||||
let extensionContent = ImageExtensionGenerator.getExtensionContent(
|
||||
images: images,
|
||||
staticVar: true,
|
||||
isStatic: true,
|
||||
extensionName: "GenImages",
|
||||
inputFilename: "myInputFilename",
|
||||
isSwiftUI: true,
|
||||
visibility: .package
|
||||
visibility: .package,
|
||||
assetBundle: .module
|
||||
)
|
||||
|
||||
// Expect
|
||||
@@ -157,11 +161,11 @@ final class ImageExtensionGeneratorTests: XCTestCase {
|
||||
extension GenImages {
|
||||
|
||||
package static var image_one: Image {
|
||||
Image("image_one")
|
||||
Image("image_one", bundle: Bundle.module)
|
||||
}
|
||||
|
||||
package static var image_two: Image {
|
||||
Image("image_two")
|
||||
Image("image_two", bundle: Bundle.module)
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
@@ -48,13 +48,14 @@ final class ParsedImageTests: XCTestCase {
|
||||
let property = parsedImage.getImageProperty(
|
||||
isStatic: false,
|
||||
isSwiftUI: false,
|
||||
visibility: .public
|
||||
visibility: .public,
|
||||
assetBundle: .main
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
public var \(imageName): UIImage {
|
||||
UIImage(named: "\(imageName)")!
|
||||
UIImage(named: "\(imageName)", in: Bundle.main, with: nil)!
|
||||
}
|
||||
"""
|
||||
|
||||
@@ -75,13 +76,14 @@ final class ParsedImageTests: XCTestCase {
|
||||
let property = parsedImage.getImageProperty(
|
||||
isStatic: true,
|
||||
isSwiftUI: false,
|
||||
visibility: .internal
|
||||
visibility: .internal,
|
||||
assetBundle: .module
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
internal static var \(imageName): UIImage {
|
||||
UIImage(named: "\(imageName)")!
|
||||
UIImage(named: "\(imageName)", in: Bundle.module, with: nil)!
|
||||
}
|
||||
"""
|
||||
|
||||
@@ -102,13 +104,14 @@ final class ParsedImageTests: XCTestCase {
|
||||
let property = parsedImage.getImageProperty(
|
||||
isStatic: false,
|
||||
isSwiftUI: true,
|
||||
visibility: .private
|
||||
visibility: .private,
|
||||
assetBundle: .main
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
private var \(imageName): Image {
|
||||
Image("\(imageName)")
|
||||
Image("\(imageName)", bundle: Bundle.main)
|
||||
}
|
||||
"""
|
||||
|
||||
@@ -129,13 +132,14 @@ final class ParsedImageTests: XCTestCase {
|
||||
let property = parsedImage.getImageProperty(
|
||||
isStatic: true,
|
||||
isSwiftUI: true,
|
||||
visibility: .package
|
||||
visibility: .package,
|
||||
assetBundle: .module
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
package static var \(imageName): Image {
|
||||
Image("\(imageName)")
|
||||
Image("\(imageName)", bundle: Bundle.module)
|
||||
}
|
||||
"""
|
||||
|
||||
|
@@ -94,9 +94,24 @@ final class DefinitionTests: XCTestCase {
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getNSLocalizedStringProperty(forLang: "fr", visibility: .public)
|
||||
let propertyEn = definition.getNSLocalizedStringProperty(forLang: "en", visibility: .public)
|
||||
let propertyEnUs = definition.getNSLocalizedStringProperty(forLang: "en-us", visibility: .public)
|
||||
let propertyFr = definition.getNSLocalizedStringProperty(
|
||||
forLang: "fr",
|
||||
isStatic: false,
|
||||
visibility: .public,
|
||||
assetBundle: .main
|
||||
)
|
||||
let propertyEn = definition.getNSLocalizedStringProperty(
|
||||
forLang: "en",
|
||||
isStatic: false,
|
||||
visibility: .public,
|
||||
assetBundle: .main
|
||||
)
|
||||
let propertyEnUs = definition.getNSLocalizedStringProperty(
|
||||
forLang: "en-us",
|
||||
isStatic: false,
|
||||
visibility: .public,
|
||||
assetBundle: .main
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
@@ -149,9 +164,24 @@ final class DefinitionTests: XCTestCase {
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getNSLocalizedStringProperty(forLang: "fr", visibility: .private)
|
||||
let propertyEn = definition.getNSLocalizedStringProperty(forLang: "en", visibility: .private)
|
||||
let propertyEnUs = definition.getNSLocalizedStringProperty(forLang: "en-us", visibility: .private)
|
||||
let propertyFr = definition.getNSLocalizedStringProperty(
|
||||
forLang: "fr",
|
||||
isStatic: false,
|
||||
visibility: .private,
|
||||
assetBundle: .main
|
||||
)
|
||||
let propertyEn = definition.getNSLocalizedStringProperty(
|
||||
forLang: "en",
|
||||
isStatic: false,
|
||||
visibility: .private,
|
||||
assetBundle: .main
|
||||
)
|
||||
let propertyEnUs = definition.getNSLocalizedStringProperty(
|
||||
forLang: "en-us",
|
||||
isStatic: false,
|
||||
visibility: .private,
|
||||
assetBundle: .main
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
@@ -203,9 +233,24 @@ final class DefinitionTests: XCTestCase {
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getNSLocalizedStringProperty(forLang: "fr", visibility: .public)
|
||||
let propertyEn = definition.getNSLocalizedStringProperty(forLang: "en", visibility: .public)
|
||||
let propertyEnUs = definition.getNSLocalizedStringProperty(forLang: "en-us", visibility: .public)
|
||||
let propertyFr = definition.getNSLocalizedStringProperty(
|
||||
forLang: "fr",
|
||||
isStatic: false,
|
||||
visibility: .public,
|
||||
assetBundle: .main
|
||||
)
|
||||
let propertyEn = definition.getNSLocalizedStringProperty(
|
||||
forLang: "en",
|
||||
isStatic: false,
|
||||
visibility: .public,
|
||||
assetBundle: .main
|
||||
)
|
||||
let propertyEnUs = definition.getNSLocalizedStringProperty(
|
||||
forLang: "en-us",
|
||||
isStatic: false,
|
||||
visibility: .public,
|
||||
assetBundle: .main
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
@@ -246,7 +291,7 @@ final class DefinitionTests: XCTestCase {
|
||||
XCTAssertEqual(propertyEnUs.adaptForXCTest(), expectEnUs.adaptForXCTest())
|
||||
}
|
||||
|
||||
// MARK: - getNSLocalizedStringStaticProperty
|
||||
// MARK: - getNSLocalizedStringProperty - static
|
||||
|
||||
func testGeneratedNSLocalizedStringStaticProperty() {
|
||||
// Given
|
||||
@@ -260,9 +305,24 @@ final class DefinitionTests: XCTestCase {
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getNSLocalizedStringStaticProperty(forLang: "fr", visibility: .public)
|
||||
let propertyEn = definition.getNSLocalizedStringStaticProperty(forLang: "en", visibility: .public)
|
||||
let propertyEnUs = definition.getNSLocalizedStringStaticProperty(forLang: "en-us", visibility: .public)
|
||||
let propertyFr = definition.getNSLocalizedStringProperty(
|
||||
forLang: "fr",
|
||||
isStatic: true,
|
||||
visibility: .public,
|
||||
assetBundle: .main
|
||||
)
|
||||
let propertyEn = definition.getNSLocalizedStringProperty(
|
||||
forLang: "en",
|
||||
isStatic: true,
|
||||
visibility: .public,
|
||||
assetBundle: .main
|
||||
)
|
||||
let propertyEnUs = definition.getNSLocalizedStringProperty(
|
||||
forLang: "en-us",
|
||||
isStatic: true,
|
||||
visibility: .public,
|
||||
assetBundle: .main
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
@@ -315,9 +375,24 @@ final class DefinitionTests: XCTestCase {
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getNSLocalizedStringStaticProperty(forLang: "fr", visibility: .internal)
|
||||
let propertyEn = definition.getNSLocalizedStringStaticProperty(forLang: "en", visibility: .internal)
|
||||
let propertyEnUs = definition.getNSLocalizedStringStaticProperty(forLang: "en-us", visibility: .internal)
|
||||
let propertyFr = definition.getNSLocalizedStringProperty(
|
||||
forLang: "fr",
|
||||
isStatic: true,
|
||||
visibility: .internal,
|
||||
assetBundle: .main
|
||||
)
|
||||
let propertyEn = definition.getNSLocalizedStringProperty(
|
||||
forLang: "en",
|
||||
isStatic: true,
|
||||
visibility: .internal,
|
||||
assetBundle: .main
|
||||
)
|
||||
let propertyEnUs = definition.getNSLocalizedStringProperty(
|
||||
forLang: "en-us",
|
||||
isStatic: true,
|
||||
visibility: .internal,
|
||||
assetBundle: .main
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
@@ -369,9 +444,24 @@ final class DefinitionTests: XCTestCase {
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getNSLocalizedStringStaticProperty(forLang: "fr", visibility: .internal)
|
||||
let propertyEn = definition.getNSLocalizedStringStaticProperty(forLang: "en", visibility: .internal)
|
||||
let propertyEnUs = definition.getNSLocalizedStringStaticProperty(forLang: "en-us", visibility: .internal)
|
||||
let propertyFr = definition.getNSLocalizedStringProperty(
|
||||
forLang: "fr",
|
||||
isStatic: true,
|
||||
visibility: .internal,
|
||||
assetBundle: .main
|
||||
)
|
||||
let propertyEn = definition.getNSLocalizedStringProperty(
|
||||
forLang: "en",
|
||||
isStatic: true,
|
||||
visibility: .internal,
|
||||
assetBundle: .main
|
||||
)
|
||||
let propertyEnUs = definition.getNSLocalizedStringProperty(
|
||||
forLang: "en-us",
|
||||
isStatic: true,
|
||||
visibility: .internal,
|
||||
assetBundle: .main
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
@@ -422,7 +512,12 @@ final class DefinitionTests: XCTestCase {
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getNSLocalizedStringProperty(forLang: "fr", visibility: .internal)
|
||||
let propertyFr = definition.getNSLocalizedStringProperty(
|
||||
forLang: "fr",
|
||||
isStatic: false,
|
||||
visibility: .internal,
|
||||
assetBundle: .main
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
@@ -458,7 +553,12 @@ final class DefinitionTests: XCTestCase {
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getNSLocalizedStringProperty(forLang: "fr", visibility: .private)
|
||||
let propertyFr = definition.getNSLocalizedStringProperty(
|
||||
forLang: "fr",
|
||||
isStatic: false,
|
||||
visibility: .private,
|
||||
assetBundle: .main
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
@@ -495,8 +595,18 @@ final class DefinitionTests: XCTestCase {
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getNSLocalizedStringProperty(forLang: "fr", visibility: .public)
|
||||
let propertyEn = definition.getNSLocalizedStringProperty(forLang: "en", visibility: .public)
|
||||
let propertyFr = definition.getNSLocalizedStringProperty(
|
||||
forLang: "fr",
|
||||
isStatic: false,
|
||||
visibility: .public,
|
||||
assetBundle: .main
|
||||
)
|
||||
let propertyEn = definition.getNSLocalizedStringProperty(
|
||||
forLang: "en",
|
||||
isStatic: false,
|
||||
visibility: .public,
|
||||
assetBundle: .main
|
||||
)
|
||||
|
||||
let expectFr = """
|
||||
/// Translation in fr :
|
||||
@@ -556,9 +666,21 @@ final class DefinitionTests: XCTestCase {
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getProperty(forLang: "fr", visibility: .public)
|
||||
let propertyEn = definition.getProperty(forLang: "en", visibility: .public)
|
||||
let propertyEnUs = definition.getProperty(forLang: "en-us", visibility: .public)
|
||||
let propertyFr = definition.getProperty(
|
||||
forLang: "fr",
|
||||
visibility: .public,
|
||||
isStatic: false
|
||||
)
|
||||
let propertyEn = definition.getProperty(
|
||||
forLang: "en",
|
||||
visibility: .public,
|
||||
isStatic: false
|
||||
)
|
||||
let propertyEnUs = definition.getProperty(
|
||||
forLang: "en-us",
|
||||
visibility: .public,
|
||||
isStatic: false
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
@@ -611,9 +733,21 @@ final class DefinitionTests: XCTestCase {
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getProperty(forLang: "fr", visibility: .package)
|
||||
let propertyEn = definition.getProperty(forLang: "en", visibility: .package)
|
||||
let propertyEnUs = definition.getProperty(forLang: "en-us", visibility: .package)
|
||||
let propertyFr = definition.getProperty(
|
||||
forLang: "fr",
|
||||
visibility: .package,
|
||||
isStatic: false
|
||||
)
|
||||
let propertyEn = definition.getProperty(
|
||||
forLang: "en",
|
||||
visibility: .package,
|
||||
isStatic: false
|
||||
)
|
||||
let propertyEnUs = definition.getProperty(
|
||||
forLang: "en-us",
|
||||
visibility: .package,
|
||||
isStatic: false
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
@@ -665,9 +799,21 @@ final class DefinitionTests: XCTestCase {
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getProperty(forLang: "fr", visibility: .private)
|
||||
let propertyEn = definition.getProperty(forLang: "en", visibility: .private)
|
||||
let propertyEnUs = definition.getProperty(forLang: "en-us", visibility: .private)
|
||||
let propertyFr = definition.getProperty(
|
||||
forLang: "fr",
|
||||
visibility: .private,
|
||||
isStatic: false
|
||||
)
|
||||
let propertyEn = definition.getProperty(
|
||||
forLang: "en",
|
||||
visibility: .private,
|
||||
isStatic: false
|
||||
)
|
||||
let propertyEnUs = definition.getProperty(
|
||||
forLang: "en-us",
|
||||
visibility: .private,
|
||||
isStatic: false
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
@@ -722,9 +868,21 @@ final class DefinitionTests: XCTestCase {
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getStaticProperty(forLang: "fr", visibility: .internal)
|
||||
let propertyEn = definition.getStaticProperty(forLang: "en", visibility: .internal)
|
||||
let propertyEnUs = definition.getStaticProperty(forLang: "en-us", visibility: .internal)
|
||||
let propertyFr = definition.getProperty(
|
||||
forLang: "fr",
|
||||
visibility: .internal,
|
||||
isStatic: true
|
||||
)
|
||||
let propertyEn = definition.getProperty(
|
||||
forLang: "en",
|
||||
visibility: .internal,
|
||||
isStatic: true
|
||||
)
|
||||
let propertyEnUs = definition.getProperty(
|
||||
forLang: "en-us",
|
||||
visibility: .internal,
|
||||
isStatic: true
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
@@ -777,9 +935,21 @@ final class DefinitionTests: XCTestCase {
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getStaticProperty(forLang: "fr", visibility: .internal)
|
||||
let propertyEn = definition.getStaticProperty(forLang: "en", visibility: .internal)
|
||||
let propertyEnUs = definition.getStaticProperty(forLang: "en-us", visibility: .internal)
|
||||
let propertyFr = definition.getProperty(
|
||||
forLang: "fr",
|
||||
visibility: .internal,
|
||||
isStatic: true
|
||||
)
|
||||
let propertyEn = definition.getProperty(
|
||||
forLang: "en",
|
||||
visibility: .internal,
|
||||
isStatic: true
|
||||
)
|
||||
let propertyEnUs = definition.getProperty(
|
||||
forLang: "en-us",
|
||||
visibility: .internal,
|
||||
isStatic: true
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
@@ -831,9 +1001,21 @@ final class DefinitionTests: XCTestCase {
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getStaticProperty(forLang: "fr", visibility: .internal)
|
||||
let propertyEn = definition.getStaticProperty(forLang: "en", visibility: .internal)
|
||||
let propertyEnUs = definition.getStaticProperty(forLang: "en-us", visibility: .internal)
|
||||
let propertyFr = definition.getProperty(
|
||||
forLang: "fr",
|
||||
visibility: .internal,
|
||||
isStatic: true
|
||||
)
|
||||
let propertyEn = definition.getProperty(
|
||||
forLang: "en",
|
||||
visibility: .internal,
|
||||
isStatic: true
|
||||
)
|
||||
let propertyEnUs = definition.getProperty(
|
||||
forLang: "en-us",
|
||||
visibility: .internal,
|
||||
isStatic: true
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
|
@@ -11,7 +11,7 @@ import ToolCore
|
||||
extension StringsFileGeneratorTests {
|
||||
|
||||
static func getExtensionContentExpectation(
|
||||
staticVar: Bool,
|
||||
isStatic: Bool,
|
||||
s1DefOneFr: String = "Section Un - Definition Un",
|
||||
s1DefOneComment: String = "",
|
||||
s1DefTwoFr: String = "Section Un - Definition Deux",
|
||||
@@ -20,7 +20,8 @@ extension StringsFileGeneratorTests {
|
||||
s2DefOneComment: String = "",
|
||||
s2DefTwoFr: String = "Section Deux - Definition Deux",
|
||||
s2DefTwoComment: String = "",
|
||||
visibility: ExtensionVisibility = .internal
|
||||
visibility: ExtensionVisibility = .internal,
|
||||
assetBundle: AssetBundle = .main
|
||||
) -> String {
|
||||
"""
|
||||
// Generated by ResgenSwift.Strings.Stringium \(ResgenSwiftVersion)
|
||||
@@ -54,8 +55,8 @@ extension StringsFileGeneratorTests {
|
||||
///
|
||||
/// Comment :
|
||||
/// \(s1DefOneComment.isEmpty ? "No comment" : s1DefOneComment)
|
||||
\(visibility) \(staticVar ? "static " : "")var s1_def_one: String {
|
||||
NSLocalizedString("s1_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Un", comment: "\(s1DefOneComment)")
|
||||
\(visibility) \(isStatic ? "static " : "")var s1_def_one: String {
|
||||
NSLocalizedString("s1_def_one", tableName: kStringsFileName, bundle: Bundle.\(assetBundle), value: "Section Un - Definition Un", comment: "\(s1DefOneComment)")
|
||||
}
|
||||
|
||||
/// Translation in fr :
|
||||
@@ -63,8 +64,8 @@ extension StringsFileGeneratorTests {
|
||||
///
|
||||
/// Comment :
|
||||
/// \(s1DefTwoComment.isEmpty ? "No comment" : s1DefTwoComment)
|
||||
\(visibility) \(staticVar ? "static " : "")var s1_def_two: String {
|
||||
NSLocalizedString("s1_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Deux", comment: "\(s1DefTwoComment)")
|
||||
\(visibility) \(isStatic ? "static " : "")var s1_def_two: String {
|
||||
NSLocalizedString("s1_def_two", tableName: kStringsFileName, bundle: Bundle.\(assetBundle), value: "Section Un - Definition Deux", comment: "\(s1DefTwoComment)")
|
||||
}
|
||||
|
||||
// MARK: - section_two
|
||||
@@ -74,8 +75,8 @@ extension StringsFileGeneratorTests {
|
||||
///
|
||||
/// Comment :
|
||||
/// \(s2DefOneComment.isEmpty ? "No comment" : s2DefOneComment)
|
||||
\(visibility) \(staticVar ? "static " : "")var s2_def_one: String {
|
||||
NSLocalizedString("s2_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Un", comment: "\(s2DefOneComment)")
|
||||
\(visibility) \(isStatic ? "static " : "")var s2_def_one: String {
|
||||
NSLocalizedString("s2_def_one", tableName: kStringsFileName, bundle: Bundle.\(assetBundle), value: "Section Deux - Definition Un", comment: "\(s2DefOneComment)")
|
||||
}
|
||||
|
||||
/// Translation in fr :
|
||||
@@ -83,8 +84,8 @@ extension StringsFileGeneratorTests {
|
||||
///
|
||||
/// Comment :
|
||||
/// \(s2DefTwoComment.isEmpty ? "No comment" : s2DefTwoComment)
|
||||
\(visibility) \(staticVar ? "static " : "")var s2_def_two: String {
|
||||
NSLocalizedString("s2_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Deux", comment: "\(s2DefTwoComment)")
|
||||
\(visibility) \(isStatic ? "static " : "")var s2_def_two: String {
|
||||
NSLocalizedString("s2_def_two", tableName: kStringsFileName, bundle: Bundle.\(assetBundle), value: "Section Deux - Definition Deux", comment: "\(s2DefTwoComment)")
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
@@ -377,16 +377,17 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
sections: [sectionOne, sectionTwo],
|
||||
defaultLang: "fr",
|
||||
tags: ["ios", "iosonly", "notranslation"],
|
||||
staticVar: false,
|
||||
isStatic: false,
|
||||
inputFilename: "myInputFilename",
|
||||
extensionName: "GenStrings",
|
||||
extensionSuffix: "strings",
|
||||
visibility: .internal
|
||||
visibility: .internal,
|
||||
assetBundle: .main
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expect = Self.getExtensionContentExpectation(
|
||||
staticVar: false
|
||||
isStatic: false
|
||||
)
|
||||
|
||||
if extensionContent != expect {
|
||||
@@ -411,16 +412,17 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
sections: [sectionOne, sectionTwo],
|
||||
defaultLang: "fr",
|
||||
tags: ["ios", "iosonly", "notranslation"],
|
||||
staticVar: false,
|
||||
isStatic: false,
|
||||
inputFilename: "myInputFilename",
|
||||
extensionName: "GenStrings",
|
||||
extensionSuffix: "strings",
|
||||
visibility: .public
|
||||
visibility: .public,
|
||||
assetBundle: .main
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expect = Self.getExtensionContentExpectation(
|
||||
staticVar: false,
|
||||
isStatic: false,
|
||||
s1DefOneComment: "This is a comment",
|
||||
s1DefTwoComment: "This is a comment",
|
||||
s2DefOneComment: "This is a comment",
|
||||
@@ -435,7 +437,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
}
|
||||
|
||||
// MARK: - Extension Content Static
|
||||
func testGeneratedExtensionContentWithStaticVar() {
|
||||
func testGeneratedExtensionContentWithIsStatic() {
|
||||
// Given
|
||||
let sectionOne = Section.Mock.getSectionOne()
|
||||
let sectionTwo = Section.Mock.getSectionTwo()
|
||||
@@ -445,17 +447,19 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
sections: [sectionOne, sectionTwo],
|
||||
defaultLang: "fr",
|
||||
tags: ["ios", "iosonly", "notranslation"],
|
||||
staticVar: true,
|
||||
isStatic: true,
|
||||
inputFilename: "myInputFilename",
|
||||
extensionName: "GenStrings",
|
||||
extensionSuffix: "strings",
|
||||
visibility: .package
|
||||
visibility: .package,
|
||||
assetBundle: .module
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expect = Self.getExtensionContentExpectation(
|
||||
staticVar: true,
|
||||
visibility: .package
|
||||
isStatic: true,
|
||||
visibility: .package,
|
||||
assetBundle: .module
|
||||
)
|
||||
|
||||
if extensionContent != expect {
|
||||
@@ -464,7 +468,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedExtensionContentWithStaticVarWithComment() {
|
||||
func testGeneratedExtensionContentWithIsStaticWithComment() {
|
||||
// Given
|
||||
let sectionOne = Section.Mock.getSectionOne(
|
||||
defOneComment: "This is a comment",
|
||||
@@ -480,21 +484,23 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
sections: [sectionOne, sectionTwo],
|
||||
defaultLang: "fr",
|
||||
tags: ["ios", "iosonly", "notranslation"],
|
||||
staticVar: true,
|
||||
isStatic: true,
|
||||
inputFilename: "myInputFilename",
|
||||
extensionName: "GenStrings",
|
||||
extensionSuffix: "strings",
|
||||
visibility: .internal
|
||||
visibility: .internal,
|
||||
assetBundle: .module
|
||||
)
|
||||
|
||||
// Expect
|
||||
let expect = Self.getExtensionContentExpectation(
|
||||
staticVar: true,
|
||||
isStatic: true,
|
||||
s1DefOneComment: "This is a comment",
|
||||
s1DefTwoComment: "This is a comment",
|
||||
s2DefOneComment: "This is a comment",
|
||||
s2DefTwoComment: "This is a comment",
|
||||
visibility: .internal
|
||||
visibility: .internal,
|
||||
assetBundle: .module
|
||||
)
|
||||
|
||||
if extensionContent != expect {
|
||||
|
@@ -49,7 +49,7 @@ final class TagsGeneratorTests: XCTestCase {
|
||||
sections: [sectionOne, sectionTwo, sectionThree],
|
||||
lang: "ium",
|
||||
tags: ["ios", "iosonly"],
|
||||
staticVar: false,
|
||||
isStatic: false,
|
||||
extensionName: "GenTags",
|
||||
visibility: .public
|
||||
)
|
||||
|
Reference in New Issue
Block a user