feat core: Transition -install to new logging method

This commit is contained in:
prplwtf 2024-01-15 18:34:11 +01:00
parent f763638361
commit 3310b20cdb

View file

@ -238,8 +238,8 @@ if [[ $1 != "-bash" ]]; then
PRINT INFO "Put application into maintenance mode." PRINT INFO "Put application into maintenance mode."
php artisan down &>> $BLUEPRINT__DEBUG php artisan down &>> $BLUEPRINT__DEBUG
# Clear view cache. # Flush cache.
PRINT INFO "Clearing view, config and route cache.." PRINT INFO "Flushing view, config and route cache.."
{ {
php artisan view:clear php artisan view:clear
php artisan config:clear php artisan config:clear
@ -707,7 +707,6 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) ]]; then VCMD="y"
ln -s -T $FOLDER/.blueprint/extensions/"$identifier"/public "$identifier" 2>> $BLUEPRINT__DEBUG ln -s -T $FOLDER/.blueprint/extensions/"$identifier"/public "$identifier" 2>> $BLUEPRINT__DEBUG
cd $FOLDER || throw 'cdMissingDirectory' cd $FOLDER || throw 'cdMissingDirectory'
log_bright "[INFO] Placing public directory contents.."
cp -R ".blueprint/tmp/$n/$data_public/"* ".blueprint/extensions/$identifier/public/" 2>> $BLUEPRINT__DEBUG cp -R ".blueprint/tmp/$n/$data_public/"* ".blueprint/extensions/$identifier/public/" 2>> $BLUEPRINT__DEBUG
fi fi
@ -727,24 +726,22 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) ]]; then VCMD="y"
# Start creating data directory. # Start creating data directory.
log_bright "[INFO] Creating data directory.." PRINT INFO "Cloning and linking private directory.."
mkdir -p ".blueprint/extensions/$identifier/private" mkdir -p ".blueprint/extensions/$identifier/private"
mkdir -p ".blueprint/extensions/$identifier/private/.store" mkdir -p ".blueprint/extensions/$identifier/private/.store"
log_bright "[INFO] Caching extension config inside of data directory.." if [[ $data_directory != "" ]]; then cp -R ".blueprint/tmp/$n/$data_directory/"* ".blueprint/extensions/$identifier/private/"; fi
cp ".blueprint/tmp/$n/conf.yml" ".blueprint/extensions/$identifier/private/.store/conf.yml" #backup conf.yml cp ".blueprint/tmp/$n/conf.yml" ".blueprint/extensions/$identifier/private/.store/conf.yml" #backup conf.yml
if [[ -f ".blueprint/tmp/$n/$dashboard_components/Components.yml" ]]; then if [[ -f ".blueprint/tmp/$n/$dashboard_components/Components.yml" ]]; then
cp ".blueprint/tmp/$n/$dashboard_components/Components.yml" ".blueprint/extensions/$identifier/private/.store/Components.yml" #backup Components.yml cp ".blueprint/tmp/$n/$dashboard_components/Components.yml" ".blueprint/extensions/$identifier/private/.store/Components.yml" #backup Components.yml
fi fi
if [[ $data_directory != "" ]]; then
log_bright "[INFO] Placing private directory contents.."
cp -R ".blueprint/tmp/$n/$data_directory/"* ".blueprint/extensions/$identifier/private/"
fi
# End creating data directory. # End creating data directory.
# Link and create assets folder. # Link and create assets folder
PRINT INFO "Linking and writing assets directory.."
if [[ $DUPLICATE != "y" ]]; then if [[ $DUPLICATE != "y" ]]; then
# Create assets folder if the extension is not updating. # Create assets folder if the extension is not updating.
mkdir .blueprint/extensions/"$identifier"/assets mkdir .blueprint/extensions/"$identifier"/assets
@ -765,26 +762,26 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) ]]; then VCMD="y"
CONTENT=$(cat .blueprint/tmp/"$n"/"$admin_view") CONTENT=$(cat .blueprint/tmp/"$n"/"$admin_view")
if [[ $admin_css != "" ]]; then if [[ $admin_css != "" ]]; then
log_bright "[INFO] Placing admin css.." PRINT INFO "Cloning and linking admin css.."
updateCacheReminder updateCacheReminder
sed -i "s~@import url(/assets/extensions/$identifier/admin.style.css);~~g" ".blueprint/extensions/blueprint/assets/admin.extensions.css" sed -i "s~@import url(/assets/extensions/$identifier/admin.style.css);~~g" ".blueprint/extensions/blueprint/assets/admin.extensions.css"
echo -e "@import url(/assets/extensions/$identifier/admin.style.css);" >> ".blueprint/extensions/blueprint/assets/admin.extensions.css" echo -e "@import url(/assets/extensions/$identifier/admin.style.css);" >> ".blueprint/extensions/blueprint/assets/admin.extensions.css"
cp ".blueprint/tmp/$n/$admin_css" ".blueprint/extensions/$identifier/assets/admin.style.css" cp ".blueprint/tmp/$n/$admin_css" ".blueprint/extensions/$identifier/assets/admin.style.css"
fi fi
if [[ $dashboard_css != "" ]]; then if [[ $dashboard_css != "" ]]; then
log_bright "[INFO] Placing dashboard css.." PRINT INFO "Cloning and linking dashboard css.."
YARN="y" YARN="y"
sed -i "s~@import url(./imported/$identifier.css);~~g" "resources/scripts/blueprint/css/extensions.css" sed -i "s~@import url(./imported/$identifier.css);~~g" "resources/scripts/blueprint/css/extensions.css"
echo -e "@import url(./imported/$identifier.css);" >> "resources/scripts/blueprint/css/extensions.css" echo -e "@import url(./imported/$identifier.css);" >> "resources/scripts/blueprint/css/extensions.css"
cp ".blueprint/tmp/$n/$dashboard_css" "resources/scripts/blueprint/css/imported/$identifier.css" cp ".blueprint/tmp/$n/$dashboard_css" "resources/scripts/blueprint/css/imported/$identifier.css"
fi fi
if [[ $name == *"~"* ]]; then log_yellow "[WARNING] 'name' contains '~' and may result in an error.";fi if [[ $name == *"~"* ]]; then PRINT WARNING "'name' contains '~' and may result in an error.";fi
if [[ $description == *"~"* ]]; then log_yellow "[WARNING] 'description' contains '~' and may result in an error.";fi if [[ $description == *"~"* ]]; then PRINT WARNING "'description' contains '~' and may result in an error.";fi
if [[ $version == *"~"* ]]; then log_yellow "[WARNING] 'version' contains '~' and may result in an error.";fi if [[ $version == *"~"* ]]; then PRINT WARNING "'version' contains '~' and may result in an error.";fi
if [[ $CONTENT == *"~"* ]]; then log_yellow "[WARNING] 'CONTENT' contains '~' and may result in an error.";fi if [[ $CONTENT == *"~"* ]]; then PRINT WARNING "'CONTENT' contains '~' and may result in an error.";fi
if [[ $ICON == *"~"* ]]; then log_yellow "[WARNING] 'ICON' contains '~' and may result in an error.";fi if [[ $ICON == *"~"* ]]; then PRINT WARNING "'ICON' contains '~' and may result in an error.";fi
if [[ $identifier == *"~"* ]]; then log_yellow "[WARNING] 'identifier' contains '~' and may result in an error.";fi if [[ $identifier == *"~"* ]]; then PRINT WARNING "'identifier' contains '~' and may result in an error.";fi
# Replace $name variables. # Replace $name variables.
sed -i "s~␀title␀~$name~g" ".blueprint/extensions/blueprint/private/build/extensions/admin.blade.php.bak" sed -i "s~␀title␀~$name~g" ".blueprint/extensions/blueprint/private/build/extensions/admin.blade.php.bak"
@ -830,11 +827,13 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) ]]; then VCMD="y"
ADMINCONTROLLER_NAME="${identifier}ExtensionController.php" ADMINCONTROLLER_NAME="${identifier}ExtensionController.php"
# Place admin extension view. # Place admin extension view.
PRINT INFO "Cloning admin view.."
mkdir -p "resources/views/admin/extensions/$identifier" mkdir -p "resources/views/admin/extensions/$identifier"
touch "resources/views/admin/extensions/$identifier/index.blade.php" touch "resources/views/admin/extensions/$identifier/index.blade.php"
echo "$ADMINVIEW_RESULT" > "resources/views/admin/extensions/$identifier/index.blade.php" echo "$ADMINVIEW_RESULT" > "resources/views/admin/extensions/$identifier/index.blade.php"
# Place admin extension view controller. # Place admin extension view controller.
PRINT INFO "Cloning admin controller.."
mkdir -p "app/Http/Controllers/Admin/Extensions/$identifier" mkdir -p "app/Http/Controllers/Admin/Extensions/$identifier"
touch "app/Http/Controllers/Admin/Extensions/$identifier/$ADMINCONTROLLER_NAME" touch "app/Http/Controllers/Admin/Extensions/$identifier/$ADMINCONTROLLER_NAME"
if [[ $controller_type == "default" ]]; then if [[ $controller_type == "default" ]]; then
@ -848,6 +847,7 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) ]]; then VCMD="y"
if [[ $DUPLICATE != "y" ]]; then if [[ $DUPLICATE != "y" ]]; then
# Place admin route if extension is not updating. # Place admin route if extension is not updating.
PRINT INFO "Editing admin routes.."
{ echo " { echo "
// $identifier:start"; // $identifier:start";
echo "$ADMINROUTE_RESULT"; echo "$ADMINROUTE_RESULT";
@ -861,7 +861,7 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) ]]; then VCMD="y"
# Place dashboard wrapper # Place dashboard wrapper
if [[ $dashboard_wrapper != "" ]]; then if [[ $dashboard_wrapper != "" ]]; then
log_bright "[INFO] Placing dashboard wrapper.." PRINT INFO "Cloning and injecting dashboard wrapper.."
if [[ $DUPLICATE == "y" ]]; then if [[ $DUPLICATE == "y" ]]; then
sed -n -i "/<!--␀$identifier:start␀-->/{p; :a; N; /<!--␀$identifier:stop␀-->/!ba; s/.*\n//}; p" "resources/views/templates/wrapper.blade.php" sed -n -i "/<!--␀$identifier:start␀-->/{p; :a; N; /<!--␀$identifier:stop␀-->/!ba; s/.*\n//}; p" "resources/views/templates/wrapper.blade.php"
sed -i "s~<!--␀$identifier:start␀-->~~g" "resources/views/templates/wrapper.blade.php" sed -i "s~<!--␀$identifier:start␀-->~~g" "resources/views/templates/wrapper.blade.php"
@ -877,7 +877,7 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) ]]; then VCMD="y"
# Place admin wrapper # Place admin wrapper
if [[ $admin_wrapper != "" ]]; then if [[ $admin_wrapper != "" ]]; then
log_bright "[INFO] Placing admin wrapper.." PRINT INFO "Cloning and injecting admin wrapper.."
if [[ $DUPLICATE == "y" ]]; then if [[ $DUPLICATE == "y" ]]; then
sed -n -i "/<!--␀$identifier:start␀-->/{p; :a; N; /<!--␀$identifier:stop␀-->/!ba; s/.*\n//}; p" "resources/views/layouts/admin.blade.php" sed -n -i "/<!--␀$identifier:start␀-->/{p; :a; N; /<!--␀$identifier:stop␀-->/!ba; s/.*\n//}; p" "resources/views/layouts/admin.blade.php"
sed -i "s~<!--␀$identifier:start␀-->~~g" "resources/views/layouts/admin.blade.php" sed -i "s~<!--␀$identifier:start␀-->~~g" "resources/views/layouts/admin.blade.php"
@ -892,51 +892,52 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) ]]; then VCMD="y"
fi fi
# Create backup of generated values. # Create backup of generated values.
log_bright "[INFO] Backing up (some) build files.."
mkdir -p ".blueprint/extensions/$identifier/private/.store/build" mkdir -p ".blueprint/extensions/$identifier/private/.store/build"
cp ".blueprint/extensions/blueprint/private/build/extensions/button.blade.php.bak" ".blueprint/extensions/$identifier/private/.store/build/button.blade.php" cp ".blueprint/extensions/blueprint/private/build/extensions/button.blade.php.bak" ".blueprint/extensions/$identifier/private/.store/build/button.blade.php"
cp ".blueprint/extensions/blueprint/private/build/extensions/route.php.bak" ".blueprint/extensions/$identifier/private/.store/build/route.php" cp ".blueprint/extensions/blueprint/private/build/extensions/route.php.bak" ".blueprint/extensions/$identifier/private/.store/build/route.php"
# Remove temporary built files. # Remove temporary built files.
log_bright "[INFO] Cleaning up temporary built files.." PRINT INFO "Cleaning up build files.."
rm ".blueprint/extensions/blueprint/private/build/extensions/admin.blade.php.bak" rm ".blueprint/extensions/blueprint/private/build/extensions/admin.blade.php.bak"
if [[ $controller_type == "default" ]]; then if [[ $controller_type == "default" ]]; then
rm ".blueprint/extensions/blueprint/private/build/extensions/controller.php.bak" rm ".blueprint/extensions/blueprint/private/build/extensions/controller.php.bak"
fi fi
rm ".blueprint/extensions/blueprint/private/build/extensions/route.php.bak" rm ".blueprint/extensions/blueprint/private/build/extensions/route.php.bak"
rm ".blueprint/extensions/blueprint/private/build/extensions/button.blade.php.bak" rm ".blueprint/extensions/blueprint/private/build/extensions/button.blade.php.bak"
log_bright "[INFO] Cleaning up temp files.."
rm -R ".blueprint/tmp/$n" rm -R ".blueprint/tmp/$n"
if [[ $database_migrations != "" ]]; then if [[ $database_migrations != "" ]]; then
log_blue "[INPUT] Do you want to migrate your database? (Y/n)" PRINT INPUT "Would you like to migrate your database? (Y/n)"
read -r YN read -r YN
if [[ ( $YN == "y"* ) || ( $YN == "Y"* ) || ( $YN == "" ) ]]; then if [[ ( $YN == "y"* ) || ( $YN == "Y"* ) || ( $YN == "" ) ]]; then
log_bright "[INFO] Running database migrations.." PRINT INFO "Running database migrations.."
php artisan migrate --force php artisan migrate --force
else else
log_bright "[INFO] Database migrations have been skipped." PRINT INFO "Database migrations have been skipped."
fi fi
fi fi
if [[ $YARN == "y" ]]; then if [[ $YARN == "y" ]]; then
if [[ ( $F_developerIgnoreRebuild == true ) && ( $dev == true ) ]]; then if ! [[ ( $F_developerIgnoreRebuild == true ) && ( $dev == true ) ]]; then
log_yellow "[WARNING] Rebuilding skipped due to 'developerIgnoreRebuild' flag being present." PRINT INFO "Rebuilding panel assets.."
else
log_bright "[INFO] Rebuilding panel.."
yarn run build:production yarn run build:production
fi fi
fi fi
log_bright "[INFO] Updating route cache to include recent changes.." # Flush cache.
php artisan route:cache &>> $BLUEPRINT__DEBUG PRINT INFO "Flushing view, config and route cache.."
{
php artisan view:clear
php artisan config:clear
php artisan route:cache
} &>> $BLUEPRINT__DEBUG
chown -R www-data:www-data "$FOLDER/.blueprint/extensions/$identifier/private" chown -R www-data:www-data "$FOLDER/.blueprint/extensions/$identifier/private"
chmod --silent -R +x ".blueprint/extensions/"* 2>> $BLUEPRINT__DEBUG chmod --silent -R +x ".blueprint/extensions/"* 2>> $BLUEPRINT__DEBUG
if [[ ( $F_developerIgnoreInstallScript == false ) || ( $dev != true ) ]]; then if [[ ( $F_developerIgnoreInstallScript == false ) || ( $dev != true ) ]]; then
if $F_hasInstallScript; then if $F_hasInstallScript; then
log_yellow "[WARNING] This extension uses a custom installation script, proceed with caution." PRINT WARNING "Extension runs a custom installation script, proceed with caution."
chmod +x ".blueprint/extensions/$identifier/private/install.sh" chmod +x ".blueprint/extensions/$identifier/private/install.sh"
# Run script while also parsing some useful variables for the install script to use. # Run script while also parsing some useful variables for the install script to use.
@ -950,24 +951,22 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) ]]; then VCMD="y"
echo -e "\e[0m\x1b[0m\033[0m" echo -e "\e[0m\x1b[0m\033[0m"
fi fi
else
log_bright "[INFO] Custom installation scripts will be skipped on developer commands due to the 'developerIgnoreInstallScript' flag."
fi fi
if [[ $DUPLICATE != "y" ]]; then if [[ $DUPLICATE != "y" ]]; then
PRINT INFO "Add '$identifier' to installed extensions list.."
echo "${identifier}," >> ".blueprint/extensions/blueprint/private/db/installed_extensions" echo "${identifier}," >> ".blueprint/extensions/blueprint/private/db/installed_extensions"
log_bright "[INFO] Added '$identifier' to the list of installed extensions."
fi fi
if [[ $dev != true ]]; then if [[ $dev != true ]]; then
if [[ $DUPLICATE == "y" ]]; then if [[ $DUPLICATE == "y" ]]; then
log_green "\n\n[SUCCESS] $identifier should now be updated." PRINT SUCCESS "$identifier has been updated."
else else
log_green "\n\n[SUCCESS] $identifier should now be installed." PRINT SUCCESS "$identifier has been installed."
fi fi
sendTelemetry "FINISH_EXTENSION_INSTALLATION" >> $BLUEPRINT__DEBUG sendTelemetry "FINISH_EXTENSION_INSTALLATION" >> $BLUEPRINT__DEBUG
elif [[ $dev == true ]]; then elif [[ $dev == true ]]; then
log_green "\n\n[SUCCESS] $identifier should now be built." PRINT SUCCESS "$identifier has been built."
sendTelemetry "BUILD_DEVELOPMENT_EXTENSION" >> $BLUEPRINT__DEBUG sendTelemetry "BUILD_DEVELOPMENT_EXTENSION" >> $BLUEPRINT__DEBUG
fi fi
fi fi
@ -1199,8 +1198,13 @@ if [[ ( $2 == "-r" ) || ( $2 == "-remove" ) ]]; then VCMD="y"
yarn run build:production yarn run build:production
fi fi
log_bright "[INFO] Updating route cache to include recent changes.." # Flush cache.
php artisan route:cache &>> $BLUEPRINT__DEBUG PRINT INFO "Flushing view, config and route cache.."
{
php artisan view:clear
php artisan config:clear
php artisan route:cache
} &>> $BLUEPRINT__DEBUG
# Remove from installed list # Remove from installed list
log_bright "[INFO] Removing extension from installed extensions list.." log_bright "[INFO] Removing extension from installed extensions list.."
@ -1644,13 +1648,13 @@ if [[ $2 == "-upgrade" ]]; then VCMD="y"
bash blueprint.sh --post-upgrade bash blueprint.sh --post-upgrade
# Ask user if they'd like to migrate their database. # Ask user if they'd like to migrate their database.
log_blue "[INPUT] Do you want to migrate your database? (Y/n)" PRINT INPUT "Would you like to migrate your database? (Y/n)"
read -r YN read -r YN
if [[ ( ${YN} == "y" ) || ( ${YN} == "Y" ) || ( ${YN} == "" ) ]]; then if [[ ( $YN == "y"* ) || ( $YN == "Y"* ) || ( $YN == "" ) ]]; then
log_bright "[INFO] Running database migrations.." PRINT INFO "Running database migrations.."
php artisan migrate --force php artisan migrate --force
else else
log_bright "[INFO] Database migrations have been skipped." PRINT INFO "Database migrations have been skipped."
fi fi
YN="" YN=""