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:
parent
e829a839d1
commit
b30ddbdc28
6 changed files with 122 additions and 24 deletions
|
@ -74,7 +74,6 @@
|
||||||
|
|
||||||
self::writeProgramTemplate($project_manager);
|
self::writeProgramTemplate($project_manager);
|
||||||
self::writeMainEntryTemplate($project_manager);
|
self::writeMainEntryTemplate($project_manager);
|
||||||
self::writeMakefileTemplate($project_manager);
|
|
||||||
|
|
||||||
$project_manager->save();
|
$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')
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -11,10 +11,13 @@ all: build
|
||||||
build:
|
build:
|
||||||
ncc build --config=$(CONFIG) --log-level $(LOG_LEVEL)
|
ncc build --config=$(CONFIG) --log-level $(LOG_LEVEL)
|
||||||
|
|
||||||
install:
|
install: build
|
||||||
ncc package install --package=$(PACKAGE) --skip-dependencies --reinstall -y --log-level $(LOG_LEVEL)
|
ncc package install --package=$(PACKAGE) --skip-dependencies --build-source --reinstall -y --log-level $(LOG_LEVEL)
|
||||||
|
|
||||||
|
test: build
|
||||||
|
phpunit
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf build
|
rm -rf build
|
||||||
|
|
||||||
.PHONY: all build install clean
|
.PHONY: all build install test clean
|
61
src/ncc/Classes/PhpExtension/Templates/MakefileTemplate.php
Normal file
61
src/ncc/Classes/PhpExtension/Templates/MakefileTemplate.php
Normal 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')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -40,8 +40,11 @@
|
||||||
class PhpUnitTemplate implements TemplateInterface
|
class PhpUnitTemplate implements TemplateInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* Applies the necessary templates for the given project.
|
||||||
* @param ProjectManager $project_manager
|
*
|
||||||
|
* @param ProjectManager $project_manager Manager responsible for handling project-related tasks.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function applyTemplate(ProjectManager $project_manager): void
|
public static function applyTemplate(ProjectManager $project_manager): void
|
||||||
{
|
{
|
||||||
|
@ -49,6 +52,14 @@
|
||||||
self::createPhpUnitTemplate($project_manager);
|
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
|
private static function createPhpUnitTemplate(ProjectManager $project_manager): void
|
||||||
{
|
{
|
||||||
IO::fwrite(
|
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
|
private static function createPhpUnitBootstrapTemplate(ProjectManager $project_manager): void
|
||||||
{
|
{
|
||||||
IO::fwrite(
|
IO::fwrite(
|
||||||
|
|
|
@ -34,5 +34,23 @@
|
||||||
*/
|
*/
|
||||||
case PHP_CLI = 'phpcli';
|
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';
|
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';
|
||||||
}
|
}
|
|
@ -30,6 +30,7 @@
|
||||||
use ncc\Classes\PhpExtension\NccCompiler;
|
use ncc\Classes\PhpExtension\NccCompiler;
|
||||||
use ncc\Classes\PhpExtension\Templates\CliTemplate;
|
use ncc\Classes\PhpExtension\Templates\CliTemplate;
|
||||||
use ncc\Classes\PhpExtension\Templates\LibraryTemplate;
|
use ncc\Classes\PhpExtension\Templates\LibraryTemplate;
|
||||||
|
use ncc\Classes\PhpExtension\Templates\MakefileTemplate;
|
||||||
use ncc\Classes\PhpExtension\Templates\PhpUnitTemplate;
|
use ncc\Classes\PhpExtension\Templates\PhpUnitTemplate;
|
||||||
use ncc\Enums\CompilerExtensions;
|
use ncc\Enums\CompilerExtensions;
|
||||||
use ncc\Enums\Options\BuildConfigurationOptions;
|
use ncc\Enums\Options\BuildConfigurationOptions;
|
||||||
|
@ -199,10 +200,27 @@
|
||||||
LibraryTemplate::applyTemplate($this);
|
LibraryTemplate::applyTemplate($this);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ProjectTemplates::PHP_MAKE->value:
|
||||||
|
MakefileTemplate::applyTemplate($this);
|
||||||
|
break;
|
||||||
|
|
||||||
case ProjectTemplates::PHP_UNIT->value:
|
case ProjectTemplates::PHP_UNIT->value:
|
||||||
PhpUnitTemplate::applyTemplate($this);
|
PhpUnitTemplate::applyTemplate($this);
|
||||||
break;
|
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:
|
default:
|
||||||
throw new NotSupportedException('The given template \'' . $template_name . '\' is not supported');
|
throw new NotSupportedException('The given template \'' . $template_name . '\' is not supported');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue