Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.
DevNewCommand
Kabir Oberai8d17b71b3c0e
diff --git a/Sources/SupersignCLISupport/DevCommand.swift b/Sources/SupersignCLISupport/DevCommand.swiftindex e6a50b1..98d4b9c 100644--- a/Sources/SupersignCLISupport/DevCommand.swift+++ b/Sources/SupersignCLISupport/DevCommand.swift@@ -130,6 +130,7 @@ struct DevCommand: AsyncParsableCommand {abstract: "Develop iOS apps with SwiftPM",subcommands: [DevSetupCommand.self,+ DevNewCommand.self,DevSDKCommand.self,DevBuildCommand.self,DevRunCommand.self,diff --git a/Sources/SupersignCLISupport/DevNewCommand.swift b/Sources/SupersignCLISupport/DevNewCommand.swiftnew file mode 100644index 0000000..e29ab94--- /dev/null+++ b/Sources/SupersignCLISupport/DevNewCommand.swift@@ -0,0 +1,146 @@+import ArgumentParser+import Foundation++struct DevNewCommand: AsyncParsableCommand {+ static let configuration = CommandConfiguration(+ commandName: "new",+ abstract: "Create a new project"+ )++ @Argument var name: String?++ func run() async throws {+ let name = try await Console.promptRequired("Package name: ", existing: self.name)+ let baseURL = URL(fileURLWithPath: name)++ guard !baseURL.exists else {+ throw Console.Error("Cannot create \(name): a file already exists at that path.")+ }++ print("Creating package: \(name)")++ let files: [(String, String)] = [+ (+ "Package.swift",+ """+ // swift-tools-version: 6.0++ import PackageDescription++ let package = Package(+ name: "\(name)",+ platforms: [+ .iOS(.v17),+ .macOS(.v14),+ ],+ products: [+ // A Swiftpack project should contain exactly one library target,+ // representing the main app.+ .library(+ name: "\(name)",+ targets: ["\(name)"]+ ),+ ],+ targets: [+ .target(+ name: "\(name)"+ ),+ ]+ )+ """+ ),++ (+ "swiftpack.yml",+ """+ version: 1+ bundleID: com.example.\(name)+ """+ ),++ (+ ".gitignore",+ """+ .DS_Store+ /.build+ /Packages+ xcuserdata/+ DerivedData/+ .swiftpm/configuration/registries.json+ .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata+ .netrc++ /swiftpack+ /.sourcekit-lsp+ """+ ),++ (+ ".sourcekit-lsp/config.json",+ """+ {+ "swiftPM": {+ "swiftSDK": "arm64-apple-ios"+ }+ }+ """+ ),++ (+ "Sources/\(name)/\(name)App.swift",+ """+ import SwiftUI++ @main+ struct \(name)App: App {+ var body: some Scene {+ WindowGroup {+ ContentView()+ }+ }+ }+ """+ ),++ (+ "Sources/\(name)/ContentView.swift",+ """+ import SwiftUI++ struct ContentView: View {+ var body: some View {+ VStack {+ Image(systemName: "globe")+ .imageScale(.large)+ .foregroundStyle(.tint)+ Text("Hello, world!")+ }+ .padding()+ }+ }+ """+ ),+ ]++ for (path, contents) in files {+ let url = baseURL.appendingPathComponent(path)+ try? FileManager.default.createDirectory(+ at: url.deletingLastPathComponent(),+ withIntermediateDirectories: true+ )+ print("Creating \(path)")+ try "\(contents)\n".write(to: url, atomically: true, encoding: .utf8)+ }++ let gitInit = Process()+ gitInit.executableURL = URL(fileURLWithPath: "/usr/bin/env")+ gitInit.arguments = ["git", "init"]+ gitInit.currentDirectoryURL = baseURL+ try gitInit.run()+ await gitInit.waitForExit()++ print("\nFinished generating project \(name). Next steps:")+ print("- Enter the directory with `cd \(name)`")+ print("- Build and run with `supersign dev`")+ }+}