[js-formatter]Converted scripts to use local node_modules copy instead of global
authorJavier Armendáriz <javier.armendariz@openbravo.com>
Thu, 17 Jan 2019 10:37:23 +0100
changeset 36082 9ab0cf14ca0b
parent 36081 adb54f61630b
child 36083 f15197137be8
[js-formatter]Converted scripts to use local node_modules copy instead of global

This gives us more control on the version of the packages uses and makes upgrade
simpler.
.hgignore
modules/org.openbravo.client.kernel/jsbeautify/jscheck-btfy
modules/org.openbravo.client.kernel/jsbeautify/jscheck-btfy-hg
modules/org.openbravo.client.kernel/jsbeautify/jscheck-btfy-module
modules/org.openbravo.client.kernel/jsbeautify/jscheck-btfy-module-hg
modules/org.openbravo.client.kernel/jsformatter/jscheck-format
modules/org.openbravo.client.kernel/jsformatter/jscheck-format-hg
modules/org.openbravo.client.kernel/jsformatter/jscheck-format-module
modules/org.openbravo.client.kernel/jsformatter/jscheck-format-module-hg
modules/org.openbravo.client.kernel/jsformatter/jsformatter
modules/org.openbravo.client.kernel/jsformatter/jsformatter-module
modules/org.openbravo.client.kernel/jslint/jslint
modules/org.openbravo.client.kernel/jslint/jslint-module
package.json
--- a/.hgignore	Wed Jan 16 12:33:03 2019 +0100
+++ b/.hgignore	Thu Jan 17 10:37:23 2019 +0100
@@ -47,3 +47,4 @@
 
 sources
 scripts
+node_modules
--- a/modules/org.openbravo.client.kernel/jsbeautify/jscheck-btfy	Wed Jan 16 12:33:03 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-#!/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) 2016-2019 Openbravo SLU
-# * All Rights Reserved.
-# * Contributor(s):  ______________________________________.
-# ************************************************************************
-
-set -e
-replaceparam=$1
-
- echo ""
- echo "-----------------------------------------------"
-if [ "$replaceparam" != "replace" ] ; then
- echo "Performing formatting check on all js resources"
-else
- echo "Performing formatting replacement on all js resources"
-fi
- echo "-----------------------------------------------"
- echo ""
-files=$(./modules/org.openbravo.client.kernel/jscheck/jsfiles ./modules)
-
-for changedfile in echo $files; do
-  if [ -f "$changedfile" -a -n "$(echo $changedfile | awk '/.js$/')" ]; then
-    source ./modules/org.openbravo.client.kernel/jsformatter/jsformatter $changedfile $replaceparam
-  fi
-done
-exit $ERROR
--- a/modules/org.openbravo.client.kernel/jsbeautify/jscheck-btfy-hg	Wed Jan 16 12:33:03 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-#!/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) 2016-2019 Openbravo SLU
-# * All Rights Reserved.
-# * Contributor(s):  ______________________________________.
-# ************************************************************************
-
-set -e
-# Mercurial pre-commit hook for js formatter
-
-replaceparam=$1
-if [ "$replaceparam" != "replace" ] ; then
- echo "Performing formatting check on all js resources"
-else
- echo "Performing formatting replacement on all js resources"
-fi
-
-for changedfile in $(hg st -ma)
-do
-  if [ -f "$changedfile" -a -n "$(echo $changedfile | awk '/.js$/ && ! /^web/')" ]; then
-    source ./modules/org.openbravo.client.kernel/jsformatter/jsformatter $changedfile $replaceparam
-  fi
-done
-exit $ERROR
--- a/modules/org.openbravo.client.kernel/jsbeautify/jscheck-btfy-module	Wed Jan 16 12:33:03 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-#!/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) 2016-2019 Openbravo SLU
-# * All Rights Reserved.
-# * Contributor(s):  ______________________________________.
-# ************************************************************************
-
-set -e
-replaceparam=$1
-
- echo ""
- echo "***********************************************"
-if [ "$replaceparam" != "replace" ] ; then
- echo "Performing formatting check on all js resources"
-else
- echo "Performing formatting replacement on all js resources"
-fi
- echo "***********************************************"
- echo ""
-files=$(../org.openbravo.client.kernel/jscheck/jsfiles ./)
-
-for changedfile in echo $files;
-do
-  if [ -f "$changedfile" -a -n "$(echo $changedfile | awk '/.js$/')" ]; then
-  source ../org.openbravo.client.kernel/jsformatter/jsformatter-module $changedfile $replaceparam
-  fi
-done
-exit $ERROR
--- a/modules/org.openbravo.client.kernel/jsbeautify/jscheck-btfy-module-hg	Wed Jan 16 12:33:03 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-#!/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) 2016-2019 Openbravo SLU
-# * All Rights Reserved.
-# * Contributor(s):  ______________________________________.
-# ************************************************************************
-
-set -e
-# Mercurial pre-commit hook for jsbeautify
-replaceparam=$1
-if [ "$replaceparam" != "replace" ] ; then
- echo "Performing formatting check on all js resources"
-else
- echo "Performing formatting replacement on all js resources"
-fi
-
-for changedfile in $(hg st -ma)
-do
-  if [ -f "$changedfile" -a -n "$(echo $changedfile | awk '/.js$/')" ]; then
-    source ../org.openbravo.client.kernel/jsformatter/jsformatter-module $changedfile $replaceparam
-  fi
-done
-exit $ERROR
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.client.kernel/jsformatter/jscheck-format	Thu Jan 17 10:37:23 2019 +0100
@@ -0,0 +1,38 @@
+#!/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):  ______________________________________.
+# ************************************************************************
+
+set -e
+replaceparam=$1
+
+ echo ""
+ echo "-----------------------------------------------"
+if [ "$replaceparam" != "replace" ] ; then
+ echo "Performing formatting check on all js resources"
+else
+ echo "Performing formatting replacement on all js resources"
+fi
+ echo "-----------------------------------------------"
+ echo ""
+files=$(./modules/org.openbravo.client.kernel/jscheck/jsfiles ./modules)
+
+for changedfile in echo $files; do
+  if [ -f "$changedfile" -a -n "$(echo $changedfile | awk '/.js$/')" ]; then
+    source ./modules/org.openbravo.client.kernel/jsformatter/jsformatter $changedfile $replaceparam
+  fi
+done
+exit $ERROR
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.client.kernel/jsformatter/jscheck-format-hg	Thu Jan 17 10:37:23 2019 +0100
@@ -0,0 +1,35 @@
+#!/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):  ______________________________________.
+# ************************************************************************
+
+set -e
+# Mercurial pre-commit hook for js formatter
+
+replaceparam=$1
+if [ "$replaceparam" != "replace" ] ; then
+ echo "Performing formatting check on all js resources"
+else
+ echo "Performing formatting replacement on all js resources"
+fi
+
+for changedfile in $(hg st -ma)
+do
+  if [ -f "$changedfile" -a -n "$(echo $changedfile | awk '/.js$/ && ! /^web/')" ]; then
+    source ./modules/org.openbravo.client.kernel/jsformatter/jsformatter $changedfile $replaceparam
+  fi
+done
+exit $ERROR
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.client.kernel/jsformatter/jscheck-format-module	Thu Jan 17 10:37:23 2019 +0100
@@ -0,0 +1,39 @@
+#!/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):  ______________________________________.
+# ************************************************************************
+
+set -e
+replaceparam=$1
+
+ echo ""
+ echo "***********************************************"
+if [ "$replaceparam" != "replace" ] ; then
+ echo "Performing formatting check on all js resources"
+else
+ echo "Performing formatting replacement on all js resources"
+fi
+ echo "***********************************************"
+ echo ""
+files=$(../org.openbravo.client.kernel/jscheck/jsfiles ./)
+
+for changedfile in echo $files;
+do
+  if [ -f "$changedfile" -a -n "$(echo $changedfile | awk '/.js$/')" ]; then
+  source ../org.openbravo.client.kernel/jsformatter/jsformatter-module $changedfile $replaceparam
+  fi
+done
+exit $ERROR
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.client.kernel/jsformatter/jscheck-format-module-hg	Thu Jan 17 10:37:23 2019 +0100
@@ -0,0 +1,34 @@
+#!/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):  ______________________________________.
+# ************************************************************************
+
+set -e
+# Mercurial pre-commit hook for jsbeautify
+replaceparam=$1
+if [ "$replaceparam" != "replace" ] ; then
+ echo "Performing formatting check on all js resources"
+else
+ echo "Performing formatting replacement on all js resources"
+fi
+
+for changedfile in $(hg st -ma)
+do
+  if [ -f "$changedfile" -a -n "$(echo $changedfile | awk '/.js$/')" ]; then
+    source ../org.openbravo.client.kernel/jsformatter/jsformatter-module $changedfile $replaceparam
+  fi
+done
+exit $ERROR
--- a/modules/org.openbravo.client.kernel/jsformatter/jsformatter	Wed Jan 16 12:33:03 2019 +0100
+++ b/modules/org.openbravo.client.kernel/jsformatter/jsformatter	Thu Jan 17 10:37:23 2019 +0100
@@ -18,19 +18,14 @@
 
 set -e
 
-if ! [[ -x "$(command -v prettier)" ]]; then
-    echo -e "\n\033[0;33mERROR:\033[0m prettier command not found. Install using"
-    echo -e "# sudo npm install -g prettier@^1.15.3\n"
+if [[ ! -d ./node_modules || -z "$(find ./node_modules -name prettier)" ]]; then
+    echo -e "\n\033[0;33mERROR:\033[0m prettier command not found. Install using \"npm install\" at the root of the project\n"
     exit 1
 fi
 
-if ! [[ "$(eslint -v)" =~ ^1.15* ]]; then
-    echo -e "\n\033[0;33mWARNING:\033[0m For better compatibility it is recommended to use a 1.x version of prettier\n"
-fi
-
 changedfile=$1
 replaceparam=$2
-prettier --config ./modules/org.openbravo.client.kernel/jsformatter/.prettierrc.json "$changedfile" > "$changedfile.prettier"
+npm run jsformatter -s -- --config ./modules/org.openbravo.client.kernel/jsformatter/.prettierrc.json "$changedfile" > "$changedfile.prettier"
 if ! diff -u "$changedfile" "$changedfile.prettier"; then
   if [ "$replaceparam" != "replace" ] ; then
     echo ""
--- a/modules/org.openbravo.client.kernel/jsformatter/jsformatter-module	Wed Jan 16 12:33:03 2019 +0100
+++ b/modules/org.openbravo.client.kernel/jsformatter/jsformatter-module	Thu Jan 17 10:37:23 2019 +0100
@@ -18,19 +18,18 @@
 
 set -e
 
-if ! [[ -x "$(command -v prettier)" ]]; then
-    echo -e "\n\033[0;33mERROR:\033[0m prettier command not found. Install using"
-    echo -e "# sudo npm install -g prettier@^1.15.3\n"
+if [[ ! -d ../../node_modules || -z "$(find ../../node_modules -name prettier)" ]]; then
+    echo -e "\n\033[0;33mERROR:\033[0m prettier command not found. Install using \"npm install\" at the root of the project\n"
     exit 1
 fi
+#if ! [[ -x "$(command -v prettier)" ]]; then
+#    echo -e "\n\033[0;33mERROR:\033[0m prettier command not found. Install using npm install at the root of the project"
+#    exit 1
+#fi
 
-if ! [[ "$(eslint -v)" =~ ^1.15* ]]; then
-    echo -e "\n\033[0;33mWARNING:\033[0m For better compatibility it is recommended to use a 1.x version of prettier\n"
-fi
-
-changedfile=$1
+changedfile="$(pwd)/$1"
 replaceparam=$2
-prettier --config ../org.openbravo.client.kernel/jsformatter/.prettierrc.json "$changedfile" > "$changedfile.prettier"
+npm run jsformatter -s --prefix ../.. -- "$changedfile" > "$changedfile.prettier"
 if ! diff -u "$changedfile" "$changedfile.prettier"; then
   if [ "$replaceparam" != "replace" ] ; then
     echo ""
--- a/modules/org.openbravo.client.kernel/jslint/jslint	Wed Jan 16 12:33:03 2019 +0100
+++ b/modules/org.openbravo.client.kernel/jslint/jslint	Thu Jan 17 10:37:23 2019 +0100
@@ -2,14 +2,9 @@
 
 echo "Checking --> $@"
 
-if ! [[ -x "$(command -v eslint)" ]]; then
-    echo -e "\n\033[0;33mERROR:\033[0m eslint command not found. Install using"
-    echo -e "# sudo npm install -g eslint@^5.12.0\n"
+if [[ ! -d ./node_modules || -z "$(find ./node_modules -name eslint)" ]]; then
+    echo -e "\n\033[0;33mERROR:\033[0m eslint command not found. Install using \"npm install\" at the root of the project\n"
     exit 1
 fi
 
-if ! [[ "$(eslint -v)" =~ ^v5.12* ]]; then
-    echo -e "\n\033[0;33mWARNING:\033[0m For better compatibility it is recommended to use a 5.x version of eslint\n"
-fi
-
-eslint -c ./modules/org.openbravo.client.kernel/jslint/.eslintrc.json "$@"
+npm run jslint -s -- "$@"
--- a/modules/org.openbravo.client.kernel/jslint/jslint-module	Wed Jan 16 12:33:03 2019 +0100
+++ b/modules/org.openbravo.client.kernel/jslint/jslint-module	Thu Jan 17 10:37:23 2019 +0100
@@ -2,15 +2,9 @@
 
 echo "Checking --> $@"
 
-if ! [[ -x "$(command -v eslint)" ]]; then
-    echo -e "\n\033[0;33mERROR:\033[0m eslint command not found. Install using"
-    echo -e "# sudo npm install -g eslint@^5.12.0\n"
+if [[ ! -d ../../node_modules || -z "$(find ../../node_modules -name eslint)" ]]; then
+    echo -e "\n\033[0;33mERROR:\033[0m eslint command not found. Install using \"npm install\" at the root of the project\n"
     exit 1
 fi
 
-if ! [[ "$(eslint -v)" =~ ^v5.12* ]]; then
-    echo -e "\n\033[0;33mWARNING:\033[0m For better compatibility it is recommended to use a 5.x version of eslint\n"
-    exit 1
-fi
-
-eslint -c ../org.openbravo.client.kernel/jslint/.eslintrc.json "$@"
+npm run jslint -s --prefix ../.. -- "$(pwd)/$@"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/package.json	Thu Jan 17 10:37:23 2019 +0100
@@ -0,0 +1,15 @@
+{
+  "name": "openbravo",
+  "version": "1.0.0",
+  "description": "This contains some utilities used to format and lint Javascript code",
+  "scripts": {
+    "jslint": "eslint -c ./modules/org.openbravo.client.kernel/jslint/.eslintrc.json",
+    "jsformatter": "prettier --config ./modules/org.openbravo.client.kernel/jsformatter/.prettierrc.json"
+  },
+  "author": "Openbravo SLU",
+  "license": "Openbravo Public License Version  1.1",
+  "dependencies": {
+    "eslint": "^5.12.0",
+    "prettier": "^1.15.3"
+  }
+}