Added compiler extension and version structure detection
This commit is contained in:
parent
a7f7c1bdfd
commit
03185d3dc7
5 changed files with 141 additions and 7 deletions
13
src/ncc/Abstracts/CompilerExtensionDefaultVersions.php
Normal file
13
src/ncc/Abstracts/CompilerExtensionDefaultVersions.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace ncc\Abstracts;
|
||||
|
||||
abstract class CompilerExtensionDefaultVersions
|
||||
{
|
||||
// ----------------------------------------------------------------
|
||||
// [0] = MinimumVersion
|
||||
// [1] = MaximumVersion
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
const PHP = ['8.0', '8.1'];
|
||||
}
|
8
src/ncc/Abstracts/CompilerExtensionSupportedVersions.php
Normal file
8
src/ncc/Abstracts/CompilerExtensionSupportedVersions.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace ncc\Abstracts;
|
||||
|
||||
abstract class CompilerExtensionSupportedVersions
|
||||
{
|
||||
const PHP = ['8.0', '8.1'];
|
||||
}
|
12
src/ncc/Abstracts/CompilerExtensions.php
Normal file
12
src/ncc/Abstracts/CompilerExtensions.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace ncc\Abstracts;
|
||||
|
||||
abstract class CompilerExtensions
|
||||
{
|
||||
const PHP = 'php';
|
||||
|
||||
const All = [
|
||||
CompilerExtensions::PHP
|
||||
];
|
||||
}
|
|
@ -58,6 +58,10 @@
|
|||
ProjectMenu::start($args);
|
||||
exit(0);
|
||||
|
||||
case 'build':
|
||||
BuildMenu::start($args);
|
||||
exit(0);
|
||||
|
||||
case 'credential':
|
||||
CredentialMenu::start($args);
|
||||
exit(0);
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
namespace ncc\CLI;
|
||||
|
||||
use Exception;
|
||||
use ncc\Abstracts\CompilerExtensionDefaultVersions;
|
||||
use ncc\Abstracts\CompilerExtensions;
|
||||
use ncc\Abstracts\CompilerExtensionSupportedVersions;
|
||||
use ncc\Exceptions\InvalidPackageNameException;
|
||||
use ncc\Exceptions\InvalidProjectNameException;
|
||||
use ncc\Exceptions\ProjectAlreadyExistsException;
|
||||
|
@ -73,15 +76,103 @@
|
|||
|
||||
// Fetch the rest of the information needed for the project
|
||||
//$compiler_extension = Console::getOptionInput($args, 'ce', 'Compiler Extension (php, java): ');
|
||||
$compiler_extension = 'php'; // Always php, for now.
|
||||
$package_name = Console::getOptionInput($args, 'package', 'Package Name (com.example.foo): ');
|
||||
$project_name = Console::getOptionInput($args, 'name', 'Project Name (Foo Bar Library): ');
|
||||
|
||||
// Create the compiler configuration
|
||||
$Compiler = new Compiler();
|
||||
|
||||
// Detect the specified compiler extension
|
||||
if(isset($args['ext']) || isset($args['extension']))
|
||||
{
|
||||
$compiler_extension = strtolower(($args['extension'] ?? $args['ext']));
|
||||
|
||||
if(in_array($compiler_extension, CompilerExtensions::All))
|
||||
{
|
||||
$Compiler->Extension = $compiler_extension;
|
||||
$Compiler->MaximumVersion = '8.1';
|
||||
$Compiler->MinimumVersion = '7.4';
|
||||
}
|
||||
else
|
||||
{
|
||||
Console::outError('Unsupported extension: ' . $compiler_extension, true, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Default PHP Extension
|
||||
$Compiler->Extension = CompilerExtensions::PHP;
|
||||
}
|
||||
|
||||
// If a minimum and maximum version is specified
|
||||
if(
|
||||
(isset($args['max-version']) || isset($args['max-ver'])) &&
|
||||
(isset($args['min-version']) || isset($args['min-ver']))
|
||||
)
|
||||
{
|
||||
$max_version = strtolower($args['max-version'] ?? $args['max-ver']);
|
||||
$min_version = strtolower($args['min-version'] ?? $args['min-ver']);
|
||||
|
||||
switch($Compiler->Extension)
|
||||
{
|
||||
case CompilerExtensions::PHP:
|
||||
|
||||
if(!in_array($max_version, CompilerExtensionSupportedVersions::PHP))
|
||||
{
|
||||
Console::outError('The extension \'' . $Compiler->Extension . '\' does not support version ' . $max_version, true, 1);
|
||||
return;
|
||||
}
|
||||
if(!in_array($min_version, CompilerExtensionSupportedVersions::PHP))
|
||||
{
|
||||
Console::outError('The extension \'' . $Compiler->Extension . '\' does not support version ' . $min_version, true, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
$Compiler->MaximumVersion = $max_version;
|
||||
$Compiler->MinimumVersion = $min_version;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
Console::outError('Unsupported extension: ' . $Compiler->Extension, true, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// If a single version is specified
|
||||
elseif(isset($args['version']) || isset($args['ver']))
|
||||
{
|
||||
$version = strtolower($args['version'] ?? $args['ver']);
|
||||
switch($Compiler->Extension)
|
||||
{
|
||||
case CompilerExtensions::PHP:
|
||||
if(!in_array($version, CompilerExtensionSupportedVersions::PHP))
|
||||
{
|
||||
Console::outError('The extension \'' . $Compiler->Extension . '\' does not support version ' . $version, true, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
$Compiler->MaximumVersion = $version;
|
||||
$Compiler->MinimumVersion = $version;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
Console::outError('Unsupported extension: ' . $Compiler->Extension, true, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// If no version is specified, use the default version
|
||||
else
|
||||
{
|
||||
switch($Compiler->Extension)
|
||||
{
|
||||
case CompilerExtensions::PHP:
|
||||
$Compiler->MinimumVersion = CompilerExtensionDefaultVersions::PHP[1];
|
||||
$Compiler->MaximumVersion = CompilerExtensionDefaultVersions::PHP[0];
|
||||
break;
|
||||
|
||||
default:
|
||||
Console::outError('Unsupported extension: ' . $Compiler->Extension, true, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Now create the project
|
||||
$ProjectManager = new ProjectManager($current_directory);
|
||||
|
@ -93,18 +184,22 @@
|
|||
catch (InvalidPackageNameException $e)
|
||||
{
|
||||
Console::outException('The given package name is invalid, the value must follow the standard package naming convention', $e, 1);
|
||||
return;
|
||||
}
|
||||
catch (InvalidProjectNameException $e)
|
||||
{
|
||||
Console::outException('The given project name is invalid, cannot be empty or larger than 126 characters', $e, 1);
|
||||
return;
|
||||
}
|
||||
catch (ProjectAlreadyExistsException $e)
|
||||
{
|
||||
Console::outException('A project has already been initialized in \'' . $current_directory . '\'', $e, 1);
|
||||
return;
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
Console::outException('There was an unexpected error while trying to initialize the project', $e, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
Console::out('Project successfully created');
|
||||
|
@ -121,7 +216,9 @@
|
|||
$options = [
|
||||
new CliHelpSection(['help'], 'Displays this help menu about the value command'),
|
||||
new CliHelpSection(['create', '--src', '--package', '--name'], 'Creates a new NCC project'),
|
||||
new CliHelpSection(['create', '--makefile'], 'Generates a Makefile for the project'),
|
||||
new CliHelpSection(['create', '--ext'], 'Specifies the compiler extension'),
|
||||
new CliHelpSection(['create', '--min-version', '--min-ver', '--maximum-ver', '-max-ver'], 'Specifies the compiler extension version'),
|
||||
new CliHelpSection(['create-makefile'], 'Generates a Makefile for the project'),
|
||||
];
|
||||
|
||||
$options_padding = \ncc\Utilities\Functions::detectParametersPadding($options) + 4;
|
||||
|
|
Loading…
Add table
Reference in a new issue