Skip to content

CaptureContext/package-resources-cli

Repository files navigation

package-resources-cli

CI

Code generator for swift-package-resources

Table of contents

Installation

  1. 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")
),
  1. 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

Makefile

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` command

Usage

Supported 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.

Configuration

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.

Command plugin

You can run commands manually using swift package resources

Generate command

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"

Config init command

Dumps default configuration into a config file

swift package resources config init --format yaml # `json` is also supported

If 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 entries

Config edit command

Utility for editing config files, overrides specific values in config file

swift package resources config edit \
  --indentor "\s" \
  --tab-size 2

Also 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

Todos

  • Localized strings support
  • Excludes support
  • Filesystem expressions support
  • Resources validation

License

This library is released under the MIT license. See LICENSE for details.

About

Code generator for swift-package-resources

Resources

License

Stars

Watchers

Forks

Packages

No packages published