Skip to content

Instantly share code, notes, and snippets.

@dre1080
Created November 9, 2013 01:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dre1080/7380287 to your computer and use it in GitHub Desktop.
Save dre1080/7380287 to your computer and use it in GitHub Desktop.
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
Copy link

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