Skip to content

Commit

Permalink
Merge pull request #12 from gurhub/feature-FinalActions
Browse files Browse the repository at this point in the history
Feature final actions merged to the master branch
  • Loading branch information
gurhub committed Feb 6, 2022
2 parents 6a73176 + 48f78d4 commit b0f74b5
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 89 deletions.
54 changes: 29 additions & 25 deletions Demo/SM/Surfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>output_path</key>
<string>build</string>
<key>framework</key>
<string>xcf</string>
<key>targets</key>
<array>
<dict>
<key>sdk</key>
<string>iOS</string>
<key>workspace</key>
<string>surmagic-demo.xcworkspace</string>
<key>scheme</key>
<string>xcf</string>
</dict>
<dict>
<key>sdk</key>
<string>iOSSimulator</string>
<key>workspace</key>
<string>surmagic-demo.xcworkspace</string>
<key>scheme</key>
<string>xcf</string>
</dict>
</array>
</dict>
<dict>
<key>output_path</key>
<string>build</string>
<key>framework</key>
<string>xcf</string>
<key>targets</key>
<array>
<dict>
<key>sdk</key>
<string>iOS</string>
<key>workspace</key>
<string>surmagic-demo.xcworkspace</string>
<key>scheme</key>
<string>xcf</string>
</dict>
<dict>
<key>sdk</key>
<string>iOSSimulator</string>
<key>workspace</key>
<string>surmagic-demo.xcworkspace</string>
<key>scheme</key>
<string>xcf</string>
</dict>
</array>
<key>finalActions</key>
<array>
<string>openDirectory</string>
</array>
</dict>
</plist>
Binary file modified bin/surmagic
Binary file not shown.
2 changes: 1 addition & 1 deletion surmagic/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.3
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
19 changes: 19 additions & 0 deletions surmagic/Sources/surmagic/FinalAction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// FinalAction.swift
// Surmagic
//
// Created by Muhammed Gurhan Yerlikaya on 6.02.2022.
// Copyright 漏 2022 https://github.com/gurhub/surmagic.
//

import Foundation

public enum FinalAction: String, Codable {
case openDirectory /// Opens the target directory.

var description: String {
switch self {
case .openDirectory: return "openDirectory"
}
}
}
121 changes: 78 additions & 43 deletions surmagic/Sources/surmagic/Surfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,6 @@ import Foundation
> as a Plist
<dict>
<key>output_path</key>
<string>_OUTPUT_DIRECTORY_NAME_HERE_</string>
<key>framework</key>
<string>_FRAMEWORK_NAME_HERE_</string>
<key>targets</key>
<array>
<dict>
<key>sdk</key>
<string>_TARGET_OS_HERE_</string>
<key>workspace</key>
<string>_WORKSPACE_NAME_HERE_.xcworkspace</string>
<key>scheme</key>
<string>_SCHEME_NAME_HERE_</string>
</dict>
</array>
</dict>
> as a JSON:
{
"output_path": "_OUTPUT_DIRECTORY_NAME_HERE_",
"framework": "_FRAMEWORK_NAME_HERE_",
"targets": [
{
"sdk": "_TARGET_OS_HERE_",
"workspace": "_WORKSPACE_NAME_HERE_.xcworkspace",
"scheme": "_SCHEME_NAME_HERE_"
}]
}
> as a File form.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>output_path</key>
<string>_OUTPUT_DIRECTORY_NAME_HERE_</string>
Expand All @@ -65,27 +28,98 @@ import Foundation
<string>_SCHEME_NAME_HERE_</string>
</dict>
</array>
<key>finalActions</key>
<array>
<string>openDirectory</string>
</array>
</dict>
</plist>
> as a JSON:
{
"output_path": "_OUTPUT_DIRECTORY_NAME_HERE_",
"framework": "_FRAMEWORK_NAME_HERE_",
"targets": [
{
"sdk": "_TARGET_OS_HERE_",
"workspace": "_WORKSPACE_NAME_HERE_.xcworkspace",
"scheme": "_SCHEME_NAME_HERE_"
}],
"finalActions": ["openDirectory"]
}
> as a File form.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>end_action</key>
<string>_OUTPUT_DIRECTORY_NAME_HERE_</string>
<key>output_path</key>
<string>_OUTPUT_DIRECTORY_NAME_HERE_</string>
<key>framework</key>
<string>_FRAMEWORK_NAME_HERE_</string>
<key>targets</key>
<array>
<dict>
<key>sdk</key>
<string>_TARGET_OS_HERE_</string>
<key>workspace</key>
<string>_WORKSPACE_NAME_HERE_.xcworkspace</string>
<key>scheme</key>
<string>_SCHEME_NAME_HERE_</string>
</dict>
</array>
<key>finalActions</key>
<array>
<string>openDirectory</string>
</array>
</dict>
</plist>
**********************************/

/// Check the content of the Surfile.
/// Content of the Surfile.
public class Surfile: Codable {

// MARK: Properties
// MARK: - Properties

/// output_path specifies the directory where any created archives will be placed,
/// or the archive that should be exported.
/// For a successful result .xcframework will be found in this directory.
let output_path: String

/// Name of the target framework.
let framework: String

/// The array of the target frameworks to create.
let targets: [Target]?

/// Final actions after finishing the work. If it's empty, no action will take by the system.
/// - @usage: ["openDirectory", ...etc]
let finalActions: [FinalAction]?

public var desc: String {
return ("output_path: \(String(output_path)) \n" +
" framework: \(String(framework)) \n"
)
var result = (
" output_path: \(String(output_path)) \n" +
" framework: \(String(framework)) \n"
)

if let targets = targets {
for item in targets {
result.append(contentsOf: " target: " + item.desc + " \n")
}
}

if let finalActions = finalActions {
for item in finalActions {
result.append(contentsOf: " finalAction: " + item.rawValue + " \n")
}
}

return result
}

// MARK: - Types
Expand All @@ -94,5 +128,6 @@ public class Surfile: Codable {
case output_path = "output_path"
case framework = "framework"
case targets = "targets"
case finalActions = "finalActions"
}
}
36 changes: 19 additions & 17 deletions surmagic/Sources/surmagic/Target.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import Foundation

public class Target: Codable {

// MARK: - Enums


/// SDK type names changes per OS.
public enum SDK: String, Codable {
case iOS
case iOSSimulator
Expand All @@ -21,21 +22,21 @@ public class Target: Codable {
case tvOSSimulator
case watchOS
case watchSimulator

var description: String {
switch self {
case .iOS: return "iphoneos"
case .iOSSimulator: return "iphonesimulator"
case .macOS: return "macosx"
case .macOSCatalyst: return "macOSCatalyst"
case .tvOS: return "appletvos"
case .tvOSSimulator: return "appletvsimulator"
case .watchOS: return "watchos"
case .watchSimulator: return "watchsimulator"
case .iOS: return "iphoneos"
case .iOSSimulator: return "iphonesimulator"
case .macOS: return "macosx"
case .macOSCatalyst: return "macOSCatalyst"
case .tvOS: return "appletvos"
case .tvOSSimulator: return "appletvsimulator"
case .watchOS: return "watchos"
case .watchSimulator: return "watchsimulator"
}
}
}

// MARK: - Types

enum CodingKeys: String, CodingKey {
Expand All @@ -54,10 +55,11 @@ public class Target: Codable {

// MARK: - Description
public var desc: String {
return ("sdk: \(String(sdk.rawValue)) \n" +
" workspace: \(String(workspace ?? "-")) \n" +
" project: \(String(project ?? "-")) \n" +
" scheme: \(String(scheme)) \n"
)
return (
"sdk: \(String(sdk.rawValue)) \n" +
" workspace: \(String(workspace ?? "-")) \n" +
" project: \(String(project ?? "-")) \n" +
" scheme: \(String(scheme)) \n"
)
}
}
28 changes: 25 additions & 3 deletions surmagic/Sources/surmagic/XCFCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public class XCFCommand {
Remove this comment and add more targets for Simulators and the Devices.
-->
</array>
<key>finalActions</key>
<array>
<string>openDirectory</string>
</array>
</dict>
</plist>
"""
Expand All @@ -70,7 +74,7 @@ public class XCFCommand {
throw RuntimeError("Couldn't write to file '\(SurmagicConstants.surfileDirectory)'!")
}

// Finaly open the output path
// Finaly open the template file directory.
openOutputPath(file)
}

Expand Down Expand Up @@ -133,6 +137,24 @@ public class XCFCommand {
}
}

/// Runs final actions if any available.
private func runFinalActions(_ surfile: Surfile) {
if let finalActions = surfile.finalActions {
for action in finalActions {
let message = "\n 鈿笍 Action: \(action)\n"
SurmagicHelper.shared.writeLine(message, inColor: .cyan, bold: false)

switch action {
case .openDirectory:
openOutputPath(surfile.output_path)
}
}
} else {
let message = "\n 馃弫 No Final Actions to run\n"
SurmagicHelper.shared.writeLine(message, inColor: .green, bold: false)
}
}

/// Opens the output directory
/// - Parameter directory: the directory to open.
private func openOutputPath(_ path: String) {
Expand Down Expand Up @@ -246,8 +268,8 @@ public class XCFCommand {
message = "\n 馃コ Successfully created a XCFramework on the location: \(output)\n"
SurmagicHelper.shared.writeLine(message, inColor: .green, bold: false)

// Finaly open the output path
openOutputPath(directory)
// Run final actions before completing.
runFinalActions(surfile)
} catch {
exit(0)
}
Expand Down

0 comments on commit b0f74b5

Please sign in to comment.