1#!/bin/bash 2# Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15#设置执行失败,退出脚本执行 16set -e 17 18#$0表示脚本本身 19#dirname去除文件名中的非目录部分,删除最后一个“\”后面的路径,得到文件夹路径 20#获取当前脚本目录 21script_path=$(cd $(dirname $0);pwd) 22#获取项目根目录路径 23code_dir=$(dirname ${script_path})/../ 24#系统内核的名字 25case $(uname -s) in 26 Linux) 27 host_platform=linux 28 ;; 29 Darwin) 30 host_platform=darwin 31 ;; 32 *) 33 echo "Unsupported host platform: $(uname -s)" 34 exit 1 35esac 36 37#nodejs文件夹名称 38node_js_name=current 39#到automock目录 40cd ${code_dir}/automock/mock-generate/ 41#设置环境变量为下载的nodejs 42export PATH=${code_dir}/prebuilts/build-tools/common/nodejs/${node_js_name}/bin:$PATH 43#设置镜像地址 44npm config set registry https://repo.huaweicloud.com/repository/npm/ 45#执行安装 46npm install 47#跳根目录 48cd ${code_dir} 49#判断目录是否存在 50if [ -d "${code_dir}/prebuilts/build-tools/common/automock/mock-generate" ]; then 51 #转义输出,不换行 52 echo -e "\n" 53 echo "${code_dir}/prebuilts/build-tools/common/automock/mock-generate already exist, it will be replaced" 54 #删除原目录 55 /bin/rm -rf ${code_dir}/prebuilts/build-tools/common/automock/mock-generate 56 echo -e "\n" 57fi 58#创建新目录 59mkdir -p ${code_dir}/prebuilts/build-tools/common/automock/mock-generate 60#拷贝node_modules过去 61/bin/cp -rf ${code_dir}/automock/mock-generate/node_modules ${code_dir}/prebuilts/build-tools/common/automock/mock-generate/ 62