#!/usr/local/bin/bash

_pwd="$(pwd)"

_projectName=$1
_platform=$2

function generateGit
{
  cd $1
  npm install
  git init
  git add .
  git commit -m "first commit"
  clear
}

function generateLog
{
  mario-log -t success -i "
  Project is created success at ./$1"
  mario-log -t info -i "
  Happy hacking : )
  "
}

if [[ _projectName ]]; then
  if [[ $_platform ]]; then
    if [ "$_platform" = "react" ]; then # mario-new-app [projectName] react
      mario-create-react-app $_projectName
      generateGit $_projectName
      generateLog $_projectName
    elif [ "$_platform" = "koa" ]; then # mario-new-app [projectName] koa
      mario-create-koa-app $_projectName
      generateGit $_projectName
      generateLog $_projectName
    elif [ "$_platform" = "js" ]; then # mario-new-app [projectName] js
      react-native init $_projectName --template mariojs
      cd $_projectName
      rm -rf App.js
      node scripts/index.js
      git init
      git add .
      git commit -m "first commit"
      clear
      mario-log -t success -i "
      Project is created success at ./$_projectName"
      mario-log -t info -i "
        To run your app on iOS:"
      mario-log -t success -i "
          cd /Users/MeePwn/Desktop/MeePwn/ReactNative/source/$_projectName
          react-native run-ios
          - or -
          Open ios/$_projectName.xcodeproj in Xcode
          Hit the Run button"
      mario-log -t info -i "
        To run your app on Android:"
      mario-log -t success -i "
          cd /Users/MeePwn/Desktop/MeePwn/ReactNative/source/$_projectName
          Have an Android emulator running (quickest way to get started), or a device connected
          react-native run-android"
      mario-log -t info -i "
      Happy hacking : )
      "
    else
      mario-log -t error -i "
      Please choose your [platform], only support react or koa!
        eg:
          mario-new-app [projectName] [react | koa | js]
      "
    fi
  else
    react-native init $_projectName --template mario
    cd $_projectName
    rm -rf App.js
    node scripts/index.js
    git init
    git add .
    git commit -m "first commit"
    npm run build
    clear
    mario-log -t success -i "
    Project is created success at ./$_projectName"
    mario-log -t info -i "
      To run your app on iOS:"
    mario-log -t success -i "
        cd /Users/MeePwn/Desktop/MeePwn/ReactNative/source/$_projectName
        react-native run-ios
        - or -
        Open ios/$_projectName.xcodeproj in Xcode
        Hit the Run button"
    mario-log -t info -i "
      To run your app on Android:"
    mario-log -t success -i "
        cd /Users/MeePwn/Desktop/MeePwn/ReactNative/source/$_projectName
        Have an Android emulator running (quickest way to get started), or a device connected
        react-native run-android"
    mario-log -t info -i "
    Happy hacking : )
    "
  fi
else
  mario-log -t error -i "
  Please type your [projectName] name!
    eg:
      mario-new-app [projectName]
  "
fi
