1# Copyright (c) 2023 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13#!/bin/bash 14 15# ---------------------------------------------------------------------------- 16# Hvigor startup script, version 1.0.0 17# 18# Required ENV vars: 19# ------------------ 20# NODE_HOME - location of a Node home dir 21# or 22# Add /usr/local/nodejs/bin to the PATH environment variable 23# ---------------------------------------------------------------------------- 24 25HVIGOR_APP_HOME="`pwd -P`" 26HVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js 27#NODE_OPTS="--max-old-space-size=4096" 28 29fail() { 30 echo "$*" 31 exit 1 32} 33 34set_executable_node() { 35 EXECUTABLE_NODE="${NODE_HOME}/bin/node" 36 if [ -x "$EXECUTABLE_NODE" ]; then 37 return 38 fi 39 40 EXECUTABLE_NODE="${NODE_HOME}/node" 41 if [ -x "$EXECUTABLE_NODE" ]; then 42 return 43 fi 44 fail "ERROR: NODE_HOME is set to an invalid directory,check $NODE_HOME\n\nPlease set NODE_HOME in your environment to the location where your nodejs installed" 45} 46 47# Determine node to start hvigor wrapper script 48if [ -n "${NODE_HOME}" ]; then 49 set_executable_node 50else 51 EXECUTABLE_NODE="node" 52 command -v ${EXECUTABLE_NODE} &> /dev/null || fail "ERROR: NODE_HOME not set and 'node' command not found" 53fi 54 55# Check hvigor wrapper script 56if [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ]; then 57 fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}" 58fi 59 60if [ -z "${NODE_OPTS}" ]; then 61 NODE_OPTS="--" 62fi 63 64# start hvigor-wrapper script 65exec "${EXECUTABLE_NODE}" "${NODE_OPTS}" \ 66 "${HVIGOR_WRAPPER_SCRIPT}" "$@" 67