-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from IBDecodable/feature/plugin
Add plugin feature
- Loading branch information
Showing
19 changed files
with
404 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/.build | ||
/Packages | ||
/*.xcodeproj | ||
portable_iblinter.zip |
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,10 +1,10 @@ | ||
Pod::Spec.new do |s| | ||
s.name = 'IBLinter' | ||
s.version = '0.3.0' | ||
s.version = '0.4.0' | ||
s.summary = 'A linter tool for Interface Builder.' | ||
s.homepage = 'https://github.com/IBDecodable/IBLinter' | ||
s.license = { :type => 'MIT', :file => 'LICENSE' } | ||
s.author = { 'Yuta Saito' => 'kateinoigakukun@gmail.com' } | ||
s.source = { :git => "https://github.com/IBDecodable/IBLinter.git", :tag => s.version } | ||
s.preserve_paths = 'bin/*' | ||
s.source = { :http => "#{s.homepage}/releases/download/#{s.version}/portable_iblinter.zip" } | ||
s.preserve_paths = '*' | ||
end |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// EditCommand.swift | ||
// IBLinterKit | ||
// | ||
// Created by SaitoYuta on 2018/05/27. | ||
// | ||
|
||
import Result | ||
import Foundation | ||
import Commandant | ||
import Files | ||
import PathKit | ||
import xcproj | ||
|
||
struct EditCommand: CommandProtocol { | ||
|
||
let verb: String = "edit" | ||
let function: String = "Edit the IBLinterfile.swift" | ||
|
||
func run(_ options: NoOptions<CommandantError<()>>) -> Result<(), CommandantError<()>> { | ||
let ibLinterfile = Runtime.ibLinterfile.exists ? Runtime.ibLinterfile : try! createIBLinterfile() | ||
try! Runtime.resolvePackages(ibLinterfile: ibLinterfile) | ||
guard let libPath = Runtime.libPath() else { | ||
print("Could not find a libIBLinter to link against at any of: \(Runtime.potentialFolders)") | ||
return Result.failure(.commandError(())) | ||
} | ||
let arguments = CommandLine.arguments | ||
let scriptManager = try! Runtime.getScriptManager() | ||
let script = try! scriptManager.script(atPath: ibLinterfile.string, allowRemote: true) | ||
let xcodeprojPath = try! script.setupForEdit(arguments: arguments) | ||
|
||
try! addLibPathToXcodeProj(xcodeprojPath: xcodeprojPath, libPath: libPath) | ||
try! script.watch(arguments: arguments) | ||
return .success(()) | ||
} | ||
|
||
func addLibPathToXcodeProj(xcodeprojPath: String, libPath: Path) throws -> Void { | ||
let xcodeProj = try XcodeProj(pathString: xcodeprojPath) | ||
let sourceRoot = Path(xcodeprojPath).parent() | ||
|
||
let otherSwiftFlagsKey = "OTHER_SWIFT_FLAGS" | ||
xcodeProj.pbxproj.objects.buildConfigurations.forEach { (key, configuration) in | ||
configuration.buildSettings["LIBRARY_SEARCH_PATHS"] = ["$(inherited)", libPath.string] | ||
guard let flags = configuration.buildSettings[otherSwiftFlagsKey] as? [String] else { | ||
return | ||
} | ||
configuration.buildSettings[otherSwiftFlagsKey] = flags + ["-I \(libPath.string)", "-L \(libPath.string)"] | ||
} | ||
|
||
let fileReference = try xcodeProj.pbxproj.objects.addFile( | ||
at: libPath + Runtime.dylibName, toGroup: xcodeProj.pbxproj.rootGroup, | ||
sourceRoot: sourceRoot | ||
) | ||
guard let target = xcodeProj.pbxproj.objects.targets(named: "IBLinterfile").first?.object else { | ||
return | ||
} | ||
guard let buildFile = xcodeProj.pbxproj.objects | ||
.addBuildFile(toTarget: target, reference: fileReference.reference) else { return } | ||
xcodeProj.pbxproj.objects.frameworksBuildPhases.forEach { key, value in | ||
value.files.append(buildFile.reference) | ||
} | ||
|
||
try xcodeProj.write(path: Path(xcodeprojPath)) | ||
} | ||
|
||
func createIBLinterfile() throws -> Path { | ||
let template = "import IBLinter \nlet linter = IBLinter()" | ||
let data = template.data(using: .utf8)! | ||
let pathString = try FileSystem().createFile(at: Runtime.ibLinterfile.string, contents: data).path | ||
return Path(pathString) | ||
} | ||
} |
Oops, something went wrong.