From 3e11f77707786cbbc9bf36668051a0c9212bc232 Mon Sep 17 00:00:00 2001 From: Tim Condon <0xTim@users.noreply.github.com> Date: Sun, 30 Apr 2023 02:38:38 +0100 Subject: [PATCH] Update Toolbox for new Templates (#410) * Update Swift version * Add deprecation notices to most commands * Crude check for executable name in manifest * Fix warning * File fixes * Update test.yml Swift version * Update CI --- .github/workflows/test.yml | 4 +-- .gitignore | 1 + Package.swift | 4 +-- Sources/VaporToolbox/Build.swift | 2 ++ Sources/VaporToolbox/Clean.swift | 2 ++ Sources/VaporToolbox/Heroku/HerokuInit.swift | 2 ++ Sources/VaporToolbox/Heroku/HerokuPush.swift | 2 ++ Sources/VaporToolbox/Run.swift | 35 +++++++++++++++++-- .../Supervisor/SupervisorInit.swift | 4 ++- .../Supervisor/SupervisorRestart.swift | 2 ++ .../Supervisor/SupervisorUpdate.swift | 2 ++ Sources/VaporToolbox/Xcode/Xcode.swift | 2 ++ 12 files changed, 55 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6012469e..e5f8217b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,7 +18,7 @@ jobs: - --leaf - --no-leaf os: [ubuntu-latest] - image: ["swift:5.6-focal"] + image: ["swift:5.8-focal"] runs-on: ${{ matrix.os }} container: ${{ matrix.image }} steps: @@ -44,7 +44,7 @@ jobs: environments: ${{ steps.output.outputs.environments }} steps: - id: output - run: echo "::set-output name=environments::[{\"os\":\"ubuntu-latest\", \"image\":\"swift:5.4-focal\", \"toolchain\":null},{\"os\":\"ubuntu-latest\", \"image\":\"swift:5.6-focal\", \"toolchain\":null},{\"os\":\"macos-11\", \"image\":null, \"toolchain\":\"latest\"}]" + run: echo "::set-output name=environments::[{\"os\":\"ubuntu-latest\", \"image\":\"swift:5.6-focal\", \"toolchain\":null},{\"os\":\"ubuntu-latest\", \"image\":\"swift:5.8-focal\", \"toolchain\":null},{\"os\":\"macos-13\", \"image\":null, \"toolchain\":\"latest\"}]" test-toolbox: needs: createJSON diff --git a/.gitignore b/.gitignore index 867e9e72..fa2aa73f 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ DerivedData .swiftpm Tests/LinuxMain.swift Package.resolved +.vscode diff --git a/Package.swift b/Package.swift index fceca833..86549313 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.4 +// swift-tools-version:5.6 import PackageDescription let package = Package( @@ -25,7 +25,7 @@ let package = Package( .testTarget(name: "VaporToolboxTests", dependencies: [ .target(name: "VaporToolbox"), ]), - .target(name: "Executable", dependencies: [ + .executableTarget(name: "Executable", dependencies: [ .target(name: "VaporToolbox"), ]), ] diff --git a/Sources/VaporToolbox/Build.swift b/Sources/VaporToolbox/Build.swift index c073b4a6..c3427c2b 100644 --- a/Sources/VaporToolbox/Build.swift +++ b/Sources/VaporToolbox/Build.swift @@ -6,6 +6,8 @@ struct Build: AnyCommand { let help = "Builds an app in the console." func run(using context: inout CommandContext) throws { + context.console.warning("This command is deprecated. Use `swift build` instead.") + context.console.output("Building project...") var flags = [String]() diff --git a/Sources/VaporToolbox/Clean.swift b/Sources/VaporToolbox/Clean.swift index 11ec45c7..a914c2a3 100644 --- a/Sources/VaporToolbox/Clean.swift +++ b/Sources/VaporToolbox/Clean.swift @@ -37,6 +37,8 @@ class Cleaner { } func run() throws { + ctx.console.warning("This command is deprecated. Use `swift package clean` instead.") + var ops: [(String, () throws -> CleanResult)] = [] ops.append((".build", cleanBuildFolder)) ops.append(("Package.resolved", cleanPackageResolved)) diff --git a/Sources/VaporToolbox/Heroku/HerokuInit.swift b/Sources/VaporToolbox/Heroku/HerokuInit.swift index e0cfdf19..252f50f0 100644 --- a/Sources/VaporToolbox/Heroku/HerokuInit.swift +++ b/Sources/VaporToolbox/Heroku/HerokuInit.swift @@ -32,6 +32,8 @@ struct HerokuInit: Command { let help = "Configures app for deployment to Heroku." func run(using ctx: CommandContext, signature: Signature) throws { + ctx.console.warning("This command is deprecated. Use `heroku init` instead.") + // Get Swift package name let name = try Process.swift.package.dump().name ctx.console.list(key: "Package", value: name) diff --git a/Sources/VaporToolbox/Heroku/HerokuPush.swift b/Sources/VaporToolbox/Heroku/HerokuPush.swift index 25b72161..56701d25 100644 --- a/Sources/VaporToolbox/Heroku/HerokuPush.swift +++ b/Sources/VaporToolbox/Heroku/HerokuPush.swift @@ -8,6 +8,8 @@ struct HerokuPush: Command { let help = "Deploys app to Heroku." func run(using context: CommandContext, signature: Signature) throws { + context.console.warning("This command is deprecated. Use `git push heroku ` instead.") + // Get Swift package name let name = try Process.swift.package.dump().name context.console.list(key: "Package", value: name) diff --git a/Sources/VaporToolbox/Run.swift b/Sources/VaporToolbox/Run.swift index 238f4027..ec8308d6 100644 --- a/Sources/VaporToolbox/Run.swift +++ b/Sources/VaporToolbox/Run.swift @@ -3,9 +3,11 @@ import Foundation // Generates an Xcode project struct Run: AnyCommand { - let help = "Runs an app from the console.\nEquivalent to `swift run Run`.\nThe --enable-test-discovery flag is automatically set if needed." + let help = "Runs an app from the console.\nEquivalent to `swift run App`.\nThe --enable-test-discovery flag is automatically set if needed." func run(using context: inout CommandContext) throws { + context.console.warning("This command is deprecated. Use `swift run App` instead.") + var flags = [String]() if isEnableTestDiscoveryFlagNeeded() { flags.append("--enable-test-discovery") @@ -15,7 +17,36 @@ struct Run: AnyCommand { if let confirmOverride = context.console.confirmOverride { extraArguments.append(confirmOverride ? "--yes" : "--no") } - try exec(Process.shell.which("swift"), ["run"] + flags + ["Run"] + context.input.arguments + extraArguments) + + let appName: String + + let filename = "Package.swift" + let urlString = FileManager.default.currentDirectoryPath.trailingSlash.appendingPathComponents(filename) + let manifestContents: String + + guard let url = URL(string: "file://\(urlString)") else { + throw "Invalid URL: \(urlString)" + } + + context.console.info("Reading file at \(urlString)") + + do { + manifestContents = try String(contentsOf: url, encoding: .utf8) + } catch { + context.console.error("Failed to read manifest - are you in the correct directory?") + context.console.error("\(error)") + return + } + + if manifestContents.contains(".executableTarget(name: \"Run\"") { + appName = "Run" + } else { + appName = "App" + } + + context.console.info("Running \(appName)...") + + try exec(Process.shell.which("swift"), ["run"] + flags + [appName] + context.input.arguments + extraArguments) } func outputHelp(using context: inout CommandContext) { diff --git a/Sources/VaporToolbox/Supervisor/SupervisorInit.swift b/Sources/VaporToolbox/Supervisor/SupervisorInit.swift index 962591f0..bd387f5a 100644 --- a/Sources/VaporToolbox/Supervisor/SupervisorInit.swift +++ b/Sources/VaporToolbox/Supervisor/SupervisorInit.swift @@ -11,13 +11,15 @@ struct SupervisorInit: Command { } func run(using context: CommandContext, signature: Signature) throws { + context.console.warning("This command is deprecated. Follow the docs for the latest instructions at https://docs.vapor.codes/deploy/supervisor/") + let package = try Process.swift.package.dump() let cwd = FileManager.default.currentDirectoryPath let user = NSUserName() let config = SupervisorConfiguration( program: package.name, attributes: [ - "command": "\(cwd)/.build/release/Run serve --env production", + "command": "\(cwd)/.build/release/App serve --env production", "directory": cwd, "user": user, "stdout_logfile": "/var/log/supervisor/\(package.name)-stdout.log", diff --git a/Sources/VaporToolbox/Supervisor/SupervisorRestart.swift b/Sources/VaporToolbox/Supervisor/SupervisorRestart.swift index 450b9669..4272c10c 100644 --- a/Sources/VaporToolbox/Supervisor/SupervisorRestart.swift +++ b/Sources/VaporToolbox/Supervisor/SupervisorRestart.swift @@ -10,6 +10,8 @@ struct SupervisorRestart: Command { } func run(using context: CommandContext, signature: Signature) throws { + context.console.warning("This command is deprecated. Use `supervisorctl restart ` instead.") + let package = try Process.swift.package.dump() context.console.print("Restarting \(package.name).") try Process.run(Process.shell.which("supervisorctl"), "restart", package.name) diff --git a/Sources/VaporToolbox/Supervisor/SupervisorUpdate.swift b/Sources/VaporToolbox/Supervisor/SupervisorUpdate.swift index 506cf9e9..c5528749 100644 --- a/Sources/VaporToolbox/Supervisor/SupervisorUpdate.swift +++ b/Sources/VaporToolbox/Supervisor/SupervisorUpdate.swift @@ -10,6 +10,8 @@ struct SupervisorUpdate: Command { } func run(using context: CommandContext, signature: Signature) throws { + context.console.warning("This command is deprecated. Use `supervisorctl update ` instead.") + let package = try Process.swift.package.dump() try Process.run(Process.shell.which("supervisorctl"), "update", package.name) context.console.info("Supervisor entry for \(package.name) updated.") diff --git a/Sources/VaporToolbox/Xcode/Xcode.swift b/Sources/VaporToolbox/Xcode/Xcode.swift index 1dd1da95..ab18ebe8 100644 --- a/Sources/VaporToolbox/Xcode/Xcode.swift +++ b/Sources/VaporToolbox/Xcode/Xcode.swift @@ -12,6 +12,8 @@ struct Xcode: Command { /// See `Command`. func run(using ctx: CommandContext, signature: Signature) throws { + ctx.console.warning("This command is deprecated. Use `open Package.swift` or `code .` instead.") + ctx.console.info("Opening project in Xcode.") do { #if os(macOS)