Skip to content

Commit

Permalink
GH-34 Allow more flexible slicing (#35)
Browse files Browse the repository at this point in the history
Signed-off-by: Henrik Panhans <[email protected]>
  • Loading branch information
henrik-dmg authored Mar 26, 2024
1 parent f4cb89f commit 88c7bb9
Show file tree
Hide file tree
Showing 51 changed files with 373 additions and 415 deletions.
17 changes: 11 additions & 6 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ on: [push]

jobs:
build:
runs-on: macos-latest
runs-on: macos-14

steps:
- uses: actions/checkout@v2
- name: Build
run: swift build -v
- name: Run tests
run: swift test -v
- name: Checkout repository
uses: actions/checkout@v4
- name: Configure Xcode version
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "15.2"
- name: Build
run: swift build -v
- name: Run tests
run: swift test -v
2 changes: 2 additions & 0 deletions Example/example.config
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"outputSuffixes": ["iPhone X 5.8 inches"],
"screenshots": "Example/Screenshots/iPhone X/",
"templateFile": "Example/Template Files/iPhone X TemplateFile.png",
"numberOfSlices": 5,
"screenshotData": [
{
"screenshotName": "launchscreen.png",
Expand Down Expand Up @@ -91,6 +92,7 @@
"outputSuffixes": ["ipadPro", "ipadPro129"],
"screenshots": "Example/Screenshots/iPad Pro/",
"templateFile": "Example/Template Files/iPad Pro TemplateFile.png",
"numberOfSlices": 4,
"screenshotData": [
{
"screenshotName": "launchscreen.png",
Expand Down
2 changes: 2 additions & 0 deletions Example/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ deviceData:
- iPhone X 5.8 inches
screenshots: Example/Screenshots/iPhone X/
templateFile: Example/Template Files/iPhone X TemplateFile.png
numberOfSlices: 4
screenshotData:
- screenshotName: launchscreen.png
zIndex: 12
Expand Down Expand Up @@ -66,6 +67,7 @@ deviceData:
- iPad Pro 12.9 inch
screenshots: Example/Screenshots/iPad Pro/
templateFile: Example/Template Files/iPad Pro TemplateFile.png
numberOfSlices: 5
screenshotData:
- screenshotName: launchscreen.png
zIndex: 12
Expand Down
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/apple/swift-argument-parser",
"state": {
"branch": null,
"revision": "8f4d2753f0e4778c76d5f05ad16c74f707390531",
"version": "1.2.3"
"revision": "c8ed701b513cf5177118a175d85fbbbcd707ab41",
"version": "1.3.0"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// swift-tools-version:5.4
// swift-tools-version:5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "SwiftFrame",
platforms: [
.macOS(.v10_15)
.macOS(.v13)
],
products: [
.executable(name: "swiftframe", targets: ["SwiftFrame"])
Expand Down
10 changes: 6 additions & 4 deletions Sources/SwiftFrame/Render.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ struct Render: ParsableCommand {

@Flag(
name: .long,
inversion: .prefixedNo,
help: "Disables any colored output. Useful when running in CI"
)
var noColorOutput = false
var colorOutput = true

@Flag(
name: .long,
inversion: .prefixedNo,
help: "Disables clearing the output directories before writing images to them"
)
var noClearDirectories = false
var clearDirectories = true

// MARK: - Run

Expand All @@ -55,8 +57,8 @@ struct Render: ParsableCommand {
verbose: verbose,
shouldValidateManually: manualValidation,
shouldOutputWholeImage: outputWholeImage,
shouldClearDirectories: !noClearDirectories,
shouldColorOutput: !noColorOutput
shouldClearDirectories: clearDirectories,
shouldColorOutput: colorOutput
)
try processor.validate()
try processor.run()
Expand Down
6 changes: 1 addition & 5 deletions Sources/SwiftFrame/Scaffold.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,8 @@ struct Scaffold: ParsableCommand, VerbosePrintable {
print("Created \(numberOfCreatedFiles) files".formattedGreen())
}

private func lowercasedDirectoryIfNeeded(_ string: String) -> String {
lowercasedDirectories ? string.lowercased() : string
}

private func makeScaffoldRootURL() -> URL {
if let path = path {
if let path {
return URL(fileURLWithPath: path)
} else {
return URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftFrame/SwiftFrame.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct SwiftFrame: ParsableCommand {
static let configuration = CommandConfiguration(
commandName: "swiftframe",
abstract: "CLI application for speedy screenshot framing",
version: "5.0.2",
version: "6.0.0",
subcommands: [Render.self, Scaffold.self],
defaultSubcommand: Render.self,
helpNames: .shortAndLong
Expand Down
42 changes: 8 additions & 34 deletions Sources/SwiftFrameCore/Config/ConfigData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ struct ConfigData: Decodable, ConfigValidateable {
let textColorSource: ColorSource
let outputFormat: FileFormat
let localesRegex: String?
let clearDirectories: Bool?
let outputWholeImage: Bool?

@DecodableDefault.EmptyList var textGroups: [TextGroup]

Expand All @@ -31,8 +29,6 @@ struct ConfigData: Decodable, ConfigValidateable {
// MARK: - Coding Keys

enum CodingKeys: String, CodingKey {
case clearDirectories
case outputWholeImage
case deviceData
case textGroups
case stringsPath
Expand All @@ -46,16 +42,14 @@ struct ConfigData: Decodable, ConfigValidateable {

// MARK: - Init

public init(
init(
textGroups: [TextGroup] = [],
stringsPath: FileURL,
maxFontSize: CGFloat,
outputPaths: [FileURL],
fontSource: FontSource,
textColorSource: ColorSource,
outputFormat: FileFormat,
clearDirectories: Bool?,
outputWholeImage: Bool?,
deviceData: [DeviceData],
localesRegex: String? = nil)
{
Expand All @@ -66,20 +60,17 @@ struct ConfigData: Decodable, ConfigValidateable {
self.fontSource = fontSource
self.textColorSource = textColorSource
self.outputFormat = outputFormat
self.clearDirectories = clearDirectories
self.outputWholeImage = outputWholeImage
self.deviceData = deviceData
self.localesRegex = localesRegex
}

// MARK: - Processing

mutating public func process() throws {
let regex: NSRegularExpression?
if let pattern = localesRegex {
regex = try NSRegularExpression(pattern: pattern, options: .caseInsensitive)
mutating func process() throws {
let regex: Regex<AnyRegexOutput>? = if let localesRegex, !localesRegex.isEmpty {
try Regex(localesRegex)
} else {
regex = nil
nil
}

deviceData = try deviceData.map { try $0.makeProcessedData(localesRegex: regex) }
Expand All @@ -91,23 +82,7 @@ struct ConfigData: Decodable, ConfigValidateable {

// MARK: - ConfigValidateable

public func validate() throws {
if clearDirectories != nil {
let warningMessage = """
Specifying clearDirectories in the config file is deprecated and will be ignored in a future version.
Please use the CLI argument --clear-directories instead.
"""
print(CommandLineFormatter.formatWarning(text: warningMessage))
}

if outputWholeImage != nil {
let warningMessage = """
Specifying outputWholeImage in the config file is deprecated and will be ignored in a future version.
Please use the CLI argument --output-whole-image instead.
"""
print(CommandLineFormatter.formatWarning(text: warningMessage))
}

func validate() throws {
guard !deviceData.isEmpty else {
throw NSError(
description: "No screenshot data was supplied",
Expand All @@ -123,10 +98,9 @@ struct ConfigData: Decodable, ConfigValidateable {
try deviceData.forEach { try $0.validate() }
}

public func printSummary(insetByTabs tabs: Int) {
func printSummary(insetByTabs tabs: Int) {
ky_print("### Config Summary Start", insetByTabs: tabs)
CommandLineFormatter.printKeyValue("Outputs whole image as well in addition to slices", value: outputWholeImage)
CommandLineFormatter.printKeyValue("Title Color", value: textColorSource.hexString, insetBy: tabs)
CommandLineFormatter.printKeyValue("Title Color", value: textColorSource.hexString.uppercased(), insetBy: tabs)
CommandLineFormatter.printKeyValue("Title Font", value: try? fontSource.font().fontName, insetBy: tabs)
CommandLineFormatter.printKeyValue("Title Max Font Size", value: maxFontSize, insetBy: tabs)
CommandLineFormatter.printKeyValue(
Expand Down
Loading

0 comments on commit 88c7bb9

Please sign in to comment.