modules/org.openbravo.client.kernel/jsutils/check-npm-deps
author Javi Armendáriz <katanagari@gmail.com>
Fri, 24 Jan 2020 08:55:59 +0100
changeset 37000 c5ff57ca6732
parent 36357 d318e75732c2
permissions -rwxr-xr-x
FIX-42957: Update package-lock to fix npm vulnerabilities.

This also updates linter/formatter scripts to use npm ci instead of install.
This ensures that package-lock.json won't be modified by those executions.
#!/bin/bash
# *************************************************************************
# * The contents of this file are subject to the Openbravo  Public  License
# * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
# * Version 1.1  with a permitted attribution clause; you may not  use this
# * file except in compliance with the License. You  may  obtain  a copy of
# * the License at http://www.openbravo.com/legal/license.html
# * Software distributed under the License  is  distributed  on  an "AS IS"
# * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
# * License for the specific  language  governing  rights  and  limitations
# * under the License.
# * The Original Code is Openbravo ERP.
# * The Initial Developer of the Original Code is Openbravo SLU
# * All portions are Copyright (C) 2019 Openbravo SLU
# * All Rights Reserved.
# * Contributor(s):  ______________________________________.
# ************************************************************************

NPM_DEPS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source ${NPM_DEPS_SCRIPT_DIR}/../jsutils/dir-functions

if ! [[ -x "$(command -v npm)" ]]; then
    echo -e "\n\033[0;31mERROR:\033[0m npm command not found. Install using"
    echo -e "  sudo apt install npm\n";
    exit 1
fi

#
# Installs eslint and prettier if not already installed
# First argument should be the path to org.openbravo.client.kernel module
#
function installNodePackagesIfNeeded {
    if [[ ! -d ${1}/node_modules || \
            -z "$(find ${1}/node_modules -name eslint)" || \
            -z "$(find ${1}/node_modules -name prettier)" ]]; then
        echo -e "eslint and/or prettier command not found. Running npm install\n"
        originalDir="$(pwd)"
        cd "${1}"
        npm ci
        cd "${originalDir}"
    fi
    echo "Npm and all required tools are installed. Done!"
}

echo "Checking npm and required packages are installed..."

OPENBRAVO_ROOT_PATH=$(getOpenbravoRootPath)
installNodePackagesIfNeeded ${OPENBRAVO_ROOT_PATH}