Improved template system

This commit is contained in:
Netkas 2023-10-08 15:35:20 -04:00
parent aeccdaea68
commit 09debf85c6
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
3 changed files with 34 additions and 12 deletions

View file

@ -28,6 +28,7 @@
use ncc\Objects\CliHelpSection;
use ncc\Utilities\Console;
use ncc\Utilities\Functions;
use ncc\Utilities\Security;
class ProjectMenu
{
@ -60,16 +61,6 @@
*/
private static function initializeProject(array $args): int
{
if(isset($args['path']) || isset($args['p']))
{
$project_path = $args['path'] ?? $args['p'];
}
else
{
Console::outError('Missing required option: --path|-p, please specify the path to the project', true, 1);
return 1;
}
if(isset($args['name']) || isset($args['n']))
{
$project_name = $args['name'] ?? $args['n'];
@ -80,6 +71,16 @@
return 1;
}
if(isset($args['path']) || isset($args['p']))
{
$project_path = $args['path'] ?? $args['p'];
}
else
{
$project_path = Security::sanitizeFilename($project_name, false);
Console::out(sprintf('No path specified, using \'%s\'', $project_path));
}
if(isset($args['package']) || isset($args['pkg']))
{
$package_name = $args['package'] ?? $args['pkg'];

View file

@ -23,13 +23,17 @@
namespace ncc\Classes\PhpExtension\Templates;
use ncc\Classes\NccExtension\ConstantCompiler;
use ncc\Enums\Options\BuildConfigurationOptions;
use ncc\Enums\Options\ProjectOptions;
use ncc\Enums\Runners;
use ncc\Enums\SpecialConstants\AssemblyConstants;
use ncc\Enums\Types\BuildOutputType;
use ncc\Exceptions\ConfigurationException;
use ncc\Exceptions\IOException;
use ncc\Exceptions\PathNotFoundException;
use ncc\Interfaces\TemplateInterface;
use ncc\Managers\ProjectManager;
use ncc\Objects\ProjectConfiguration\Build\BuildConfiguration;
use ncc\Objects\ProjectConfiguration\ExecutionPolicy;
use ncc\Utilities\IO;
@ -51,6 +55,23 @@
$project_manager->getProjectConfiguration()->getBuild()->setMain('main_policy');
$project_manager->getProjectConfiguration()->getProject()->addOption(ProjectOptions::CREATE_SYMLINK, true);
// Create the release build configuration
$release_executable = new BuildConfiguration('release_executable',
'build' . DIRECTORY_SEPARATOR . 'release' . DIRECTORY_SEPARATOR . AssemblyConstants::ASSEMBLY_NAME
);
$release_executable->setBuildType(BuildOutputType::EXECUTABLE);
$release_executable->setOption(BuildConfigurationOptions::NCC_CONFIGURATION, 'release');
$project_manager->getProjectConfiguration()->getBuild()->addBuildConfiguration($release_executable);
// Create the debug build configuration
$debug_executable = new BuildConfiguration('debug_executable',
'build' . DIRECTORY_SEPARATOR . 'debug' . DIRECTORY_SEPARATOR . AssemblyConstants::ASSEMBLY_NAME
);
$debug_executable->setDefinedConstant('DEBUG', '1');
$debug_executable->setBuildType(BuildOutputType::EXECUTABLE);
$debug_executable->setOption(BuildConfigurationOptions::NCC_CONFIGURATION, 'debug');
$project_manager->getProjectConfiguration()->getBuild()->addBuildConfiguration($debug_executable);
self::writeProgramTemplate($project_manager);
self::writeMainEntryTemplate($project_manager);
self::writeMakefileTemplate($project_manager);

View file

@ -353,11 +353,11 @@
// Generate the Debug & Release build configurations
$debug_configuration = new ProjectConfiguration\Build\BuildConfiguration('debug',
'build' . DIRECTORY_SEPARATOR . 'debug' . DIRECTORY_SEPARATOR . AssemblyConstants::ASSEMBLY_PACKAGE
'build' . DIRECTORY_SEPARATOR . 'debug' . DIRECTORY_SEPARATOR . AssemblyConstants::ASSEMBLY_PACKAGE . '.ncc'
);
$debug_configuration->setDefinedConstant('DEBUG', '1');
$build->addBuildConfiguration(new ProjectConfiguration\Build\BuildConfiguration('release',
'build' . DIRECTORY_SEPARATOR . 'release' . DIRECTORY_SEPARATOR . AssemblyConstants::ASSEMBLY_PACKAGE
'build' . DIRECTORY_SEPARATOR . 'release' . DIRECTORY_SEPARATOR . AssemblyConstants::ASSEMBLY_PACKAGE . '.ncc'
));
$build->addBuildConfiguration($debug_configuration);
$build->setDefaultConfiguration('release');