Add new Flag to every command to choose if we want to generate static members or not
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit

This commit is contained in:
2022-08-31 15:18:44 +02:00
parent 264c221604
commit 3d60513c08
24 changed files with 323 additions and 144 deletions

140
README.md
View File

@ -4,7 +4,7 @@ ResgenSwift is a package, fully written in Swift, to help you automatize ressour
> 🧐 For all commands, see samples files in `SampleFiles`
# Fonts
## Fonts
Font generator generates an extension of `UIFont` (or a custom class). It also prints `UIAppFonts` to put in your project `.plist`.
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`.
@ -15,7 +15,8 @@ iOS required to use the **real name** of the font, this name can be different fr
swift run -c release FontTool $FORCE_FLAG "./Fonts/fonts.txt" \
--extension-output-path "./Fonts/Generated" \
--extension-name "AppFont" \
--extension-suffix "GreatApp"
--extension-suffix "GreatApp" \
--static-members true
```
**Parameters**
@ -25,11 +26,10 @@ swift run -c release FontTool $FORCE_FLAG "./Fonts/fonts.txt" \
3. `--extension-output-path`: path where to generate generated extension
4. `--extension-name` *(optional)* : name of thee class to add the extension
5. `--extension-suffix` *(optional)* : additional text which is added to the filename (ex: `AppFont+GreatApp.swift`)
> ⚠️ If extension name is not set or is `UIFont`, it will generate static property on `UIFont` instead of method in your custom class.
6. `--static-members` *(optional)*: generate static properties or not
# Colors
## Colors
Colors generator generates an extension of `UIColor` (or a custom class) along with colorsets in specified xcassets.
@ -39,7 +39,8 @@ swift run -c release ColorTool $FORCE_FLAG "./Colors/colors.txt" \
--xcassets-path "./Colors/colors.xcassets" \
--extension-output-path "./Colors/Generated/" \
--extension-name "AppColor" \
--extension-suffix "GreatApp"
--extension-suffix "GreatApp" \
--static-members true
```
**Parameters**
@ -50,15 +51,14 @@ swift run -c release ColorTool $FORCE_FLAG "./Colors/colors.txt" \
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: `AppColor+GreatApp.swift`)
7. `--static-members` *(optional)*: generate static properties or not
> ⚠️ If extension name is not set or is `UIColor`, it will generate static property on `UIColor`.
# Strings
## Strings
Strings command allows to generate `strings` files along with extensions to access those strings easily. It can do it 2 ways: Twine and Stringium. It is not recommended to use Twine except on legacy projects or while migrating to ResgenSwift, because it use https://github.com/openium/twine. Using Stringium is recommended because it does not required external dependency and allow more customisation.
## Twine (not recommended)
### Twine (not recommended)
```
swift run -c release Strings twine $FORCE_FLAG "./Twine/strings.txt" \
@ -76,7 +76,7 @@ swift run -c release Strings twine $FORCE_FLAG "./Twine/strings.txt" \
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
## Stringium (recommended)
### Stringium (recommended)
```
swift run -c release Strings stringium $FORCE_FLAG "./Strings/strings.txt" \
@ -85,7 +85,8 @@ swift run -c release Strings stringium $FORCE_FLAG "./Strings/strings.txt" \
--default-lang "en" \
--extension-output-path "./Strings/Generated" \
--extension-name "AppString" \
--extension-suffix "GreatApp"
--extension-suffix "GreatApp" \
--static-members true
```
**Parameters**
@ -97,10 +98,10 @@ swift run -c release Strings stringium $FORCE_FLAG "./Strings/strings.txt" \
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`)
7. `--static-members` *(optional)*: generate static properties or not
> ⚠️ If extension name is not set or is `String`, it will generate static property on `String`.
# Tags
## 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.
@ -109,7 +110,8 @@ swift run -c release Strings tags $FORCE_FLAG "./Tags/tags.txt" \
--lang "ium" \
--extension-output-path "./Tags/Generated" \
--extension-name "AppTags" \
--extension-suffix "GreatApp"
--extension-suffix "GreatApp" \
--static-members true
```
**Parameters**
@ -120,10 +122,11 @@ swift run -c release Strings tags $FORCE_FLAG "./Tags/tags.txt" \
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
> ⚠️ If extension name is not set or is `Tags`, it will generate static property on `Tags`. `Tags` is a typealias of `String`.
> ⚠️ If extension name is not set or is `Tags`, it will generate the following typaloas `typealias Tags = String`.
# Images
## Images
Images generator will generate images assets along with extensions to access those images easily.
@ -132,7 +135,8 @@ swift run -c release Imagium $FORCE_FLAG "./Images/images.txt" \
--xcassets-path "./Images/app.xcassets" \
--extension-output-path "./Images/Generated" \
--extension-name "AppImage" \
--extension-suffix "GreatApp"
--extension-suffix "GreatApp" \
--static-members true
```
**Parameters**
@ -143,9 +147,103 @@ swift run -c release Imagium $FORCE_FLAG "./Images/images.txt" \
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: `AppImage+GreatApp.swift`)
7. `--static-members` *(optional)*: generate static properties or not
> ⚠️ If extension name is not set or is `UIImage`, it will generate static property on `UIImage`.
# TODO
## All at once
Another command exists to generate all ressources at the same time: `generate`. It use the following commands: `Fonts`, `Colors`, `Strings/Stringium`, `Strings/Tags`, `Images`.
All parameters can be specified in a configuration file in `Yaml`:
> Order of configuration types does not matter. Order them to fit your needs.
```yaml
---
colors:
-
inputFile: String
style: [light/all]
xcassetsPath: String
extensionOutputPath: String
extensionName: String?
extensionSuffix: String?
staticMembers: Bool?
fonts:
-
inputFile: String
extensionOutputPath: String
extensionName: String?
extensionSuffix: String?
staticMembers: Bool?
images:
-
inputFile: String
xcassetsPath: String
extensionOutputPath: String
extensionName: String?
extensionSuffix: String?
staticMembers: Bool?
strings:
-
inputFile: String
outputPath: String
langs: String
defaultLang: String
extensionOutputPath: String
extensionName: String?
extensionSuffix: String?
staticMembers: Bool?
tags:
-
inputFile: String
lang: String
extensionOutputPath: String
extensionName: String?
extensionSuffix: String?
staticMembers: Bool?
```
### Multiple configurations
In some case, you may need to have 2 colors files in your projects. You will need 2 colors configurations. Every configuration type is an array and can contains as many configurations as you need.
Sample for 2 colors configurations:
```yaml
...
colors:
-
inputFile: String
style: [light/all]
xcassetsPath: String
extensionOutputPath: String
extensionName: String?
extensionSuffix: String?
staticMembers: Bool?
-
inputFile: String
style: [light/all]
xcassetsPath: String
extensionOutputPath: String
extensionName: String?
extensionSuffix: String?
staticMembers: Bool?
...
```
### No configuration
In some case, you may not need to generate tags. You must specified `tags` as an empty array :
```yaml
...
tags: []
...
```
[ ] Allow static variable generation on custom extension