Skip to content

Commit

Permalink
ask user for executable name and use it everywhere (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
EstevanBR authored Aug 9, 2024
1 parent 19689a7 commit 1e13426
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
8 changes: 5 additions & 3 deletions Sources/CreateProject/CreateProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ private struct CreateProject {
exit(1)
}

let executableName: String = try UserChoice.get(message: "Please enter the name of the executable: ")

guard try UserChoice.getBool(message: "Project will be created at: \(fileManager.currentDirectoryPath + "/Package.swift, would you like to proceed?")") else {
do {
print("Removing \(fileManager.currentDirectoryPath)")
Expand All @@ -46,13 +48,13 @@ private struct CreateProject {
default: try UserChoice.get(message: Color.yellow + "GODOT not set\n" + "Please enter the full path to the Godot 4.2 executable: ")
}

print(color: .green, "Created \(try FileFactory.createPackageFile(projectName: projectName))")
print(color: .green, "Created \(try FileFactory.createPackageFile(projectName: projectName, executableName: executableName))")
print(color: .green, "Created \(try FileFactory.copyReadmeFile())")
print(color: .green, "Created \(try FileFactory.copyGitIgnoreFile())")
print(color: .green, "Created \(try FileFactory.createEnvFile(projectName: projectName, godotPath: godotPath))")
print(color: .green, "Created \(try FileFactory.createEnvFile(projectName: projectName, executableName: executableName, godotPath: godotPath))")
print(color: .green, "Created \(try FileFactory.createSourcesDirectory())")
print(color: .green, "Created \(try FileFactory.createLibraryTarget(projectName: projectName))")
print(color: .green, "Created \(try FileFactory.createExecutableTarget(projectName: projectName))")
print(color: .green, "Created \(try FileFactory.createExecutableTarget(projectName: projectName, executableName: executableName))")
print(color: .green, "Created \(try FileFactory.copyGDDFile())")
print(color: .green, "Created \(try FileFactory.copyGodotDirectory())")
print(color: .green, "Created \(try FileFactory.createGodotProjectFile(projectName: projectName))")
Expand Down
14 changes: 7 additions & 7 deletions Sources/CreateProject/DataFactory.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

enum DataFactory {
static func makeEnvFileData(projectName: String, godotPath: String) throws -> Data {
static func makeEnvFileData(projectName: String, executableName: String, godotPath: String) throws -> Data {
let directory = FileManager().currentDirectoryPath
let godotProjectDirectory = directory + "/godot"
return try
Expand All @@ -13,13 +13,13 @@ enum DataFactory {
export GODOT_BIN_PATH=$(GODOT_PROJECT_DIRECTORY)/bin
export BUILD_PATH=./.build
export LIBRARY_NAME=$(PROJECT_NAME)
export EXECUTABLE_NAME=$(PROJECT_NAME)Game
export EXECUTABLE_NAME=\(executableName)
"""
.utf8Data
}

static func makePackageFileData(projectName: String) throws -> Data {
static func makePackageFileData(projectName: String, executableName: String) throws -> Data {
try
"""
// swift-tools-version: 5.9
Expand All @@ -31,8 +31,8 @@ enum DataFactory {
platforms: [.macOS(.v13)],
products: [
.executable(
name: "\(projectName)Game",
targets: ["\(projectName)Game"]),
name: "\(executableName)",
targets: ["\(executableName)"]),
.library(
name: "\(projectName)",
type: .dynamic,
Expand All @@ -44,7 +44,7 @@ enum DataFactory {
],
targets: [
.executableTarget(
name: "\(projectName)Game",
name: "\(executableName)",
dependencies: [
"\(projectName)",
.product(name: "SwiftGodotKit", package: "SwiftGodotKit")
Expand Down Expand Up @@ -275,7 +275,7 @@ enum DataFactory {
@echo "Going to open Godot to ensure all resources are imported."
-$(GODOT) $(GODOT_PROJECT_FILE_PATH) --headless --quit
@echo "Exporting the .pck file"
$(GODOT) --headless --path $(GODOT_PROJECT_DIRECTORY) --export-pack Packer ../Sources/$(LIBRARY_NAME)Game/Resources/$(LIBRARY_NAME).pck
$(GODOT) --headless --path $(GODOT_PROJECT_DIRECTORY) --export-pack Packer ../Sources/$(EXECUTABLE_NAME)/Resources/$(LIBRARY_NAME).pck
"""
.utf8Data
Expand Down
11 changes: 5 additions & 6 deletions Sources/CreateProject/FileFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ enum FileFactory {

}

static func createEnvFile(projectName: String, godotPath: String) throws -> String {
static func createEnvFile(projectName: String, executableName: String, godotPath: String) throws -> String {
let directory = fileManager.currentDirectoryPath
let data = try DataFactory.makeEnvFileData(projectName: projectName, godotPath: godotPath)
let data = try DataFactory.makeEnvFileData(projectName: projectName, executableName: executableName, godotPath: godotPath)
let path = directory + "/.env"
fileManager.createFile(atPath: path, contents: data)
return path
Expand All @@ -48,8 +48,7 @@ enum FileFactory {
return librarySourceFile
}

static func createExecutableTarget(projectName: String) throws -> String {
let executableName = projectName + "Game"
static func createExecutableTarget(projectName: String, executableName: String) throws -> String {
let directory = fileManager.currentDirectoryPath
let executableTargetDirectory = directory + "/Sources/\(executableName)"

Expand All @@ -64,10 +63,10 @@ enum FileFactory {
return mainPath
}

static func createPackageFile(projectName: String) throws -> String {
static func createPackageFile(projectName: String, executableName: String) throws -> String {
let directory = fileManager.currentDirectoryPath
let path = directory + "/Package.swift"
let data = try DataFactory.makePackageFileData(projectName: projectName)
let data = try DataFactory.makePackageFileData(projectName: projectName, executableName: executableName)
guard fileManager.createFile(atPath: path, contents: data) else {
throw Error.couldNotCreateFile(path: path)
}
Expand Down

0 comments on commit 1e13426

Please sign in to comment.