2024-06-19 21:11:42 -04:00
using CliFx ;
using CliFx.Attributes ;
using CliFx.Infrastructure ;
using ReCodeIt.CrossCompiler ;
2024-06-19 21:34:46 -04:00
using ReCodeIt.Utils ;
2024-06-19 21:11:42 -04:00
using ReCodeItLib.Utils ;
namespace ReCodeIt.Commands ;
[Command("Build", Description = "Build your project and get a dll output for the original assembly. You dont need to provide a path if the last project you built is the one you want to target")]
public class BuildCommand : ICommand
{
private ReCodeItCrossCompiler CrossCompiler { get ; set ; }
[CommandParameter(0, IsRequired = false, Description = "the location of your project file")]
public string ProjectJsonPath { get ; init ; }
public ValueTask ExecuteAsync ( IConsole console )
{
if ( ProjectJsonPath is not null & & ProjectJsonPath ! = string . Empty )
{
CrossCompiler = new ( ) ;
ProjectManager . LoadProject ( ProjectJsonPath ) ;
CrossCompiler . StartCrossCompile ( ) ;
return default ;
}
console . Output . WriteLine ( RegistryHelper . GetRegistryValue < string > ( "LastLoadedProject" ) ) ;
if ( RegistryHelper . GetRegistryValue < string > ( "LastLoadedProject" ) ! = null )
{
CrossCompiler = new ( ) ;
2024-06-19 21:34:46 -04:00
DataProvider . LoadAppSettings ( ) ;
2024-06-19 21:11:42 -04:00
ProjectManager . LoadProject ( RegistryHelper . GetRegistryValue < string > ( "LastLoadedProject" ) , true ) ;
2024-06-19 22:33:08 -04:00
if ( ! Validate ( console ) ) { return default ; }
2024-06-19 21:11:42 -04:00
CrossCompiler . StartCrossCompile ( ) ;
2024-06-19 21:34:46 -04:00
DataProvider . SaveAppSettings ( ) ;
2024-06-19 21:11:42 -04:00
return default ;
}
return default ;
}
2024-06-19 22:33:08 -04:00
private bool Validate ( IConsole console )
{
if ( ProjectManager . ActiveProject = = null )
{
console . Output . WriteLine ( "No project loaded, go create or load a project in the gui first" ) ;
return false ;
}
if ( ProjectManager . ActiveProject . RemapModels . Count = = 0 )
{
console . Output . WriteLine ( "No Remaps present, go to the gui and create some first" ) ;
return false ;
}
if ( ProjectManager . ActiveProject . ChangedTypes . Count = = 0 )
{
console . Output . WriteLine ( "There are no changed types, have you created and used a remapped reference? \nRun the command `buildRef` to generate a project reference" ) ;
return false ;
}
return true ;
}
2024-06-19 21:11:42 -04:00
}