Skip to content

Commit

Permalink
Merge pull request #6 from mackoj/feat/disableArgumentName
Browse files Browse the repository at this point in the history
Improvement
  • Loading branch information
mackoj authored Oct 22, 2022
2 parents b1bc8d2 + e26cec6 commit e60b7be
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
24 changes: 17 additions & 7 deletions Plugins/SchemeGeneratorPlugin/SchemeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ public struct SchemeGenerator {
var toolConfig = getDefaultConfigurationName(toolConfigFileURL)

/// Prepare configuration
let configurationFileURL = getConfigurationFileURL(packageDirectory, arguments)
toolConfig = updateDefaultConfigFileName(arguments, toolConfig)
saveToolConfig(toolConfig, toolConfigFileURL)
let configurationFileURL = getConfigurationFileURL(packageDirectory, arguments, toolConfig.defaultConfigFileName)
if FileManager.default.fileExists(atPath: configurationFileURL.path) == false {
createDefaultConfiguration(configurationFileURL)
}
let config = loadConfiguration(configurationFileURL)
validateConfiguration(config, configurationFileURL)

if config.verbose { print("toolConfigFileURL:", toolConfigFileURL.path) }

// if config.verbose { print("toolConfigFileURL:", toolConfigFileURL.path) }
if config.verbose { print(toolConfig) }

/// Prepare productNames
toolConfig = testProductNamesContent(productNames, packageTempFolder, toolConfig)
saveToolConfig(toolConfig, toolConfigFileURL)
Expand All @@ -35,7 +38,7 @@ public struct SchemeGenerator {

// MARK: - Private

// MARK: Configuration
// MARK: Tool Configuration
private static func saveToolConfig(_ toolConfig: ToolConfiguration, _ toolConfigFileURL: FileURL) {
do {
let data = try JSONEncoder().encode(toolConfig)
Expand All @@ -59,16 +62,23 @@ public struct SchemeGenerator {
saveToolConfig(toolConfig, toolConfigFileURL)
return toolConfig
}

private static func getConfigurationFileURL(_ packageDirectory: FileURL, _ arguments: [String]) -> FileURL {
var configurationFileName = "schemeGenerator.json"

// MARK: Configuration
private static func updateDefaultConfigFileName(_ arguments: [String], _ toolConfig: ToolConfiguration) -> ToolConfiguration {
var toolConfig = toolConfig
var configurationFileName = toolConfig.defaultConfigFileName
if let cf = arguments.firstIndex(of: "--confFile") {
let param = arguments.index(after: cf)
if param != cf {
let confFile = arguments[param]
configurationFileName = confFile
}
}
toolConfig.defaultConfigFileName = configurationFileName
return toolConfig
}

private static func getConfigurationFileURL(_ packageDirectory: FileURL, _ arguments: [String], _ configurationFileName: String) -> FileURL {
let configurationFileURL = packageDirectory.appendingPathComponent(configurationFileName)
return configurationFileURL
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public struct SchemeGeneratorConfiguration: Codable, CustomStringConvertible {
public var description: String {
"""
SchemeGeneratorConfiguration:
-----------------------------
schemesDirectory: \(schemesDirectory?.path ?? "nil")
verbose: \(verbose)
overwriteAlreadyGeneratedSchemes: \(overwriteAlreadyGeneratedSchemes)
Expand Down
12 changes: 10 additions & 2 deletions Plugins/SchemeGeneratorPlugin/ToolConfiguration.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import Foundation

struct ToolConfiguration: Codable {
let defaultConfigFileName: String
struct ToolConfiguration: Codable, CustomStringConvertible {
var defaultConfigFileName: String
var lastProductNamesHash: String?

var description: String {
"""
ToolConfiguration:
lastProductNamesHash: \(lastProductNamesHash ?? "nil")
defaultConfigFileName: \(defaultConfigFileName)
"""
}

init(defaultConfigFileName: String = "schemeGenerator.json", lastProductNamesHash: String? = nil) {
self.defaultConfigFileName = defaultConfigFileName
self.lastProductNamesHash = lastProductNamesHash
Expand Down

0 comments on commit e60b7be

Please sign in to comment.