You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2022/05/23 22:57:50 UTC
[accumulo] branch main updated: Improve JS formatter script (#2720)
This is an automated email from the ASF dual-hosted git repository.
ctubbsii pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push:
new fb898bce2f Improve JS formatter script (#2720)
fb898bce2f is described below
commit fb898bce2f617dee3f68dd37fafd9f71db7c19c9
Author: Christopher Tubbs <ct...@apache.org>
AuthorDate: Mon May 23 18:56:02 2022 -0400
Improve JS formatter script (#2720)
Improve script that formats the JavaScript by echoing the command used
to format, and falling back to formatting one file at a time to support
formatting using older versions of npm/npx
This fixes #2720 to support older versions of npm/npx
Also limit the echo-ing of commands in run-shellcheck.sh to only the
main command
---
contrib/ci/run-shellcheck.sh | 3 ++-
server/monitor/src/main/scripts/format-js.sh | 17 ++++++++++++++++-
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/contrib/ci/run-shellcheck.sh b/contrib/ci/run-shellcheck.sh
index f42122feb5..f69ebbddfb 100755
--- a/contrib/ci/run-shellcheck.sh
+++ b/contrib/ci/run-shellcheck.sh
@@ -21,7 +21,8 @@
# Run ShellCheck on all bash scripts
set -e
-set -x
mapfile -t filestocheck < <(shfmt -f .)
+
+set -x
shellcheck -P SCRIPTDIR -x "${filestocheck[@]}"
diff --git a/server/monitor/src/main/scripts/format-js.sh b/server/monitor/src/main/scripts/format-js.sh
index d5b4052f4d..c84954591e 100755
--- a/server/monitor/src/main/scripts/format-js.sh
+++ b/server/monitor/src/main/scripts/format-js.sh
@@ -20,8 +20,23 @@
# This script will attempt to format JavaScript files
+jsDir='src/main/resources/org/apache/accumulo/monitor/resources/js'
+
+function beautify() {
+ set -x
+ npx js-beautify@^1.14 -r -q -n -j -s 2 -f "$@"
+ { set +x; } 2>/dev/null
+}
+
if hash npx 2>/dev/null; then
- npx js-beautify -r -n -j -s 2 src/main/resources/org/apache/accumulo/monitor/resources/js/*.js
+ echo "Found 'npx'; formatting JavaScript files (if needed) in place"
+ if ! beautify "$jsDir"/*.js; then
+ echo "Error formatting files; you may be using an older version of npm/npx"
+ echo "Attempting to format files one at a time..."
+ for js in "$jsDir"/*.js; do
+ beautify "$js" || echo "Error formatting $js"
+ done
+ fi
else
echo "Skipping formatting of JavaScript files, since 'npx' is not present"
fi