From 7bd9cc928a0646fd817259ebb7992e5b3c580f17 Mon Sep 17 00:00:00 2001 From: Ian Leitch Date: Wed, 18 Dec 2024 20:29:06 +0000 Subject: [PATCH] Add Bazel support to guided setup --- Sources/BUILD.bazel | 1 + Sources/Frontend/BazelProjectSetupGuide.swift | 32 +++++++++++++++++++ Sources/Frontend/GuidedSetup.swift | 13 ++++++-- Sources/Logger/Logger.swift | 2 +- 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 Sources/Frontend/BazelProjectSetupGuide.swift diff --git a/Sources/BUILD.bazel b/Sources/BUILD.bazel index 5cc503a1c..1edbc2559 100644 --- a/Sources/BUILD.bazel +++ b/Sources/BUILD.bazel @@ -206,6 +206,7 @@ swift_library( swift_binary( name = "Frontend", srcs = [ + "Frontend/BazelProjectSetupGuide.swift", "Frontend/Commands/CheckUpdateCommand.swift", "Frontend/Commands/ClearCacheCommand.swift", "Frontend/Commands/FrontendCommand.swift", diff --git a/Sources/Frontend/BazelProjectSetupGuide.swift b/Sources/Frontend/BazelProjectSetupGuide.swift new file mode 100644 index 000000000..c49ae7284 --- /dev/null +++ b/Sources/Frontend/BazelProjectSetupGuide.swift @@ -0,0 +1,32 @@ +import Foundation +import Logger +import ProjectDrivers +import Shared +import SystemPackage + +final class BazelProjectSetupGuide: SetupGuideHelpers, SetupGuide { + static func detect() -> Self? { + guard BazelProjectDriver.isSupported else { return nil } + return Self() + } + + var projectKindName: String { + "Bazel" + } + + func perform() throws -> ProjectKind { + print(colorize("\nAdd the following snippet to your MODULE.bazel file:", .bold)) + print(colorize(""" + bazel_dep(name = "periphery", version = "\(PeripheryVersion)") + use_repo(use_extension("@periphery//bazel:generated.bzl", "generated"), "periphery_generated") + """, .lightGray)) + print(colorize("\nEnter to continue when ready ", .bold), terminator: "") + _ = readLine() + + return .bazel + } + + var commandLineOptions: [String] { + ["--bazel"] + } +} diff --git a/Sources/Frontend/GuidedSetup.swift b/Sources/Frontend/GuidedSetup.swift index 7a1ead2e1..8d0c9db5c 100644 --- a/Sources/Frontend/GuidedSetup.swift +++ b/Sources/Frontend/GuidedSetup.swift @@ -34,10 +34,14 @@ final class GuidedSetup: SetupGuideHelpers { } #endif + if let guide = BazelProjectSetupGuide.detect() { + projectGuides.append(guide) + } + var projectGuide_: SetupGuide? if projectGuides.count > 1 { - print(colorize("Please select which project to use:", .bold)) + print(colorize("Select which project to use:", .bold)) let kindName = select(single: projectGuides.map(\.projectKindName)) projectGuide_ = projectGuides.first { $0.projectKindName == kindName } print("") @@ -85,6 +89,11 @@ final class GuidedSetup: SetupGuideHelpers { } let parts = [bareCommand] + options - return parts.joined(separator: " \\\n ") + + if options.count > 1 { + return parts.joined(separator: " \\\n ") + } + + return parts.joined(separator: " ") } } diff --git a/Sources/Logger/Logger.swift b/Sources/Logger/Logger.swift index ed664d6fe..0376addd6 100644 --- a/Sources/Logger/Logger.swift +++ b/Sources/Logger/Logger.swift @@ -17,7 +17,7 @@ public enum ANSIColor: String { case magenta = "\u{001B}[0;35m" case boldMagenta = "\u{001B}[0;1;35m" case cyan = "\u{001B}[0;36m" - case white = "\u{001B}[0;37m" + case lightGray = "\u{001B}[0;37m" case gray = "\u{001B}[0;1;30m" }