Skip to content

Commit

Permalink
Improve personalization
Browse files Browse the repository at this point in the history
* To use perl instead of sed
* Handle new lines with \n
* Replace module template namespace in services.yaml

Signed-off-by: Anton Fedurtsya <[email protected]>
  • Loading branch information
Sieg committed Jun 3, 2024
1 parent 5c0930a commit 8f558e2
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions bin/personalize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,44 @@ module_id='oe_moduletemplate'
company='OXID eSales AG'
target_directory='oe/moduletemplate'

echo
echo "In order to convert this module template to your own, you will be asked for some information."
echo
echo "Please enter package name (original: $package_name):"
echo -e "\nIn order to convert this module template to your own, you will be asked for some information."
echo -e "\nPlease enter package name (original: $package_name):"
read -r package_name_input
sed -ri "s#$package_name#$package_name_input#g;" ./composer.json
sed -ri "s#$package_name#$package_name_input#g;" ./.github/oxid-esales/module-template.yaml
echo

echo "Please enter module namespace (original: $namespace):"
perl -pi -e "s#$package_name#$package_name_input#g;" ./composer.json
perl -pi -e "s#$package_name#$package_name_input#g;" ./.github/oxid-esales/module-template.yaml

echo -e "\nPlease enter module namespace (original: $namespace):"
# Prepare original namespace for replacement in composer.json file
namespace=$(echo "$namespace" | sed -r 's#\\#\\\\\\\\#g')
namespace=$(echo "$namespace" | perl -pe 's#\\#\\\\\\\\#g')
read -r namespace_input

# Extract vendor name from provided namespace, will be need for later use
vendor_name=$(echo "$namespace_input" | sed 's#\([^\\]*\)\\.*#\1#g')
vendor_name=$(echo "$namespace_input" | perl -pe 's#([^\\]*).*#\1#g')
# Extract module name from provided namespace, will be need for later use
module_name=$(echo "$namespace_input" | sed 's#.*\\\(.*\)#\1#g')
module_name=$(echo "$namespace_input" | perl -pe 's#.*\\(.*)#\1#g')

# Prepare provided namespace for replacement in composer.json file
namespace_input=$(echo "$namespace_input" | sed -r 's#\\{1,}#\\\\\\\\#g')
sed -ri "s#$namespace#$namespace_input#g;" ./composer.json
namespace_input=$(echo "$namespace_input" | perl -pe 's#\\{1,}#\\\\\\\\#g')
perl -pi -e "s#$namespace#$namespace_input#g;" ./composer.json

# Prepare original namespace for replacement in the module files by handling \ counts
namespace=$(echo "$namespace" | sed -r 's#\\\\\\\\#\\\\#g')
namespace=$(echo "$namespace" | perl -pe 's#\\\\\\\\#\\\\#g')
# Prepare input namespace for replacement in the module files by handling \ counts
namespace_input=$(echo "$namespace_input" | sed -r 's#\\\\\\\\#\\\\#g')
namespace_input=$(echo "$namespace_input" | perl -pe 's#\\\\\\\\#\\\\#g')
find . -type f \( ! -name "personalize.sh" -and ! -name "README.md" \) -exec grep -l "$namespace" {} \; |xargs perl -pi -e "s#$namespace#$namespace_input#g;"
echo

services_namespace=$(echo "$namespace" | perl -pe 's#\\\\#\\\\\\\\#g')
services_namespace_input=$(echo "$namespace_input" | perl -pe 's#\\\\#\\\\\\\\#g')
find . -type f \( ! -name "personalize.sh" -and ! -name "README.md" \) -exec grep -l "$services_namespace" {} \; |xargs perl -pi -e "s#$services_namespace#$services_namespace_input#g;"

# Compose module id based on <yourVendorPrefix> and <yourModuleRootDirectory> directories
module_root_directory=${PWD##*/}
vendor_directory_path=$(echo "$PWD" | sed -r "s#$module_root_directory##g")
vendor_directory_path=$(echo "$PWD" | perl -pe "s#$module_root_directory##g")
vendor_prefix="${vendor_directory_path%"${vendor_directory_path##*[!/]}"}"
vendor_prefix="${vendor_prefix##*/}"
composed_module_id="${vendor_prefix}_${module_root_directory}"
echo "Your module id is: '$composed_module_id'!"
echo
echo -e "\nYour module id is: '$composed_module_id'!"

# Replace module id everywhere except in this file
find . -type f \( ! -name "personalize.sh" -and ! -name "README.md" \) -exec grep -l "$module_id" {} \; |xargs perl -pi -e "s#$module_id#$composed_module_id#g;"
Expand All @@ -52,19 +55,19 @@ find . -type f \( ! -name "personalize.sh" -and ! -name "README.md" \) -exec gre
perl -pi -e "s#OxidEsales Module Template \(OEMT\)#CHANGE MY TITLE#g;" ./metadata.php

#File headers
echo "Please enter company name (original: $company)"
echo -e "\nPlease enter company name (original: $company)"
read company_input
find . -type f \( ! -name "personalize.sh" \) -exec grep -l "$company" {} \; |xargs perl -pi -e "s#$company#$company_input#g;"

#target directory
composed_target_directory="${vendor_prefix}/${module_root_directory}"
perl -pi -e "s#$target_directory#$composed_target_directory#g;" ./composer.json
perl -pi -e "s#$target_directory#$composed_target_directory#g;" ./metadata.php
perl -pi -e "s#$target_directory#$composed_target_directory#g;" ./tests/Codeception/acceptance.suite.yml
perl -pi -e "s#$target_directory#$composed_target_directory#g;" ./tests/Codeception/Acceptance.suite.yml
perl -pi -e "s#$target_directory#$composed_target_directory#g;" ./.github/oxid-esales/module-template.yaml

#update acceptance suite
perl -pi -e "s#$package_name#$package_name_input#g;" ./tests/Codeception/acceptance.suite.yml
perl -pi -e "s#$package_name#$package_name_input#g;" ./tests/Codeception/Acceptance.suite.yml

# Prepare ./.github/workflows/development.yml file
perl -pi -e "s#project_key: 'OXID-eSales_module-template'#project_key: 'CHANGE SONARCLOUD ORGANIZATION'#g;" ./.github/oxid-esales/module-template.yaml
Expand All @@ -79,5 +82,4 @@ perl -0777pi\
-e 's#(^.*?\#\# \[1\.0\.0\] - Unreleased)(.*?)$#\1#gs'\
./CHANGELOG.md

echo
echo 'Please review and commit the changes. Your module is now ready to go and be adapted to your needs.'
echo -e "Please review and commit the changes. Your module is now ready to go and be adapted to your needs."

0 comments on commit 8f558e2

Please sign in to comment.