#!/usr/bin/env bash

function determine_demos_dir() {
  local __result="$1"
  local default_dir="$(pwd)/demos"
  local demos_dir="${DEMOS_DIR:-$default_dir}"

  if [[ "$demos_dir" == "$default_dir" ]] && [[ ! -d "$demos_dir" ]]; then
    mkdir "$default_dir"
  fi

  eval $__result="$demos_dir"
}

function check_for_demos() {
  local demos_list="$(ls $1)"
  local __result="$2"
  local empty_list=false

  if [[ -z "$demos_list" ]]; then
    empty_list=true
  fi

  eval $__result="$empty_list"
}

function main() {
  determine_demos_dir path
  check_for_demos $path empty_list

  if [[ "$empty_list" == true ]]; then
    echo "Demos dir is empty!" >&2
    exit 1
  fi

  ls $path | xargs -I file ./demo_processing.js "$path/file"
}

main "$@"

#!/usr/bin/env bash

function determine_demos_dir() {
  local __result="$1"
  local default_dir="$(pwd)/demos"
  local demos_dir="${DEMOS_DIR:-$default_dir}"

  if [[ "$demos_dir" == "$default_dir" ]] && [[ ! -d "$demos_dir" ]]; then
    mkdir "$default_dir"
  fi

  eval $__result="$demos_dir"
}

function check_for_demos() {
  local demos_path="$(ls $1)"
  local __result="$2"
  local empty_path=false

  if [[ -z "$demos_path" ]]; then
    empty_path=true
  fi

  eval $__result="$empty_path"
}

function main() {
  determine_demos_dir path
  check_for_demos $path bool

  if [[ "$bool" == true ]]; then
    echo "Demos dir is empty!" >&2
    exit 1
  fi

  ls $path | xargs -I file ./demo_processing.js "$path/file"
}

main "$@"

--- 
+++ 
@@ -13,22 +13,22 @@
 }
 
 function check_for_demos() {
-  local demos_list="$(ls $1)"
+  local demos_path="$(ls $1)"
   local __result="$2"
-  local empty_list=false
+  local empty_path=false
 
-  if [[ -z "$demos_list" ]]; then
-    empty_list=true
+  if [[ -z "$demos_path" ]]; then
+    empty_path=true
   fi
 
-  eval $__result="$empty_list"
+  eval $__result="$empty_path"
 }
 
 function main() {
   determine_demos_dir path
-  check_for_demos $path empty_list
+  check_for_demos $path bool
 
-  if [[ "$empty_list" == true ]]; then
+  if [[ "$bool" == true ]]; then
     echo "Demos dir is empty!" >&2
     exit 1
   fi
Change variable names in check_for_demos

The variables names demos_path and empty_path didn't make much sense,
as those are used for checking whether the demos dir length is non
zero and store that boolean value. This will ensure that those variable
names are a little more sane.

Signed-off-by: Cullen Taylor <3dcbf3a94b3284553298f41295d5edcb98e95b59@outlook.com>
