Skip to content

Commit

Permalink
Merge pull request #12 from SH-OH/fix-generatescript
Browse files Browse the repository at this point in the history
update: 모듈 생성 스크립트 진행 중, 취소가 가능하도록 수정.
  • Loading branch information
baekteun committed Mar 12, 2024
2 parents ba1b466 + 9f35b5f commit ce2b111
Showing 1 changed file with 82 additions and 31 deletions.
113 changes: 82 additions & 31 deletions Scripts/GenerateModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ enum MicroTargetType: String {
case demo = "Demo"
}

struct ModuleInfo {
let moduleName: String
let hasInterface: Bool
let hasTesting: Bool
let hasUnitTests: Bool
let hasUITests: Bool
let hasDemo: Bool
}

let fileManager = FileManager.default
let currentPath = "./"
let bash = Bash()
Expand Down Expand Up @@ -175,6 +184,62 @@ func updateFileContent(
try? writeHandle.close()
}

func makeModuleInfo() -> ModuleInfo {
print("Enter module name", terminator: " : ")
let moduleInput = readLine()
guard let moduleNameUnwrapping = moduleInput, !moduleNameUnwrapping.isEmpty else {
print("Module name is empty")
exit(1)
}
let moduleName = moduleNameUnwrapping
print("Module name: \(moduleName)\n")

print("This module has a 'Interface' Target? (y\\n, default = n)", terminator: " : ")
let hasInterface = readLine()?.lowercased() == "y"

print("This module has a 'Testing' Target? (y\\n, default = n)", terminator: " : ")
let hasTesting = readLine()?.lowercased() == "y"

print("This module has a 'UnitTests' Target? (y\\n, default = n)", terminator: " : ")
let hasUnitTests = readLine()?.lowercased() == "y"

print("This module has a 'UITests' Target? (y\\n, default = n)", terminator: " : ")
let hasUITests = readLine()?.lowercased() == "y"

print("This module has a 'Demo' Target? (y\\n, default = n)", terminator: " : ")
let hasDemo = readLine()?.lowercased() == "y"

return ModuleInfo(
moduleName: moduleName,
hasInterface: hasInterface,
hasTesting: hasTesting,
hasUnitTests: hasUnitTests,
hasUITests: hasUITests,
hasDemo: hasDemo
)
}

func checkModuleInfo() -> Bool {
print("")
print("------------------------------------------------------------------------------------------------------------------------")
print("Is this the correct module information you are generating? (y\\n, default = y)")
print("Layer: \(layer.rawValue)")
print("Module name: \(moduleName)")
print("interface: \(hasInterface), testing: \(hasTesting), unitTests: \(hasUnitTests), uiTests: \(hasUITests), demo: \(hasDemo)")
print("------------------------------------------------------------------------------------------------------------------------")

guard var checkInput = readLine() else {
exit(1)
}

if checkInput.isEmpty {
checkInput = "y"
}

let isCorrect = checkInput.lowercased() == "y"
return !isCorrect
}

// MARK: - Starting point

print("Enter layer name\n(Feature | Domain | Core | Shared | UserInterface)", terminator: " : ")
Expand All @@ -190,40 +255,26 @@ else {
let layer = layerUnwrapping
print("Layer: \(layer.rawValue)\n")

print("Enter module name", terminator: " : ")
let moduleInput = readLine()
guard let moduleNameUnwrapping = moduleInput, !moduleNameUnwrapping.isEmpty else {
print("Module name is empty")
exit(1)
var moduleName: String = ""
var hasInterface: Bool = false
var hasTesting: Bool = false
var hasUnitTests: Bool = false
var hasUITests: Bool = false
var hasDemo: Bool = false

repeat {
let moduleInfo = makeModuleInfo()
moduleName = moduleInfo.moduleName
hasInterface = moduleInfo.hasInterface
hasTesting = moduleInfo.hasTesting
hasUnitTests = moduleInfo.hasUnitTests
hasUITests = moduleInfo.hasUITests
hasDemo = moduleInfo.hasDemo
}
var moduleName = moduleNameUnwrapping
print("Module name: \(moduleName)\n")

print("This module has a 'Interface' Target? (y\\n, default = n)", terminator: " : ")
let hasInterface = readLine()?.lowercased() == "y"

print("This module has a 'Testing' Target? (y\\n, default = n)", terminator: " : ")
let hasTesting = readLine()?.lowercased() == "y"

print("This module has a 'UnitTests' Target? (y\\n, default = n)", terminator: " : ")
let hasUnitTests = readLine()?.lowercased() == "y"

print("This module has a 'UITests' Target? (y\\n, default = n)", terminator: " : ")
let hasUITests = readLine()?.lowercased() == "y"

print("This module has a 'Demo' Target? (y\\n, default = n)", terminator: " : ")
let hasDemo = readLine()?.lowercased() == "y"

print("")

while checkModuleInfo()

registerModuleDependency()

print("")
print("------------------------------------------------------------------------------------------------------------------------")
print("Layer: \(layer.rawValue)")
print("Module name: \(moduleName)")
print("interface: \(hasInterface), testing: \(hasTesting), unitTests: \(hasUnitTests), uiTests: \(hasUITests), demo: \(hasDemo)")
print("------------------------------------------------------------------------------------------------------------------------")
print("✅ Module is created successfully!")

// MARK: - Bash
Expand Down

0 comments on commit ce2b111

Please sign in to comment.