diff --git a/bin/cog b/bin/cog index b58a06b..613f295 100755 --- a/bin/cog +++ b/bin/cog @@ -1,25 +1,37 @@ #!/bin/bash -CMD=${1:-help} # Yarn global adds the cog binary to your $PATH through a bunch of # symlinks. `readlink -f` isn't available on Mac, so this uses # Python to grab the fully resolved path of `cog` and then two # `dirname`s to back out to the true installed repo directory. -DIR=$(dirname $(dirname $(python -c "import os; print(os.path.realpath('${BASH_SOURCE[0]}'))"))) +export COG_DIRECTORY=$(dirname $(dirname $(python -c "import os; print(os.path.realpath('${BASH_SOURCE[0]}'))"))); +# Color Format +export GREEN='\033[0;32m' +export YELLOW='\033[0;33m' +export BLUE='\033[0;34m' +export BOLD='\033[0;22m' +export NC='\033[0m' # No Color # Include all scripts inside the tools folder -for file in $DIR/tools/*; do +for file in $COG_DIRECTORY/tools/*; do source $file done -# Drop next argument -shift +if [ -e .env ]; then + source ./.env +fi + + +# cog requires an argument. If there is no argument, cog will call cog-help +CMD=${1:-help}; shift # Check if /bin exist in current directory and automaticlly include the .env file -if [ -f "./bin/cog-$CMD" ]; then - # Overwrite script exist. Run this +if [ -d "./bin" ]; then + if [ -f "./bin/cog-$CMD" ]; then ( set -a; source .env 2> /dev/null; "./bin/cog-$CMD" "${@}") else - # Execute default scripts - ( set -a; source .env 2> /dev/null; "$DIR/bin/cog-$CMD" "${@}" ) -fi + ( set -a; source .env 2> /dev/null; "$COG_DIRECTORY/bin/cog-$CMD" "${@}" ) + fi +else + ( set -a; source .env 2> /dev/null; "$COG_DIRECTORY/bin/cog-$CMD" "${@}" ) +fi \ No newline at end of file diff --git a/bin/cog-clone b/bin/cog-clone deleted file mode 100755 index 98f47b0..0000000 --- a/bin/cog-clone +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -git clone git@github.com:happycog/$1.git -cd $1 \ No newline at end of file diff --git a/bin/cog-help b/bin/cog-help index cf1c67c..f4bf97b 100755 --- a/bin/cog-help +++ b/bin/cog-help @@ -1,16 +1,53 @@ #!/bin/bash - # Set tabs space tabs 4 -# Color Format -GREEN='\033[0;32m' -YELLOW='\033[0;33m' -BLUE='\033[0;34m' -BOLD='\033[0;22m' -NC='\033[0m' # No Color +displayGlobalCommands() { + echo -e "${YELLOW}Global commands:${NC}" + echo "" + for file in $COG_DIRECTORY/bin/*; do + base_file=$(basename "$file"); + # Ignore specific scripts + if [[ "$base_file" == "cog" ]] || [[ "$base_file" == "cog-help" ]] || [[ "$base_file" == "cog-ssl-check" ]]; then + continue + fi + + COG_COMMAND=$(sed -e 's#.*-\(\)#\1#' <<< "$base_file"); + COG_DESCRIPTION=$(sed -n 's/# Description: //p' $file); + # nameLength ${#COG_COMMAND}; + echo -e "\t${GREEN}$COG_COMMAND${NC} $COG_DESCRIPTION"; + echo ""; + done +} + +displayProjectCommands() { + if [ -d "$PWD/bin" ]; then + echo -e "${YELLOW}Project commands:${NC}" + echo "" + for file in $PWD/bin/*; do + base_file=$(basename "$file"); + COG_COMMAND=$(sed -e 's#.*-\(\)#\1#' <<< "$base_file"); + COG_DESCRIPTION=$(sed -n 's/# Description: //p' $file); + echo -e "\t${GREEN}$COG_COMMAND${NC} $COG_DESCRIPTION"; + echo ""; + done + fi +} + +# Create even spacing for description +nameLength() { + length=$1; + + if (( $length > $descriptionSpacing )); then + descriptionSpacing=$length; + fi +} + # Default help screen +echo "" +echo -e "$(packageName) ${GREEN}$(packageVersion)${NC}"; + echo ' MMMMMMMMMMMMMMM MMMMMMMMMMMMMMM MMMMMMMMMMN MMMMMMMMMMN @@ -20,37 +57,9 @@ echo ' MMMMMMMMMMN MMMMMMMMMMN MMMMMMMMMMMMMMM MMMMMMMMMMMMMMM ' - -echo -e "${YELLOW}Usage:${NC}" -echo -e "\tcommand [options] [arguments]" +displayGlobalCommands; echo "" -echo -e "${YELLOW}Available commands:${NC}" -echo -e "\t${GREEN}go${NC} Run the project at localhost:${WEBSERVER_PORT:-8000}." -echo -e "\t ${BLUE}-h, --host${NC} " -echo -e "\t ${BLUE}-p, --port${NC} " -echo -e "\t ${BLUE}-d, --dir${NC} " +displayProjectCommands; echo "" -echo -e "\t${GREEN}make${NC} Run the make command" -echo -e "\t ${BLUE}:script${NC} Pass in the name argument to create a new script" -echo -e "\t ${BLUE}:env${NC} Creates a .env file for your project" echo "" -echo -e "\t${GREEN}serve${NC} Create localhost tunnel with ngrok" -echo "" -echo -e "\t${GREEN}git-backup${NC} Git clone a remote repository to a local folder and then checkout all remote branches so you have a complete backup" -echo "" -echo -e "\t${GREEN}compile${NC} Run the default preprocessor task (gulp compile, grunt compile, etc.)." -echo "" -echo -e "\t${GREEN}convert${NC} Converts any .mov and .mp4 files into .gif" -echo "" -echo -e "\t${GREEN}watch${NC} Run the default preprocessor watch task (gulp watch, grunt watch, etc.)." -echo "" -echo -e "\t${GREEN}tag${NC} Create git tags [${BLUE} major | minor | patch | push${NC}]" -echo "" -echo -e "\t${GREEN}update${NC} Create git tags [${BLUE} major | minor | patch | push${NC}]" -echo "" -echo -e "\t${GREEN}ssl-check${NC} Outputs info and runs some validity checks on a domain's SSL certificate" -echo "" -echo "Visit https://github.com/happycog/cog/ to learn more about cog." - -#TODO -#Add abilty to search local bin for new commands +echo "Visit https://github.com/happycog/cog/ to learn more about cog." \ No newline at end of file diff --git a/bin/cog-make b/bin/cog-make deleted file mode 100755 index ab95370..0000000 --- a/bin/cog-make +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -#add make commands diff --git a/bin/cog-make:env b/bin/cog-make:env index 8ff01f9..90391d3 100755 --- a/bin/cog-make:env +++ b/bin/cog-make:env @@ -1,12 +1,12 @@ #!/bin/bash +# Description: Create .env file -# Variables ARG_FILENAME=$1 if [ -f ".env" ]; then echo "⚠️ File already exist. Please try again" exit 0 fi -touch .env.example -echo -e "APP_ENV=\nAPP_URL=\nDB_CONNECTION=\nDB_HOST=\nDB_PORT=\nDB_DATABASE=\nDB_USERNAME=\nDB_PASSWORD=\nDB_BACKUP_NAME=\nWEBSERVER_HOST=\nWEBSERVER_PORT=\nARG_DIR=\nS3_KEY=\nS3_SECRET=\nS3_REGION=\nS3_BUCKET=\nS3_BACKUP_BUCKET="> .env.example +touch .env +echo -e "APP_ENV=\nAPP_URL=\nDB_CONNECTION=\nDB_HOST=\nDB_PORT=\nDB_DATABASE=\nDB_USERNAME=\nDB_PASSWORD=\nDB_BACKUP_NAME=\nWEBSERVER_HOST=\nWEBSERVER_PORT=\nARG_DIR=\nS3_KEY=\nS3_SECRET=\nS3_REGION=\nS3_BUCKET=\nS3_BACKUP_BUCKET=" > .env echo '✨ .env.example was created. Rename the file to .env to use.' diff --git a/bin/cog-make:script b/bin/cog-make:script index 9121ae1..7f3c5bc 100755 --- a/bin/cog-make:script +++ b/bin/cog-make:script @@ -1,35 +1,5 @@ #!/bin/bash +# Description: Pass a script name to create an executable script for cog -# Variables -ARG_FILENAME=$1 - -# Check to see if name argument was passed -if [ -z "$ARG_FILENAME" ]; then - echo '⚠️ Not enough arguments (missing: "name").' - echo '⚠️ Example: cog make:script ' - exit 0 -fi - -# Check if bin folder exist -if [ ! -d './bin' ]; then - echo '🗄 Creating bin folder...' - mkdir bin -fi - -cd ./bin - -# Check if file exist -if [ ! -f "cog-$ARG_FILENAME" ]; then - echo "[1/3] 📄 Creating cog-$ARG_FILENAME script..." - touch cog-$ARG_FILENAME - - echo "[2/3] ⌨️ Making cog-$ARG_FILENAME Executable..." - chmod u+x cog-$ARG_FILENAME - - echo "#!/bin/bash" > cog-$ARG_FILENAME -else - echo "⚠️ File already exist. Please try again" - exit 0 -fi - -echo "[3/3] ✨ Finished. cog-$ARG_FILENAME script was created in ./bin/" +source $COG_DIRECTORY/tools/create.sh; +createScript $1; \ No newline at end of file diff --git a/bin/cog-update b/bin/cog-update index de0dbaf..f6f33a2 100755 --- a/bin/cog-update +++ b/bin/cog-update @@ -1,10 +1,5 @@ #!/bin/bash - -# cog update -# This command will update all the this package to the latest version. -for file in ./tools/*; do - source $file -done +# Description: Update hc-cog to its latest version. echo -e "💻 Updating $(name)@$(version)..." diff --git a/deprecated/cog-clone b/deprecated/cog-clone new file mode 100755 index 0000000..e79870c --- /dev/null +++ b/deprecated/cog-clone @@ -0,0 +1,4 @@ +#!/bin/bash + +COG_DESCRIPTION='This is a test'; +# Description: hey diff --git a/bin/cog-compile b/deprecated/cog-compile similarity index 100% rename from bin/cog-compile rename to deprecated/cog-compile diff --git a/bin/cog-convert b/deprecated/cog-convert similarity index 100% rename from bin/cog-convert rename to deprecated/cog-convert diff --git a/bin/cog-dev b/deprecated/cog-dev similarity index 99% rename from bin/cog-dev rename to deprecated/cog-dev index 1069b36..6d0fa9b 100755 --- a/bin/cog-dev +++ b/deprecated/cog-dev @@ -3,6 +3,7 @@ if [ -e .env ]; then source ./.env fi + # Check if gulpfile.js exist if [ -f 'gulpfile.js' ]; then COMPILE_TASK="gulp" diff --git a/bin/cog-ec2-deploy b/deprecated/cog-ec2-deploy similarity index 100% rename from bin/cog-ec2-deploy rename to deprecated/cog-ec2-deploy diff --git a/bin/cog-git-backup b/deprecated/cog-git-backup similarity index 100% rename from bin/cog-git-backup rename to deprecated/cog-git-backup diff --git a/bin/cog-go b/deprecated/cog-go similarity index 100% rename from bin/cog-go rename to deprecated/cog-go diff --git a/bin/cog-s3-deploy b/deprecated/cog-s3-deploy similarity index 100% rename from bin/cog-s3-deploy rename to deprecated/cog-s3-deploy diff --git a/bin/cog-serve b/deprecated/cog-serve similarity index 100% rename from bin/cog-serve rename to deprecated/cog-serve diff --git a/bin/cog-tag b/deprecated/cog-tag similarity index 98% rename from bin/cog-tag rename to deprecated/cog-tag index db84721..80a5055 100755 --- a/bin/cog-tag +++ b/deprecated/cog-tag @@ -1,4 +1,5 @@ #!/bin/bash +# Description: Easicly Update tag # Color Format GREEN='\033[0;32m' diff --git a/bin/cog-watch b/deprecated/cog-watch similarity index 100% rename from bin/cog-watch rename to deprecated/cog-watch diff --git a/tools/ask.sh b/tools/ask.sh index e8b4670..c67428b 100644 --- a/tools/ask.sh +++ b/tools/ask.sh @@ -20,3 +20,4 @@ ask() { esac done } +export -f ask; diff --git a/tools/create.sh b/tools/create.sh new file mode 100644 index 0000000..d56024a --- /dev/null +++ b/tools/create.sh @@ -0,0 +1,41 @@ +createScript() { + +# Variables +ARG_FILENAME=$1 + +# Check to see if name argument was passed +if [ -z "$ARG_FILENAME" ]; then + echo '⚠️ Not enough arguments (missing: "name").' + echo '⚠️ Example: cog make:script ' + exit 0 +fi + +# Check if bin folder exist +if [ ! -d './bin' ]; then + echo '🗄 Creating bin folder...' + mkdir bin +fi + +cd ./bin + +# Check if file exist +if [ ! -f "cog-$ARG_FILENAME" ]; then + echo "[1/3] 📄 Creating cog-$ARG_FILENAME script..." + touch cog-$ARG_FILENAME + + echo "[2/3] ⌨️ Making cog-$ARG_FILENAME Executable..." + chmod u+x cog-$ARG_FILENAME + + echo "#!/bin/bash" >> cog-$ARG_FILENAME + echo "#################################################" >> cog-$ARG_FILENAME + echo "# Description: Add your descripton here" >> cog-$ARG_FILENAME + echo "#################################################" >> cog-$ARG_FILENAME +else + echo "⚠️ File already exist. Please try again" + exit 0 +fi + +echo "[3/3] ✨ Finished. cog-$ARG_FILENAME script was created in ./bin/" + +} +export -f createScript; diff --git a/tools/exists.sh b/tools/exists.sh index bf55728..734f430 100644 --- a/tools/exists.sh +++ b/tools/exists.sh @@ -1,3 +1,4 @@ exists () { type "$1" &> /dev/null ; } +export -f exists; diff --git a/tools/package.sh b/tools/package.sh index e1c7174..b9891ba 100644 --- a/tools/package.sh +++ b/tools/package.sh @@ -1,8 +1,10 @@ -name() { - awk '/name/{gsub(/("|",)/,"",$0); print $2; exit};' package.json +packageName() { + awk '/name/{gsub(/("|",)/,"",$0); print $2; exit};' $COG_DIRECTORY/package.json } -version() { - awk '/version/{gsub(/("|",)/,"",$2); print $2; exit};' package.json +packageVersion() { + awk '/version/{gsub(/("|",)/,"",$2); print $2; exit};' $COG_DIRECTORY/package.json } +export -f packageName; +export -f packageVersion; \ No newline at end of file diff --git a/tools/rule.sh b/tools/rule.sh index 80554f2..45d6253 100644 --- a/tools/rule.sh +++ b/tools/rule.sh @@ -1,3 +1,4 @@ rule() { eval printf %.0s= '{1..'"${COLUMNS:-$(tput cols)}"\}; echo } +export -f rule; \ No newline at end of file