• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
14#!/bin/bash
15
16# ----------------------------------------------------------------------------
17#  Hvigor startup script, version 1.0.0
18#
19#  Required ENV vars:
20#  ------------------
21#    NODE_HOME - location of a Node home dir
22#    or
23#    Add /usr/local/nodejs/bin to the PATH environment variable
24# ----------------------------------------------------------------------------
25
26HVIGOR_APP_HOME="`pwd -P`"
27HVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js
28warn() {
29	echo ""
30	echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
31}
32
33error() {
34	echo ""
35	echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
36}
37
38fail() {
39	error "$@"
40	exit 1
41}
42
43# Determine node to start hvigor wrapper script
44if [ -n "${NODE_HOME}" ];then
45   EXECUTABLE_NODE="${NODE_HOME}/bin/node"
46   if [ ! -x "$EXECUTABLE_NODE" ];then
47       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"
48   fi
49else
50   EXECUTABLE_NODE="node"
51   which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path"
52fi
53
54# Check hvigor wrapper script
55if [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then
56	fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}"
57fi
58
59# start hvigor-wrapper script
60exec "${EXECUTABLE_NODE}" \
61	"${HVIGOR_WRAPPER_SCRIPT}" "$@"
62