Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeehut committed Feb 23, 2016
2 parents 60966a9 + 39b327d commit d496679
Show file tree
Hide file tree
Showing 22 changed files with 2,804 additions and 114 deletions.
148 changes: 63 additions & 85 deletions BartyCrouch CLI/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,125 +8,103 @@

import Foundation

let currentPath = Process.arguments[0]

let inputStoryboardArguments = ["--input-storyboard", "-in"]
let outputStringsFilesArguments = ["--output-strings-files", "-out"]
let outputAllLanguagesArguments = ["--output-all-languages", "-all"]
// Configure command line interface

let cli = CommandLine()

let input = StringOption(
shortFlag: "i",
longFlag: "input",
required: true,
helpMessage: "Path to your Storyboard or XIB source file to be translated."
)

let output = MultiStringOption(
shortFlag: "o",
longFlag: "output",
required: false,
helpMessage: "A list of paths to your strings files to be incrementally updated."
)

let auto = BoolOption(
shortFlag: "a",
longFlag: "auto",
required: false,
helpMessage: "Automatically finds all strings files to update based on the Xcode defaults."
)

cli.addOptions(input, output, auto)


// Parse input data or exit with usage instructions

do {
try cli.parse()
} catch {
cli.printUsage(error)
exit(EX_USAGE)
}


// Do requested action(s)

enum OutputType {
case StringsFiles
case AllLanguages
case Automatic
case None
}

func run() {

let inputStoryboardIndexOptional: Int? = {
for inputStoryboardArgument in inputStoryboardArguments {
if let index = Process.arguments.indexOf(inputStoryboardArgument) {
return index
}
}
return nil
}()

guard let inputStoryboardIndex = inputStoryboardIndexOptional else {
print("Error! Missing input key '\(inputStoryboardArguments[0])' or '\(inputStoryboardArguments[1])'")
return
}

guard inputStoryboardIndex+1 <= Process.arguments.count else {
print("Error! Missing input path after key '\(inputStoryboardArguments[0])' or '\(inputStoryboardArguments[1])'")
return
}

let inputStoryboardPath = Process.arguments[inputStoryboardIndex+1]

let outputStringsFilesIndexOptional: Int? = {
for outputStringsFilesArgument in outputStringsFilesArguments {
if let index = Process.arguments.indexOf(outputStringsFilesArgument) {
return index
}
}
return nil
}()

let outputAllLanguagesIndexOptional: Int? = {
for outputAllLanguagesArgument in outputAllLanguagesArguments {
if let index = Process.arguments.indexOf(outputAllLanguagesArgument) {
return index
}
}
return nil
}()


let outputType: OutputType = {
if outputStringsFilesIndexOptional != nil {
if output.wasSet {
return .StringsFiles
}
if outputAllLanguagesIndexOptional != nil {
return .AllLanguages
if auto.wasSet {
return .Automatic
}
return .None
}()

guard outputType != .None else {
print("Error! Missing output key '\(outputStringsFilesArguments[1])' or '\(outputAllLanguagesArguments[1])'")
return
}

let outputIndex: Int = {
switch outputType {
case .StringsFiles:
return outputStringsFilesIndexOptional!
case .AllLanguages:
return outputAllLanguagesIndexOptional!
case .None:
return -1
}
}()

guard outputType == .AllLanguages || outputIndex+1 <= Process.arguments.count else {
print("Error! Missing input path(s) after key '\(outputStringsFilesArguments[0])' or '\(outputStringsFilesArguments[1])'")
return
}
let inputIbFilePath = input.value!

let outputStringsFilesPaths: [String] = {
switch outputType {
case .StringsFiles:
return Process.arguments[outputIndex+1].componentsSeparatedByString(",")
case .AllLanguages:
return StringsFilesSearch.sharedInstance.findAll(inputStoryboardPath)
return output.value!
case .Automatic:
return StringsFilesSearch.sharedInstance.findAll(inputIbFilePath)
case .None:
return []
print("Error! Missing output key '\(output.shortFlag!)' or '\(auto.shortFlag!)'.")
exit(EX_USAGE)
}
}()

guard NSFileManager.defaultManager().fileExistsAtPath(inputStoryboardPath) else {
print("Error! No file exists at input path '\(inputStoryboardPath)'")
return
guard NSFileManager.defaultManager().fileExistsAtPath(inputIbFilePath) else {
print("Error! No file exists at input path '\(inputIbFilePath)'")
exit(EX_NOINPUT)
}

for outputStringsFilePath in outputStringsFilesPaths {
guard NSFileManager.defaultManager().fileExistsAtPath(outputStringsFilePath) else {
print("Error! No file exists at output path '\(outputStringsFilePath)'")
return
print("Error! No file exists at output path '\(outputStringsFilePath)'.")
exit(EX_CONFIG)
}
}

let extractedStringsFilePath = inputStoryboardPath + ".tmpstrings"
let extractedStringsFilePath = inputIbFilePath + ".tmpstrings"

guard IBToolCommander.sharedInstance.export(stringsFileToPath: extractedStringsFilePath, fromStoryboardAtPath: inputStoryboardPath) else {
print("Error! Could not extract strings from Storyboard at path '\(inputStoryboardPath)'")
return
guard IBToolCommander.sharedInstance.export(stringsFileToPath: extractedStringsFilePath, fromIbFileAtPath: inputIbFilePath) else {
print("Error! Could not extract strings from Storyboard or XIB at path '\(inputIbFilePath)'.")
exit(EX_UNAVAILABLE)
}

for outputStringsFilePath in outputStringsFilesPaths {

guard let stringsFileUpdater = StringsFileUpdater(path: outputStringsFilePath) else {
print("Error! Could not update strings file at path '\(outputStringsFilePath)'")
return
print("Error! Could not read strings file at path '\(outputStringsFilePath)'")
exit(EX_CONFIG)
}

stringsFileUpdater.incrementallyUpdateKeys(withStringsFileAtPath: extractedStringsFilePath)
Expand All @@ -135,12 +113,12 @@ func run() {

do {
try NSFileManager.defaultManager().removeItemAtPath(extractedStringsFilePath)
print("BartyCrouch: Successfully updated Strings files from Storyboard.")
} catch {
print("Error! Temporary strings file couldn't be deleted at path '\(extractedStringsFilePath)'")
return
exit(EX_IOERR)
}

print("BartyCrouch: Successfully updated strings file(s) of Storyboard or XIB file.")

}

Expand Down
31 changes: 31 additions & 0 deletions BartyCrouch.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
820649D31C7CA71E009E501E /* CommandLine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 820649D01C7CA71E009E501E /* CommandLine.swift */; };
820649D41C7CA71E009E501E /* Option.swift in Sources */ = {isa = PBXBuildFile; fileRef = 820649D11C7CA71E009E501E /* Option.swift */; };
820649D51C7CA71E009E501E /* StringExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 820649D21C7CA71E009E501E /* StringExtensions.swift */; };
821DED3A1C70CFBB00B8353B /* StringsFilesSearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 821DED391C70CFBB00B8353B /* StringsFilesSearch.swift */; };
821DED3C1C70D04B00B8353B /* StringsFilesSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 821DED3B1C70D04B00B8353B /* StringsFilesSearchTests.swift */; };
828ED5351C710C2B00E0E947 /* StringsFileUpdater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82CDE2DF1C6BF35500055FE6 /* StringsFileUpdater.swift */; };
Expand Down Expand Up @@ -46,6 +49,10 @@
/* Begin PBXFileReference section */
8203A2971C6D159D00BCE479 /* NewExample.strings */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; path = NewExample.strings; sourceTree = "<group>"; };
8203A2981C6D159D00BCE479 /* OldExample.strings */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; path = OldExample.strings; sourceTree = "<group>"; };
820649CD1C7CA636009E501E /* Cartfile */ = {isa = PBXFileReference; lastKnownFileType = text; path = Cartfile; sourceTree = "<group>"; };
820649D01C7CA71E009E501E /* CommandLine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CommandLine.swift; sourceTree = "<group>"; };
820649D11C7CA71E009E501E /* Option.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Option.swift; sourceTree = "<group>"; };
820649D21C7CA71E009E501E /* StringExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtensions.swift; sourceTree = "<group>"; };
821DED391C70CFBB00B8353B /* StringsFilesSearch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringsFilesSearch.swift; sourceTree = "<group>"; };
821DED3B1C70D04B00B8353B /* StringsFilesSearchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringsFilesSearchTests.swift; sourceTree = "<group>"; };
821DED3F1C70D11F00B8353B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Example.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -100,13 +107,34 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
820649CE1C7CA6FA009E501E /* Carthage */ = {
isa = PBXGroup;
children = (
820649CF1C7CA705009E501E /* CommandLine */,
);
path = Carthage;
sourceTree = "<group>";
};
820649CF1C7CA705009E501E /* CommandLine */ = {
isa = PBXGroup;
children = (
820649D01C7CA71E009E501E /* CommandLine.swift */,
820649D11C7CA71E009E501E /* Option.swift */,
820649D21C7CA71E009E501E /* StringExtensions.swift */,
);
name = CommandLine;
path = Checkouts/CommandLine/CommandLine;
sourceTree = "<group>";
};
82CDE23C1C6ABB3300055FE6 = {
isa = PBXGroup;
children = (
820649CD1C7CA636009E501E /* Cartfile */,
82CDE2611C6ABBF500055FE6 /* Sources */,
82CDE2681C6ABC0200055FE6 /* Tests */,
82CDE2741C6ABE5D00055FE6 /* BartyCrouch CLI */,
82CDE2471C6ABB3300055FE6 /* Products */,
820649CE1C7CA6FA009E501E /* Carthage */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -369,9 +397,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
820649D31C7CA71E009E501E /* CommandLine.swift in Sources */,
828ED5361C710C2F00E0E947 /* IBToolCommander.swift in Sources */,
828ED5351C710C2B00E0E947 /* StringsFileUpdater.swift in Sources */,
820649D51C7CA71E009E501E /* StringExtensions.swift in Sources */,
828ED5371C710C3100E0E947 /* StringsFilesSearch.swift in Sources */,
820649D41C7CA71E009E501E /* Option.swift in Sources */,
82CDE2761C6ABE5D00055FE6 /* main.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,6 @@
ReferencedContainer = "container:BartyCrouch.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "-in &quot;/Users/Dschee/Code/Flinesoft/iOS/Cruciverber/Sources/User Interface/Base.lproj/Main.storyboard&quot; -all"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-in &quot;/Users/Dschee/Code/Flinesoft/iOS/Cruciverber/Sources/User Interface/Base.lproj/Main.storyboard&quot; -out &quot;/Users/Dschee/Code/Flinesoft/iOS/Cruciverber/Sources/User Interface/de.lproj/Main.strings,/Users/Dschee/Code/Flinesoft/iOS/Cruciverber/Sources/User Interface/en.lproj/Main.strings&quot;"
isEnabled = "NO">
</CommandLineArgument>
</CommandLineArguments>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
Expand Down
2 changes: 2 additions & 0 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# A pure Swift library for creating command-line interfaces
github "jatoben/CommandLine"
1 change: 1 addition & 0 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github "jatoben/CommandLine" "v2.0.0"
19 changes: 19 additions & 0 deletions Carthage/Checkouts/CommandLine/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate

5 changes: 5 additions & 0 deletions Carthage/Checkouts/CommandLine/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: objective-c # this is a lie
xcode_project: CommandLine.xcodeproj
xcode_scheme: CommandLine
script: xcodebuild -scheme CommandLine test
osx_image: xcode7
1 change: 1 addition & 0 deletions Carthage/Checkouts/CommandLine/Carthage/Build
Loading

0 comments on commit d496679

Please sign in to comment.