2017-02-22 22:25:34 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2017-11-09 21:30:03 +00:00
|
|
|
function validate_file {
|
|
|
|
filename=$1;
|
|
|
|
|
2017-02-22 22:25:34 +00:00
|
|
|
validate_result=$(node_modules/.bin/acorn --module --silent $filename 2>&1);
|
|
|
|
validate_exit_code=$?;
|
|
|
|
validate_output=$([[ ${validate_exit_code} -eq 0 ]] && echo ok || echo ${validate_result});
|
|
|
|
echo ${filename}: ${validate_output}
|
2017-11-09 21:30:03 +00:00
|
|
|
# Use /dev/shm here since apparently while is in a subshell, so it can't modify variables in the main program O.o
|
2017-02-22 22:25:34 +00:00
|
|
|
if ! [ ${validate_exit_code} -eq 0 ]; then
|
2017-02-23 18:09:48 +00:00
|
|
|
error_count=$(cat ${counter_filename});
|
|
|
|
echo incrementing ${error_count} \($(expr ${error_count} + 1)\);
|
|
|
|
echo $(expr ${error_count} + 1) >${counter_filename};
|
2017-02-22 22:25:34 +00:00
|
|
|
fi
|
2017-11-09 21:30:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
counter_filename=$(mktemp -p /dev/shm/ -t bash.XXXXXXXXX.tmp);
|
|
|
|
echo 0 >${counter_filename};
|
|
|
|
# Parallelisation trick from https://stackoverflow.com/a/33058618/1460422
|
|
|
|
find . -name "*.js" -not -path "./node_modules/*" | while read filename;
|
|
|
|
do
|
|
|
|
validate_file "${filename}" &
|
|
|
|
|
|
|
|
# Run at most the number of CPU cores jobs at once
|
|
|
|
[ $( jobs | wc -l ) -ge $( nproc ) ] && wait
|
2017-02-22 22:25:34 +00:00
|
|
|
done
|
|
|
|
|
2017-11-09 21:30:03 +00:00
|
|
|
wait
|
|
|
|
|
2017-02-23 18:09:48 +00:00
|
|
|
error_count=$(cat ${counter_filename});
|
2017-02-23 18:15:18 +00:00
|
|
|
|
|
|
|
echo
|
2017-02-22 22:25:34 +00:00
|
|
|
echo Errors: $error_count
|
2017-02-23 18:09:48 +00:00
|
|
|
|
2017-02-23 18:13:53 +00:00
|
|
|
# Uncomment to make npm die if this script doesn't work correctly
|
|
|
|
#if [[ ${error_count} -ne 0 ]]; then
|
|
|
|
# exit 1;
|
|
|
|
#fi
|
2017-02-23 18:09:48 +00:00
|
|
|
|
|
|
|
exit 0;
|