-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from torenware/factor-env-builder
Factor env builder
- Loading branch information
Showing
6 changed files
with
166 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,8 @@ | ||
#! /usr/bin/env bash | ||
#ddev-generated | ||
|
||
y_flag='' | ||
|
||
print_usage() { | ||
printf "Usage: $0 [-y]" | ||
} | ||
|
||
while getopts 'y' flag; do | ||
case "${flag}" in | ||
y) y_flag='true' ;; | ||
*) | ||
print_usage | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
# defaults | ||
PROJ_DIR=frontend | ||
|
||
# check for special cases | ||
if [ "$DDEV_PROJECT_TYPE" = "laravel" ]; then | ||
PROJ_DIR=. | ||
fi | ||
|
||
# @see https://stackoverflow.com/a/27650122/8600734 | ||
mapfile VITE_SETTINGS <<VITE | ||
# start vite | ||
VITE_PROJECT_DIR=$PROJ_DIR | ||
VITE_PRIMARY_PORT=5173 | ||
VITE_SECONDARY_PORT=5273 | ||
# end vite | ||
VITE | ||
|
||
echo "New settings are:" | ||
printf %s "${VITE_SETTINGS[@]}" | ||
echo "--------------" | ||
echo | ||
|
||
cd .ddev | ||
|
||
if [ -f "./.env" ]; then | ||
if grep "^# start vite" .env >/dev/null; then | ||
echo "Found vite settings in your .ddev/.env file." | ||
if [ -z "$y_flag" ]; then | ||
echo -n "Replace old settings (y/n)? " | ||
read replace | ||
else | ||
replace=y | ||
fi | ||
if [ "$replace" == "y" ]; then | ||
sed -i.bak '/^# start vite/,/^\# end vite/d;' .env | ||
printf %s "${VITE_SETTINGS[@]}" >>.env | ||
else | ||
echo "Skipping changes to your .env file." | ||
fi | ||
else | ||
echo "You have an existing .ddev/.env file." | ||
if [ -z "$y_flag" ]; then | ||
echo "May I append settings for this add-on to" | ||
echo -n "your .env file (y/n)? " | ||
read replace | ||
else | ||
replace=y | ||
fi | ||
|
||
if [ "$replace" == "y" ]; then | ||
printf %s "${VITE_SETTINGS[@]}" >>.env | ||
else | ||
echo "Skipping changes to your .env file." | ||
fi | ||
fi | ||
else | ||
echo "Create a .ddev/.env file with your add-on settings:" | ||
printf %s "${VITE_SETTINGS[@]}" >.env | ||
fi | ||
echo | ||
echo "Your .ddev/.env file now contains:" | ||
echo "----------------------------------" | ||
cat .env | ||
BASE_DIR=$(dirname $0) | ||
echo "BASEDIR $BASE_DIR" | ||
$BASE_DIR/build-dotenv1.sh "$@" | ||
$BASE_DIR/build-dotenv2.sh | ||
$BASE_DIR/build-dotenv3.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#! /usr/bin/env bash | ||
#ddev-generated | ||
|
||
y_flag='' | ||
|
||
print_usage() { | ||
printf "Usage: $0 [-y]" | ||
} | ||
|
||
while getopts 'y' flag; do | ||
case "${flag}" in | ||
y) y_flag='true' ;; | ||
*) | ||
print_usage | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
# defaults | ||
PROJ_DIR=frontend | ||
|
||
# check for special cases | ||
if [ "$DDEV_PROJECT_TYPE" = "laravel" ]; then | ||
PROJ_DIR=. | ||
fi | ||
|
||
# @see https://stackoverflow.com/a/27650122/8600734 | ||
mapfile VITE_SETTINGS <<VITE | ||
# start vite | ||
VITE_PROJECT_DIR=$PROJ_DIR | ||
VITE_PRIMARY_PORT=5173 | ||
VITE_SECONDARY_PORT=5273 | ||
# end vite | ||
VITE | ||
|
||
echo | ||
echo "New settings are:" | ||
printf %s "${VITE_SETTINGS[@]}" | ||
echo "--------------" | ||
echo | ||
|
||
cd .ddev | ||
if [ -f .allow-upgrade ]; then | ||
rm .allow-upgrade | ||
fi | ||
printf %s "${VITE_SETTINGS[@]}" >.env-frag | ||
|
||
allow_upgrade=${y_flag} | ||
|
||
if [ "$allow_upgrade" = "" ]; then | ||
if [ ! -f "./.env" ]; then | ||
allow_upgrade="true" | ||
else | ||
if grep "^# start vite" .env >/dev/null; then | ||
echo "Found vite settings in your .ddev/.env file." | ||
echo -n "Replace old settings (y/n)? " | ||
allow_upgrade=ask | ||
fi | ||
fi | ||
fi | ||
echo $allow_upgrade >.allow-upgrade |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#! /usr/bin/env bash | ||
#ddev-generated | ||
cd .ddev | ||
if [ -f .allow-upgrade ]; then | ||
if grep ask .allow-upgrade >/dev/null; then | ||
read replace | ||
if [ "$replace" = "y" ]; then | ||
echo "true" >.allow-upgrade | ||
else | ||
echo "false" >.allow-upgrade | ||
fi | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#! /usr/bin/env bash | ||
#ddev-generated | ||
cd .ddev | ||
if [ -f .allow-upgrade ]; then | ||
if grep "true" .allow-upgrade >/dev/null; then | ||
if [ -f .env ]; then | ||
sed -i.bak '/^# start vite/,/^\# end vite/d;' .env | ||
# strip weird null characters from sed output. | ||
tr <.env -d '\000' >.env-post-sed | ||
cat .env-post-sed .env-frag >.env | ||
echo ".env updated to:" | ||
cat .env | ||
rm .env-post-sed | ||
else | ||
cp .env-frag .env | ||
fi | ||
rm .env-frag | ||
fi | ||
fi |