Skip to content
Snippets Groups Projects
Commit 060eb3a9 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Remove all bundle creation commands

They are now part of the server template (via the maker bundle)
parent bfdb5e94
No related branches found
No related tags found
No related merge requests found
Pipeline #184502 passed
...@@ -4,12 +4,6 @@ stages: ...@@ -4,12 +4,6 @@ stages:
- test - test
- deploy - deploy
test-bundle:
stage: test
script:
- ./bin/cli show-bundle-names --vendor=myvendor --category=mycategory --unique-name=greenlight --friendly-name="Electronic Covid Access Permits" --example-entity=Permit
- ./bin/cli generate-bundle --vendor=myvendor --category=mycategory --unique-name=greenlight --friendly-name="Electronic Covid Access Permits" --example-entity=Permit
publish: publish:
stage: deploy stage: deploy
only: only:
......
#!/usr/bin/env php
<?php
/**
* This script generates DBP Symfony bundles
* Example parameters to show generated names:
* --unique-name=greenlight --friendly-name="Electronic Covid Access Permits" --example-entity=Permit
*
* Use "--generate-bundle" if you also want to generate the bundle in a subdirectory of the current directory
*/
declare(strict_types=1);
$longOpts = [
'vendor::',
'category::',
'unique-name:',
'friendly-name:',
'example-entity::',
'generate-bundle',
];
$options = getopt('', $longOpts);
if (!isset($options['unique-name'])) {
echo "Please set a --unique-name!\n";
exit(1);
}
if (!isset($options['friendly-name'])) {
echo "Please set a --friendly-name!\n";
exit(1);
}
$vendor = $options['vendor'] ?? 'dbp';
$category = $options['category'] ?? 'relay';
$uniqueName = $options['unique-name'];
$friendlyName = $options['friendly-name'];
$exampleEntity = $options['example-entity'] ?? 'Place';
$generateBundle = isset($options['generate-bundle']);
function plural(string $in): string
{
return $in.'s';
}
function normalize(string $in): string
{
return strtolower(str_replace(['-', '_'], ' ', $in));
}
function pascal(string $in): string
{
return str_replace(' ', '', ucwords(normalize($in)));
}
function kebap(string $in): string
{
return str_replace(' ', '-', normalize($in));
}
function snake(string $in): string
{
return str_replace(' ', '_', normalize($in));
}
function color(string $in): string
{
return "\033[32m".$in." \033[0m";
}
/**
* Lists all files in a folder by a pattern recursively
*/
function recursiveFileList($folder, $pattern): array
{
$dir = new RecursiveDirectoryIterator($folder);
$ite = new RecursiveIteratorIterator($dir);
$files = new RegexIterator($ite, $pattern, RegexIterator::GET_MATCH);
$fileList = array();
foreach($files as $file) {
if (is_file($file[0])) {
$fileList[] = $file[0];
}
}
return $fileList;
}
/**
* Replaces text in files recursively
*/
function recursiveFileTextReplace($folder, $pattern, $replace)
{
foreach(recursiveFileList($folder, "/.+/") as $file) {
$content = file_get_contents($file);
$content = str_replace($pattern, $replace, $content);
file_put_contents($file, $content);
}
}
$directoryName = kebap($category).'-'.kebap($uniqueName).'-bundle';
$composerPackageName = kebap($vendor).'/'.kebap($category).'-'.kebap($uniqueName).'-bundle';
printf("%25s: %s\n", 'Composer Package Name', color($composerPackageName));
$phpNamespace = pascal($vendor).'\\'.pascal($category).'\\'.pascal($uniqueName).'Bundle';
printf("%25s: %s\n", 'PHP Namespace', color($phpNamespace));
$symfonyBundleBaseName = pascal($vendor).pascal($category).pascal($uniqueName);
$symfonyBundleName = $symfonyBundleBaseName.'Bundle';
printf("%25s: %s\n", 'Symfony Bundle Name', color($symfonyBundleName));
$bundleConfigKey = snake($vendor.' '.$category.' '.$uniqueName);
printf("%25s: %s\n", 'Bundle Config Key', color($bundleConfigKey));
$phpClassName = pascal($exampleEntity);
$variableName = lcfirst($phpClassName);
printf("%25s: %s\n", 'PHP Class Name', color($phpClassName));
$apiPlatformShortName = pascal($uniqueName).pascal($exampleEntity);
printf("%25s: %s\n", 'API-Platform Short Name', color($apiPlatformShortName));
$resourcePath = '/'.kebap($uniqueName).'/'.kebap(plural($exampleEntity));
printf("%25s: %s\n", 'Resource Path', color($resourcePath));
$serializationGroup = pascal($uniqueName).pascal($exampleEntity).':some-group';
printf("%25s: %s\n", 'Serialization Group', color($serializationGroup));
$openAPITag = $friendlyName;
printf("%25s: %s\n", 'Open API Tag', color($openAPITag));
$gitRepositoryName = kebap($vendor).'-'.kebap($category).'-'.kebap($uniqueName).'-bundle';
printf("%25s: %s\n", 'GIT Repository Name', color($gitRepositoryName));
echo "\n";
if (!$generateBundle) {
exit;
}
exec("git clone --depth=1 https://gitlab.tugraz.at/dbp/relay/dbp-relay-template-bundle.git \"$directoryName\"", $output, $resultCode);
if ($resultCode !== 0) {
echo "Could not clone template bundle into directory '$directoryName'!\n";
exit -1;
}
if (!chdir($directoryName)) {
echo "Could not change to directory '$directoryName'!\n";
exit -1;
}
// Remove git folder
exec('rm -rf .git');
$args = [
'./.bundle-rename',
'--vendor='.escapeshellarg($vendor),
'--category='.escapeshellarg($category),
'--unique-name='.escapeshellarg($uniqueName),
'--friendly-name='.escapeshellarg($friendlyName),
'--example-entity='.escapeshellarg($exampleEntity),
];
$cmd = implode(' ', $args);
$res = exec($cmd);
if ($res === false) {
echo "failed";
exit -1;
}
exec('rm -rf .bundle-rename');
...@@ -60,12 +60,6 @@ case $1 in ...@@ -60,12 +60,6 @@ case $1 in
"update-app") "update-app")
update_app $2 update_app $2
;; ;;
"generate-bundle")
$BIN_PATH/bundle-generator --generate-bundle "${@:2}"
;;
"show-bundle-names")
$BIN_PATH/bundle-generator "${@:2}"
;;
*) *)
echo "Unknown command: $1"; echo "Unknown command: $1";
exit 1; exit 1;
......
...@@ -4,8 +4,7 @@ ...@@ -4,8 +4,7 @@
"description": "CLI to manage DBP frontend applications and Symfony bundles", "description": "CLI to manage DBP frontend applications and Symfony bundles",
"license": "LGPL-2.1-or-later", "license": "LGPL-2.1-or-later",
"bin": { "bin": {
"cli": "bin/cli", "cli": "bin/cli"
"bundle-generator": "bin/bundle-generator"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment