diff --git a/.cogconfig.example b/.cogconfig.example new file mode 100644 index 0000000..e1207ba --- /dev/null +++ b/.cogconfig.example @@ -0,0 +1,3 @@ +# Comma-separated list of Cog plugin directories where cog-{command} +# scripts can be found +COG_PLUGIN_DIRECTORIES= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7e583a2..f28cb46 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store .idea -/node_modules/ \ No newline at end of file +/node_modules/ +.cogconfig \ No newline at end of file diff --git a/README.md b/README.md index 4200f04..3806c79 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,17 @@ Whenever you create, delete, or modify a script, you must update `bin/cog-help`. ## Usage Running `cog` on the command line will list all of the available scripts and a short description. Any new script you make will overwrite the global defaults. You can run `cog make:script dev` and create a custom bash script based on that specific project +## Plugins +You can add plugins to `cog` through the .cogconfig file. A plugin consists of a directory of `cog-` commands, which can exist anywhere within your file system. + +Run `cog config` to create the `.cogconfig` file in your home directory. + +You can then edit the `COG_PLUGIN_DIRECTORIES=` variable with a comma-separated list of paths where your `cog-` scripts are stored. + ## Update -Run `cog update` to receive the latest version. To update this package, run `yarn version {patch, minor, major}` followed by `yarn publish` +Run `cog update` to receive the latest version. + +To update this package, run `yarn version {patch, minor, major}` followed by `yarn publish` ## Builds If you're using `Go` to write any commands, put your source `.go` file into the `src` directory and run this command to build it into a binary in the `bin` directory: diff --git a/bin/cog b/bin/cog index b58a06b..71244f9 100755 --- a/bin/cog +++ b/bin/cog @@ -1,11 +1,27 @@ -#!/bin/bash +#!/usr/bin/env bash +set -o pipefail + CMD=${1:-help} + +# function to get the directory containing cog +get_script_dir () { + SOURCE="${BASH_SOURCE[0]}" + # While $SOURCE is a symlink, resolve it + while [ -h "$SOURCE" ]; do + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$( readlink "$SOURCE" )" + # If $SOURCE was a relative symlink (so no "/" as prefix, need to resolve it relative to the symlink base directory + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" + done + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + echo "$DIR" +} + # 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]}'))"))) +# symlinks. So this uses the get_script_dir function to find the +# directory containing the cog script and then navigates up the tree +DIR=$(dirname $(get_script_dir)) # Include all scripts inside the tools folder for file in $DIR/tools/*; do @@ -15,11 +31,30 @@ done # Drop next argument 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 - ( 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 +# load up .cogconfig +source ~/.cogconfig &>/dev/null + +# split the .cogconfig variable by comma +IFS=, read -a plugin_directories <<< "$COG_PLUGIN_DIRECTORIES" + +# create an array of directories to search +# start with ./bin, then any plugin directories +# and last the cog directory +BIN_DIRECTORIES=() +BIN_DIRECTORIES+=( "./bin" ) +BIN_DIRECTORIES+=( ${plugin_directories[@]} ) +BIN_DIRECTORIES+=( "$DIR/bin" ) + +# Export Variables for use in cog commands later + +# Cog paths +export COG_PLUGIN_DIRECTORIES=${COG_PLUGIN_DIRECTORIES} +export COG_PATH=${DIR} + +for bin_dir in "${BIN_DIRECTORIES[@]}" +do + if [ -f ${bin_dir}/cog-${CMD} ]; then + ( set -a; source .env &> /dev/null; "${bin_dir}/cog-$CMD" "${@}") + break + fi +done \ No newline at end of file diff --git a/bin/cog-config b/bin/cog-config new file mode 100755 index 0000000..ba6010a --- /dev/null +++ b/bin/cog-config @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -euo pipefail + +echo "⚙️ Create .cogconfig" + +if [[ ! -f ~/.cogconfig ]]; then + cp $COG_PATH/.cogconfig.example ~/.cogconfig +else + echo "Oops .cogconfig already exists in home directory!" +fi + +echo "" +echo -e "Find your ${GREEN}.cogconfig${NC} at 👉 ${MAGENTA}$HOME/.cogconfig${NC}" \ No newline at end of file diff --git a/bin/cog-help b/bin/cog-help index cf1c67c..56dcf6c 100755 --- a/bin/cog-help +++ b/bin/cog-help @@ -4,27 +4,32 @@ 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 +#GREEN='\033[0;32m' +#YELLOW='\033[0;33m' +#BLUE='\033[0;34m' +#BOLD='\033[0;22m' +#NC='\033[0m' # No Color # Default help screen -echo ' - MMMMMMMMMMMMMMM MMMMMMMMMMMMMMM - MMMMMMMMMMN MMMMMMMMMMN - NMMMMMMMM MMMMMMMMMMMMMM - NMMMMMMMM MMMMMMMMMMMMMMMM - NMMMMMMMM MMMMMMMMMMMMMM - MMMMMMMMMMN MMMMMMMMMMN - MMMMMMMMMMMMMMM MMMMMMMMMMMMMMM -' +echo -e "${YELLOW} +7MMF 7MMF .g8'''bgd + MM MM .dP' 'M + MM MM ,6'Yb. '7MMpdMAo.'7MMpdMAo.'7M' 'MF' dM' ,pW'Wq. .P'Ybm + MMmmmmmmMM 8) MM MM 'Wb MM 'Wb VA ,V MM 6' 'Wb MI I8 + MM MM ,pm9MM MM M8 MM M8 VA ,V MM. 8M M8 WmmmP' + MM MM 8M MM MM ,AP MM ,AP VVV 'Mb. , YA. ,A9 M +JMML JMML 'Moo9^Yo. MMbmmd' MMbmmd' ,V ''bmmmd' 'Ybmd9' YMMMMM + MM MM ,V 6' d + JMML JMML OOb Ybmmd' +${NC}" +echo "Cog is a bash script that helps automate the development workflow" +echo "" echo -e "${YELLOW}Usage:${NC}" echo -e "\tcommand [options] [arguments]" echo "" -echo -e "${YELLOW}Available commands:${NC}" +echo -e "⚙️ ${MAGENTA}Built-in Commands:${NC}" +echo "" 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} " @@ -40,6 +45,8 @@ echo -e "\t${GREEN}git-backup${NC} Git clone a remote repository to a local echo "" echo -e "\t${GREEN}compile${NC} Run the default preprocessor task (gulp compile, grunt compile, etc.)." echo "" +echo -e "\t${GREEN}config${NC} Create the ~/.cogconfig file if it does not exists." +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.)." @@ -50,7 +57,20 @@ echo -e "\t${GREEN}update${NC} Create git tags [${BLUE} major | minor | 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." +#echo "Visit https://github.com/happycog/cog/ to learn more about cog." + +# split the plugin directories variable by comma +IFS=, read -a plugin_directories <<< "$COG_PLUGIN_DIRECTORIES" + +# run plugin directory help commands +for bin_dir in "${plugin_directories[@]}" +do + if [ -f ${bin_dir}/.cog-help ]; then + ( set -a; source .env &> /dev/null; "${bin_dir}/.cog-help" "${@}") + fi +done -#TODO -#Add abilty to search local bin for new commands +# run local help command +if [ -f ./bin/.cog-help ]; then + ( set -a; source .env &> /dev/null; "./bin/.cog-help" "${@}") +fi \ No newline at end of file diff --git a/bin/cog-myip b/bin/cog-myip old mode 100644 new mode 100755 diff --git a/bin/cog-ssl-check b/bin/cog-ssl-check old mode 100644 new mode 100755 diff --git a/bin/cog-update b/bin/cog-update index de0dbaf..31eded6 100755 --- a/bin/cog-update +++ b/bin/cog-update @@ -1,7 +1,9 @@ #!/bin/bash # cog update -# This command will update all the this package to the latest version. +# This command will update this package to the latest version. +cd $COG_PATH + for file in ./tools/*; do source $file done diff --git a/package.json b/package.json index 381f0bd..30f6ab5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hc-cog", - "version": "0.7.6", + "version": "0.8", "description": "Happy Cog bash script that helps automate the development workflow", "main": "index.js", "scripts": { @@ -32,6 +32,10 @@ { "name": "Matt Weinberg", "url": "https://github.com/mrw" + }, + { + "name": "Jeremy Gimbel", + "url": "https://github.com/dreadfullyposh" } ], "homepage": "https://github.com/happycog/cog#readme", diff --git a/tools/colors.sh b/tools/colors.sh new file mode 100644 index 0000000..1ba92bd --- /dev/null +++ b/tools/colors.sh @@ -0,0 +1,8 @@ +# Colors +export RED='\033[0;91m' +export GREEN='\033[0;32m' +export YELLOW='\033[0;33m' +export BLUE='\033[0;34m' +export MAGENTA='\033[0;35m' +export BOLD='\033[0;22m' +export NC='\033[0m' # No Color \ No newline at end of file