2014-01-09 22:37:19 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
import os
|
|
|
|
import glob
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2014-01-09 23:14:47 +01:00
|
|
|
import time
|
2014-01-09 22:37:19 +01:00
|
|
|
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
os.chdir(settings.DEPLOY_ROOT)
|
|
|
|
STATIC_PATH = 'static/'
|
|
|
|
|
2014-01-09 23:14:47 +01:00
|
|
|
def get_templates():
|
|
|
|
return glob.glob(os.path.join(STATIC_PATH, 'templates/*.handlebars'))
|
|
|
|
|
2014-01-09 22:37:19 +01:00
|
|
|
def run():
|
|
|
|
subprocess.check_call(['tools/node', 'node_modules/.bin/handlebars']
|
2014-01-09 23:14:47 +01:00
|
|
|
+ get_templates()
|
2014-01-09 22:37:19 +01:00
|
|
|
+ ['--output', os.path.join(STATIC_PATH, 'templates/compiled.js'),
|
|
|
|
'--known', 'if,unless,each,with'])
|
|
|
|
|
2014-01-09 23:14:47 +01:00
|
|
|
def run_forever():
|
|
|
|
# Keep polling for file changes, similar to how Django does it in
|
|
|
|
# django/utils/autoreload.py. If any of our templates change, rebuild
|
|
|
|
# compiled.js
|
|
|
|
mtimes = {}
|
|
|
|
while True:
|
|
|
|
changed = False
|
|
|
|
for fn in get_templates():
|
|
|
|
new_mtime = os.stat(fn).st_mtime
|
|
|
|
if new_mtime != mtimes.get(fn, None):
|
|
|
|
changed = True
|
|
|
|
mtimes[fn] = new_mtime
|
|
|
|
if changed:
|
|
|
|
print 'Recompiling templates'
|
|
|
|
try:
|
|
|
|
run()
|
|
|
|
print 'done'
|
|
|
|
except:
|
|
|
|
print '\n\n\nPLEASE FIX!!\n\n'
|
|
|
|
time.sleep(0.200)
|
|
|
|
|
2014-01-09 22:37:19 +01:00
|
|
|
if __name__ == '__main__':
|
2014-01-09 23:14:47 +01:00
|
|
|
if len(sys.argv) == 2 and sys.argv[1] == 'forever':
|
|
|
|
run_forever()
|
2014-01-09 22:37:19 +01:00
|
|
|
run()
|