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#设置nodejs版本 37node_js_ver=v12.18.4 38#nodejs文件夹名称 39node_js_name=node-${node_js_ver}-${host_platform}-x64 40#到automock目录 41cd ${code_dir}/ace/automock/mock-generate/ 42#设置环境变量为下载的nodejs 43export PATH=${code_dir}/prebuilts/build-tools/common/nodejs/${node_js_name}/bin:$PATH 44#设置镜像地址 45npm config set registry https://repo.huaweicloud.com/repository/npm/ 46#执行安装 47npm install 48#跳根目录 49cd ${code_dir} 50#判断目录是否存在 51if [ -d "${code_dir}/prebuilts/build-tools/common/automock/mock-generate" ]; then 52 #转义输出,不换行 53 echo -e "\n" 54 echo "${code_dir}/prebuilts/build-tools/common/automock/mock-generate already exist, it will be replaced with node-${node_js_ver}" 55 #删除原目录 56 /bin/rm -rf ${code_dir}/prebuilts/build-tools/common/automock/mock-generate 57 echo -e "\n" 58fi 59#创建新目录 60mkdir -p ${code_dir}/prebuilts/build-tools/common/automock/mock-generate 61#拷贝node_modules过去 62/bin/cp -rf ${code_dir}/ace/automock/mock-generate/node_modules ${code_dir}/prebuilts/build-tools/common/automock/mock-generate/ 63