diff --git a/src/ncc/Abstracts/Versions.php b/src/ncc/Abstracts/Versions.php index eada0c3..98825ac 100644 --- a/src/ncc/Abstracts/Versions.php +++ b/src/ncc/Abstracts/Versions.php @@ -12,5 +12,5 @@ /** * The current version of the package structure file format */ - const PackageStructureVersion = '1.0.0'; + const PackageStructureVersion = '1.0'; } \ No newline at end of file diff --git a/src/ncc/CLI/BuildMenu.php b/src/ncc/CLI/BuildMenu.php new file mode 100644 index 0000000..389237d --- /dev/null +++ b/src/ncc/CLI/BuildMenu.php @@ -0,0 +1,139 @@ +Project->Compiler->Extension)) + { + case CompilerExtensions::PHP: + /** @var CompilerInterface $Compiler */ + $Compiler = new Compiler($ProjectConfiguration); + break; + + default: + Console::outError('The extension '. $ProjectConfiguration->Project->Compiler->Extension . ' is not supported', true, 1); + return; + } + + $build_configuration = BuildConfigurationValues::DefaultConfiguration; + + if(isset($args['config'])) + { + $build_configuration = $args['config']; + } + + try + { + $ProjectConfiguration->Build->getBuildConfiguration($build_configuration); + } + catch (BuildConfigurationNotFoundException $e) + { + Console::outException('The build configuration \'' . $build_configuration . '\' does not exist in the project configuration', $e, 1); + return; + } + + Console::out( + ' ===== BUILD INFO ===== ' . PHP_EOL . + ' Package Name: ' . $ProjectConfiguration->Assembly->Package . PHP_EOL . + ' Version: ' . $ProjectConfiguration->Assembly->Version . PHP_EOL . + ' Compiler Extension: ' . $ProjectConfiguration->Project->Compiler->Extension . PHP_EOL . + ' Compiler Version: ' . $ProjectConfiguration->Project->Compiler->MaximumVersion . ' - ' . $ProjectConfiguration->Project->Compiler->MinimumVersion . PHP_EOL . + ' Build Configuration: ' . $build_configuration . PHP_EOL + ); + + Console::out('Preparing package'); + + try + { + $Compiler->prepare([], getcwd(), $build_configuration); + } + catch (PackagePreparationFailedException $e) + { + Console::outException('The package preparation process failed', $e, 1); + return; + } + + exit(0); + } + + /** + * Displays the main options section + * + * @return void + */ + private static function displayOptions(): void + { + $options = [ + new CliHelpSection(['help'], 'Displays this help menu about the value command'), + new CliHelpSection(['build'], 'Builds the current project using the default build configuration'), + new CliHelpSection(['build', '--config'], 'Builds the current project with a specified build configuration') + ]; + + $options_padding = \ncc\Utilities\Functions::detectParametersPadding($options) + 4; + + Console::out('Usage: ncc build [options]'); + Console::out('Options:' . PHP_EOL); + foreach($options as $option) + { + Console::out(' ' . $option->toString($options_padding)); + } + } + } \ No newline at end of file diff --git a/src/ncc/CLI/Main.php b/src/ncc/CLI/Main.php index ce9c2d1..c8fe242 100644 --- a/src/ncc/CLI/Main.php +++ b/src/ncc/CLI/Main.php @@ -74,7 +74,7 @@ } catch(Exception $e) { - Console::out('Error: ' . $e->getMessage() . ' (Code: ' . $e->getCode() . ')'); + Console::outException('Error: ' . $e->getMessage() . ' (Code: ' . $e->getCode() . ')', $e, 1); exit(1); } diff --git a/src/ncc/Classes/PhpExtension/Compiler.php b/src/ncc/Classes/PhpExtension/Compiler.php index 754b4d9..996c536 100644 --- a/src/ncc/Classes/PhpExtension/Compiler.php +++ b/src/ncc/Classes/PhpExtension/Compiler.php @@ -5,11 +5,10 @@ namespace ncc\Classes\PhpExtension; use FilesystemIterator; - use ncc\Abstracts\CompilerOptions; use ncc\Abstracts\ComponentFileExtensions; use ncc\Abstracts\Options\BuildConfigurationValues; - use ncc\Abstracts\Versions; use ncc\Exceptions\BuildConfigurationNotFoundException; + use ncc\Exceptions\BuildException; use ncc\Exceptions\PackagePreparationFailedException; use ncc\Interfaces\CompilerInterface; use ncc\ncc; @@ -18,6 +17,7 @@ use ncc\ThirdParty\theseer\DirectoryScanner\DirectoryScanner; use ncc\ThirdParty\theseer\DirectoryScanner\Exception; use ncc\Utilities\Console; + use ncc\Utilities\Functions; use SplFileInfo; class Compiler implements CompilerInterface @@ -45,12 +45,12 @@ * This function must be called before calling the build function, otherwise the operation will fail * * @param array $options - * @param string $src + * @param string $path * @param string $build_configuration * @return void * @throws PackagePreparationFailedException */ - public function prepare(array $options, string $src, string $build_configuration=BuildConfigurationValues::DefaultConfiguration) + public function prepare(array $options, string $path, string $build_configuration=BuildConfigurationValues::DefaultConfiguration): void { // Auto-select the default build configuration if($build_configuration == BuildConfigurationValues::DefaultConfiguration) @@ -79,9 +79,8 @@ if(ncc::cliMode()) { - Console::out('Building autoloader'); + Console::out('Scanning project files'); Console::out('theseer\DirectoryScanner - Copyright (c) 2009-2014 Arne Blankerts All rights reserved.'); - Console::out('theseer\Autoload - Copyright (c) 2010-2016 Arne Blankerts and Contributors All rights reserved.'); } // First scan the project files and create a file struct. @@ -89,8 +88,7 @@ try { - $DirectoryScanner->unsetFlag(FilesystemIterator:: - FOLLOW_SYMLINKS); + $DirectoryScanner->unsetFlag(FilesystemIterator::FOLLOW_SYMLINKS); } catch (Exception $e) { @@ -101,61 +99,84 @@ $DirectoryScanner->setIncludes(ComponentFileExtensions::Php); $DirectoryScanner->setExcludes($selected_build_configuration->ExcludeFiles); + // Append trailing slash to the end of the path if it's not already there + if(substr($path, -1) !== DIRECTORY_SEPARATOR) + { + $path .= DIRECTORY_SEPARATOR; + } + + $source_path = $path . $this->project->Build->SourcePath; + // Scan for components first. - Console::out('Scanning for components...', false); + Console::out('Scanning for components... ', false); /** @var SplFileInfo $item */ - foreach($DirectoryScanner($src, true) as $item) + foreach($DirectoryScanner($source_path, true) as $item) { // Ignore directories, they're not important. :-) - if(is_dir($item->getPath())) + if(is_dir($item->getPathName())) continue; $Component = new Package\Component(); - $Component->Name = $item->getPath(); + $Component->Name = Functions::removeBasename($item->getPathname(), $path); $this->package->Components[] = $Component; } - if(count($this->package->Components) > 0) + if(ncc::cliMode()) { - Console::out(count($this->package->Components) . ' component(s) found'); - } - else - { - Console::out('No components found'); + if(count($this->package->Components) > 0) + { + Console::out(count($this->package->Components) . ' component(s) found'); + } + else + { + Console::out('No components found'); + } } - // Now scan for resources - Console::out('Scanning for resources...', false); + + // Clear previous excludes and includes + $DirectoryScanner->setExcludes([]); + $DirectoryScanner->setIncludes([]); + + // Ignore component files $DirectoryScanner->setExcludes(array_merge( $selected_build_configuration->ExcludeFiles, ComponentFileExtensions::Php )); - // Scan for components first. + Console::out('Scanning for resources... ', false); /** @var SplFileInfo $item */ - foreach($DirectoryScanner($src, true) as $item) + foreach($DirectoryScanner($source_path, true) as $item) { // Ignore directories, they're not important. :-) - if(is_dir($item->getPath())) + if(is_dir($item->getPathName())) continue; $Resource = new Package\Resource(); - $Resource->Name = $item->getPath(); + $Resource->Name = Functions::removeBasename($item->getPathname(), $path); $this->package->Resources[] = $Resource; } - if(count($this->package->Resources) > 0) + if(ncc::cliMode()) { - Console::out(count($this->package->Resources) . ' resources(s) found'); - } - else - { - Console::out('No resources found'); + if(count($this->package->Resources) > 0) + { + Console::out(count($this->package->Resources) . ' resources(s) found'); + } + else + { + Console::out('No resources found'); + } } } - public function build(array $options, string $src) + public function build(array $options, string $path): string { - // TODO: Implement build() method. + if($this->package == null) + { + throw new BuildException('The prepare() method must be called before building the package'); + } + + // TODO: Implement build() method } } \ No newline at end of file diff --git a/src/ncc/Objects/Package.php b/src/ncc/Objects/Package.php index d0b64db..bb73978 100644 --- a/src/ncc/Objects/Package.php +++ b/src/ncc/Objects/Package.php @@ -80,6 +80,8 @@ public function __construct() { $this->MagicBytes = new MagicBytes(); + $this->Header = new Header(); + $this->Assembly = new Assembly(); $this->Components = []; $this->Dependencies = []; $this->Resources = []; diff --git a/src/ncc/Objects/ProjectConfiguration.php b/src/ncc/Objects/ProjectConfiguration.php index ba3126e..0d68738 100644 --- a/src/ncc/Objects/ProjectConfiguration.php +++ b/src/ncc/Objects/ProjectConfiguration.php @@ -108,9 +108,9 @@ { $ProjectConfigurationObject = new ProjectConfiguration(); - $ProjectConfigurationObject->Project = Functions::array_bc($data, 'project'); - $ProjectConfigurationObject->Assembly = Functions::array_bc($data, 'assembly'); - $ProjectConfigurationObject->Build = Functions::array_bc($data, 'build'); + $ProjectConfigurationObject->Project = Project::fromArray(Functions::array_bc($data, 'project')); + $ProjectConfigurationObject->Assembly = Assembly::fromArray(Functions::array_bc($data, 'assembly')); + $ProjectConfigurationObject->Build = Build::fromArray(Functions::array_bc($data, 'build')); return $ProjectConfigurationObject; }