Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,4 @@ fastlane/test_output
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/
.DS_Store
6 changes: 4 additions & 2 deletions .ribscodegen_rename
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interactor:
- "listener: __RIB_NAME__Listener?"
- "presenter: __RIB_NAME__Presentable"
- "deactivate__RIB_NAME__"
- "finish__RIB_NAME__"
router:
- "__RIB_NAME__Router.swift"
- "protocol __RIB_NAME__Interactable:"
Expand All @@ -35,7 +36,7 @@ builder:
- "class __RIB_NAME__Builder:"
- "__RIB_NAME__Dependency"
- "__RIB_NAME__Component"
- "__RIB_NAME__ViewController"
- "__RIB_NAME__ViewController"
- "__RIB_NAME_LOWER_CASED_FIRST_LETTER__ViewController"
- "__RIB_NAME__ViewControllable"
- "__RIB_NAME__Listener"
Expand All @@ -61,6 +62,7 @@ parentInteractor:
- "detach__RIB_NAME__"
- "remove__RIB_NAME__"
- "deactivate__RIB_NAME__"
- "finish__RIB_NAME__"
parentRouter:
- " __RIB_NAME__Listener"
- "routeTo__RIB_NAME__"
Expand All @@ -81,7 +83,7 @@ parentNeedleBuilder:
- "__RIB_NAME_LOWER_CASED_FIRST_LETTER__Builder: __RIB_NAME_LOWER_CASED_FIRST_LETTER__Builder"
- "__RIB_NAME_LOWER_CASED_FIRST_LETTER__Component"
- "__RIB_NAME__Component"
parentComponentExtension:
parentComponentExtension:
- "__PARENT_RIB_NAME__Component+__RIB_NAME__.swift"
- "scope of __PARENT_RIB_NAME__ to provide for the __RIB_NAME__ scope."
- "__PARENT_RIB_NAME__Dependency__RIB_NAME__"
Expand Down
26 changes: 4 additions & 22 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ let package = Package(
.executable(name: "ribscodegen", targets: ["RIBsCodeGen"])
],
dependencies: [
.package(url: "https://github.com/jpsim/SourceKitten", from: "0.37.0"),
.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "602.0.0"),
.package(url: "https://github.com/jpsim/Yams.git", from: "5.0.5"),
.package(url: "https://github.com/kylef/PathKit", from: "1.0.1"),
.package(url: "https://github.com/onevcat/Rainbow", from: "3.2.0")
],
targets: [
.executableTarget(
name: "RIBsCodeGen",
name: "RIBsCodeGen",
dependencies: [
.product(name: "SourceKittenFramework", package: "SourceKitten"),
.product(name: "SwiftParser", package: "swift-syntax"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
"PathKit",
"Rainbow"]
"Yams",
"Rainbow"
]
)
]
)
2 changes: 0 additions & 2 deletions Sources/RIBsCodeGen/Commands/CreateComponentExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import Foundation
import SourceKittenFramework
import PathKit

struct CreateComponentExtension: Command {
Expand Down Expand Up @@ -82,4 +81,3 @@ private extension CreateComponentExtension {
try Path(filePath).write(replacedText)
}
}

2 changes: 0 additions & 2 deletions Sources/RIBsCodeGen/Commands/CreateRIBCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import Foundation
import SourceKittenFramework
import PathKit

struct CreateRIBCommand: Command {
Expand Down Expand Up @@ -44,7 +43,6 @@ struct CreateRIBCommand: Command {
let parentDirectory = isNeedle ? setting.templateDirectory + "/Needle" : setting.templateDirectory + "/Normal"
templateDirectory = isOwnsView ? parentDirectory + "/OwnsView" : parentDirectory + "/Default"


self.target = target
self.isOwnsView = isOwnsView
self.isNeedle = isNeedle
Expand Down
13 changes: 5 additions & 8 deletions Sources/RIBsCodeGen/Commands/DeleteRIBCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@
//

import Foundation

import Foundation
import SourceKittenFramework
import PathKit

struct DeleteRIBCommand: Command {
private let paths: [String]
private let targetName: String

init(paths: [String], targetName: String) {
self.paths = paths
self.targetName = targetName
}

func run() -> Result {
print("\nStart deleting \(targetName) RIB.\n".bold)

guard let interactorPath = paths.filter({ $0.contains("/\(targetName)/\(targetName)Interactor.swift") }).first else {
return .failure(error: .failedToDelete("Not found \(targetName)/\(targetName)Interactor.swift. Interrupt deleting operation."))
}
Expand All @@ -28,11 +25,11 @@ struct DeleteRIBCommand: Command {
guard directoryPath.isDirectory else {
return .failure(error: .failedToDelete("\(directoryPath) is not Directory. Failed to detect the target directory. Interrupt deleting operation."))
}

print("\tDelete ".magenta + " \(directoryPath) ".onMagenta + ".".magenta)
let shellResult = shell("rm -rf \(directoryPath)")
print("\t\(shellResult)")

return .success(message: "\nSuccessfully finished deleting \(targetName) RIB.".green.bold)
}
}
10 changes: 4 additions & 6 deletions Sources/RIBsCodeGen/Commands/DependencyCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import Foundation
import SourceKittenFramework
import Rainbow
import PathKit

Expand All @@ -24,7 +23,7 @@ struct DependencyCommand: Command {
init(paths: [String], parent: String, child: String) {
self.parent = parent
self.child = child

guard let parentInteractorPath = paths.filter({ $0.contains("/" + parent + "Interactor.swift") }).first else {
fatalError("Not found \(parent)Interactor.swift".red.bold)
}
Expand Down Expand Up @@ -56,7 +55,7 @@ struct DependencyCommand: Command {
self.childRouterPath = childRouterPath
self.childBuilderPath = childBuilderPath
}

func run() -> Result {
print("\nStart adding dependency and builder initialize".bold)

Expand Down Expand Up @@ -212,11 +211,10 @@ private extension DependencyCommand {

var initArgumentEndPosition = 0

guard let lastArgumentLength = initArguments.last?["key.length"] as? Int64,
let lastArgumentOffset = initArguments.last?["key.offset"] as? Int64 else {
guard let lastArgument = initArguments.last else {
return
}
initArgumentEndPosition = Int(lastArgumentOffset + lastArgumentLength)
initArgumentEndPosition = lastArgument.getKeyOffset() + lastArgument.getKeyLength()

var text = try String.init(contentsOfFile: parentRouterFile.path!, encoding: .utf8)
let argumentInsertIndex = text.utf8.index(text.startIndex, offsetBy: initArgumentEndPosition)
Expand Down
4 changes: 2 additions & 2 deletions Sources/RIBsCodeGen/Commands/HelpCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ struct HelpCommand: Command {

- unlink RIB
ribscodegen unlink [target RIB name] --parent [parent RIB name]

- remove RIB
ribscodegen remove [target RIB name]

cf. More details in https://github.com/imairi/RIBsCodeGen/

""".lightBlue
Expand Down
Loading