#!/bin/bash
#read env
echo 玩命打包中....
echo '程序会自动npm prune,旧包将备份在build/backup文件夹下'
echo ''
backup(){
    if [ ! -d "build/backup" ];then
        mkdir build/backup
    fi
    zipFiles=`ls build/output/*.zip |wc -w`
    if [ "$zipFiles" -gt "0" ];then
        mv build/output/*.zip build/backup/
     fi
     otherFile=`ls build/output/* |wc -w`
     if [ "$otherFile" -gt "0" ];then
         rm build/output/*
     fi
}

bundle(){
    node package.js bundle $1
}



package(){
    currentPath=`pwd`;
    workPath=build/output
    cd $workPath;
    android=`ls android*.ppk`;
    ios=`ls ios*.ppk`;
    zip -r `date '+%Y-%m-%d-%H时%M分%S秒'.zip` ./
    rm *.ppk *.json
    cd $currentPath;
    echo '打包完毕,将自动打开Finder...'
}

backup && npm prune && bundle '--platform ios' && bundle '--platform android'
package && open build/output




