Swiftpack.co -  EduDo-Inc/spmgen as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
EduDo-Inc/spmgen
Resources boilerplate code generator for Swift
.package(url: "https://github.com/EduDo-Inc/spmgen.git", from: "1.0.2")

SPMGen

Code generator for Swift.

Installation

Homebrew

brew install edudo-inc/formulae/spmgen

Makefile

# Download repo
git clone https://github.com/edudo-inc/spmgen.git

# Navigate to repo directory
cd spmgen

# Build and install using Make
make install

# You can also delete spmgen using `make uninstall` command

Resources command

SPMGen provides static resource factories for various resource types.

Supported resources:

Resource Extensions Is reliable
ColorResource .xcassets true
FontResource .ttf .otf true
ImageResource .xcassets true
NibResource .xib not used
StoryboardResource .storyboard not used
SCNSceneResource .scnassets/.scn true

Integration

Add SPMGen dependency to your package

.package(url: "https://github.com/edudo-inc/spmgen.git", from: "1.0.1")

Create <#Project#>Resources target with a following structure

Sources
  <#Project#>Resources
    Resources
      <#Assets#>

Specify resource processing and add SPMResources dependency to your target

.target(
  name: "<#Project#>Resources",
  dependencies: [
    .product(
      name: "SPMResources",
      package: "spmgen"
    )
  ],
  resources: [
    .process("Resources")
  ]
)

Add a script to your Run Script target build phases

spmgen resources "$SRCROOT/Sources/<#Project#>Resources/Resources" \
  --output "$SRCROOT/Sources/<#Project#>Resources/SPMGen.swift" \
  --indentor " " \
  --indentation-width 2

# You can also add `--disable-exports` flag to disable `@_exported` attribute
# for `import SPMResources` declaration in generated file

Add <#Project#>Resources target as a dependency to other targets

.target(
  name: "<#Project#>Module",
  dependencies: [
    .target(name: "<#Project#>Resources")
  ]
)

Usage

Import your <#Project#>Resources package and initialize objects using .resource() static factory

import <#Project#>Resources
import UIKit

let label = UILabel()
label.backgroundColor = .resource(.accentColor)
label.textColor = .resource(.primaryText)
label.font = .primary(ofSize: 12, weight: .semibold, style: .italic)

let imageView = UIImageView(image: .resource(.logo))

Note: Fonts require additional setup

For example you want to add Monsterrat and Arimo fonts with different styles

  • Download fonts and add them to Sources/<#Project#>Resources/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.

CasePaths command

Generate CasePaths for all enums in your project using following command

spmgen casepaths "<path_to_sources>" \
  --indentor " " \
  --indentation-width 2

Todo: Support configuration file with exclude paths and typename-based excludes.

GitHub

link
Stars: 5
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

1.0.1
12 weeks ago

Tiny fix for broken generation

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API