From ff04349ae4a386f5e9c25f0c21657e9934479f04 Mon Sep 17 00:00:00 2001 From: Netkas Date: Fri, 16 Dec 2022 00:38:04 -0500 Subject: [PATCH] Added method \ncc\Classes\NccExtension > PackageCompiler > tryCompile() --- .../Classes/NccExtension/PackageCompiler.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/ncc/Classes/NccExtension/PackageCompiler.php b/src/ncc/Classes/NccExtension/PackageCompiler.php index fc66a12..f27f2ac 100644 --- a/src/ncc/Classes/NccExtension/PackageCompiler.php +++ b/src/ncc/Classes/NccExtension/PackageCompiler.php @@ -7,6 +7,8 @@ use ncc\Abstracts\ConstantReferences; use ncc\Abstracts\LogLevel; use ncc\Abstracts\Options\BuildConfigurationValues; + use ncc\Abstracts\ProjectType; + use ncc\Classes\ComposerExtension\ComposerSourceBuiltin; use ncc\Classes\PhpExtension\PhpCompiler; use ncc\CLI\Main; use ncc\Exceptions\AccessDeniedException; @@ -18,6 +20,7 @@ use ncc\Exceptions\PackagePreparationFailedException; use ncc\Exceptions\ProjectConfigurationNotFoundException; use ncc\Exceptions\UnsupportedCompilerExtensionException; + use ncc\Exceptions\UnsupportedProjectTypeException; use ncc\Exceptions\UnsupportedRunnerException; use ncc\Interfaces\CompilerInterface; use ncc\Managers\ProjectManager; @@ -84,6 +87,39 @@ ); } + /** + * Attempts to detect the project type and convert it accordingly before compiling + * Returns the compiled package path + * + * @param string $path + * @return string + * @throws BuildException + * @throws UnsupportedProjectTypeException + */ + public static function tryCompile(string $path): string + { + $project_type = Resolver::detectProjectType($path); + + try + { + if($project_type->ProjectType == ProjectType::Composer) + return ComposerSourceBuiltin::fromLocal($project_type->ProjectPath); + + if($project_type->ProjectType == ProjectType::Ncc) + { + $project_manager = new ProjectManager($project_type->ProjectPath); + return $project_manager->build(); + } + } + catch(Exception $e) + { + throw new BuildException('Failed to build project', $e); + } + + + throw new UnsupportedProjectTypeException('The project type \'' . $project_type->ProjectType . '\' is not supported'); + } + /** * Compiles the execution policies of the package *