#!/bin/bash
set -e
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
## 初始化
root_path=$(cd `dirname $0`;cd ..;pwd)
echo $root_path
cd $root_path
rm -rf $root_path/output
rm -rf node_modules
#rm -rf package-lock.json
## 安装node
export PATH=$NODEJS_BIN_LATEST:$PATH
node --version
npm --version

npm config set registry https://registry.npm.taobao.org
# 安装依赖
npm install
if [ $? -eq 0 ];then
    echo 'npm install completely'
else
    echo 'npm install fail'
    exit 1
fi
# 编译H5
npm run build:h5
# 打包到output
static_dir=$root_path/output/webroot/med-h5
template_dir=$root_path/output/template/med-h5
mkdir -p $static_dir
mkdir -p $template_dir
cd $root_path/dist-h5/dist
mv index.html $template_dir
mv MP_verify_L2QgtQuzLzDe4U41.txt $template_dir
mv static $static_dir
# 压缩.tar
cd $root_path/output
tar -zcf static.tar.gz webroot
tar -zcf template.tar.gz template
rm -rf webroot
rm -rf template
cd $root_path
echo 'build completely!'