|  | @@ -0,0 +1,112 @@
 | 
	
		
			
				|  |  | +#!/bin/bash
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +scriptfolder=$(dirname "$0")
 | 
	
		
			
				|  |  | +addwhat="$1"
 | 
	
		
			
				|  |  | +name="$2"
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +if [ -z "$name" ]
 | 
	
		
			
				|  |  | +then
 | 
	
		
			
				|  |  | +    echo "needs a name"
 | 
	
		
			
				|  |  | +    exit
 | 
	
		
			
				|  |  | +fi
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +case "$addwhat" in
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    reducer)
 | 
	
		
			
				|  |  | +        if [ -d "reducers" ]
 | 
	
		
			
				|  |  | +        then
 | 
	
		
			
				|  |  | +            sed "s/example/$name/g" $scriptfolder/exampleReducer.js > reducers/$name.js
 | 
	
		
			
				|  |  | +            sed -i "s/import { combineReducers } from 'redux';/import { combineReducers } from 'redux';\nimport $name from '.\/$name.js';/g" reducers/index.js
 | 
	
		
			
				|  |  | +            sed -i "s/combineReducers({/combineReducers({\n    $name,/g" reducers/index.js
 | 
	
		
			
				|  |  | +        else
 | 
	
		
			
				|  |  | +            #TODO: add reducers folder and template reducers/index.js if not present (with user confirmation?)
 | 
	
		
			
				|  |  | +            echo "need reducers folder (for now)"
 | 
	
		
			
				|  |  | +        fi
 | 
	
		
			
				|  |  | +        echo "added reducer $name to reducers/ and reducers/index.js"
 | 
	
		
			
				|  |  | +        ;;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    action)
 | 
	
		
			
				|  |  | +        if [ ! -e "actions.js" ]
 | 
	
		
			
				|  |  | +        then
 | 
	
		
			
				|  |  | +            echo "creating actions.js (don't forget to import in other files)"
 | 
	
		
			
				|  |  | +        fi
 | 
	
		
			
				|  |  | +        actiontype=$(echo $name | sed -e 's/\(.*\)/\U\1/' -e 's/\s/-/g')
 | 
	
		
			
				|  |  | +        camelcase=$(echo $name | sed -e 's/\b\(.\)/\u\1/g' -e 's/\(.*\)/\l\1/' -e 's/\s//g')
 | 
	
		
			
				|  |  | +        reducer="$3"
 | 
	
		
			
				|  |  | +        props="${@:4}"
 | 
	
		
			
				|  |  | +        actargs=$(echo $props | sed 's/\s\+/, /g')
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        objprops=""
 | 
	
		
			
				|  |  | +        if [ ! -z "$props" ]
 | 
	
		
			
				|  |  | +        then
 | 
	
		
			
				|  |  | +            for p in $props
 | 
	
		
			
				|  |  | +            do
 | 
	
		
			
				|  |  | +                objprops="$objprops        $p,\n"
 | 
	
		
			
				|  |  | +            done
 | 
	
		
			
				|  |  | +        fi
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        sed \
 | 
	
		
			
				|  |  | +            -e "s/example/$camelcase/g" \
 | 
	
		
			
				|  |  | +            -e "s/()/($actargs)/g" \
 | 
	
		
			
				|  |  | +            -e "s/^    };/$objprops    };/g" \
 | 
	
		
			
				|  |  | +            -e "s/EXAMPLE/$actiontype/g" \
 | 
	
		
			
				|  |  | +            $scriptfolder/exampleAction.js >> actions.js
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if [ -e "$reducer" ]
 | 
	
		
			
				|  |  | +        then
 | 
	
		
			
				|  |  | +            sed -i \
 | 
	
		
			
				|  |  | +                -e "s/default:/case '$actiontype':\n            return $camelcase(state, action);\n        default:/" \
 | 
	
		
			
				|  |  | +                $reducer
 | 
	
		
			
				|  |  | +            sed "s/name/$camelcase/g" $scriptfolder/exampleReducerAction.js >> $reducer
 | 
	
		
			
				|  |  | +        fi
 | 
	
		
			
				|  |  | +        ;;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    epic)
 | 
	
		
			
				|  |  | +        echo "add epic"
 | 
	
		
			
				|  |  | +        if [ -d "epics" ]
 | 
	
		
			
				|  |  | +        then
 | 
	
		
			
				|  |  | +            sed "s/example/$name/g" $scriptfolder/exampleEpic.js > epics/$name.js
 | 
	
		
			
				|  |  | +            sed -i "s/import { combineEpics } from 'redux-observable';/import { combineEpics } from 'redux-observable';\nimport $name from '.\/$name.js';/g" epics/index.js
 | 
	
		
			
				|  |  | +            sed -i "s/combineEpics(/combineEpics(\n    $name,/g" epics/index.js
 | 
	
		
			
				|  |  | +        else
 | 
	
		
			
				|  |  | +            #TODO: add epics folder and template epics/index.js if not present (with user confirmation?)
 | 
	
		
			
				|  |  | +            echo "need epics folder (for now)"
 | 
	
		
			
				|  |  | +        fi
 | 
	
		
			
				|  |  | +        echo "added epic $name to epics/ and epics/index.js"
 | 
	
		
			
				|  |  | +        ;;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    *)
 | 
	
		
			
				|  |  | +        echo "possible actions:"
 | 
	
		
			
				|  |  | +        echo "- add component"
 | 
	
		
			
				|  |  | +        echo "- add reducer"
 | 
	
		
			
				|  |  | +        echo "- add action and include in specific reducer"
 | 
	
		
			
				|  |  | +        echo "- add epic"
 | 
	
		
			
				|  |  | +        ;;
 | 
	
		
			
				|  |  | +esac
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +# ADD REDUCER
 | 
	
		
			
				|  |  | +# 1. add reducer template file to reducers/
 | 
	
		
			
				|  |  | +# 2. import reducer in reducers/index.js
 | 
	
		
			
				|  |  | +# 3. include name of reducer in combineReducers in reducers/index.js
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +# ADD ACTION AND INCLUDE IN REDUCER
 | 
	
		
			
				|  |  | +# 1. append action creator function in actions.js
 | 
	
		
			
				|  |  | +# 2. insert action case statement into designated reducer
 | 
	
		
			
				|  |  | +# 3. append function in reducer file
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +# ADD EPIC
 | 
	
		
			
				|  |  | +# 1. add epic template file to epics/
 | 
	
		
			
				|  |  | +# 2. import epic in epics/index.js
 | 
	
		
			
				|  |  | +# 3. include name of epic in combineEpics in epics/index.js
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +# ADD COMPONENT
 | 
	
		
			
				|  |  | +# 1. add component template file to components/
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 |