Skip to content

Commit

Permalink
fix(POM-235): project bootstrap (#148)
Browse files Browse the repository at this point in the history
* Remove mint package manager in favour of brew that is already used 
to reduce dependencies count and speed up project bootstrap
* Use custom xcassets swiftgen template
* Add /opt/homebrew/bin to PATH in Xcode build scripts

https://checkout.atlassian.net/browse/POM-235
  • Loading branch information
andrii-vysotskyi-cko authored Aug 11, 2023
1 parent 04e9204 commit 5e4d88c
Show file tree
Hide file tree
Showing 20 changed files with 429 additions and 100 deletions.
9 changes: 1 addition & 8 deletions .github/actions/bootstrap-project/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ runs:
with:
ruby-version: '3.1.2'
bundler-cache: true
- name: Cache Mint Packages
uses: actions/cache@v3
with:
path: ~/.mint/packages
key: ${{ runner.os }}-mint-${{ hashFiles('**/Mintfile') }}
restore-keys: |
${{ runner.os }}-mint-
- name: Write Constants
run: |
CONSTANTS=$'${{ inputs.test-project-constants }}'
Expand All @@ -30,5 +23,5 @@ runs:
shell: bash
# - name: Bootstrap Example Project
# if: ${{ inputs.test-project-constants != '' }}
# run: cd Example && ./Scripts/BootstrapProject.sh --skip-mint-bootstrap
# run: cd Example && ./Scripts/BootstrapProject.sh
# shell: bash
5 changes: 4 additions & 1 deletion Brewfile
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
brew "mint"
brew "xcodegen"
brew "swiftlint"
brew "swiftgen"
brew "sourcery"
1 change: 0 additions & 1 deletion Example/Brewfile

This file was deleted.

3 changes: 3 additions & 0 deletions Example/Brewfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
brew "xcodegen"
brew "swiftlint"
brew "swiftgen"
1 change: 0 additions & 1 deletion Example/Mintfile

This file was deleted.

7 changes: 1 addition & 6 deletions Example/Scripts/BootstrapProject.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@ set -euo pipefail
# Installs brew dependencies
brew bundle -q

# Installs mint dependencies if needed
if ! [[ "$@" =~ '--skip-mint-bootstrap' ]]; then
mint bootstrap
fi

# Generates project
mint run xcodegen generate
xcodegen generate

# Creates hardlink to Package.resolved
SWIFTPM_DIR='Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm'
Expand Down
6 changes: 5 additions & 1 deletion Example/Scripts/Lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

set -euo pipefail

mint run swiftlint lint --strict
# Add brew binaries to PATH
export PATH="/opt/homebrew/bin:$PATH"

# Lint
swiftlint lint --strict
6 changes: 5 additions & 1 deletion Example/Scripts/SwiftGen/SwiftGen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

set -euo pipefail

mint run swiftgen config run
# Add brew binaries to PATH
export PATH="/opt/homebrew/bin:$PATH"

# Run SwiftGen
swiftgen config run
2 changes: 1 addition & 1 deletion Example/swiftgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ xcassets:
- Images.xcassets
- Colors.xcassets
outputs:
- templateName: swift5
- templatePath: ${SRCROOT}/../Templates/xcassets.stencil
params:
forceFileNameEnum: true
forceProvidesNamespaces: true
Expand Down
4 changes: 0 additions & 4 deletions Mintfile

This file was deleted.

5 changes: 1 addition & 4 deletions Scripts/BootstrapProject.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ export CURRENT_VERSION="$(cat Version.resolved)"
# Installs brew dependencies
brew bundle -q

# Installs mint dependencies
mint bootstrap

# Installs bundler dependencies if needed
if ! [[ "$@" =~ '--skip-bundle-instal' ]]; then
bundle check || bundle install
fi

# Creates project
mint run xcodegen generate
xcodegen generate
2 changes: 1 addition & 1 deletion Scripts/CMark/CreateXcframework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ cp "$SCRIPT_DIR/module.modulemap" src/
cp "$SCRIPT_DIR/project.yml" .

# Generate project
mint run xcodegen generate
xcodegen generate

# Create frameworks for needed platforms
xcodebuild archive -scheme cmark -destination "generic/platform=iOS" -archivePath ./cmark-iOS
Expand Down
6 changes: 5 additions & 1 deletion Scripts/Lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

set -euo pipefail

mint run swiftlint lint --strict
# Add brew binaries to PATH
export PATH="/opt/homebrew/bin:$PATH"

# Lint
swiftlint lint --strict
8 changes: 6 additions & 2 deletions Scripts/Sourcery.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

set -euo pipefail

mint run sourcery \
# Add brew binaries to PATH
export PATH="/opt/homebrew/bin:$PATH"

# Run sourcery
sourcery \
--sources $PROJECT_DIR/Sources/$TARGET_NAME/Sources \
--templates $PROJECT_DIR/Templates \
--templates $PROJECT_DIR/Templates/AutoAsync.stencil \
--parseDocumentation \
--output $PROJECT_DIR/Sources/$TARGET_NAME/Sources/Generated/Sourcery+Generated.swift
6 changes: 5 additions & 1 deletion Scripts/SwiftGen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

set -euo pipefail

mint run swiftgen config run --config "${TARGET_ROOT}/swiftgen.yml"
# Add brew binaries to PATH
export PATH="/opt/homebrew/bin:$PATH"

# Run SwiftGen
swiftgen config run --config "${TARGET_ROOT}/swiftgen.yml"
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension Strings {
///
/// The implementation falls back to the framework's bundle in case the main application doesn't
/// provide translations for missing languages to ensure that we don't display untranslated strings.
static func localized(_ key: String, _ table: String) -> String {
static func localized(_ key: String, _ table: String, _: String) -> String {
if Bundle.main.preferredLocalizations.first == BundleLocator.bundle.preferredLocalizations.first {
return BundleLocator.bundle.localizedString(forKey: key, value: nil, table: table)
}
Expand Down
22 changes: 0 additions & 22 deletions Sources/ProcessOut/Sources/Generated/Assets+Generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
import UIKit
#endif

// Deprecated typealiases
@available(*, deprecated, renamed: "ColorAsset.Color", message: "This typealias will be removed in SwiftGen 7.0")
internal typealias AssetColorTypeAlias = ColorAsset.Color
@available(*, deprecated, renamed: "ImageAsset.Image", message: "This typealias will be removed in SwiftGen 7.0")
internal typealias AssetImageTypeAlias = ImageAsset.Image

// swiftlint:disable superfluous_disable_command file_length implicit_return

// MARK: - Asset Catalogs
Expand Down Expand Up @@ -155,19 +149,3 @@ internal struct ImageAsset {
}
#endif
}

internal extension ImageAsset.Image {
@available(iOS 8.0, tvOS 9.0, watchOS 2.0, *)
@available(macOS, deprecated,
message: "This initializer is unsafe on macOS, please use the ImageAsset.image property")
convenience init?(asset: ImageAsset) {
#if os(iOS) || os(tvOS)
let bundle = BundleLocator.bundle
self.init(named: asset.name, in: bundle, compatibleWith: nil)
#elseif os(macOS)
self.init(named: NSImage.Name(asset.name))
#elseif os(watchOS)
self.init(named: asset.name)
#endif
}
}
73 changes: 61 additions & 12 deletions Sources/ProcessOut/Sources/Generated/Fonts+Generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
#elseif os(iOS) || os(tvOS) || os(watchOS)
import UIKit.UIFont
#endif
#if canImport(SwiftUI)
import SwiftUI
#endif

// Deprecated typealiases
@available(*, deprecated, renamed: "FontConvertible.Font", message: "This typealias will be removed in SwiftGen 7.0")
internal typealias Font = FontConvertible.Font

// swiftlint:disable superfluous_disable_command
// swiftlint:disable file_length
// swiftlint:disable superfluous_disable_command file_length implicit_return

// MARK: - Fonts

Expand Down Expand Up @@ -66,12 +68,41 @@ internal struct FontConvertible {
return font
}

#if canImport(SwiftUI)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
internal func swiftUIFont(size: CGFloat) -> SwiftUI.Font {
return SwiftUI.Font.custom(self, size: size)
}

@available(iOS 14.0, tvOS 14.0, watchOS 7.0, macOS 11.0, *)
internal func swiftUIFont(fixedSize: CGFloat) -> SwiftUI.Font {
return SwiftUI.Font.custom(self, fixedSize: fixedSize)
}

@available(iOS 14.0, tvOS 14.0, watchOS 7.0, macOS 11.0, *)
internal func swiftUIFont(size: CGFloat, relativeTo textStyle: SwiftUI.Font.TextStyle) -> SwiftUI.Font {
return SwiftUI.Font.custom(self, size: size, relativeTo: textStyle)
}
#endif

internal func register() {
// swiftlint:disable:next conditional_returns_on_newline
guard let url = url else { return }
CTFontManagerRegisterFontsForURL(url as CFURL, .process, nil)
}

fileprivate func registerIfNeeded() {
#if os(iOS) || os(tvOS) || os(watchOS)
if !UIFont.fontNames(forFamilyName: family).contains(name) {
register()
}
#elseif os(macOS)
if let url = url, CTFontManagerGetScopeForURL(url as CFURL) == .none {
register()
}
#endif
}

fileprivate var url: URL? {
// swiftlint:disable:next implicit_return
return BundleLocator.bundle.url(forResource: path, withExtension: nil)
Expand All @@ -80,16 +111,34 @@ internal struct FontConvertible {

internal extension FontConvertible.Font {
convenience init?(font: FontConvertible, size: CGFloat) {
#if os(iOS) || os(tvOS) || os(watchOS)
if !UIFont.fontNames(forFamilyName: font.family).contains(font.name) {
font.register()
}
#elseif os(macOS)
if let url = font.url, CTFontManagerGetScopeForURL(url as CFURL) == .none {
font.register()
}
#endif

font.registerIfNeeded()
self.init(name: font.name, size: size)
}
}

#if canImport(SwiftUI)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
internal extension SwiftUI.Font {
static func custom(_ font: FontConvertible, size: CGFloat) -> SwiftUI.Font {
font.registerIfNeeded()
return custom(font.name, size: size)
}
}

@available(iOS 14.0, tvOS 14.0, watchOS 7.0, macOS 11.0, *)
internal extension SwiftUI.Font {
static func custom(_ font: FontConvertible, fixedSize: CGFloat) -> SwiftUI.Font {
font.registerIfNeeded()
return custom(font.name, fixedSize: fixedSize)
}

static func custom(
_ font: FontConvertible,
size: CGFloat,
relativeTo textStyle: SwiftUI.Font.TextStyle
) -> SwiftUI.Font {
font.registerIfNeeded()
return custom(font.name, size: size, relativeTo: textStyle)
}
}
#endif
Loading

0 comments on commit 5e4d88c

Please sign in to comment.