Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commands #5

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions bin/cog
Original file line number Diff line number Diff line change
@@ -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
4 changes: 0 additions & 4 deletions bin/cog-clone

This file was deleted.

85 changes: 47 additions & 38 deletions bin/cog-help
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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} <host> "
echo -e "\t ${BLUE}-p, --port${NC} <port> "
echo -e "\t ${BLUE}-d, --dir${NC} <directory> "
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."
3 changes: 0 additions & 3 deletions bin/cog-make

This file was deleted.

6 changes: 3 additions & 3 deletions bin/cog-make:env
Original file line number Diff line number Diff line change
@@ -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.'
36 changes: 3 additions & 33 deletions bin/cog-make:script
Original file line number Diff line number Diff line change
@@ -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 <name>'
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;
7 changes: 1 addition & 6 deletions bin/cog-update
Original file line number Diff line number Diff line change
@@ -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)..."

Expand Down
4 changes: 4 additions & 0 deletions deprecated/cog-clone
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

COG_DESCRIPTION='This is a test';
# Description: hey
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions bin/cog-dev → deprecated/cog-dev
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ if [ -e .env ]; then
source ./.env
fi


# Check if gulpfile.js exist
if [ -f 'gulpfile.js' ]; then
COMPILE_TASK="gulp"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions bin/cog-tag → deprecated/cog-tag
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# Description: Easicly Update tag

# Color Format
GREEN='\033[0;32m'
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions tools/ask.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ ask() {
esac
done
}
export -f ask;
41 changes: 41 additions & 0 deletions tools/create.sh
Original file line number Diff line number Diff line change
@@ -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 <name>'
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;
1 change: 1 addition & 0 deletions tools/exists.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
exists () {
type "$1" &> /dev/null ;
}
export -f exists;
10 changes: 6 additions & 4 deletions tools/package.sh
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions tools/rule.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
rule() {
eval printf %.0s= '{1..'"${COLUMNS:-$(tput cols)}"\}; echo
}
export -f rule;