Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
Apous now creates a binary .apousscript.
Browse files Browse the repository at this point in the history
Adds support for nested directories (issue #1).
Added nested folder sample.
  • Loading branch information
owensd committed Jul 6, 2015
1 parent b1af46f commit 94b7eea
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ Carthage/

# Apous
bin/
.apous.swift
.apousscript

12 changes: 6 additions & 6 deletions Features.md
Original file line number Diff line number Diff line change
@@ -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

5 changes: 5 additions & 0 deletions apous.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -45,6 +46,7 @@
7D0F00931B4AF32F003B6EF0 /* apoustest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = apoustest.swift; sourceTree = "<group>"; };
7D0F00951B4AF32F003B6EF0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7D0F009A1B4AF3F1003B6EF0 /* Features.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = Features.md; sourceTree = "<group>"; };
7D0F00B01B4B18B6003B6EF0 /* Xcode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Xcode.swift; sourceTree = "<group>"; };
7D3AC3421B49F1FC0068CC83 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
7D3AC3441B49F62F0068CC83 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
7D3AC3451B49F99B0068CC83 /* Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -96,6 +98,7 @@
7D3AC3451B49F99B0068CC83 /* Utils.swift */,
7D3AC3471B49FE170068CC83 /* ErrorCodes.swift */,
7D3AC3491B4A37BC0068CC83 /* Tools.swift */,
7D0F00B01B4B18B6003B6EF0 /* Xcode.swift */,
);
path = src;
sourceTree = "<group>";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -369,6 +373,7 @@
7D0F00971B4AF32F003B6EF0 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
4 changes: 4 additions & 0 deletions samples/nested/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

print("Testing Nested Directories")
print("abspath: \(abspath())")
print("basename: \(basename())")
4 changes: 4 additions & 0 deletions samples/nested/os/path/abspath.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

func abspath() -> String {
return "abspath!"
}
4 changes: 4 additions & 0 deletions samples/nested/os/path/basename.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

func basename() -> String {
return "basename!"
}
17 changes: 15 additions & 2 deletions src/Tools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion src/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down
23 changes: 23 additions & 0 deletions src/Xcode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Xcode.swift
// apous
//
// Created by David Owens on 7/6/15.
// Copyright © 2015 owensd.io. All rights reserved.
//

// <name>.xcodeproj/
// project.pbxproj
// project.xcworkspace/
// contents.xcworkspacedata


import Foundation

func workspaceContents(project: String) -> String {
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Workspace\n version = \"1.0\">\n <FileRef\n location = \"self:\(project).xcodeproj\">\n </FileRef>\n</Workspace>"
}

func projectFile() -> String {
return ""
}
18 changes: 9 additions & 9 deletions src/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ 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.")
exit(.CarthageNotInstalled)
}

carthage.run("update")
frameworkPaths += ["-F", "Carthage/Build/Mac"]
}

if fileManager.fileExistsAtPath(path.stringByAppendingPathComponent(PodfileConfig)) {
Expand All @@ -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()
Expand Down

0 comments on commit 94b7eea

Please sign in to comment.