Skip to content

Instantly share code, notes, and snippets.

@francesko
Last active August 29, 2015 14:15
Show Gist options
  • Save francesko/46fef424c30b085fe81a to your computer and use it in GitHub Desktop.
Save francesko/46fef424c30b085fe81a to your computer and use it in GitHub Desktop.
compile js files to coffee looking recursively into subdirectories and outputting to given folder
#!/bin/bash
# requires https://www.npmjs.com/package/js2coffee
INPUT_FOLDER=$1
OUTPUT_FOLDER=$2
mkdir -p ${OUTPUT_FOLDER}
JS_FILE_LIST="`find ${INPUT_FOLDER} -type f -regex ".*\.\(js\)"`"
for js_file in ${JS_FILE_LIST}
do
echo "compiling ${js_file} to coffee"
COFFEE_FILE="`sed 's,^[^/]*/,,' <<< "${js_file%.js}.coffee"`"
COFFEE_FILE="${OUTPUT_FOLDER}/${COFFEE_FILE}"
COFFEE_DIR=$(dirname "${COFFEE_FILE}")
`mkdir -p ${COFFEE_DIR}`
`js2coffee ${js_file} > ${COFFEE_FILE}`
done
echo "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment