Commit 58ea785e by David Baumgold

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

Watch and process xmodule assets
parents c82e928b 82c0206c
...@@ -109,6 +109,30 @@ class XModuleSassWatcher(SassWatcher): ...@@ -109,6 +109,30 @@ class XModuleSassWatcher(SassWatcher):
traceback.print_exc() 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(): def coffeescript_files():
""" """
return find command for paths containing coffee files return find command for paths containing coffee files
...@@ -163,6 +187,8 @@ def compile_sass(options): ...@@ -163,6 +187,8 @@ def compile_sass(options):
sh(cmd(*parts)) sh(cmd(*parts))
print("\t\tFinished compiling sass.")
def compile_templated_sass(systems, settings): def compile_templated_sass(systems, settings):
""" """
...@@ -172,6 +198,7 @@ def compile_templated_sass(systems, settings): ...@@ -172,6 +198,7 @@ def compile_templated_sass(systems, settings):
""" """
for sys in systems: for sys in systems:
sh(django_cmd(sys, settings, 'preprocess_assets')) sh(django_cmd(sys, settings, 'preprocess_assets'))
print("\t\tFinished preprocessing {} assets.".format(sys))
def process_xmodule_assets(): def process_xmodule_assets():
...@@ -179,6 +206,19 @@ def process_xmodule_assets(): ...@@ -179,6 +206,19 @@ def process_xmodule_assets():
Process XModule static assets. Process XModule static assets.
""" """
sh('xmodule_assets common/static/xmodule') 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): def collect_assets(systems, settings):
...@@ -189,6 +229,7 @@ def collect_assets(systems, settings): ...@@ -189,6 +229,7 @@ def collect_assets(systems, settings):
""" """
for sys in systems: for sys in systems:
sh(django_cmd(sys, settings, "collectstatic --noinput > /dev/null")) sh(django_cmd(sys, settings, "collectstatic --noinput > /dev/null"))
print("\t\tFinished collecting {} assets.".format(sys))
@task @task
...@@ -206,6 +247,7 @@ def watch_assets(options): ...@@ -206,6 +247,7 @@ def watch_assets(options):
CoffeeScriptWatcher().register(observer) CoffeeScriptWatcher().register(observer)
SassWatcher().register(observer) SassWatcher().register(observer)
XModuleSassWatcher().register(observer) XModuleSassWatcher().register(observer)
XModuleAssetsWatcher().register(observer)
print("Starting asset watcher...") print("Starting asset watcher...")
observer.start() observer.start()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment