Skip to content

Commit

Permalink
Merge pull request #6 from happycog/add-plugins
Browse files Browse the repository at this point in the history
Add plugins support and a bunch of other enhancements
  • Loading branch information
dreadfullyposh authored May 5, 2020
2 parents 86381d6 + 8eb8a48 commit 6d827ba
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .cogconfig.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Comma-separated list of Cog plugin directories where cog-{command}
# scripts can be found
COG_PLUGIN_DIRECTORIES=
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
.idea
/node_modules/
/node_modules/
.cogconfig
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-<command>` 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-<command>` 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:
Expand Down
61 changes: 48 additions & 13 deletions bin/cog
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
13 changes: 13 additions & 0 deletions bin/cog-config
Original file line number Diff line number Diff line change
@@ -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}"
56 changes: 38 additions & 18 deletions bin/cog-help
Original file line number Diff line number Diff line change
Expand Up @@ -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} <host> "
echo -e "\t ${BLUE}-p, --port${NC} <port> "
Expand All @@ -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.)."
Expand All @@ -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
Empty file modified bin/cog-myip
100644 → 100755
Empty file.
Empty file modified bin/cog-ssl-check
100644 → 100755
Empty file.
4 changes: 3 additions & 1 deletion bin/cog-update
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions tools/colors.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6d827ba

Please sign in to comment.