Skip to content

Commit c63f3b9

Browse files
committed
[#577] Create workspace file not for SPM and clean up workspace
1 parent 8e10138 commit c63f3b9

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpiOSProject.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,15 @@ class SetUpIOSProject {
338338
if fileManager.fileExists(atPath: "\(currentDirectory)/Project.swift.cocoapods") {
339339
try fileManager.removeItem(atPath: "\(currentDirectory)/Project.swift.cocoapods")
340340
}
341-
// Remove Workspace.swift for SPM
341+
// Remove Workspace.swift and any existing workspace files for SPM
342342
if fileManager.fileExists(atPath: "\(currentDirectory)/Workspace.swift") {
343343
try fileManager.removeItem(atPath: "\(currentDirectory)/Workspace.swift")
344344
}
345+
// Remove any existing workspace files
346+
let workspaceFiles = try fileManager.contentsOfDirectory(atPath: currentDirectory).filter { $0.hasSuffix(".xcworkspace") }
347+
for workspaceFile in workspaceFiles {
348+
try fileManager.removeItem(atPath: "\(currentDirectory)/\(workspaceFile)")
349+
}
345350
} else {
346351
print("❌ Error: Project.swift.spm not found")
347352
throw NSError(domain: "iOSTemplateMaker", code: 1, userInfo: [NSLocalizedDescriptionKey: "Project.swift.spm not found"])
@@ -353,6 +358,12 @@ class SetUpIOSProject {
353358
if fileManager.fileExists(atPath: "\(currentDirectory)/Project.swift.spm") {
354359
try fileManager.removeItem(atPath: "\(currentDirectory)/Project.swift.spm")
355360
}
361+
// Ensure Workspace.swift exists and has correct project name
362+
if fileManager.fileExists(atPath: "\(currentDirectory)/Workspace.swift") {
363+
var workspaceContent = try String(contentsOfFile: "\(currentDirectory)/Workspace.swift", encoding: .utf8)
364+
workspaceContent = workspaceContent.replacingOccurrences(of: "{PROJECT_NAME}", with: projectNameNoSpace)
365+
try workspaceContent.write(toFile: "\(currentDirectory)/Workspace.swift", atomically: true, encoding: .utf8)
366+
}
356367
} else {
357368
print("❌ Error: Project.swift.cocoapods not found")
358369
throw NSError(domain: "iOSTemplateMaker", code: 1, userInfo: [NSLocalizedDescriptionKey: "Project.swift.cocoapods not found"])
@@ -374,7 +385,20 @@ class SetUpIOSProject {
374385
// Run Tuist generate
375386
print("🚀 Running Tuist generate...")
376387
do {
377-
let output = try safeShell("tuist generate")
388+
let tuistCommand: String
389+
switch dependencyManager {
390+
case .spm:
391+
tuistCommand = "tuist generate --no-open"
392+
case .cocoapods:
393+
tuistCommand = "tuist generate"
394+
case .none:
395+
throw NSError(
396+
domain: "iOSTemplateMaker",
397+
code: 1,
398+
userInfo: [NSLocalizedDescriptionKey: "Dependency manager not selected"]
399+
)
400+
}
401+
let output = try safeShell(tuistCommand)
378402
print("📝 Tuist output: \(output ?? "No output")")
379403
} catch {
380404
print("❌ Error running Tuist: \(error.localizedDescription)")

0 commit comments

Comments
 (0)