Seperated Makefile template into it's own template, added phpcli_full & phplib_full to combine all Templates together for building a PHP project

This commit is contained in:
netkas 2024-09-23 15:17:15 -04:00
parent e829a839d1
commit b30ddbdc28
6 changed files with 122 additions and 24 deletions

View file

@ -74,7 +74,6 @@
self::writeProgramTemplate($project_manager);
self::writeMainEntryTemplate($project_manager);
self::writeMakefileTemplate($project_manager);
$project_manager->save();
}
@ -114,22 +113,4 @@
)
);
}
/**
* Writes the Makefile to the project directory
*
* @param ProjectManager $project_manager
* @return void
* @throws IOException
* @throws PathNotFoundException
*/
private static function writeMakefileTemplate(ProjectManager $project_manager): void
{
IO::fwrite(
$project_manager->getProjectPath() . DIRECTORY_SEPARATOR . 'Makefile',
ConstantCompiler::compileConstants($project_manager->getProjectConfiguration(),
IO::fread(__DIR__ . DIRECTORY_SEPARATOR . 'Makefile.tpl')
)
);
}
}

View file

@ -11,10 +11,13 @@ all: build
build:
ncc build --config=$(CONFIG) --log-level $(LOG_LEVEL)
install:
ncc package install --package=$(PACKAGE) --skip-dependencies --reinstall -y --log-level $(LOG_LEVEL)
install: build
ncc package install --package=$(PACKAGE) --skip-dependencies --build-source --reinstall -y --log-level $(LOG_LEVEL)
test: build
phpunit
clean:
rm -rf build
.PHONY: all build install clean
.PHONY: all build install test clean

View file

@ -0,0 +1,61 @@
<?php
/*
* Copyright (c) Nosial 2022-2024, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Classes\PhpExtension\Templates;
use ncc\Classes\NccExtension\ConstantCompiler;
use ncc\Exceptions\IOException;
use ncc\Exceptions\PathNotFoundException;
use ncc\Managers\ProjectManager;
use ncc\Utilities\IO;
class MakefileTemplate
{
/**
* @inheritDoc
* @param ProjectManager $project_manager
* @throws IOException
* @throws PathNotFoundException
*/
public static function applyTemplate(ProjectManager $project_manager): void
{
self::writeMakefileTemplate($project_manager);
}
/**
* Writes the Makefile to the project directory
*
* @param ProjectManager $project_manager
* @return void
* @throws IOException
* @throws PathNotFoundException
*/
private static function writeMakefileTemplate(ProjectManager $project_manager): void
{
IO::fwrite(
$project_manager->getProjectPath() . DIRECTORY_SEPARATOR . 'Makefile',
ConstantCompiler::compileConstants($project_manager->getProjectConfiguration(),
IO::fread(__DIR__ . DIRECTORY_SEPARATOR . 'Makefile.tpl')
)
);
}
}

View file

@ -40,8 +40,11 @@
class PhpUnitTemplate implements TemplateInterface
{
/**
* @inheritDoc
* @param ProjectManager $project_manager
* Applies the necessary templates for the given project.
*
* @param ProjectManager $project_manager Manager responsible for handling project-related tasks.
*
* @return void
*/
public static function applyTemplate(ProjectManager $project_manager): void
{
@ -49,6 +52,14 @@
self::createPhpUnitTemplate($project_manager);
}
/**
* Creates a PHPUnit template in the specified project directory.
*
* @param ProjectManager $project_manager The project manager instance containing project configuration and path details.
* @return void
* @throws IOException
* @throws PathNotFoundException
*/
private static function createPhpUnitTemplate(ProjectManager $project_manager): void
{
IO::fwrite(
@ -64,6 +75,12 @@
}
}
/**
* Creates the PHPUnit bootstrap template file for the given project.
*
* @param ProjectManager $project_manager The project manager instance handling project configuration and paths.
* @return void
*/
private static function createPhpUnitBootstrapTemplate(ProjectManager $project_manager): void
{
IO::fwrite(

View file

@ -34,5 +34,23 @@
*/
case PHP_CLI = 'phpcli';
/**
* A template for generating a Makefile for the PHP project
*/
case PHP_MAKE = 'phpmake';
/**
* A template used for creating PHP Unit testing bootstrap
*/
case PHP_UNIT = 'phpunit';
/**
* Template that combines PHP_LIBRARY, PHP_MAKE and PHP_UNIT in one
*/
case PHP_LIBRARY_FULL = 'phplib_full';
/**
* Template that combines PHP_LIBRARY, PHP_MAKE, PHP_UNIT and PHP_CLI in one
*/
case PHP_CLI_FULL = 'phpcli_full';
}

View file

@ -30,6 +30,7 @@
use ncc\Classes\PhpExtension\NccCompiler;
use ncc\Classes\PhpExtension\Templates\CliTemplate;
use ncc\Classes\PhpExtension\Templates\LibraryTemplate;
use ncc\Classes\PhpExtension\Templates\MakefileTemplate;
use ncc\Classes\PhpExtension\Templates\PhpUnitTemplate;
use ncc\Enums\CompilerExtensions;
use ncc\Enums\Options\BuildConfigurationOptions;
@ -199,10 +200,27 @@
LibraryTemplate::applyTemplate($this);
break;
case ProjectTemplates::PHP_MAKE->value:
MakefileTemplate::applyTemplate($this);
break;
case ProjectTemplates::PHP_UNIT->value:
PhpUnitTemplate::applyTemplate($this);
break;
case ProjectTemplates::PHP_LIBRARY_FULL->value:
LibraryTemplate::applyTemplate($this);
MakefileTemplate::applyTemplate($this);
PhpUnitTemplate::applyTemplate($this);
break;
case ProjectTemplates::PHP_CLI_FULL:
CliTemplate::applyTemplate($this);
LibraryTemplate::applyTemplate($this);
MakefileTemplate::applyTemplate($this);
PhpUnitTemplate::applyTemplate($this);
break;
default:
throw new NotSupportedException('The given template \'' . $template_name . '\' is not supported');
}