1#!/bin/bash 2# Copyright (c) 2024 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 -x 17 18if [ -z "${ROOT_DIR+x}" ]; then 19 export ROOT_DIR=$(pwd) 20 echo "ROOT_DIR was not set. Initialized to $ROOT_DIR" 21else 22 echo "ROOT_DIR is already set to $ROOT_DIR" 23fi 24 25NODE_VERSION=v22.3.0 26NODE_HOME=$ROOT_DIR/pre_scripts/node-$NODE_VERSION-linux-x64 27NODE_URL=https://gitee.com/muya318/pre_scripts/raw/master/node-v22.3.0-linux-x64.tar.gz 28NODE_BIN=node-v22.3.0-linux-x64.tar.gz 29 30prepare_nodejs() { 31 echo "### preparing nodejs" 32 if [ ! -d "$NODE_HOME" ]; then 33 cd $ROOT_DIR/pre_scripts 34 tar -xf $NODE_BIN 35 chmod 777 $NODE_HOME/bin/* 36 cd - 37 export PATH=$NODE_HOME/bin:$PATH 38 fi 39 npm config set registry=https://repo.huaweicloud.com/repository/npm/ 40 npm config set strict-ssl false 41 echo "###nodejs env ready" 42} 43 44git clone https://gitee.com/muya318/pre_scripts.git 45 46prepare_nodejs 47 48pwd 49cd $ROOT_DIR 50 51node -v 52npm -v 53 54npm install 55npm run test 56 57if [ $? -ne 0 ]; then 58 echo "************* Unit test failed *************" 59 exit 1 60fi 61 62echo "************* Unit test success *************" 63 64npm pack 65if [ $? -ne 0 ]; then 66 echo "************* Npm pack failed *************" 67 exit 1 68fi 69echo "************* Npm pack success *************" 70 71exit 0