Code generator for swift-package-resources
- Add required dependencies to your package
.package(
url: "https://github.com/capturecontext/package-resources-cli.git",
.upToNextMajor(from: "1.0.0")
),
.package(
url: "https://github.com/capturecontext/swift-package-resources.git",
.upToNextMajor(from: "4.0.0")
),- Add plugin and target dependency
.target(
name: "AppUI",
product: .library(.static),
dependencies: [
.product(
name: "PackageResources",
package: "swift-package-resources
)
],
resources: [...],
plugins: [
.plugin(
name: "package-resources-plugin",
package: "package-resources-cli"
),
]
),Tip
You can skip adding swift-package-resources dependency explicitly if you use exported alias instead:
.product(
name: "_ExportedPackageResources",
package: "package-resources-cli
)
it will still work as import PackageResources
Make allows you to build and install package-resources-cli globally or locally, if you don't want to use swiftpm plugin
# Download repo
git clone https://github.com/capturecontext/package-resources-cli.git
# Navigate to repo directory
cd package-resources-cli
# Build and install globally using `make install`
# or see Makefile for more options
make install
# You can also delete package-resources-cli using `make uninstall` commandSupported resource types:
| Resource | Extensions | Is reliable |
|---|---|---|
| ColorResource | .xcassets |
yes |
| FontResource | .ttf .otf |
yes |
| ImageResource | .xcassets |
yes |
| SCNSceneResource | .scnassets/.scn |
yes |
| NibResource | .xib |
not used/tested |
| StoryboardResource | .storyboard |
not used/tested |
Warning
Fonts require additional setup
For example you want to add Monsterrat and Arimo fonts with different styles
-
Download fonts and add them to your resources folder
-
Add a static factories for your custom fonts (Example)
-
Register custom fonts on app launch (in AppDelegate, for example)
UIFont.bootstrap()if you are using code from the example above.
✅ Except of some hectic with fonts, installation is enough for using the plugin with swift-package-resources.
Package plugin uses .packageresources file at the root of the package with as it's configuration file
output: "<path-to-output-file>"
indentor: "\t"
tab-size: 1
acronyms-processing: default
acronyms:
- id
- ID
- Id
...| Argument | Description |
|---|---|
output |
Path to output file. Default is dynamically calculated as input + /Resources.generated.swift |
indentor |
Indentation symbol. Default is \t |
tab-size |
Amount of indentors per indent level. Default is 1 |
acronyms-processing |
See CamelCaseConfig.Acronyms.ProcessingPolicy. Default is always-match-case. |
acronyms |
Overrides all default acronyms. Default ones can be found here. |
You can run commands manually using swift package resources
swift package resources generate \
--input "<path-to-lookup-root>" \
--config "<path-to-configuration-file>" \
--output "<path-to-output-file>" \
--indentor "\t" \
--tab-size 1 \
--acronyms-processing default \
--acronyms "acronym1" "acronym2"Dumps default configuration into a config file
swift package resources config init --format yaml # `json` is also supportedIf you already have a config file you can also use
swift package resources config init --mode force # rewrite config file
swift package resources config init --mode append # add missing entriesUtility for editing config files, overrides specific values in config file
swift package resources config edit \
--indentor "\s" \
--tab-size 2Also can remove specific keys from the config, just pass --remove- prefixed arguments as flags
swift package resources config edit --remove-acronyms Tip
Path to config file can be specified for config commands
swift package resources config \
--path "<path-to-config-file>" \
edit --remove-output- Localized strings support
- Excludes support
- Filesystem expressions support
- Resources validation
This library is released under the MIT license. See LICENSE for details.