#!/bin/bash export LANG=en_US.UTF-8 #############1.设置字体颜色的方法######################## R(){ echo "\033[31m"$1"\033[0m" } G(){ echo "\033[32m"$1"\033[0m" } P(){ echo "\033[35m"$1"\033[0m" } ####全局统一配置##### HIVE_RESOURCES_PATH=${0%/*} HIVE_RESOURCES_PATH=$HIVE_RESOURCES_PATH/.. [ -z $APP_TEMPLATE ] && { APP_TEMPLATE="$HIVE_RESOURCES_PATH/templates/HiveAppTemplate"; } BASE_APPNAME=`basename $APP_TEMPLATE` BASEDIR=$HIVE_RESOURCES_PATH/templates if [ $# != 1 ] ; then echo 'Invalid parameters' exit; fi if [ -d $1 ]; then echo "The directory $1 already exists, do you want to replace the it?(Y/N)" while read var do if [ $var == 'Y' ]; then rm -rf $1 break elif [ $var == 'N' ]; then exit else echo "Unknown command: $var" fi done fi ## 将appname中的'-'字符修改成'_' appname=`echo $1 | sed "s/-/_/g"` function proc_file_content() { if [ -f $1 ]; then sed "s/$BASE_APPNAME/${appname}/g" $1 > $1'.tmp' rm -f $1 mv $1'.tmp' $1 fi } function make_target() { target=`echo $1 | sed "s/$BASE_APPNAME/${appname}/g"` target_length=${#target} proj="$BASEDIR" proj_length=${#proj}+1 target_length=$target_length-$proj_length target=${target:proj_length:target_length} echo $target } function replace_filename() { source=$1 target=`make_target "$1"` echo $target if [ -d "$source" ] ; then mkdir -p $target else if [[ ! -d `dirname $target` ]]; then mkdir -p `dirname $target` fi cp -va $source $target fi proj='project.pbxproj' position=${#target}-${#proj} length=${#proj} if [ ${target:position:length}==$proj ]; then proc_file_content $target fi proj='xcscheme' position=${#target}-${#proj} length=${#proj} if [ ${target:position:length} == $proj ]; then proc_file_content $target fi proj='Aggregate.xcscheme' position=${#target}-${#proj} length=${#proj} if [ ${target:position:length} == $proj ]; then proc_file_content $target fi proj='De-Info.plist' position=${#target}-${#proj} length=${#proj} if [ ${target:position:length} == $proj ]; then proc_file_content $target fi proj="${appname}.podspec" if [ `basename $target` == $proj ]; then proc_file_content $target fi proj="Podfile" if [ `basename $target` == $proj ] ; then proc_file_content $target fi proj="Podfile.sample" if [ `basename $target` == $proj ] ; then proc_file_content $target fi proj="${appname}AppDelegate" position=${#target}-2 length=2 if [ ${target:position:length} == '.h' ] ; then proc_file_content $target fi if [ ${target:position:length} == '.m' ] ; then proc_file_content $target fi } function list() { for file in `ls $1` do replace_filename $1/$file if [ -d "$1/$file" ] ; then list "$1/$file"; fi done } list "$APP_TEMPLATE" echo "COPY----gitigonre" cp -v $HIVE_RESOURCES_PATH/templates/HiveAppTemplate/.gitignore $1/