Merge pull request #9660 from OmarIthawi/edraak/watch-xmodule-assets

Watch and process xmodule assets
This commit is contained in:
David Baumgold
2015-09-15 11:43:35 -04:00

View File

@@ -109,6 +109,30 @@ class XModuleSassWatcher(SassWatcher):
traceback.print_exc()
class XModuleAssetsWatcher(PatternMatchingEventHandler):
"""
Watches for css and js file changes
"""
ignore_directories = True
patterns = ['*.css', '*.js']
def register(self, observer):
"""
Register files with observer
"""
observer.schedule(self, 'common/lib/xmodule/', recursive=True)
def on_modified(self, event):
print('\tCHANGED:', event.src_path)
try:
process_xmodule_assets()
except Exception: # pylint: disable=broad-except
traceback.print_exc()
# To refresh the hash values of static xmodule content
restart_django_servers()
def coffeescript_files():
"""
return find command for paths containing coffee files
@@ -163,6 +187,8 @@ def compile_sass(options):
sh(cmd(*parts))
print("\t\tFinished compiling sass.")
def compile_templated_sass(systems, settings):
"""
@@ -172,6 +198,7 @@ def compile_templated_sass(systems, settings):
"""
for sys in systems:
sh(django_cmd(sys, settings, 'preprocess_assets'))
print("\t\tFinished preprocessing {} assets.".format(sys))
def process_xmodule_assets():
@@ -179,6 +206,19 @@ def process_xmodule_assets():
Process XModule static assets.
"""
sh('xmodule_assets common/static/xmodule')
print("\t\tFinished processing xmodule assets.")
def restart_django_servers():
"""
Restart the django server.
`$ touch` makes the Django file watcher thinks that something has changed, therefore
it restarts the server.
"""
sh(cmd(
"touch", 'lms/urls.py', 'cms/urls.py',
))
def collect_assets(systems, settings):
@@ -189,6 +229,7 @@ def collect_assets(systems, settings):
"""
for sys in systems:
sh(django_cmd(sys, settings, "collectstatic --noinput > /dev/null"))
print("\t\tFinished collecting {} assets.".format(sys))
@task
@@ -206,6 +247,7 @@ def watch_assets(options):
CoffeeScriptWatcher().register(observer)
SassWatcher().register(observer)
XModuleSassWatcher().register(observer)
XModuleAssetsWatcher().register(observer)
print("Starting asset watcher...")
observer.start()