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