Skip to content

Instantly share code, notes, and snippets.

@hparra
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hparra/9c4de5fcc0073c628376 to your computer and use it in GitHub Desktop.
Save hparra/9c4de5fcc0073c628376 to your computer and use it in GitHub Desktop.
Add "import Ember from 'ember';" to the top of each file that jshint says needs it
#!/bin/bash
# See http://www.ember-cli.com/#using-modules
# Assumes your ember JS is in app/js/
#
# TODO:
# - make ember js src directory a variable
# - make error to search for variable
# - make replacement string variable
# - abstract into function
#
# Assumes GNU sed, which is not on Mac OS X. `brew install gnu-sed` and use `gsed` instead
SED=sed
#
# Add "import DS from 'ember-data';" to the top of each file JSHint complains about
#
jshint app/js/ | # Run JSHint
$SED -e "s=\(app/js/.*.js\).*'DS' is not defined.$=\1=" -e 'tx' -e 'd' -e ':x' | # Replace lines with only path when object is not define, delete others
uniq | # Remove duplicates
xargs $SED -i "1iimport DS from 'ember-data';" # Prepend line to each file
#
# Add "import Ember from 'ember';" to the top of each file JSHint complains about
#
jshint app/js/ | # Run JSHint
$SED -e "s=\(app/js/.*.js\).*'Ember' is not defined.$=\1=" -e 'tx' -e 'd' -e ':x' | # Replace lines with only path when object is not define, delete others
uniq | # Remove duplicates
xargs $SED -i "1iimport Ember from 'ember';" # Prepend line to each file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment