Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-34 Allow more flexible slicing #35

Merged
merged 25 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
65e8f9a
Upgrade dependencies
henrik-dmg Mar 7, 2024
be6fb44
Upgrade Swift tools version
henrik-dmg Mar 7, 2024
41f9044
Remove obsolete properties
henrik-dmg Mar 7, 2024
14058cd
Create slice size calculation logic and add tests
henrik-dmg Mar 7, 2024
ad23539
Revert some changes to reduce diff
henrik-dmg Mar 7, 2024
a3566d0
Nicer names for tests and more useful tests for DeviceData
henrik-dmg Mar 7, 2024
c792021
Remove a bunch of unused code and reduce access levels
henrik-dmg Mar 7, 2024
61452ad
More easy tests
henrik-dmg Mar 7, 2024
3025001
A lot more cleanup
henrik-dmg Mar 7, 2024
c6c0475
Remove unused method
henrik-dmg Mar 7, 2024
22bd938
Update example config files
henrik-dmg Mar 7, 2024
ef848b4
Use safer shebang in install script
henrik-dmg Mar 7, 2024
836c2e6
Make benchmark script independent of external libs
henrik-dmg Mar 7, 2024
a225d45
Remove accidentaly committed periphery file
henrik-dmg Mar 7, 2024
c0ee0fa
Fix GH Actions
henrik-dmg Mar 7, 2024
683498b
Upgrade to Swift 5.9
henrik-dmg Mar 7, 2024
5ba29bf
Set Xcode version instead of Swift version
henrik-dmg Mar 7, 2024
1262765
Use specif Xcode version
henrik-dmg Mar 7, 2024
0f722b4
Maybe using Swift 5.7 it works
henrik-dmg Mar 7, 2024
017ab5b
Fix Swift 5.7 incompatible syntax
henrik-dmg Mar 7, 2024
052763b
Revert Regex changes to hopefully fix GH Actions
henrik-dmg Mar 7, 2024
e4f193b
Use newest checkout version and also pin Xcode version
henrik-dmg Mar 11, 2024
8c2949e
Reapply all the changes made to satisfy GH Actions
henrik-dmg Mar 11, 2024
b6c1749
Even safer validation of slice size
henrik-dmg Mar 11, 2024
7938466
Simplify error printing
henrik-dmg Mar 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes so much more sense now that I'm seeing this :D

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