-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* new spm command * integrate SPM package processing in graph command * added multi-edge configuration for graph * show complexity info in label at bottom * remove extra character * fixed package * fix issue with grah * update documentation * fix graph issues * added new option to show externals dependencies * added unit tests * remove dependency * remove unused import * compare working with SPM * refactor compare command * refactor compare command * implemented history command for SPM * update documentation * fix order * make graph command to update graph and stats according to the parameter * adapt compare command to multi/regular config * adapt history command
- Loading branch information
Showing
17 changed files
with
689 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,3 @@ public struct Module: Hashable { | |
self.dependencies = dependencies | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import Foundation | ||
import DependencyModule | ||
import Shell | ||
|
||
public struct Package: Decodable { | ||
public let targets: [Target] | ||
|
||
public struct Target: Decodable { | ||
let name: String | ||
let targetDependencies: [String]? | ||
let productDependencies: [String]? | ||
|
||
var dependencies: [String] { | ||
[targetDependencies, productDependencies].compactMap { $0 }.flatMap { $0 } | ||
} | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case name | ||
case targetDependencies = "target_dependencies" | ||
case productDependencies = "product_dependencies" | ||
} | ||
} | ||
} | ||
|
||
public enum TargetError: Error { | ||
case targetNotFound(target: String) | ||
} | ||
|
||
public enum PackageError: Error { | ||
case nonDecodable(raw: String) | ||
} | ||
|
||
extension TargetError: CustomStringConvertible { | ||
public var description: String { | ||
switch self { | ||
case .targetNotFound(let target): | ||
return "\"\(target)\" target not found in Package.swift!. Please, provide an existent target in your Package." | ||
} | ||
} | ||
} | ||
|
||
public func extracPackageModules(from packageRaw: String, target: String) throws -> ([Module], [String]) { | ||
|
||
guard | ||
let data = packageRaw.data(using: .utf8) | ||
else { | ||
throw PackageError.nonDecodable(raw: packageRaw) | ||
} | ||
|
||
let package = try JSONDecoder().decode(Package.self, from: data) | ||
|
||
guard let targetModules = package.targets.filter({ $0.name == target }).first else { | ||
throw TargetError.targetNotFound(target: target) | ||
} | ||
|
||
let dependencies = extractDependencies(from: package, on: target) | ||
let external = targetModules.productDependencies?.compactMap { Module(name: $0, dependencies: []) } ?? [] | ||
|
||
let targetDependencies = targetModules.dependencies | ||
return (dependencies + external, targetDependencies) | ||
} | ||
|
||
|
||
public func extractDependencies(from package: Package, on target: String) -> [Module] { | ||
guard | ||
let targetModules = package.targets.filter({ $0.name == target }).first | ||
else { | ||
return [] | ||
} | ||
|
||
var dependencies: Set<Module> = Set() | ||
|
||
for dependency in targetModules.dependencies { | ||
let modules = extractDependencies(from: package, on: dependency) | ||
for module in modules { | ||
dependencies.insert(module) | ||
} | ||
} | ||
return [Module(name: target, dependencies: targetModules.dependencies)] + Array(dependencies) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,28 @@ | ||
import Foundation | ||
|
||
public func shell(_ command: String, at currentDirectoryURL: URL? = nil) throws -> String { | ||
@discardableResult public func shell(_ command: String, at directory: URL? = nil, skipErrorsOutput: Bool = true) throws -> String { | ||
let task = Process() | ||
let pipe = Pipe() | ||
|
||
let errorPipe = Pipe() | ||
|
||
if !skipErrorsOutput { | ||
task.standardError = pipe | ||
} else { | ||
task.standardError = errorPipe | ||
} | ||
task.standardOutput = pipe | ||
task.standardError = pipe | ||
task.arguments = ["--login", "-c", command] | ||
task.launchPath = "/bin/zsh" | ||
task.standardInput = nil | ||
if let currentDirectoryURL = currentDirectoryURL { | ||
task.currentDirectoryURL = currentDirectoryURL | ||
if let directory = directory { | ||
task.currentDirectoryURL = directory | ||
} | ||
|
||
try task.run() | ||
|
||
let data = pipe.fileHandleForReading.readDataToEndOfFile() | ||
let output = String(data: data, encoding: .utf8)! | ||
let output = String(data: data, encoding: .utf8) ?? "" | ||
|
||
return output | ||
} | ||
|
Oops, something went wrong.