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