16e7c69efSopenharmony_ci#!/bin/bash
26e7c69efSopenharmony_ci
36e7c69efSopenharmony_ci# ----------------------------------------------------------------------------
46e7c69efSopenharmony_ci#/*
56e7c69efSopenharmony_ci# * Copyright (c) 2024 Huawei Device Co., Ltd.
66e7c69efSopenharmony_ci# * Licensed under the Apache License, Version 2.0 (the "License");
76e7c69efSopenharmony_ci# * you may not use this file except in compliance with the License.
86e7c69efSopenharmony_ci# * You may obtain a copy of the License at
96e7c69efSopenharmony_ci# *
106e7c69efSopenharmony_ci# *     http://www.apache.org/licenses/LICENSE-2.0
116e7c69efSopenharmony_ci# *
126e7c69efSopenharmony_ci# * Unless required by applicable law or agreed to in writing, software
136e7c69efSopenharmony_ci# * distributed under the License is distributed on an "AS IS" BASIS,
146e7c69efSopenharmony_ci# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
156e7c69efSopenharmony_ci# * See the License for the specific language governing permissions and
166e7c69efSopenharmony_ci# * limitations under the License.
176e7c69efSopenharmony_ci# */
186e7c69efSopenharmony_ci# ----------------------------------------------------------------------------
196e7c69efSopenharmony_ci# ----------------------------------------------------------------------------
206e7c69efSopenharmony_ci#  Hvigor startup script, version 1.0.0
216e7c69efSopenharmony_ci#
226e7c69efSopenharmony_ci#  Required ENV vars:
236e7c69efSopenharmony_ci#  ------------------
246e7c69efSopenharmony_ci#    NODE_HOME - location of a Node home dir
256e7c69efSopenharmony_ci#    or
266e7c69efSopenharmony_ci#    Add /usr/local/nodejs/bin to the PATH environment variable
276e7c69efSopenharmony_ci# ----------------------------------------------------------------------------
286e7c69efSopenharmony_ci
296e7c69efSopenharmony_ciHVIGOR_APP_HOME="`pwd -P`"
306e7c69efSopenharmony_ciHVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js
316e7c69efSopenharmony_ci#NODE_OPTS="--max-old-space-size=4096"
326e7c69efSopenharmony_ci
336e7c69efSopenharmony_cifail() {
346e7c69efSopenharmony_ci  echo "$*"
356e7c69efSopenharmony_ci  exit 1
366e7c69efSopenharmony_ci}
376e7c69efSopenharmony_ci
386e7c69efSopenharmony_ciset_executable_node() {
396e7c69efSopenharmony_ci  EXECUTABLE_NODE="${NODE_HOME}/bin/node"
406e7c69efSopenharmony_ci  if [ -x "$EXECUTABLE_NODE" ]; then
416e7c69efSopenharmony_ci    return
426e7c69efSopenharmony_ci  fi
436e7c69efSopenharmony_ci
446e7c69efSopenharmony_ci  EXECUTABLE_NODE="${NODE_HOME}/node"
456e7c69efSopenharmony_ci  if [ -x "$EXECUTABLE_NODE" ]; then
466e7c69efSopenharmony_ci    return
476e7c69efSopenharmony_ci  fi
486e7c69efSopenharmony_ci  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"
496e7c69efSopenharmony_ci}
506e7c69efSopenharmony_ci
516e7c69efSopenharmony_ci# Determine node to start hvigor wrapper script
526e7c69efSopenharmony_ciif [ -n "${NODE_HOME}" ]; then
536e7c69efSopenharmony_ci  set_executable_node
546e7c69efSopenharmony_cielse
556e7c69efSopenharmony_ci  EXECUTABLE_NODE="node"
566e7c69efSopenharmony_ci  command -v ${EXECUTABLE_NODE} &> /dev/null || fail "ERROR: NODE_HOME not set and 'node' command not found"
576e7c69efSopenharmony_cifi
586e7c69efSopenharmony_ci
596e7c69efSopenharmony_ci# Check hvigor wrapper script
606e7c69efSopenharmony_ciif [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ]; then
616e7c69efSopenharmony_ci  fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}"
626e7c69efSopenharmony_cifi
636e7c69efSopenharmony_ci
646e7c69efSopenharmony_ciif [ -z "${NODE_OPTS}" ]; then
656e7c69efSopenharmony_ci  NODE_OPTS="--"
666e7c69efSopenharmony_cifi
676e7c69efSopenharmony_ci
686e7c69efSopenharmony_ci# start hvigor-wrapper script
696e7c69efSopenharmony_ciexec "${EXECUTABLE_NODE}" "${NODE_OPTS}" \
706e7c69efSopenharmony_ci  "${HVIGOR_WRAPPER_SCRIPT}" "$@"
71