From 94b7eead2057755668fff5ccc5c2475596428620 Mon Sep 17 00:00:00 2001 From: David Owens II Date: Mon, 6 Jul 2015 14:50:28 -0700 Subject: [PATCH] Apous now creates a binary .apousscript. Adds support for nested directories (issue #1). Added nested folder sample. --- .gitignore | 2 +- Features.md | 12 ++++++------ apous.xcodeproj/project.pbxproj | 5 +++++ samples/nested/main.swift | 4 ++++ samples/nested/os/path/abspath.swift | 4 ++++ samples/nested/os/path/basename.swift | 4 ++++ src/Tools.swift | 17 +++++++++++++++-- src/Utils.swift | 2 +- src/Xcode.swift | 23 +++++++++++++++++++++++ src/main.swift | 18 +++++++++--------- 10 files changed, 72 insertions(+), 19 deletions(-) create mode 100644 samples/nested/main.swift create mode 100644 samples/nested/os/path/abspath.swift create mode 100644 samples/nested/os/path/basename.swift create mode 100644 src/Xcode.swift diff --git a/.gitignore b/.gitignore index d697c7f..ceaea2a 100644 --- a/.gitignore +++ b/.gitignore @@ -36,5 +36,5 @@ Carthage/ # Apous bin/ -.apous.swift +.apousscript diff --git a/Features.md b/Features.md index 8428180..409732b 100644 --- a/Features.md +++ b/Features.md @@ -1,9 +1,9 @@ Features Planned for v0.2.0: - 1. Travis CI Support - 2. Refactoring project to support unit tests - 3. Creating an Xcode project to support: - 1. Nested directories - 2. Xcode authoring - + 1. Refactoring project to support unit tests + 2. Support nested directories for the script + +Possible for v0.2.0: + + 1. Creation of implicit Xcode file for Xcode authoring support \ No newline at end of file diff --git a/apous.xcodeproj/project.pbxproj b/apous.xcodeproj/project.pbxproj index b0c3838..bd58a4b 100644 --- a/apous.xcodeproj/project.pbxproj +++ b/apous.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ 7D0373391B49021700E2711D /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D0373381B49021700E2711D /* main.swift */; }; 7D0373401B49028E00E2711D /* apous in Deploy Locally */ = {isa = PBXBuildFile; fileRef = 7D0373351B49021700E2711D /* apous */; }; 7D0F00941B4AF32F003B6EF0 /* apoustest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D0F00931B4AF32F003B6EF0 /* apoustest.swift */; }; + 7D0F00B11B4B18B6003B6EF0 /* Xcode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D0F00B01B4B18B6003B6EF0 /* Xcode.swift */; }; 7D3AC3461B49F99B0068CC83 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D3AC3451B49F99B0068CC83 /* Utils.swift */; }; 7D3AC3481B49FE170068CC83 /* ErrorCodes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D3AC3471B49FE170068CC83 /* ErrorCodes.swift */; }; 7D3AC34A1B4A37BC0068CC83 /* Tools.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D3AC3491B4A37BC0068CC83 /* Tools.swift */; }; @@ -45,6 +46,7 @@ 7D0F00931B4AF32F003B6EF0 /* apoustest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = apoustest.swift; sourceTree = ""; }; 7D0F00951B4AF32F003B6EF0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 7D0F009A1B4AF3F1003B6EF0 /* Features.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = Features.md; sourceTree = ""; }; + 7D0F00B01B4B18B6003B6EF0 /* Xcode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Xcode.swift; sourceTree = ""; }; 7D3AC3421B49F1FC0068CC83 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 7D3AC3441B49F62F0068CC83 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; 7D3AC3451B49F99B0068CC83 /* Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; @@ -96,6 +98,7 @@ 7D3AC3451B49F99B0068CC83 /* Utils.swift */, 7D3AC3471B49FE170068CC83 /* ErrorCodes.swift */, 7D3AC3491B4A37BC0068CC83 /* Tools.swift */, + 7D0F00B01B4B18B6003B6EF0 /* Xcode.swift */, ); path = src; sourceTree = ""; @@ -210,6 +213,7 @@ 7D3AC3461B49F99B0068CC83 /* Utils.swift in Sources */, 7D3AC3481B49FE170068CC83 /* ErrorCodes.swift in Sources */, 7D0373391B49021700E2711D /* main.swift in Sources */, + 7D0F00B11B4B18B6003B6EF0 /* Xcode.swift in Sources */, 7D3AC34A1B4A37BC0068CC83 /* Tools.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -369,6 +373,7 @@ 7D0F00971B4AF32F003B6EF0 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/samples/nested/main.swift b/samples/nested/main.swift new file mode 100644 index 0000000..521bb34 --- /dev/null +++ b/samples/nested/main.swift @@ -0,0 +1,4 @@ + +print("Testing Nested Directories") +print("abspath: \(abspath())") +print("basename: \(basename())") diff --git a/samples/nested/os/path/abspath.swift b/samples/nested/os/path/abspath.swift new file mode 100644 index 0000000..30227df --- /dev/null +++ b/samples/nested/os/path/abspath.swift @@ -0,0 +1,4 @@ + +func abspath() -> String { + return "abspath!" +} \ No newline at end of file diff --git a/samples/nested/os/path/basename.swift b/samples/nested/os/path/basename.swift new file mode 100644 index 0000000..fbdca0a --- /dev/null +++ b/samples/nested/os/path/basename.swift @@ -0,0 +1,4 @@ + +func basename() -> String { + return "basename!" +} \ No newline at end of file diff --git a/src/Tools.swift b/src/Tools.swift index 9518c68..2d49873 100644 --- a/src/Tools.swift +++ b/src/Tools.swift @@ -16,15 +16,24 @@ protocol Tool { /// `true` when the output of the tool should be printed to `stdout`. var printOutput: Bool { get } - + + /// Runs the tool and returns result of the execution. + func run(args: [String]) -> (out: String, err: String, code: Int32) + /// Runs the tool and returns result of the execution. func run(args: String...) -> (out: String, err: String, code: Int32) } extension Tool { var printOutput: Bool { return true } + + func run(args: String...) -> (out: String, err: String, code: Int32) { + return run(args) + } + + func run(args: [String]) -> (out: String, err: String, code: Int32) { let output = NSPipe() let error = NSPipe() @@ -175,8 +184,12 @@ struct SwiftTool : Tool { init?() { let which = WhichTool() - let result = which.run("swift") + let result = which.run("swiftc") if result.out.characters.count == 0 { return nil } self.launchPath = result.out } } + +struct ApousScriptTool : Tool { + let launchPath = "./.apousscript" +} diff --git a/src/Utils.swift b/src/Utils.swift index e31b16b..c72b3ab 100644 --- a/src/Utils.swift +++ b/src/Utils.swift @@ -48,7 +48,7 @@ func filesAtPath(path: String) -> [String] { let items: [String] = { do { - return try NSFileManager.defaultManager().contentsOfDirectoryAtPath(path) + return try NSFileManager.defaultManager().subpathsAtPath(path) ?? [] } catch { return [] diff --git a/src/Xcode.swift b/src/Xcode.swift new file mode 100644 index 0000000..22f556d --- /dev/null +++ b/src/Xcode.swift @@ -0,0 +1,23 @@ +// +// Xcode.swift +// apous +// +// Created by David Owens on 7/6/15. +// Copyright © 2015 owensd.io. All rights reserved. +// + +// .xcodeproj/ +// project.pbxproj +// project.xcworkspace/ +// contents.xcworkspacedata + + +import Foundation + +func workspaceContents(project: String) -> String { + return "\n \n \n" +} + +func projectFile() -> String { + return "" +} \ No newline at end of file diff --git a/src/main.swift b/src/main.swift index 8c9f77d..89d657a 100644 --- a/src/main.swift +++ b/src/main.swift @@ -53,6 +53,8 @@ func run() throws { // The tools need to be run under the context of the script directory. fileManager.changeCurrentDirectoryPath(path) + var frameworkPaths: [String] = [] + if fileManager.fileExistsAtPath(path.stringByAppendingPathComponent(CartfileConfig)) { guard let carthage = CarthageTool() else { print("Carthage does not seem to be installed or in your path.") @@ -60,6 +62,7 @@ func run() throws { } carthage.run("update") + frameworkPaths += ["-F", "Carthage/Build/Mac"] } if fileManager.fileExistsAtPath(path.stringByAppendingPathComponent(PodfileConfig)) { @@ -69,24 +72,21 @@ func run() throws { } pods.run("install", "--no-integrate") + frameworkPaths += ["-F", "Rome"] } let files = filesAtPath(path) - - var script = "" - for f in files { - script += try "// file: \(f)\n" + String(contentsOfFile: f, encoding: NSUTF8StringEncoding) + "\n" - } - - let scriptPath = path.stringByAppendingPathComponent(ApousScriptFile) - try script.writeToFile(scriptPath, atomically: true, encoding: NSUTF8StringEncoding) + let args = frameworkPaths + ["-o", ".apousscript"] + files guard let swift = SwiftTool() else { print("Unable to find a version of Swift in your path.") exit(.SwiftNotInstalled) } - swift.run("-F", "Carthage/Build/Mac", "-F", "Rome", scriptPath) + swift.run(args) + + let script = ApousScriptTool() + try script.run() } try run()