Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: CLI build command (WIP) #175

Draft
wants to merge 9 commits into
base: development
Choose a base branch
from
Draft
Prev Previous commit
Next Next commit
refactor: reimplementing stuff after the rebase from dev
  • Loading branch information
brmassa committed Sep 17, 2024
commit bd5b640af6c305c489099bee5ae0f89835941594
2 changes: 2 additions & 0 deletions Prowl.Editor/Build/ProjectBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Reflection;

using Prowl.Editor.Assets;
using Prowl.Editor.Utilities;
using Prowl.Runtime;

Expand All @@ -18,6 +19,7 @@ public void StartBuild(AssetRef<Scene>[] scenes, DirectoryInfo output)
return;
}

AssetDatabase.Update();
if (!AreScenesValid(scenes))
return;

Expand Down
24 changes: 19 additions & 5 deletions Prowl.Editor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,32 +163,46 @@ private static int Run(CliOpenOptions options)
return 0;
}

/// <summary>
/// Build the final version of the game via command line `prowl build --project PATH`
/// </summary>
/// <param name="options">Command Line options for build command</param>
/// <returns></returns>
private static int BuildCommand(CliBuildOptions options)
{
Console.WriteLine($"Building project from\t'{options.ProjectPath}'");
Debug.Log($"Building project from\t'{options.ProjectPath}'");
if (options.ProjectPath is null || !options.ProjectPath.Exists)
{
Console.WriteLine("Path is not valid or already exists");
Debug.LogError("Path is not valid or already exists");
return 1;
}

var pathBuild = new DirectoryInfo(Path.Combine(options.ProjectPath.ToString(), "Builds",
DateTime.UtcNow.ToString("yyyyMMddHHmmss")));

Console.WriteLine($"Building path\t\t'{pathBuild}'");
Debug.Log($"Building output path\t'{pathBuild}'");
if (pathBuild.Exists)
{
Console.WriteLine("Build path is not valid or already exists");
Debug.LogError("Build path is not valid or already exists");
return 1;
}

// Open the project, and if it's ok, load it
var project = new Project(options.ProjectPath);
Project.Open(project);

// Set up the app
Application.DataPath = options.ProjectPath.ToString();
Application.AssetProvider = new EditorAssetProvider();

AssetDatabase.Update();

// TODO: instead calling the builders[0], use a command line argument
pathBuild.Create();
var builders = ProjectBuilder.GetAll().ToList();
Application.AssetProvider = new EditorAssetProvider();
builders[0].StartBuild(BuildProjectSetting.Instance.Scenes, pathBuild);

// TODO: since StartBuild return void, we cannot say if the code executed fine
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion Prowl.Runtime/Utils/ScriptableSingleton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected string GetFilePath(string? dataPath)
ArgumentNullException.ThrowIfNull(dataPath);

// Persistent across sessions for a single project
if (Application.IsEditor == false)
if (Application.IsRunning && Application.IsEditor == false)
throw new InvalidOperationException("Editor Settings are only available in the editor");
directory = Path.Combine(dataPath, "ProjectSettings", "Editor");
break;
Expand Down