Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Js2Coffee a directory recursively. Excludes node_modules, app/assets and public directories.
for FILE in `find . -name "*.js" -type f -o -path './node_modules' -prune -o -path './app/assets' -prune -o -path './public' -prune`
do
if [ -e $FILE ] ; then
COFFEE=${FILE//.js/.coffee}
echo "converting ${FILE} to ${COFFEE}"
js2coffee "$FILE" > "$COFFEE"
else
echo "File: {$1} does not exist!"
fi
done
@rattrayalex

This comment has been minimized.

Copy link

commented Aug 27, 2014

Thanks for this! Extremely helpful.

I would suggest changing './node_modules' to simply 'node_modules' (same with components) so that subdirs aren't converted either.

I also found this addition at the top of the file helpful:

# either current directory or argument.
if [ ! "$1" ]; then
  DIR='.'
else
  DIR="$1"
fi
echo $DIR

Then replacing . with $DIR in the find command. This way, you can pass in a directory to the command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.