Skip to content

Commit

Permalink
Features 25, 23 and Fixes 21 and 24 (#26)
Browse files Browse the repository at this point in the history
* 📦 NEW: fix npm WARN lifecycle The node binary mistmatch...

* 🐛 FIX: #23

* 🐛 FIX: refactored parsing rountines

* 🐛 FIX: smoother install of github-changelog-generator

* 📖 DOC: improve log msg

* 👌 IMPROVE: messages and spinners

* 👌 IMPROVE: log utils

* 🐛 FIX: #24

* 📖 DOC: ending message

* 📖 DOC: console messages

* 🤖 TEST: logs

* 🐛 FIX: dev qa complete for #24

* 👌 IMPROVE: colorized spinner

* 👌 IMPROVE: colorized spinner ansi 256
  • Loading branch information
apolopena authored Feb 6, 2021
1 parent 5c709a9 commit 0e13d83
Show file tree
Hide file tree
Showing 11 changed files with 310 additions and 112 deletions.
3 changes: 3 additions & 0 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ USER gitpod
RUN sudo touch /var/log/workspace-image.log \
&& sudo chmod 666 /var/log/workspace-image.log

RUN sudo touch /var/log/workspace-init.log \
&& sudo chmod 666 /var/log/workspace-init.log

RUN sudo touch /var/log/xdebug.log \
&& sudo chmod 666 /var/log/xdebug.log

Expand Down
3 changes: 2 additions & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ tasks:
bash bash/init-gitpod.sh &&
source ~/.bash_profile &&
url=$(gp url 8000); sed -i'' "s#^APP_URL=http://localhost*#APP_URL=$url\nASSET_URL=$url#g" .env &&
. bash/init-optional-scaffolding.sh
bash bash/init-optional-scaffolding.sh &&
bash bash/init-complete.sh
name: Init
- openMode: split-left
command: |
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scripts-prepend-node-path=true
89 changes: 63 additions & 26 deletions bash/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

# helpers.sh
# Author: Apolo Pena
# Description: A variety of useful functions with that depend on gitpod other
# binaries, aliases and functions in .bashrc
# Description: A variety of useful functions with that depend on gitpod
# and other binaries, aliases and functions such as code in .bashrc
# other than coreutils.
# Note: Do not execute this script witout calling a function from it
# Additional Note: some functions use functions from .bashrc so the -i flag
# is the safest way to invoke functions from this script.
#
# Usage: bash -i <function name> arg1 arg2 arg3 ...
#

version () {
echo "helpers.sh version 0.0.2"
echo "helpers.sh version 0.0.3"
}

# start_server
Expand All @@ -34,33 +36,68 @@ start_server() {
# Bump the value of the default_server in starter.ini to lowercase
server=$(echo "$s" | tr '[:upper:]' '[:lower:]')
if [ -z "$1" ]; then
case "$server" in
'php')
start_php_dev
;;
'apache')
start_apache
;;
*)
echo "$err invalid default server: $server. Check the file $GITPOD_REPO_ROOT/starter.ini"
;;
esac
case "$server" in
'php')
start_php_dev
;;
'apache')
start_apache
;;
*)
echo "$err invalid default server: $server. Check the file $GITPOD_REPO_ROOT/starter.ini"
;;
esac
else
echo $(echo "$1" | tr '[:upper:]' '[:lower:]')
case $(echo "$1" | tr '[:upper:]' '[:lower:]') in
'php')
start_php_dev
;;
'apache')
start_apache
;;
*)
echo "$err invalid server type: $1"
;;
esac
case $(echo "$1" | tr '[:upper:]' '[:lower:]') in
'php')
start_php_dev
;;
'apache')
start_apache
;;
*)
echo "$err invalid server type: $1"
;;
esac
fi
}

# add_global_rake_task
# Description:
# Writes a rake task multiline string ($1) to a file named by the command ($2) in ~/.rake
#
# Notes:
# Depending on how the task is written you may need to
# invoke a global rake task using the -g flag like so: rake -g hello-world
# Do not use the .rake suffic in your command. The rake file name will
# automatically written as to "$2.rake"
# Any exisitng rake command in ~/.rake will be clobbered.
#
# Usage:
# Example: a dynamically created hello world rake task
# # create a safe multiline string (with variable interpolation) to pass to add_global_rake_task
# name='Apolo'
# rake_task_name='hello'
# IFS='' read -r -d '' __task <<EOF
# task "$rake_task_name" do
# puts "Hello $name, this is a global rake task"
# end
# EOF
# bash bash/helpers.sh add_global_rake_task "$__task" "$rake_task_name"
add_global_rake_task() {
local root=~/.rake
local file="$2.rake"
local err="Helpers.sh: Error: add_global_rake_task:"
local usage="Usage: add_global_rake_task task file.rake"

[[ -z $1 || -z $2 ]] && echo "$err requires exactly two arguments." && echo $usage && return

mkdir -p $root
touch -c "$root/$2"
echo -e "$1" > "$root/$file"
}

# Call functions from this script gracefully
if declare -f "$1" > /dev/null
then
Expand All @@ -69,4 +106,4 @@ then
else
echo "helpers.sh: '$1' is not a known function name." >&2
exit 1
fi
fi
14 changes: 14 additions & 0 deletions bash/init-complete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

workspace_log='/var/log/workspace-image.log'
init_log='/var/log/workspace-init.log'
echo -e "\n\e[38;5;171mSUMMARY 📃\e[0m\n"
echo -en "\e[38;5;194mResults of building the workspace image\e[0m \e[38;5;34m$workspace_log\e[0m ➥\n\e[38;5;183m"
cat $workspace_log
echo -en "\e[0m"
echo ''
echo -en "\e[38;5;194mResults of the gitpod initialization\e[0m \e[38;5;34m$init_log\e[0m ➥\e[38;5;39m"
cat $init_log
echo -en "\e[0m"
echo -en "\n\e[38;5;171mALL DONE 🚀\e[0m\n"
echo -e "\e[38;5;194mIf everything looks good in the above results then push the newly created\n project files to your git repo and get started coding your project\e[0m"
86 changes: 65 additions & 21 deletions bash/init-gitpod.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,88 @@
#!/bin/bash
#printf "\033c"

# 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
}


# Load spinner
. bash/third-party/spinner.sh

# Bootstrap scaffolding
if [ ! -d "$GITPOD_REPO_ROOT/bootstrap" ]; then
echo "Results of building the workspace image ➥"
cat /var/log/workspace-image.log
echo -e "\nMoving Laravel project from ~/temp-app to $GITPOD_REPO_ROOT ..."
# Todo replacespinner with a real progress bar for coreutils
msg="\nMoving Laravel project from ~/temp-app to $GITPOD_REPO_ROOT"
log_silent "$msg" && start_spinner "$msg"
shopt -s dotglob
mv --no-clobber ~/test-app/* $GITPOD_REPO_ROOT
RESULT=$?
if [ $? -ne 0 ]; then
>&2 echo "ERROR: Failed to move Laravel project from ~/temp-app to $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
else
echo "SUCCESS: moved Laravel project from ~/temp-app to $GITPOD_REPO_ROOT"
stop_spinner $err_code
log "SUCCESS: moved Laravel project from ~/temp-app to $GITPOD_REPO_ROOT"
fi
# BEGIN: Optional configurations
# Super user account for phpmyadmin
installed_phpmyadmin=$(. /tmp/utils.sh parse_ini_value /tmp/starter.ini phpmyadmin install)
if [ $installed_phpmyadmin -eq 1 ]; then
echo "Creating phpmyadmin superuser: pmasu..."
if [ "$installed_phpmyadmin" == 1 ]; then
msg="Creating phpmyadmin superuser: pmasu"
log_silent "$msg" && start_spinner "$msg"
mysql -e "CREATE USER 'pmasu'@'%' IDENTIFIED BY '123456';"
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'pmasu'@'%';"
RESULT=$?
if [ $? -ne 0 ]; then
>&2 echo "ERROR: failed to create phpmyadmin superuser: pmasu"
err_code=$?
if [ $err_code != 0 ]; then
stop_spinner $err_code
log "ERROR: failed to create phpmyadmin superuser: pmasu" -e
else
echo "SUCCESS: created phpmyadmin superuser: pmasu"
stop_spinner $err_code
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)
if [ "$installed_changelog_gen" == 1 ]; then
msg="Installing github-changelog-generator"
log_silent "$msg" && start_spinner "$msg" &&
gem install github_changelog_generator --no-document --silent &&
stop_spinner $?
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
mv ~/test-app/README.md $GITPOD_REPO_ROOT/README_LARAVEL.md
rmdir ~/test-app
fi

# Aliases for git
echo "Writing git aliases..."
bash bash/utils.sh add_file_to_file_after \\[alias\\] bash/snippets/emoji-log ~/.gitconfig
bash bash/utils.sh add_file_to_file_after \\[alias\\] bash/snippets/git-aliases ~/.gitconfig
echo "Writing git aliases complete, check the log for any possible errors."
echo "try: git a or: git aliases for a list your git aliases."
# Rake tasks (will be written to ~/.rake).
# Some rake tasks are dynamic and depend on the configuration in starter.ini
bash bash/init-rake-tasks.sh

# Aliases for git
msg="Writing git aliases"
log_silent "$msg" && start_spinner "$msg" &&
bash bash/utils.sh add_file_to_file_after \\[alias\\] bash/snippets/emoji-log ~/.gitconfig &&
bash bash/utils.sh add_file_to_file_after \\[alias\\] bash/snippets/git-aliases ~/.gitconfig &&
stop_spinner $?
log "try: git a or: git aliases for a list your git aliases.\n"

echo "If the above results are successful then make sure to add, commit and push the changes to your git repository."
# Messages for github_changelog_generator
[ "$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"
Loading

0 comments on commit 0e13d83

Please sign in to comment.