Skip to content

Commit

Permalink
🐛 FIX: splice in changes from https://github.com/apolopena/q-and-a-ch…
Browse files Browse the repository at this point in the history
  • Loading branch information
apolopena committed Mar 4, 2021
1 parent 9898b4d commit b892185
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 72 deletions.
20 changes: 18 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
# Begin: merged in from laravel8 starter project
.starter.env
/vendor/
/node_modules/
/public/phpmyadmin
# END: merged in from laravel8 starter project
/node_modules
/public/hot
/public/storage
/storage/*.key
/vendor
.env
.env.backup
.phpunit.result.cache
docker-compose.override.yml
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
# Laravel Mix artifacts
/public/js
/public/css
/public/build
/public/mix-manifest.json
4 changes: 2 additions & 2 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ RUN sudo touch /var/log/xdebug.log \
&& sudo chmod 666 /var/log/xdebug.log

RUN sudo apt-get update -q \
&& sudo apt-get install -y php-dev

&& sudo apt-get install -y rsync
RUN wget http://xdebug.org/files/xdebug-3.0.2.tgz \
&& tar -xvzf xdebug-3.0.2.tgz \
&& cd xdebug-3.0.2 \
Expand Down
13 changes: 11 additions & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
image:
file: .gitpod.Dockerfile

ports:
- port: 8001
onOpen: ignore
Expand All @@ -16,10 +16,14 @@ tasks:
init: |
bash bash/init-gitpod.sh &&
bash bash/init-optional-scaffolding.sh &&
bash bash/init-project.sh &&
bash bash/init-complete.sh
name: Startup
- openMode: split-left
command: |
if [ $(bash bash/helpers.sh is_inited) == 1 ]; then \
gp sync-done gitpod-inited
fi;
UP=$(pgrep mysql | wc -l); \
if [ "$UP" -ne 1 ]; then \
. bash/third-party/spinner.sh &&
Expand All @@ -33,7 +37,12 @@ tasks:
name: Web Server
- openMode: split-top
command: |
default_server=$(bash bash/utils.sh parse_ini_value starter.ini development default_server); open_preview $default_server
. bash/third-party/spinner.sh &&
start_spinner "Opening preview when system is ready..."
gp sync-await gitpod-inited &&
default_server=$(bash bash/utils.sh parse_ini_value starter.ini development default_server); \
open_preview $default_server &&
stop_spinner $?
name: Main Terminal

vscode:
Expand Down
76 changes: 60 additions & 16 deletions bash/init-gitpod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,28 @@ start_spinner "Initializing MySql..." &&
gp await-port 3306 &&
stop_spinner $?

# Bootstrap scaffolding
if [ ! -d "$GITPOD_REPO_ROOT/bootstrap" ]; then
msg="\nMoving Laravel project from ~/temp-app to $GITPOD_REPO_ROOT"
# BEGIN: Bootstrap Laravel scaffolding

# Move Laravel project files if they are not already in version control
if [ ! -d "$GITPOD_REPO_ROOT/vendor" ]; then
msg="\nMoving Laravel project from ~/temp-app to $GITPOD_REPO_ROOT using rsync"
# TODO: replace spinner with a real progress bar for coreutils
log_silent "$msg" && start_spinner "$msg"
shopt -s dotglob
mv --no-clobber ~/test-app/* $GITPOD_REPO_ROOT
rsync -rlptgoD --ignore-existing ~/test-app/ $GITPOD_REPO_ROOT
err_code=$?
if [ $err_code != 0 ]; then
stop_spinner $err_code
log "ERROR: Failed to move Laravel project from ~/temp-app to $GITPOD_REPO_ROOT" -e
log "ERROR: Failed to move Laravel project from ~/temp-app to $GITPOD_REPO_ROOT using rsync" -e
else
stop_spinner $err_code
log "SUCCESS: moved Laravel project from ~/temp-app to $GITPOD_REPO_ROOT"
log "SUCCESS: moved Laravel project from ~/temp-app to $GITPOD_REPO_ROOT using rsync"
fi

# BEGIN: parse configurations

# Configure .editorconfig
if [ -e .editorconfig ]; then
if [ -e .editorconfig ]; then
ec_type=$(bash bash/utils.sh parse_ini_value starter.ini .editorconfig type)
case $(echo "$ec_type" | tr '[:upper:]' '[:lower:]') in
'laravel-js-2space')
Expand All @@ -59,17 +61,45 @@ if [ ! -d "$GITPOD_REPO_ROOT/bootstrap" ]; then
;;
esac
fi
# Laravel .env

# Laravel .env
[ -e .env ] && url=$(gp url 8000); sed -i'' "s#^APP_URL=http://localhost*#APP_URL=$url\nASSET_URL=$url#g" .env
# END: parse configurations

# Create laravel database if it does not exist
# TODO: think more about making this dynamic as per .env
__laravel_db_exists=$(mysqlshow 2>/dev/null | grep laravel >/dev/null 2>&1 && echo "1" || echo "0")
if [ $__laravel_db_exists == 0 ]; then
__laravel_db_msg="laravel database did not exist in mysql. Creating database: laravel"
log_silent "$__laravel_db_msg" && start_spinner "$__laravel_db_msg"
mysql -e "CREATE DATABASE laravel;"
err_code=$?
if [ $err_code != 0 ]; then
stop_spinner $err_code
log "ERROR: Failed to move createe mysql database: laravel" -e
else
stop_spinner $err_code
log "SUCCESS: created mysql database: laravel"
fi
fi
# Install node packages if needed, in case the Laravel Ui front end is already in version control
if [[ -f "package.json" && ! -d "node_modules" ]]; then
log "Found a package.json but there are no node modules installed"
log " --> Assume that there is Laravel ui frontend scaffolding already installed"
log " --> Installing node packages..."
yarn install
log " --> Node packages installed"
log " --> Running Laravel Mix..."
yarn run dev
log " --> Running Laravel Mix complete"
fi

# BEGIN: Optional configurations
# Super user account for phpmyadmin
installed_phpmyadmin=$(. bash/utils.sh parse_ini_value starter.ini phpmyadmin install)
if [ "$installed_phpmyadmin" == 1 ]; then
msg="Creating phpmyadmin superuser: pmasu"
log_silent "$msg" && start_spinner "$msg"
log_silent "$msg" && start_spinner "$msg"
mysql -e "CREATE USER 'pmasu'@'%' IDENTIFIED BY '123456';"
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'pmasu'@'%';"
err_code=$?
Expand All @@ -79,6 +109,20 @@ if [ ! -d "$GITPOD_REPO_ROOT/bootstrap" ]; then
else
stop_spinner $err_code
fi
if [ ! -d 'public/phpmyadmin/node_modules' ]; then
log "phpmyadmin node modules have not yet been installed, installing now..."
cd public/phpmyadmin && yarn install && cd ../../
if [ $? == 0 ]; then
__pmaurl=$(gp url 8001)/phpmyadmin
log "phpmyadmin node modules installed."
log "To login to phpmyadmin:"
log " --> 1. Make sure you are serving it with apache"
log " --> 2. In the browser go to $__pmaurl"
log " --> 3. You should be able to login here using the default account. user: pmasu, pw: 123456"
else
log "ERROR: installing phpmyadmin node modules. Try installing them manually." -e
fi
fi
fi
# Install https://github.com/github-changelog-generator/github-changelog-generator
installed_changelog_gen=$(bash bash/utils.sh parse_ini_value starter.ini github-changelog-generator install)
Expand All @@ -90,14 +134,14 @@ if [ ! -d "$GITPOD_REPO_ROOT/bootstrap" ]; then
fi
# END: Optional configurations

# Move and or merge necessary failes then cleanup
(echo; cat ~/test-app/.gitignore) >> $GITPOD_REPO_ROOT/.gitignore && rm ~/test-app/.gitignore
# Move and merge necessary files, then cleanup
mv ~/test-app/README.md $GITPOD_REPO_ROOT/README_LARAVEL.md
rmdir ~/test-app
rm -rf ~/test-app
fi
# END: Bootstrap Laravel scaffolding

# Messages for github_changelog_generator
[ "$installed_changelog_gen" == 1 ] &&
[ "$installed_changelog_gen" == 1 ] &&
log "You may auto generate a CHANGELOG.md from github commits by running the command:\nrake changelog [...options]\n" &&
log "See starter.ini (github_changelog_generator section) for configurable options" &&
log "For a full list of options see the github-changelog-generator repository on github"
log "For a full list of options see the github-changelog-generator repository on github"
114 changes: 66 additions & 48 deletions bash/init-optional-scaffolding.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,23 @@ install_bootstrap=$(eval $parse bootstrap install)
# BEGIN: Install Laravel ui if needed
if [[ $install_react == 1 || $install_bootstrap == 1 ]]; then
log "Optional installations that require laravel/ui scaffolding were found"
log "Installing laravel/ui scaffolding"
composer require laravel/ui:^3.2.0
err_code=$?
if [ $err_code == 0 ]; then
log "SUCCESS: laravel/ui scaffolding installed"
log "Compiling fresh scaffolding and running Laravel Mix"
yarn install && yarn run dev

# Assume we are using composer 2 or higher, check if the laravel/ui package has already been installed
composer show | grep laravel/ui >/dev/null && __ui=1 || __ui=0

if [ "$__ui" == 1 ]; then
log "However it appears that laravel/ui has already been installed, skipping this installation."
else
log "ERROR $err_code: There was a problem installing laravel/ui" -e
log "Installing laravel/ui scaffolding"
composer require laravel/ui:^3.2.0
err_code=$?
if [ $err_code == 0 ]; then
log "SUCCESS: laravel/ui scaffolding installed"
log "Compiling fresh scaffolding and running Laravel Mix"
yarn install && yarn run dev
else
log "ERROR $err_code: There was a problem installing laravel/ui" -e
fi
fi
fi
# END: Install Laravel ui if needed
Expand All @@ -48,29 +56,34 @@ fi
if [ "$install_react" == 1 ]; then
version=$(eval $parse react version)
auth=$(eval $parse react auth)
__installed=$(bash bash/utils.sh node_package_exists react)
[ -z "$version" ] && version_msg='' || version_msg=" version $version"
[ "$auth" != 1 ] && auth_msg='' || auth_msg=' with --auth'
log "React/React DOM install directive found in starter.ini"
log "Installing React and React DOM"
if [ "$auth" == 1 ]; then
php artisan ui react --auth
if [ "$__installed" == 1 ]; then
log "However it appears that React/React DOM has already been installed, skipping this installation."
else
php artisan ui react
fi
err_code=$?
if [ $err_code == 0 ]; then
log "SUCCESS: React and React DOM$version_msg$auth_msg has been installed"
log "Compiling fresh scaffolding and running Laravel Mix"
yarn install && yarn run dev && sleep 1 && yarn run dev
if [ ! -z "$version" ]; then
log "Setting react and react-dom to$version_msg"
# TODO: validate semver and valid version for the package so users cant pass in junk
yarn upgrade react@$version react-dom@$version
log "Installing React and React DOM"
if [ "$auth" == 1 ]; then
php artisan ui react --auth
else
php artisan ui react
fi
err_code=$?
if [ $err_code == 0 ]; then
log "SUCCESS: React and React DOM$version_msg$auth_msg have been installed"
log "Compiling fresh scaffolding and running Laravel Mix"
yarn install && yarn run dev && sleep 1 && yarn run dev
if [ ! -z "$version" ]; then
log "Setting react and react-dom to$version_msg"
# TODO: validate semver and valid version for the package so users cant pass in junk
yarn upgrade react@$version react-dom@$version
fi
[ "$install_bootstrap" == 1 ] && log "Bootstrap install directive found but ignored. Already installed"
[ "$install_vue" == 1 ] && log "Vue install directive found but ignored. The install of react superceded this"
else
log "ERROR $err_code: There was a problem installing React/React DOM$version_msg$auth_msg" -e
fi
[ "$install_bootstrap" == 1 ] && log "Bootstrap install directive found but ignored. Already installed"
[ "$install_vue" == 1 ] && log "Vue install directive found but ignored. The install of react superceded this"
else
log "ERROR $err_code: There was a problem installing React/React DOM$version_msg$auth_msg" -e
fi
fi
# END: Optional react and react-dom install
Expand All @@ -79,32 +92,41 @@ fi
if [[ "$install_vue" == 1 && "$install_react" == 0 ]]; then
version=$(eval $parse vue version)
auth=$(eval $parse vue auth)
__installed=$(bash bash/utils.sh node_package_exists vue)
[ -z "$version" ] && version_msg='' || version_msg=" version $version"
[ "$auth" != 1 ] && auth_msg='' || auth_msg=' with --auth'
log "Vue install directive found in starter.ini"
log "Installing Vue..."
if [ "$auth" == 1 ]; then
php artisan ui vue --auth
if [ "$__installed" == 1 ]; then
log "However it appears that Vue has already been installed, skipping this installation."
else
php artisan ui vue
fi
err_code=$?
if [ $err_code == 0 ]; then
log "SUCCESS: Vue$version_msg$auth_msg has been installed"
log "Compiling fresh scaffolding and running Laravel Mix"
yarn install && yarn run dev && sleep 1 && yarn run dev
if [ ! -z "$version" ]; then
log "Setting vue to$version_msg"
# TODO: validate semver and valid version for the package so users cant pass in junk
yarn upgrade vue@$version
log "Installing Vue..."
if [ "$auth" == 1 ]; then
php artisan ui vue --auth
else
php artisan ui vue
fi
err_code=$?
if [ $err_code == 0 ]; then
log "SUCCESS: Vue$version_msg$auth_msg has been installed"
log "Compiling fresh scaffolding and running Laravel Mix"
yarn install && yarn run dev && sleep 1 && yarn run dev
if [ ! -z "$version" ]; then
log "Setting vue to$version_msg"
# TODO: validate semver and valid version for the package so users cant pass in junk
yarn upgrade vue@$version
fi
[ "$install_bootstrap" == 1 ] && log "Bootstrap install directive found but ignored. Already installed."
else
log "ERROR $err_code: There was a problem installing Vue$version_msg$auth_msg" -e
fi
[ "$install_bootstrap" == 1 ] && log "Bootstrap install directive found but ignored. Already installed."
else
log "ERROR $err_code: There was a problem installing Vue$version_msg$auth_msg" -e
fi
fi
# END: Optional vue install

# TODO: test bootstrap install without any detection for an existing install.
# If nothing is affected like app.js then install wont need to be skipped.
# otherwise implement the same fix for existing installs that we have for react and vue.

# BEGIN: Optional bootstrap install
if [[ $install_bootstrap == 1 && $install_react == 0 && $install_vue == 0 ]]; then
version=$(eval $parse bootstrap version)
Expand Down Expand Up @@ -139,8 +161,4 @@ else
yarn upgrade bootstrap@$version
fi
fi
# END: Optional bootstrap install




# END: Optional bootstrap install
37 changes: 37 additions & 0 deletions bash/init-project.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# Log to the console and a file
log () {
if [ -z "$2" ]; then
bash bash/utils.sh log "$1" /var/log/workspace-init.log
else
bash bash/utils.sh log "$1" /var/log/workspace-init.log -e
fi
}

# Log only to a file
log_silent () {
if [ -z "$2" ]; then
bash bash/utils.sh log_silent "$1" /var/log/workspace-init.log
else
bash bash/utils.sh log_silent "$1" /var/log/workspace-init.log -e
fi
}

# BEGIN example code block - migrate database
# COMMENT: Load spinner
# . bash/third-party/spinner.sh
# __migrate_msg="Migrating database"
# log_silent "$__migrate_msg" && start_spinner "$__migrate_msg"
# php artisan migrate
# err_code=$?
# if [ $err_code != 0 ]; then
# stop_spinner $err_code
# log "ERROR: Failed to migrate database" -e
# else
# stop_spinner $err_code
# log "SUCCESS: migrated database"
# fi

# BEGIN example code block - migrate database

Loading

0 comments on commit b892185

Please sign in to comment.