From e42645fbb9a073c1d680a4e992d548812664534e Mon Sep 17 00:00:00 2001 From: Oh Sangho <dhtkdgh429@gmail.com> Date: Mon, 11 Mar 2024 18:51:04 +0900 Subject: [PATCH 1/3] =?UTF-8?q?update:=20=EB=AA=A8=EB=93=88=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=B8=20=EC=A7=84?= =?UTF-8?q?=ED=96=89=20=EC=A4=91,=20=EC=B7=A8=EC=86=8C=EA=B0=80=20?= =?UTF-8?q?=EA=B0=80=EB=8A=A5=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Scripts/GenerateModule.swift | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Scripts/GenerateModule.swift b/Scripts/GenerateModule.swift index 201abc2..7d4b902 100644 --- a/Scripts/GenerateModule.swift +++ b/Scripts/GenerateModule.swift @@ -175,6 +175,14 @@ func updateFileContent( try? writeHandle.close() } +func checkInputOrTerminate(_ input: String?) -> String { + guard let input, !input.isEmpty else { + print("Input is empty or null.") + exit(1) + } + return input +} + // MARK: - Starting point print("Enter layer name\n(Feature | Domain | Core | Shared | UserInterface)", terminator: " : ") @@ -200,19 +208,24 @@ 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" +let interfaceInput = checkInputOrTerminate(readLine()) +let hasInterface = interfaceInput.lowercased() == "y" print("This module has a 'Testing' Target? (y\\n, default = n)", terminator: " : ") -let hasTesting = readLine()?.lowercased() == "y" +let testingInput = checkInputOrTerminate(readLine()) +let hasTesting = testingInput.lowercased() == "y" print("This module has a 'UnitTests' Target? (y\\n, default = n)", terminator: " : ") -let hasUnitTests = readLine()?.lowercased() == "y" +let unitTestsInput = checkInputOrTerminate(readLine()) +let hasUnitTests = unitTestsInput.lowercased() == "y" print("This module has a 'UITests' Target? (y\\n, default = n)", terminator: " : ") -let hasUITests = readLine()?.lowercased() == "y" +let uiTestsInput = checkInputOrTerminate(readLine()) +let hasUITests = uiTestsInput.lowercased() == "y" print("This module has a 'Demo' Target? (y\\n, default = n)", terminator: " : ") -let hasDemo = readLine()?.lowercased() == "y" +let demoInput = checkInputOrTerminate(readLine()) +let hasDemo = demoInput.lowercased() == "y" print("") From 1a1cae0e1d4422d184e8d17705aa134b670a6300 Mon Sep 17 00:00:00 2001 From: Oh Sangho <dhtkdgh429@gmail.com> Date: Tue, 12 Mar 2024 20:20:05 +0900 Subject: [PATCH 2/3] fix: validation of module info during script process --- Scripts/GenerateModule.swift | 118 +++++++++++++++++++++++------------ 1 file changed, 78 insertions(+), 40 deletions(-) diff --git a/Scripts/GenerateModule.swift b/Scripts/GenerateModule.swift index 7d4b902..3e7fb67 100644 --- a/Scripts/GenerateModule.swift +++ b/Scripts/GenerateModule.swift @@ -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() @@ -175,12 +184,60 @@ func updateFileContent( try? writeHandle.close() } -func checkInputOrTerminate(_ input: String?) -> String { - guard let input, !input.isEmpty else { - print("Input is empty or null.") +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" + + 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("------------------------------------------------------------------------------------------------------------------------") + + return ModuleInfo( + moduleName: moduleName, + hasInterface: hasInterface, + hasTesting: hasTesting, + hasUnitTests: hasUnitTests, + hasUITests: hasUITests, + hasDemo: hasDemo + ) +} + +func checkModuleInfo() -> Bool { + guard var checkInput = readLine() else { exit(1) } - return input + + if checkInput.isEmpty { + checkInput = "y" + } + + let isCorrect = checkInput.lowercased() == "y" + return !isCorrect } // MARK: - Starting point @@ -198,45 +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 interfaceInput = checkInputOrTerminate(readLine()) -let hasInterface = interfaceInput.lowercased() == "y" - -print("This module has a 'Testing' Target? (y\\n, default = n)", terminator: " : ") -let testingInput = checkInputOrTerminate(readLine()) -let hasTesting = testingInput.lowercased() == "y" - -print("This module has a 'UnitTests' Target? (y\\n, default = n)", terminator: " : ") -let unitTestsInput = checkInputOrTerminate(readLine()) -let hasUnitTests = unitTestsInput.lowercased() == "y" - -print("This module has a 'UITests' Target? (y\\n, default = n)", terminator: " : ") -let uiTestsInput = checkInputOrTerminate(readLine()) -let hasUITests = uiTestsInput.lowercased() == "y" - -print("This module has a 'Demo' Target? (y\\n, default = n)", terminator: " : ") -let demoInput = checkInputOrTerminate(readLine()) -let hasDemo = demoInput.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 From 9f35b5fbf3a893e90af3bbbd9ec0ebb2fbb3d463 Mon Sep 17 00:00:00 2001 From: Oh Sangho <dhtkdgh429@gmail.com> Date: Tue, 12 Mar 2024 21:03:41 +0900 Subject: [PATCH 3/3] fix: move module info print --- Scripts/GenerateModule.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Scripts/GenerateModule.swift b/Scripts/GenerateModule.swift index 3e7fb67..e5b836c 100644 --- a/Scripts/GenerateModule.swift +++ b/Scripts/GenerateModule.swift @@ -209,14 +209,6 @@ func makeModuleInfo() -> ModuleInfo { print("This module has a 'Demo' Target? (y\\n, default = n)", terminator: " : ") let hasDemo = readLine()?.lowercased() == "y" - 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("------------------------------------------------------------------------------------------------------------------------") - return ModuleInfo( moduleName: moduleName, hasInterface: hasInterface, @@ -228,6 +220,14 @@ func makeModuleInfo() -> ModuleInfo { } 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) }