Deleted unused Php.php
Updated SpecialFormat to be more consistent in it's naming Updated BuildMenu.php to take in arguments `path` or `p` for building projects. Added CLI check for Console Out methods Finalized Compiler.php Namespace import cleanup Namespace import cleanup Added Todo comments Added inline operator check Added Abstract Class \ncc\Abstracts > SpecialFormat Added validation for constants Increased Constant character limit to 64 characters Increased Character Limitation for some properties in Assembly.php Updated validate() method in ProjectConfiguration.php Added save() method to \ncc\Objects > Package Minor changes in code structure
This commit is contained in:
parent
3636ac83ec
commit
24fdbd05bf
13 changed files with 246 additions and 116 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace ncc\Abstracts;
|
namespace ncc\Abstracts;
|
||||||
|
|
||||||
abstract class ComponentFlags
|
abstract class ComponentDataType
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Indicates whether the component is represented as an AST representation
|
* Indicates whether the component is represented as an AST representation
|
|
@ -22,5 +22,5 @@
|
||||||
|
|
||||||
const WindowsPath = '/^(([%][^\/:*?<>""|]*[%])|([a-zA-Z][:])|(\\\\))((\\\\{1})|((\\\\{1})[^\\\\]([^\/:*?<>""|]*))+)$/m';
|
const WindowsPath = '/^(([%][^\/:*?<>""|]*[%])|([a-zA-Z][:])|(\\\\))((\\\\{1})|((\\\\{1})[^\\\\]([^\/:*?<>""|]*))+)$/m';
|
||||||
|
|
||||||
const ConstantName = '/^([^\x00-\x7F]|[\w_\ \.\+\-]){2,16}$/';
|
const ConstantName = '/^([^\x00-\x7F]|[\w_\ \.\+\-]){2,64}$/';
|
||||||
}
|
}
|
32
src/ncc/Abstracts/SpecialFormat.php
Normal file
32
src/ncc/Abstracts/SpecialFormat.php
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace ncc\Abstracts;
|
||||||
|
|
||||||
|
abstract class SpecialFormat
|
||||||
|
{
|
||||||
|
const AssemblyName = '%ASSEMBLY.NAME%';
|
||||||
|
|
||||||
|
const AssemblyPackage = '%ASSEMBLY.PACKAGE%';
|
||||||
|
|
||||||
|
const AssemblyDescription = '%ASSEMBLY.DESCRIPTION%';
|
||||||
|
|
||||||
|
const AssemblyCompany = '%ASSEMBLY.COMPANY%';
|
||||||
|
|
||||||
|
const AssemblyProduct = '%ASSEMBLY.PRODUCT%';
|
||||||
|
|
||||||
|
const AssemblyCopyright = '%ASSEMBLY.COPYRIGHT%';
|
||||||
|
|
||||||
|
const AssemblyTrademark = '%ASSEMBLY.TRADEMARK%';
|
||||||
|
|
||||||
|
const AssemblyVersion = '%ASSEMBLY.VERSION%';
|
||||||
|
|
||||||
|
const AssemblyUid = '%ASSEMBLY.UID%';
|
||||||
|
|
||||||
|
const CompileTimestamp = '%COMPILE_TIMESTAMP%';
|
||||||
|
|
||||||
|
const NccBuildVersion = '%NCC_BUILD_VERSION%';
|
||||||
|
|
||||||
|
const NccBuildArgs = '%NCC_BUILD_FLAGS%';
|
||||||
|
|
||||||
|
const NccBuildBranch = '%NCC_BUILD_BRANCH%';
|
||||||
|
}
|
|
@ -3,14 +3,13 @@
|
||||||
namespace ncc\CLI;
|
namespace ncc\CLI;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use JetBrains\PhpStorm\NoReturn;
|
||||||
use ncc\Abstracts\CompilerExtensions;
|
use ncc\Abstracts\CompilerExtensions;
|
||||||
use ncc\Abstracts\Options\BuildConfigurationValues;
|
use ncc\Abstracts\Options\BuildConfigurationValues;
|
||||||
use ncc\Classes\PhpExtension\Compiler;
|
use ncc\Classes\PhpExtension\Compiler;
|
||||||
use ncc\Exceptions\BuildConfigurationNotFoundException;
|
use ncc\Exceptions\BuildConfigurationNotFoundException;
|
||||||
use ncc\Exceptions\BuildException;
|
|
||||||
use ncc\Exceptions\FileNotFoundException;
|
use ncc\Exceptions\FileNotFoundException;
|
||||||
use ncc\Exceptions\MalformedJsonException;
|
use ncc\Exceptions\MalformedJsonException;
|
||||||
use ncc\Exceptions\PackagePreparationFailedException;
|
|
||||||
use ncc\Interfaces\CompilerInterface;
|
use ncc\Interfaces\CompilerInterface;
|
||||||
use ncc\Objects\CliHelpSection;
|
use ncc\Objects\CliHelpSection;
|
||||||
use ncc\Objects\ProjectConfiguration;
|
use ncc\Objects\ProjectConfiguration;
|
||||||
|
@ -24,7 +23,7 @@
|
||||||
* @param $args
|
* @param $args
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function start($args): void
|
#[NoReturn] public static function start($args): void
|
||||||
{
|
{
|
||||||
if(isset($args['help']))
|
if(isset($args['help']))
|
||||||
{
|
{
|
||||||
|
@ -44,11 +43,33 @@
|
||||||
*/
|
*/
|
||||||
private static function build($args): void
|
private static function build($args): void
|
||||||
{
|
{
|
||||||
$project_path = getcwd() . DIRECTORY_SEPARATOR . 'project.json';
|
// Determine the path of the project
|
||||||
|
if(isset($args['path']) || isset($args['p']))
|
||||||
|
{
|
||||||
|
$path_arg = ($args['path'] ?? $args['p']);
|
||||||
|
|
||||||
|
// Append trailing slash
|
||||||
|
if(substr($path_arg, -1) !== DIRECTORY_SEPARATOR)
|
||||||
|
{
|
||||||
|
$path_arg .= DIRECTORY_SEPARATOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the path exists
|
||||||
|
if(!file_exists($path_arg) || !is_dir($path_arg))
|
||||||
|
{
|
||||||
|
Console::outError('The given path \'' . $path_arg . '\' is does not exist or is not a directory', true, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$project_path = $path_arg;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$project_path = getcwd();
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$ProjectConfiguration = ProjectConfiguration::fromFile($project_path);
|
$ProjectConfiguration = ProjectConfiguration::fromFile($project_path . DIRECTORY_SEPARATOR . 'project.json');
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException $e)
|
catch (FileNotFoundException $e)
|
||||||
{
|
{
|
||||||
|
@ -82,6 +103,12 @@
|
||||||
$build_configuration = $args['config'];
|
$build_configuration = $args['config'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Auto-resolve to the default configuration if `default` is used or not specified
|
||||||
|
if($build_configuration == BuildConfigurationValues::DefaultConfiguration)
|
||||||
|
{
|
||||||
|
$build_configuration = $ProjectConfiguration->Build->DefaultConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$ProjectConfiguration->Build->getBuildConfiguration($build_configuration);
|
$ProjectConfiguration->Build->getBuildConfiguration($build_configuration);
|
||||||
|
@ -94,18 +121,18 @@
|
||||||
|
|
||||||
Console::out(
|
Console::out(
|
||||||
' ===== BUILD INFO ===== ' . PHP_EOL .
|
' ===== BUILD INFO ===== ' . PHP_EOL .
|
||||||
' Package Name: ' . $ProjectConfiguration->Assembly->Package . PHP_EOL .
|
' Package Name: ' . $ProjectConfiguration->Assembly->Package . PHP_EOL .
|
||||||
' Version: ' . $ProjectConfiguration->Assembly->Version . PHP_EOL .
|
' Version: ' . $ProjectConfiguration->Assembly->Version . PHP_EOL .
|
||||||
' Compiler Extension: ' . $ProjectConfiguration->Project->Compiler->Extension . PHP_EOL .
|
' Compiler Extension: ' . $ProjectConfiguration->Project->Compiler->Extension . PHP_EOL .
|
||||||
' Compiler Version: ' . $ProjectConfiguration->Project->Compiler->MaximumVersion . ' - ' . $ProjectConfiguration->Project->Compiler->MinimumVersion . PHP_EOL .
|
' Compiler Version: ' . $ProjectConfiguration->Project->Compiler->MaximumVersion . ' - ' . $ProjectConfiguration->Project->Compiler->MinimumVersion . PHP_EOL .
|
||||||
' Build Configuration: ' . $build_configuration . PHP_EOL
|
' Build Configuration: ' . $build_configuration . PHP_EOL
|
||||||
);
|
);
|
||||||
|
|
||||||
Console::out('Preparing package');
|
Console::out('Preparing package');
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$Compiler->prepare([], getcwd(), $build_configuration);
|
$Compiler->prepare($project_path, $build_configuration);
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
catch (Exception $e)
|
||||||
{
|
{
|
||||||
|
@ -113,9 +140,11 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Console::out('Compiling package');
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$Compiler->build([], getcwd());
|
$Compiler->build($project_path);
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
catch (Exception $e)
|
||||||
{
|
{
|
||||||
|
@ -136,6 +165,7 @@
|
||||||
$options = [
|
$options = [
|
||||||
new CliHelpSection(['help'], 'Displays this help menu about the value command'),
|
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'], 'Builds the current project using the default build configuration'),
|
||||||
|
new CliHelpSection(['build', '--path', '-p'], 'Builds the project in the specified path that contains project.json'),
|
||||||
new CliHelpSection(['build', '--config'], 'Builds the current project with a specified build configuration')
|
new CliHelpSection(['build', '--config'], 'Builds the current project with a specified build configuration')
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace ncc\Classes\Compilers;
|
|
||||||
|
|
||||||
use ncc\Classes\PhpExtension\AutoloaderGenerator;
|
|
||||||
use ncc\Interfaces\CompilerInterface;
|
|
||||||
use ncc\Objects\ProjectConfiguration;
|
|
||||||
|
|
||||||
class Php implements CompilerInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var ProjectConfiguration
|
|
||||||
*/
|
|
||||||
private ProjectConfiguration $project;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var AutoloaderGenerator
|
|
||||||
*/
|
|
||||||
private AutoloaderGenerator $autoloader;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param ProjectConfiguration $project
|
|
||||||
*/
|
|
||||||
public function __construct(ProjectConfiguration $project)
|
|
||||||
{
|
|
||||||
$this->project = $project;
|
|
||||||
$this->autoloader = new AutoloaderGenerator($project);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function prepare(array $options)
|
|
||||||
{
|
|
||||||
// TODO: Implement prepare() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
public function build(array $options)
|
|
||||||
{
|
|
||||||
// TODO: Implement build() method.
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,9 +4,10 @@
|
||||||
|
|
||||||
namespace ncc\Classes\PhpExtension;
|
namespace ncc\Classes\PhpExtension;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use FilesystemIterator;
|
use FilesystemIterator;
|
||||||
use ncc\Abstracts\ComponentFileExtensions;
|
use ncc\Abstracts\ComponentFileExtensions;
|
||||||
use ncc\Abstracts\ComponentFlags;
|
use ncc\Abstracts\ComponentDataType;
|
||||||
use ncc\Abstracts\Options\BuildConfigurationValues;
|
use ncc\Abstracts\Options\BuildConfigurationValues;
|
||||||
use ncc\Exceptions\BuildConfigurationNotFoundException;
|
use ncc\Exceptions\BuildConfigurationNotFoundException;
|
||||||
use ncc\Exceptions\BuildException;
|
use ncc\Exceptions\BuildException;
|
||||||
|
@ -17,11 +18,12 @@
|
||||||
use ncc\Objects\ProjectConfiguration;
|
use ncc\Objects\ProjectConfiguration;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Error;
|
use ncc\ThirdParty\nikic\PhpParser\Error;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\ParserFactory;
|
use ncc\ThirdParty\nikic\PhpParser\ParserFactory;
|
||||||
|
use ncc\ThirdParty\Symfony\Filesystem\Exception\IOException;
|
||||||
|
use ncc\ThirdParty\Symfony\Filesystem\Filesystem;
|
||||||
use ncc\ThirdParty\theseer\DirectoryScanner\DirectoryScanner;
|
use ncc\ThirdParty\theseer\DirectoryScanner\DirectoryScanner;
|
||||||
use ncc\ThirdParty\theseer\DirectoryScanner\Exception;
|
use ncc\Utilities\Base64;
|
||||||
use ncc\Utilities\Console;
|
use ncc\Utilities\Console;
|
||||||
use ncc\Utilities\Functions;
|
use ncc\Utilities\Functions;
|
||||||
use ncc\ZiProto\ZiProto;
|
|
||||||
use SplFileInfo;
|
use SplFileInfo;
|
||||||
|
|
||||||
class Compiler implements CompilerInterface
|
class Compiler implements CompilerInterface
|
||||||
|
@ -36,6 +38,11 @@
|
||||||
*/
|
*/
|
||||||
private $package;
|
private $package;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var ProjectConfiguration\BuildConfiguration|null
|
||||||
|
*/
|
||||||
|
private $selected_build_configuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ProjectConfiguration $project
|
* @param ProjectConfiguration $project
|
||||||
*/
|
*/
|
||||||
|
@ -48,14 +55,23 @@
|
||||||
* Prepares the PHP package by generating the Autoloader and detecting all components & resources
|
* Prepares the PHP package by generating the Autoloader and detecting all components & resources
|
||||||
* This function must be called before calling the build function, otherwise the operation will fail
|
* This function must be called before calling the build function, otherwise the operation will fail
|
||||||
*
|
*
|
||||||
* @param array $options
|
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param string $build_configuration
|
* @param string $build_configuration
|
||||||
* @return void
|
* @return void
|
||||||
* @throws PackagePreparationFailedException
|
* @throws PackagePreparationFailedException
|
||||||
*/
|
*/
|
||||||
public function prepare(array $options, string $path, string $build_configuration=BuildConfigurationValues::DefaultConfiguration): void
|
public function prepare(string $path, string $build_configuration=BuildConfigurationValues::DefaultConfiguration): void
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
/** @noinspection PhpRedundantOptionalArgumentInspection */
|
||||||
|
$this->project->validate(True);
|
||||||
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
throw new PackagePreparationFailedException($e->getMessage(), $e);
|
||||||
|
}
|
||||||
|
|
||||||
// Auto-select the default build configuration
|
// Auto-select the default build configuration
|
||||||
if($build_configuration == BuildConfigurationValues::DefaultConfiguration)
|
if($build_configuration == BuildConfigurationValues::DefaultConfiguration)
|
||||||
{
|
{
|
||||||
|
@ -65,7 +81,7 @@
|
||||||
// Select the build configuration
|
// Select the build configuration
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$selected_build_configuration = $this->project->Build->getBuildConfiguration($build_configuration);
|
$this->selected_build_configuration = $this->project->Build->getBuildConfiguration($build_configuration);
|
||||||
}
|
}
|
||||||
catch (BuildConfigurationNotFoundException $e)
|
catch (BuildConfigurationNotFoundException $e)
|
||||||
{
|
{
|
||||||
|
@ -77,7 +93,11 @@
|
||||||
$this->package->Assembly = $this->project->Assembly;
|
$this->package->Assembly = $this->project->Assembly;
|
||||||
$this->package->Dependencies = $this->project->Build->Dependencies;
|
$this->package->Dependencies = $this->project->Build->Dependencies;
|
||||||
|
|
||||||
$this->package->Header->RuntimeConstants = $selected_build_configuration->DefineConstants;
|
// Add both the defined constants from the build configuration and the global constants.
|
||||||
|
// Global constants are overridden
|
||||||
|
$this->package->Header->RuntimeConstants = array_merge($this->selected_build_configuration->DefineConstants, $this->package->Header->RuntimeConstants);
|
||||||
|
$this->package->Header->RuntimeConstants = array_merge($this->project->Build->DefineConstants, $this->package->Header->RuntimeConstants);
|
||||||
|
|
||||||
$this->package->Header->CompilerExtension = $this->project->Project->Compiler;
|
$this->package->Header->CompilerExtension = $this->project->Project->Compiler;
|
||||||
$this->package->Header->CompilerVersion = NCC_VERSION_NUMBER;
|
$this->package->Header->CompilerVersion = NCC_VERSION_NUMBER;
|
||||||
|
|
||||||
|
@ -101,7 +121,7 @@
|
||||||
|
|
||||||
// Include file components that can be compiled
|
// Include file components that can be compiled
|
||||||
$DirectoryScanner->setIncludes(ComponentFileExtensions::Php);
|
$DirectoryScanner->setIncludes(ComponentFileExtensions::Php);
|
||||||
$DirectoryScanner->setExcludes($selected_build_configuration->ExcludeFiles);
|
$DirectoryScanner->setExcludes($this->selected_build_configuration->ExcludeFiles);
|
||||||
|
|
||||||
// Append trailing slash to the end of the path if it's not already there
|
// Append trailing slash to the end of the path if it's not already there
|
||||||
if(substr($path, -1) !== DIRECTORY_SEPARATOR)
|
if(substr($path, -1) !== DIRECTORY_SEPARATOR)
|
||||||
|
@ -114,7 +134,8 @@
|
||||||
// Scan for components first.
|
// Scan for components first.
|
||||||
Console::out('Scanning for components... ', false);
|
Console::out('Scanning for components... ', false);
|
||||||
/** @var SplFileInfo $item */
|
/** @var SplFileInfo $item */
|
||||||
foreach($DirectoryScanner($source_path, true) as $item)
|
/** @noinspection PhpRedundantOptionalArgumentInspection */
|
||||||
|
foreach($DirectoryScanner($source_path, True) as $item)
|
||||||
{
|
{
|
||||||
// Ignore directories, they're not important. :-)
|
// Ignore directories, they're not important. :-)
|
||||||
if(is_dir($item->getPathName()))
|
if(is_dir($item->getPathName()))
|
||||||
|
@ -144,7 +165,7 @@
|
||||||
|
|
||||||
// Ignore component files
|
// Ignore component files
|
||||||
$DirectoryScanner->setExcludes(array_merge(
|
$DirectoryScanner->setExcludes(array_merge(
|
||||||
$selected_build_configuration->ExcludeFiles, ComponentFileExtensions::Php
|
$this->selected_build_configuration->ExcludeFiles, ComponentFileExtensions::Php
|
||||||
));
|
));
|
||||||
|
|
||||||
Console::out('Scanning for resources... ', false);
|
Console::out('Scanning for resources... ', false);
|
||||||
|
@ -177,12 +198,11 @@
|
||||||
/**
|
/**
|
||||||
* Builds the package by parsing the AST contents of the components and resources
|
* Builds the package by parsing the AST contents of the components and resources
|
||||||
*
|
*
|
||||||
* @param array $options
|
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @return string
|
* @return string
|
||||||
* @throws BuildException
|
* @throws BuildException
|
||||||
*/
|
*/
|
||||||
public function build(array $options, string $path): string
|
public function build(string $path): string
|
||||||
{
|
{
|
||||||
if($this->package == null)
|
if($this->package == null)
|
||||||
{
|
{
|
||||||
|
@ -195,14 +215,6 @@
|
||||||
$path .= DIRECTORY_SEPARATOR;
|
$path .= DIRECTORY_SEPARATOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
$source_path = $path . $this->project->Build->SourcePath;
|
|
||||||
|
|
||||||
// Append trailing slash to the end of the source path if it's not already there
|
|
||||||
if(substr($source_path, -1) !== DIRECTORY_SEPARATOR)
|
|
||||||
{
|
|
||||||
$source_path .= DIRECTORY_SEPARATOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Runtime variables
|
// Runtime variables
|
||||||
$components = [];
|
$components = [];
|
||||||
$resources = [];
|
$resources = [];
|
||||||
|
@ -220,12 +232,12 @@
|
||||||
// Process the components and attempt to create an AST representation of the source
|
// Process the components and attempt to create an AST representation of the source
|
||||||
foreach($this->package->Components as $component)
|
foreach($this->package->Components as $component)
|
||||||
{
|
{
|
||||||
if(ncc::cliMode())
|
if(ncc::cliMode() && $total_items > 5)
|
||||||
{
|
{
|
||||||
Console::inlineProgressBar($processed_items, $total_items);
|
Console::inlineProgressBar($processed_items, $total_items);
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = file_get_contents(Functions::correctDirectorySeparator($source_path . $component->Name));
|
$content = file_get_contents(Functions::correctDirectorySeparator($path . $component->Name));
|
||||||
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
|
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -235,29 +247,35 @@
|
||||||
|
|
||||||
if($encoded === false)
|
if($encoded === false)
|
||||||
{
|
{
|
||||||
$component->Flags[] = ComponentFlags::b64encoded;
|
$component->DataType = ComponentDataType::b64encoded;
|
||||||
$component->Data = Functions::byteEncode($content);
|
$component->Data = Base64::encode($content);
|
||||||
|
$component->Checksum = hash('sha1', $component->Data);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$component->Flags[] = ComponentFlags::AST;
|
$component->DataType = ComponentDataType::AST;
|
||||||
$component->Data = ZiProto::encode(json_decode($encoded));
|
$component->Data = json_decode($encoded, true);
|
||||||
|
$component->Checksum = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Error $e)
|
catch(Error $e)
|
||||||
{
|
{
|
||||||
$component->Flags[] = ComponentFlags::b64encoded;
|
$component->DataType = ComponentDataType::b64encoded;
|
||||||
$component->Data = Functions::byteEncode($content);
|
$component->Data = Base64::encode($content);
|
||||||
|
$component->Checksum = hash('sha1', $component->Data);
|
||||||
unset($e);
|
unset($e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the checksum
|
$component->Name = str_replace($this->project->Build->SourcePath, (string)null, $component->Name);
|
||||||
$component->Checksum = hash('sha1', $component->Data);
|
|
||||||
|
|
||||||
$components[] = $component;
|
$components[] = $component;
|
||||||
$processed_items += 1;
|
$processed_items += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(ncc::cliMode() && $total_items > 5)
|
||||||
|
{
|
||||||
|
print(PHP_EOL);
|
||||||
|
}
|
||||||
|
|
||||||
// Update the components
|
// Update the components
|
||||||
$this->package->Components = $components;
|
$this->package->Components = $components;
|
||||||
}
|
}
|
||||||
|
@ -274,15 +292,17 @@
|
||||||
|
|
||||||
foreach($this->package->Resources as $resource)
|
foreach($this->package->Resources as $resource)
|
||||||
{
|
{
|
||||||
if(ncc::cliMode())
|
if(ncc::cliMode() && $total_items > 5)
|
||||||
{
|
{
|
||||||
Console::inlineProgressBar($processed_items, $total_items);
|
Console::inlineProgressBar($processed_items, $total_items);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the data and
|
// Get the data and
|
||||||
$resource->Data = file_get_contents(Functions::correctDirectorySeparator($source_path . $resource->Name));
|
$resource->Data = file_get_contents(Functions::correctDirectorySeparator($path . $resource->Name));
|
||||||
$resource->Data = Functions::byteEncode($resource->Data);
|
$resource->Data = Base64::encode($resource->Data);
|
||||||
$resource->Checksum = hash('sha1', $resource->Checksum);
|
$resource->Checksum = hash('sha1', $resource->Data);
|
||||||
|
$resource->Name = str_replace($this->project->Build->SourcePath, (string)null, $resource->Name);
|
||||||
|
$resources[] = $resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the resources
|
// Update the resources
|
||||||
|
@ -291,11 +311,40 @@
|
||||||
|
|
||||||
if(ncc::cliMode())
|
if(ncc::cliMode())
|
||||||
{
|
{
|
||||||
|
if($total_items > 5)
|
||||||
|
print(PHP_EOL);
|
||||||
Console::out($this->package->Assembly->Package . ' compiled successfully');
|
Console::out($this->package->Assembly->Package . ' compiled successfully');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the package to disk
|
// Write the package to disk
|
||||||
file_put_contents(getcwd() . DIRECTORY_SEPARATOR . 'test.bin', ZiProto::encode($this->package->toArray(true)));
|
$FileSystem = new Filesystem();
|
||||||
return getcwd() . DIRECTORY_SEPARATOR . 'test.bin';
|
|
||||||
|
if($FileSystem->exists($path . $this->selected_build_configuration->OutputPath))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$FileSystem->remove($path . $this->selected_build_configuration->OutputPath);
|
||||||
|
}
|
||||||
|
catch(IOException $e)
|
||||||
|
{
|
||||||
|
throw new BuildException('Cannot delete directory \'' . $path . $this->selected_build_configuration->OutputPath . '\', ' . $e->getMessage(), $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finally write the package to the disk
|
||||||
|
$FileSystem->mkdir($path . $this->selected_build_configuration->OutputPath);
|
||||||
|
$output_file = $path . $this->selected_build_configuration->OutputPath . DIRECTORY_SEPARATOR . $this->package->Assembly->Package . '.ncc';
|
||||||
|
$FileSystem->touch($output_file);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$this->package->save($output_file);
|
||||||
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new BuildException('Cannot write to output file', $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output_file;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -15,6 +15,7 @@
|
||||||
use ncc\Objects\ProjectConfiguration\Assembly;
|
use ncc\Objects\ProjectConfiguration\Assembly;
|
||||||
use ncc\Objects\ProjectConfiguration\Dependency;
|
use ncc\Objects\ProjectConfiguration\Dependency;
|
||||||
use ncc\Utilities\Functions;
|
use ncc\Utilities\Functions;
|
||||||
|
use ncc\ZiProto\ZiProto;
|
||||||
|
|
||||||
class Package
|
class Package
|
||||||
{
|
{
|
||||||
|
@ -125,6 +126,18 @@
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes the package contents to disk
|
||||||
|
*
|
||||||
|
* @param string $output_path
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function save(string $output_path): void
|
||||||
|
{
|
||||||
|
$package_contents = $this->MagicBytes->toString() . ZiProto::encode($this->toArray(true));
|
||||||
|
file_put_contents($output_path, $package_contents);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an array representation of the object
|
* Constructs an array representation of the object
|
||||||
*
|
*
|
||||||
|
@ -148,12 +161,13 @@
|
||||||
foreach($this->Resources as $resource)
|
foreach($this->Resources as $resource)
|
||||||
$_resources[] = $resource->toArray($bytecode);
|
$_resources[] = $resource->toArray($bytecode);
|
||||||
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
($bytecode ? Functions::cbc('header') : 'header') => $this->Header->toArray($bytecode),
|
($bytecode ? Functions::cbc('header') : 'header') => $this->Header?->toArray($bytecode),
|
||||||
($bytecode ? Functions::cbc('assembly') : 'assembly') => $this->Assembly->toArray($bytecode),
|
($bytecode ? Functions::cbc('assembly') : 'assembly') => $this->Assembly?->toArray($bytecode),
|
||||||
($bytecode ? Functions::cbc('dependencies') : 'dependencies') => $_dependencies,
|
($bytecode ? Functions::cbc('dependencies') : 'dependencies') => $_dependencies,
|
||||||
($bytecode ? Functions::cbc('main_execution_policy') : 'main_execution_policy') => $this->MainExecutionPolicy->toArray($bytecode),
|
($bytecode ? Functions::cbc('main_execution_policy') : 'main_execution_policy') => $this->MainExecutionPolicy?->toArray($bytecode),
|
||||||
($bytecode ? Functions::cbc('installer') : 'installer') => $this->Installer->toArray($bytecode),
|
($bytecode ? Functions::cbc('installer') : 'installer') => $this->Installer?->toArray($bytecode),
|
||||||
($bytecode ? Functions::cbc('resources') : 'resources') => $_resources,
|
($bytecode ? Functions::cbc('resources') : 'resources') => $_resources,
|
||||||
($bytecode ? Functions::cbc('components') : 'components') => $_components
|
($bytecode ? Functions::cbc('components') : 'components') => $_components
|
||||||
];
|
];
|
||||||
|
|
|
@ -3,8 +3,14 @@
|
||||||
namespace ncc\Objects;
|
namespace ncc\Objects;
|
||||||
|
|
||||||
use ncc\Exceptions\FileNotFoundException;
|
use ncc\Exceptions\FileNotFoundException;
|
||||||
|
use ncc\Exceptions\InvalidConstantNameException;
|
||||||
|
use ncc\Exceptions\InvalidProjectBuildConfiguration;
|
||||||
use ncc\Exceptions\InvalidProjectConfigurationException;
|
use ncc\Exceptions\InvalidProjectConfigurationException;
|
||||||
|
use ncc\Exceptions\InvalidPropertyValueException;
|
||||||
use ncc\Exceptions\MalformedJsonException;
|
use ncc\Exceptions\MalformedJsonException;
|
||||||
|
use ncc\Exceptions\RuntimeException;
|
||||||
|
use ncc\Exceptions\UnsupportedCompilerExtensionException;
|
||||||
|
use ncc\Exceptions\UnsupportedExtensionVersionException;
|
||||||
use ncc\Objects\ProjectConfiguration\Assembly;
|
use ncc\Objects\ProjectConfiguration\Assembly;
|
||||||
use ncc\Objects\ProjectConfiguration\Build;
|
use ncc\Objects\ProjectConfiguration\Build;
|
||||||
use ncc\Objects\ProjectConfiguration\Project;
|
use ncc\Objects\ProjectConfiguration\Project;
|
||||||
|
@ -53,12 +59,24 @@
|
||||||
* @param bool $throw_exception
|
* @param bool $throw_exception
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws InvalidProjectConfigurationException
|
* @throws InvalidProjectConfigurationException
|
||||||
|
* @throws InvalidPropertyValueException
|
||||||
|
* @throws RuntimeException
|
||||||
|
* @throws UnsupportedCompilerExtensionException
|
||||||
|
* @throws UnsupportedExtensionVersionException
|
||||||
|
* @throws InvalidProjectBuildConfiguration
|
||||||
|
* @throws InvalidConstantNameException
|
||||||
*/
|
*/
|
||||||
public function validate(bool $throw_exception=True): bool
|
public function validate(bool $throw_exception=True): bool
|
||||||
{
|
{
|
||||||
|
if(!$this->Project->validate($throw_exception))
|
||||||
|
return false;
|
||||||
|
|
||||||
if(!$this->Assembly->validate($throw_exception))
|
if(!$this->Assembly->validate($throw_exception))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if(!$this->Build->validate($throw_exception))
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -109,10 +109,10 @@
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strlen($this->Name) > 40)
|
if(strlen($this->Name) > 126)
|
||||||
{
|
{
|
||||||
if($throw_exception)
|
if($throw_exception)
|
||||||
throw new InvalidProjectConfigurationException('The name cannot be larger than 40 characters', 'Assembly.Name');
|
throw new InvalidProjectConfigurationException('The name cannot be larger than 126 characters', 'Assembly.Name');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -133,26 +133,26 @@
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strlen($this->Product) > 64)
|
if(strlen($this->Product) > 256)
|
||||||
{
|
{
|
||||||
if($throw_exception)
|
if($throw_exception)
|
||||||
throw new InvalidProjectConfigurationException('The company cannot be larger than 64 characters', 'Assembly.Product');
|
throw new InvalidProjectConfigurationException('The company cannot be larger than 256 characters', 'Assembly.Product');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strlen($this->Copyright) > 64)
|
if(strlen($this->Copyright) > 256)
|
||||||
{
|
{
|
||||||
if($throw_exception)
|
if($throw_exception)
|
||||||
throw new InvalidProjectConfigurationException('The copyright cannot be larger than 64 characters', 'Assembly.Copyright');
|
throw new InvalidProjectConfigurationException('The copyright cannot be larger than 256 characters', 'Assembly.Copyright');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strlen($this->Trademark) > 64)
|
if(strlen($this->Trademark) > 256)
|
||||||
{
|
{
|
||||||
if($throw_exception)
|
if($throw_exception)
|
||||||
throw new InvalidProjectConfigurationException('The trademark cannot be larger than 64 characters', 'Assembly.Trademark');
|
throw new InvalidProjectConfigurationException('The trademark cannot be larger than 256 characters', 'Assembly.Trademark');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,10 @@
|
||||||
namespace ncc\Objects\ProjectConfiguration;
|
namespace ncc\Objects\ProjectConfiguration;
|
||||||
|
|
||||||
use ncc\Exceptions\BuildConfigurationNotFoundException;
|
use ncc\Exceptions\BuildConfigurationNotFoundException;
|
||||||
|
use ncc\Exceptions\InvalidConstantNameException;
|
||||||
use ncc\Exceptions\InvalidProjectBuildConfiguration;
|
use ncc\Exceptions\InvalidProjectBuildConfiguration;
|
||||||
use ncc\Utilities\Functions;
|
use ncc\Utilities\Functions;
|
||||||
|
use ncc\Utilities\Validate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Zi Xing Narrakas
|
* @author Zi Xing Narrakas
|
||||||
|
@ -87,11 +89,21 @@
|
||||||
*
|
*
|
||||||
* @param bool $throw_exception
|
* @param bool $throw_exception
|
||||||
* @return bool
|
* @return bool
|
||||||
|
* @throws InvalidConstantNameException
|
||||||
* @throws InvalidProjectBuildConfiguration
|
* @throws InvalidProjectBuildConfiguration
|
||||||
*/
|
*/
|
||||||
public function validate(bool $throw_exception=True): bool
|
public function validate(bool $throw_exception=True): bool
|
||||||
{
|
{
|
||||||
// TODO: Implement further validation logic
|
// TODO: Implement validation for Configurations, Dependencies and ExcludedFiles
|
||||||
|
|
||||||
|
// Check the defined constants
|
||||||
|
foreach($this->DefineConstants as $name => $value)
|
||||||
|
{
|
||||||
|
if(!Validate::constantName($name))
|
||||||
|
{
|
||||||
|
throw new InvalidConstantNameException('The name \'' . $name . '\' is not valid for a constant declaration, ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check for duplicate configuration names
|
// Check for duplicate configuration names
|
||||||
$build_configurations = [];
|
$build_configurations = [];
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use ncc\Abstracts\ConsoleColors;
|
use ncc\Abstracts\ConsoleColors;
|
||||||
|
use ncc\ncc;
|
||||||
|
|
||||||
class Console
|
class Console
|
||||||
{
|
{
|
||||||
|
@ -18,16 +19,16 @@
|
||||||
* @return void
|
* @return void
|
||||||
*@copyright Copyright (c) 2010, dealnews.com, Inc. All rights reserved.
|
*@copyright Copyright (c) 2010, dealnews.com, Inc. All rights reserved.
|
||||||
*/
|
*/
|
||||||
public static function inlineProgressBar(int $value, int $total, int $size=38, array $options=[])
|
public static function inlineProgressBar(int $value, int $total, int $size=38, array $options=[]): void
|
||||||
{
|
{
|
||||||
static $start_time;
|
static $start_time;
|
||||||
|
|
||||||
// if we go over our bound, just ignore it
|
// if we go over our bound, just ignore it
|
||||||
if($value > $total) return;
|
if($value > $total)
|
||||||
|
return;
|
||||||
|
|
||||||
if(empty($start_time)) $start_time=time();
|
if(empty($start_time)) $start_time=time();
|
||||||
$now = time();
|
$now = time();
|
||||||
|
|
||||||
$perc=(double)($value/$total);
|
$perc=(double)($value/$total);
|
||||||
|
|
||||||
$bar=floor($perc*$size);
|
$bar=floor($perc*$size);
|
||||||
|
@ -45,6 +46,9 @@
|
||||||
|
|
||||||
$status_bar.=" ] $disp% $value/$total";
|
$status_bar.=" ] $disp% $value/$total";
|
||||||
|
|
||||||
|
if($value == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
$rate = ($now-$start_time)/$value;
|
$rate = ($now-$start_time)/$value;
|
||||||
$left = $total - $value;
|
$left = $total - $value;
|
||||||
$eta = round($rate * $left, 2);
|
$eta = round($rate * $left, 2);
|
||||||
|
@ -75,8 +79,11 @@
|
||||||
* @param bool $newline
|
* @param bool $newline
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function out(string $message, bool $newline=true)
|
public static function out(string $message, bool $newline=true): void
|
||||||
{
|
{
|
||||||
|
if(!ncc::cliMode())
|
||||||
|
return;
|
||||||
|
|
||||||
if($newline)
|
if($newline)
|
||||||
{
|
{
|
||||||
print($message . PHP_EOL);
|
print($message . PHP_EOL);
|
||||||
|
@ -111,8 +118,11 @@
|
||||||
* @param bool $newline
|
* @param bool $newline
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function outWarning(string $message, bool $newline=true)
|
public static function outWarning(string $message, bool $newline=true): void
|
||||||
{
|
{
|
||||||
|
if(!ncc::cliMode())
|
||||||
|
return;
|
||||||
|
|
||||||
self::out(self::formatColor('Warning: ', ConsoleColors::Yellow) . $message, $newline);
|
self::out(self::formatColor('Warning: ', ConsoleColors::Yellow) . $message, $newline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,8 +134,11 @@
|
||||||
* @param int|null $exit_code
|
* @param int|null $exit_code
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function outError(string $message, bool $newline=true, ?int $exit_code=null)
|
public static function outError(string $message, bool $newline=true, ?int $exit_code=null): void
|
||||||
{
|
{
|
||||||
|
if(!ncc::cliMode())
|
||||||
|
return;
|
||||||
|
|
||||||
self::out(self::formatColor(ConsoleColors::Red, 'Error: ') . $message, $newline);
|
self::out(self::formatColor(ConsoleColors::Red, 'Error: ') . $message, $newline);
|
||||||
|
|
||||||
if($exit_code !== null)
|
if($exit_code !== null)
|
||||||
|
@ -142,8 +155,11 @@
|
||||||
* @param int|null $exit_code
|
* @param int|null $exit_code
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function outException(string $message, Exception $e, ?int $exit_code=null)
|
public static function outException(string $message, Exception $e, ?int $exit_code=null): void
|
||||||
{
|
{
|
||||||
|
if(!ncc::cliMode())
|
||||||
|
return;
|
||||||
|
|
||||||
if(strlen($message) > 0)
|
if(strlen($message) > 0)
|
||||||
{
|
{
|
||||||
self::out(self::formatColor('Error: ' . $message, ConsoleColors::Red));
|
self::out(self::formatColor('Error: ' . $message, ConsoleColors::Red));
|
||||||
|
@ -163,8 +179,11 @@
|
||||||
* @param Exception $e
|
* @param Exception $e
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function outExceptionDetails(Exception $e)
|
private static function outExceptionDetails(Exception $e): void
|
||||||
{
|
{
|
||||||
|
if(!ncc::cliMode())
|
||||||
|
return;
|
||||||
|
|
||||||
$trace_header = self::formatColor($e->getFile() . ':' . $e->getLine(), ConsoleColors::Magenta);
|
$trace_header = self::formatColor($e->getFile() . ':' . $e->getLine(), ConsoleColors::Magenta);
|
||||||
$trace_error = self::formatColor('error: ', ConsoleColors::Red);
|
$trace_error = self::formatColor('error: ', ConsoleColors::Red);
|
||||||
self::out($trace_header . ' ' . $trace_error . $e->getMessage());
|
self::out($trace_header . ' ' . $trace_error . $e->getMessage());
|
||||||
|
|
|
@ -5,9 +5,6 @@
|
||||||
use ncc\Exceptions\FileNotFoundException;
|
use ncc\Exceptions\FileNotFoundException;
|
||||||
use ncc\Exceptions\MalformedJsonException;
|
use ncc\Exceptions\MalformedJsonException;
|
||||||
use ncc\Objects\CliHelpSection;
|
use ncc\Objects\CliHelpSection;
|
||||||
use function chr;
|
|
||||||
use function is_int;
|
|
||||||
use function is_string;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Zi Xing Narrakas
|
* @author Zi Xing Narrakas
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
namespace ncc\Utilities;
|
namespace ncc\Utilities;
|
||||||
|
|
||||||
use ncc\Abstracts\Scopes;
|
use ncc\Abstracts\Scopes;
|
||||||
use ncc\Exceptions\AccessDeniedException;
|
|
||||||
use ncc\Exceptions\InvalidScopeException;
|
use ncc\Exceptions\InvalidScopeException;
|
||||||
|
|
||||||
class PathFinder
|
class PathFinder
|
||||||
|
|
Loading…
Add table
Reference in a new issue