diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4a07e5605ee0dab31125f15a546a913f464d7c72..994bec05f006bccfff5ceecb34dd74dc0df7b1aa 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,12 +4,6 @@ stages: - test - 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: stage: deploy only: diff --git a/bin/bundle-generator b/bin/bundle-generator deleted file mode 100755 index 3044182f7e8e1dc7a1dc67acfab7bd7e20f39e96..0000000000000000000000000000000000000000 --- a/bin/bundle-generator +++ /dev/null @@ -1,156 +0,0 @@ -#!/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'); diff --git a/bin/cli b/bin/cli index 4d5c2fb7e7e0721ec6cada3baad5e2513f53bfdc..20f7de145d4e9e3deedf87da2830ff3d0eec5a90 100755 --- a/bin/cli +++ b/bin/cli @@ -60,12 +60,6 @@ case $1 in "update-app") update_app $2 ;; -"generate-bundle") - $BIN_PATH/bundle-generator --generate-bundle "${@:2}" -;; -"show-bundle-names") - $BIN_PATH/bundle-generator "${@:2}" -;; *) echo "Unknown command: $1"; exit 1; diff --git a/package.json b/package.json index f4c0a8ae2ef926f1630392ea626882df31059f84..d2a9286156b6c08c61a792899731c996784a4bec 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,7 @@ "description": "CLI to manage DBP frontend applications and Symfony bundles", "license": "LGPL-2.1-or-later", "bin": { - "cli": "bin/cli", - "bundle-generator": "bin/bundle-generator" + "cli": "bin/cli" }, "repository": { "type": "git",