初始化项目文件

  • initDSRProject.sh
#!/usr/bin/bash 

# load utils 
. ./util/utils.sh
. ./util/fileUtils.sh
. ./util/gitUtils.sh

# set project related info
projectName="rolloverALoan"
templateId="641"
templateName="Rollover a loan"

# set base path 
basePath="/c/repoPath"
formPath="$basePath/src/formPath"
reviewPath="$basePath/reviewPath"
tdsPath="$basePath/TDSPath"
constantsPath="$basePath/constantPath"
repoName="RepoName"

# set Branch
releaseBranch="lendingJune"
myBranch="lendingJune-leon"
pwd=$PWD


function main {
  # print repoName
  echoSuccess "=== Curent Repo is $repoName ==="
  # got base directory
  goDirectory "$basePath"
  # get current branch
  local currentBranch=$(getCurrentBranch)
  # check current repo status
  checkClean "$repoName" 
  # fetch new code
  pullCode "$releaseBranch" --noCheck
  # create test branch base on releaseBranch
  createNewBranch "$releaseBranch" "$myBranch"
  # create project directory
  createNewDir 

  # create file under form directory
  createFormFiles
  # create files for review page
  createReviewFiles
  # create files for tds page
  createTDSFiles

  # config project entry file
  configForm

  # config review page
  configReview

  # config tds page
  configTDS

  # config config file
  configConfig

  echoSuccess "=== init dsr project success! ==="

}

# create new dir
function createNewDir {
  local projectPath=$(isDirExist "$formPath/$projectName")
  if [ -n "$projectPath" ]
  then
    goDirectory "$formPath"
    # create project directory
    mkdir "$projectName"
    # 
    cd "$projectName"
    # print create directory info
    echoNotice "=== Notice: create $projectName directory ==="
  else 
    echoWarning "=== Warning : $projectName directory has exist ==="
    cd "$formPath/$projectName"
  fi
}


function createFormFiles {
  local filePath="$pwd/codeTemplates/base"
  local fileList=(
    "$filePath/style.js"
    "$filePath/utils.js"
    "$filePath/index.js"
  )

  # count the files number
  local count=$(ls -l | grep "^-" | wc -l)
  if [ "$count" = "0" ]
  then
    cp -vr "${fileList[@]}"  "$formPath/$projectName"
    echoSuccess "=== create files under form/$projectName success ==="
  else 
    echoWarning "=== files have existed in $formPath/$projectName ==="
  fi
}

function createReviewFiles {
  local filePath="$pwd/codeTemplates/base"
  local fileTemplate="$filePath/reviewConfigData.js"
  local reviewFile="$reviewPath/${projectName}ConfigData.js"
  local reviewFileName=$(basename $reviewFile)

  if [ -f "$reviewFile" ]
  then
    echoWarning "=== Warning: file $reviewFileName has exit"
  else
    cp -vr "$fileTemplate"  "$reviewFile"
    echoSuccess "=== file $reviewFileName create success ==="
  fi
}

function createTDSFiles {
  local filePath="$pwd/codeTemplates/base"
  local fileTemplate="$filePath/tdsConfigData.js"
  local upperProjectName=$(upperFirstChar $projectName)
  local tdsFileName="${upperProjectName}ConfigData.js"
  local tdsFile="$tdsPath/${tdsFileName}"

  if [ -f "$tdsFile" ]
  then
    echoWarning "=== Warning: file $tdsFileName has exit"
  else
    cp -vr "$fileTemplate"  "$tdsFile"
    echoSuccess "=== file $tdsFileName create success ==="
  fi
}

function configForm {
  local file="$formPath/index.js"

  # insert entry file for new project
  sed -i "1i\
    import $projectName from './$projectName'\;
  " "$file"

  # insert the project config code
  local searchStr="const templateMapping = \["
  sed -i "/$searchStr/a\  {\n\
    templateId: [$templateId],\n\
    templateName: '$templateName',\n\
    processor: $projectName,\n\
    commomFeature: 'attachments,accountList'\n\
  },
  " "$file"
  # convert file format after update file
  unix2dos "$file"
}

function configReview {
  local file="$reviewPath/index.js"
  local reviewFileName="${projectName}ConfigData"

  # inert entry file for review file
  sed -i "2i\
    import $reviewFileName from './$reviewFileName'\;
  " "$file"
  # insert review config code

  local searchStr="const templateMapping = \["
  sed -i "/$searchStr/a\  {\n\
    templateId: [$templateId],\n\
    templateName: '$templateName',\n\
    dataCollect: $reviewFileName\n\
  },
  " "$file"
  # convert file format after update file
  unix2dos "$file"
}

function configTDS {
  local file="$tdsPath/index.js"
  local lowerTdsFileName="${projectName}ConfigData"
  local upperProjectName=$(upperFirstChar $projectName)
  local tdsFileName="${upperProjectName}ConfigData"

  # inert entry file for review file
  sed -i "1i\
    import $lowerTdsFileName from './$tdsFileName'\;
  " "$file"
  # insert review config code

  local searchStr="const templateMapping = \["
  sed -i "/$searchStr/a\  {\n\
    templateId: [$templateId],\n\
    templateName: '$templateName',\n\
    dataCollect: $lowerTdsFileName\n\
  },
  " "$file"
  # convert file format after update file
  unix2dos "$file"
}

function configConfig {
  local file="$constantsPath/config.js"
  local upperProjectName=$(upperFirstChar $projectName)

  # update dummy mapping
  local searchDummyStr="dummayMapping"
  sed -i "/$searchDummyStr/a\  $templateId: '/mc/mc_creation/getFormDefinitionFor${upperProjectName}.json'," "$file"
  # convert file format after update file
  unix2dos "$file"
}

main

posted @ 2023-02-15 14:51  箫笛  阅读(11)  评论(0)    收藏  举报